jungle v2: control power individually per port (#1669)

* init

* better api
This commit is contained in:
Igor Biletskyy 2023-09-25 17:58:11 -07:00 committed by GitHub
parent 62db60595b
commit b12b9b9c97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 0 deletions

View File

@ -132,6 +132,9 @@ class PandaJungle(Panda):
def set_panda_power(self, enabled): def set_panda_power(self, enabled):
self._handle.controlWrite(PandaJungle.REQUEST_OUT, 0xa0, int(enabled), 0, b'') self._handle.controlWrite(PandaJungle.REQUEST_OUT, 0xa0, int(enabled), 0, b'')
def set_panda_individual_power(self, port, enabled):
self._handle.controlWrite(PandaJungle.REQUEST_OUT, 0xa3, int(port), int(enabled), b'')
def set_harness_orientation(self, mode): def set_harness_orientation(self, mode):
self._handle.controlWrite(PandaJungle.REQUEST_OUT, 0xa1, int(mode), 0, b'') self._handle.controlWrite(PandaJungle.REQUEST_OUT, 0xa1, int(mode), 0, b'')

View File

@ -4,6 +4,7 @@ typedef void (*board_set_led)(uint8_t color, bool enabled);
typedef void (*board_board_tick)(void); typedef void (*board_board_tick)(void);
typedef bool (*board_get_button)(void); typedef bool (*board_get_button)(void);
typedef void (*board_set_panda_power)(bool enabled); typedef void (*board_set_panda_power)(bool enabled);
typedef void (*board_set_panda_individual_power)(uint8_t port_num, bool enabled);
typedef void (*board_set_ignition)(bool enabled); typedef void (*board_set_ignition)(bool enabled);
typedef void (*board_set_individual_ignition)(uint8_t bitmask); typedef void (*board_set_individual_ignition)(uint8_t bitmask);
typedef void (*board_set_harness_orientation)(uint8_t orientation); typedef void (*board_set_harness_orientation)(uint8_t orientation);
@ -23,6 +24,7 @@ struct board {
board_board_tick board_tick; board_board_tick board_tick;
board_get_button get_button; board_get_button get_button;
board_set_panda_power set_panda_power; board_set_panda_power set_panda_power;
board_set_panda_individual_power set_panda_individual_power;
board_set_ignition set_ignition; board_set_ignition set_ignition;
board_set_individual_ignition set_individual_ignition; board_set_individual_ignition set_individual_ignition;
board_set_harness_orientation set_harness_orientation; board_set_harness_orientation set_harness_orientation;
@ -75,3 +77,8 @@ void unused_board_enable_header_pin(uint8_t pin_num, bool enabled) {
UNUSED(pin_num); UNUSED(pin_num);
UNUSED(enabled); UNUSED(enabled);
} }
void unused_set_panda_individual_power(uint8_t port_num, bool enabled) {
UNUSED(port_num);
UNUSED(enabled);
}

View File

@ -164,6 +164,7 @@ const board board_v1 = {
.board_tick = &board_v1_tick, .board_tick = &board_v1_tick,
.get_button = &board_v1_get_button, .get_button = &board_v1_get_button,
.set_panda_power = &board_v1_set_panda_power, .set_panda_power = &board_v1_set_panda_power,
.set_panda_individual_power = &unused_set_panda_individual_power,
.set_ignition = &board_v1_set_ignition, .set_ignition = &board_v1_set_ignition,
.set_individual_ignition = &unused_set_individual_ignition, .set_individual_ignition = &unused_set_individual_ignition,
.set_harness_orientation = &board_v1_set_harness_orientation, .set_harness_orientation = &board_v1_set_harness_orientation,

View File

@ -178,9 +178,26 @@ void board_v2_set_can_mode(uint8_t mode) {
} }
bool panda_power = false; bool panda_power = false;
uint8_t panda_power_bitmask = 0U;
void board_v2_set_panda_power(bool enable) { void board_v2_set_panda_power(bool enable) {
panda_power = enable; panda_power = enable;
gpio_set_all_output(power_pins, sizeof(power_pins) / sizeof(gpio_t), enable); gpio_set_all_output(power_pins, sizeof(power_pins) / sizeof(gpio_t), enable);
if (enable) {
panda_power_bitmask = 0xFFU;
} else {
panda_power_bitmask = 0U;
}
}
void board_v2_set_panda_individual_power(uint8_t port_num, bool enable) {
port_num -= 1U;
if (port_num < 6U) {
panda_power_bitmask &= ~(1U << port_num);
panda_power_bitmask |= (enable ? 1U : 0U) << port_num;
} else {
print("Invalid port number ("); puth(port_num); print("): enabling failed\n");
}
gpio_set_bitmask(power_pins, sizeof(power_pins) / sizeof(gpio_t), (uint32_t)panda_power_bitmask);
} }
bool board_v2_get_button(void) { bool board_v2_get_button(void) {
@ -297,6 +314,7 @@ const board board_v2 = {
.board_tick = &board_v2_tick, .board_tick = &board_v2_tick,
.get_button = &board_v2_get_button, .get_button = &board_v2_get_button,
.set_panda_power = &board_v2_set_panda_power, .set_panda_power = &board_v2_set_panda_power,
.set_panda_individual_power = &board_v2_set_panda_individual_power,
.set_ignition = &board_v2_set_ignition, .set_ignition = &board_v2_set_ignition,
.set_individual_ignition = &board_v2_set_individual_ignition, .set_individual_ignition = &board_v2_set_individual_ignition,
.set_harness_orientation = &board_v2_set_harness_orientation, .set_harness_orientation = &board_v2_set_harness_orientation,

View File

@ -58,6 +58,10 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
case 0xa2: case 0xa2:
current_board->set_ignition((req->param1 == 1U)); current_board->set_ignition((req->param1 == 1U));
break; break;
// **** 0xa0: Set panda power per channel by bitmask.
case 0xa3:
current_board->set_panda_individual_power(req->param1, (req->param2 > 0U));
break;
// **** 0xa8: get microsecond timer // **** 0xa8: get microsecond timer
case 0xa8: case 0xa8:
time = microsecond_timer_get(); time = microsecond_timer_get();