Skip to content

Commit

Permalink
jungle: add pin header control (#1581)
Browse files Browse the repository at this point in the history
* init

* style

* clean + gpio output
  • Loading branch information
briskspirit authored Aug 15, 2023
1 parent 10a2727 commit ab70a3c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions board/jungle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,8 @@ def debug_read(self):
break
ret.append(lret)
return b''.join(ret)

# ******************* header pins *******************

def set_header_pin(self, pin_num, enabled):
self._handle.controlWrite(Panda.REQUEST_OUT, 0xf7, int(pin_num), int(enabled), b'')
9 changes: 8 additions & 1 deletion board/jungle/boards/board_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ typedef void (*board_set_individual_ignition)(uint8_t bitmask);
typedef void (*board_set_harness_orientation)(uint8_t orientation);
typedef void (*board_set_can_mode)(uint8_t mode);
typedef void (*board_enable_can_transciever)(uint8_t transciever, bool enabled);
typedef void (*board_enable_header_pin)(uint8_t pin_num, bool enabled);
typedef float (*board_get_channel_power)(uint8_t channel);
typedef uint16_t (*board_get_sbu_mV)(uint8_t channel, uint8_t sbu);

Expand All @@ -27,6 +28,7 @@ struct board {
board_set_harness_orientation set_harness_orientation;
board_set_can_mode set_can_mode;
board_enable_can_transciever enable_can_transciever;
board_enable_header_pin enable_header_pin;
board_get_channel_power get_channel_power;
board_get_sbu_mV get_sbu_mV;

Expand Down Expand Up @@ -67,4 +69,9 @@ uint8_t ignition = 0U;

void unused_set_individual_ignition(uint8_t bitmask) {
UNUSED(bitmask);
}
}

void unused_board_enable_header_pin(uint8_t pin_num, bool enabled) {
UNUSED(pin_num);
UNUSED(enabled);
}
5 changes: 3 additions & 2 deletions board/jungle/boards/board_v1.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

void board_v1_set_led(uint8_t color, bool enabled) {
switch (color){
switch (color) {
case LED_RED:
set_gpio_output(GPIOC, 9, !enabled);
break;
Expand All @@ -16,7 +16,7 @@ void board_v1_set_led(uint8_t color, bool enabled) {
}

void board_v1_enable_can_transciever(uint8_t transciever, bool enabled) {
switch (transciever){
switch (transciever) {
case 1U:
set_gpio_output(GPIOC, 1, !enabled);
break;
Expand Down Expand Up @@ -169,6 +169,7 @@ const board board_v1 = {
.set_harness_orientation = &board_v1_set_harness_orientation,
.set_can_mode = &board_v1_set_can_mode,
.enable_can_transciever = &board_v1_enable_can_transciever,
.enable_header_pin = &unused_board_enable_header_pin,
.get_channel_power = &board_v1_get_channel_power,
.get_sbu_mV = &board_v1_get_sbu_mV,
};
21 changes: 20 additions & 1 deletion board/jungle/boards/board_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void board_v2_set_harness_orientation(uint8_t orientation) {
}

void board_v2_enable_can_transciever(uint8_t transciever, bool enabled) {
switch (transciever){
switch (transciever) {
case 1U:
set_gpio_output(GPIOG, 11, !enabled);
break;
Expand All @@ -127,6 +127,14 @@ void board_v2_enable_can_transciever(uint8_t transciever, bool enabled) {
}
}

void board_v2_enable_header_pin(uint8_t pin_num, bool enabled) {
if (pin_num < 8U) {
set_gpio_output(GPIOG, pin_num, enabled);
} else {
print("Invalid pin number ("); puth(pin_num); print("): enabling failed\n");
}
}

void board_v2_set_can_mode(uint8_t mode) {
board_v2_enable_can_transciever(2U, false);
board_v2_enable_can_transciever(4U, false);
Expand Down Expand Up @@ -265,6 +273,16 @@ void board_v2_init(void) {
set_gpio_mode(GPIOF, 4, MODE_ANALOG);
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
set_gpio_mode(GPIOC, 1, MODE_ANALOG);

// Header pins
set_gpio_mode(GPIOG, 0, MODE_OUTPUT);
set_gpio_mode(GPIOG, 1, MODE_OUTPUT);
set_gpio_mode(GPIOG, 2, MODE_OUTPUT);
set_gpio_mode(GPIOG, 3, MODE_OUTPUT);
set_gpio_mode(GPIOG, 4, MODE_OUTPUT);
set_gpio_mode(GPIOG, 5, MODE_OUTPUT);
set_gpio_mode(GPIOG, 6, MODE_OUTPUT);
set_gpio_mode(GPIOG, 7, MODE_OUTPUT);
}

void board_v2_tick(void) {}
Expand All @@ -284,6 +302,7 @@ const board board_v2 = {
.set_harness_orientation = &board_v2_set_harness_orientation,
.set_can_mode = &board_v2_set_can_mode,
.enable_can_transciever = &board_v2_enable_can_transciever,
.enable_header_pin = &board_v2_enable_header_pin,
.get_channel_power = &board_v2_get_channel_power,
.get_sbu_mV = &board_v2_get_sbu_mV,
};
4 changes: 4 additions & 0 deletions board/jungle/main_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
can_silent = (req->param1 > 0U) ? ALL_CAN_SILENT : ALL_CAN_LIVE;
can_init_all();
break;
// **** 0xf7: enable/disable header pin by number
case 0xf7:
current_board->enable_header_pin(req->param1, req->param2 > 0U);
break;
// **** 0xf9: set CAN FD data bitrate
case 0xf9:
if ((req->param1 < PANDA_CAN_CNT) &&
Expand Down

0 comments on commit ab70a3c

Please sign in to comment.