Skip to content

Commit 998ac9d

Browse files
robbederksComma Device
andauthored
Init cleanup: global LED driver (#2170)
* wip * fix init * fix libpanda * cleanup --------- Co-authored-by: Comma Device <device@comma.ai>
1 parent e3e5787 commit 998ac9d

File tree

22 files changed

+85
-213
lines changed

22 files changed

+85
-213
lines changed

board/boards/black.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,6 @@ static void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
2626
}
2727
}
2828

29-
static void black_set_led(uint8_t color, bool enabled) {
30-
switch (color){
31-
case LED_RED:
32-
set_gpio_output(GPIOC, 9, !enabled);
33-
break;
34-
case LED_GREEN:
35-
set_gpio_output(GPIOC, 7, !enabled);
36-
break;
37-
case LED_BLUE:
38-
set_gpio_output(GPIOC, 6, !enabled);
39-
break;
40-
default:
41-
break;
42-
}
43-
}
44-
4529
static void black_set_usb_load_switch(bool enabled) {
4630
set_gpio_output(GPIOB, 1, !enabled);
4731
}
@@ -132,7 +116,8 @@ board board_black = {
132116
.init = black_init,
133117
.init_bootloader = black_init_bootloader,
134118
.enable_can_transceiver = black_enable_can_transceiver,
135-
.set_led = black_set_led,
119+
.led_GPIO = {GPIOC, GPIOC, GPIOC},
120+
.led_pin = {9, 7, 6},
136121
.set_can_mode = black_set_can_mode,
137122
.check_ignition = black_check_ignition,
138123
.read_voltage_mV = white_read_voltage_mV,

board/boards/board_declarations.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ typedef enum {
1313
typedef void (*board_init)(void);
1414
typedef void (*board_init_bootloader)(void);
1515
typedef void (*board_enable_can_transceiver)(uint8_t transceiver, bool enabled);
16-
typedef void (*board_set_led)(uint8_t color, bool enabled);
1716
typedef void (*board_set_can_mode)(uint8_t mode);
1817
typedef bool (*board_check_ignition)(void);
1918
typedef uint32_t (*board_read_voltage_mV)(void);
@@ -27,6 +26,8 @@ typedef void (*board_set_amp_enabled)(bool enabled);
2726

2827
struct board {
2928
harness_configuration *harness_config;
29+
GPIO_TypeDef * const led_GPIO[3];
30+
const uint8_t led_pin[3];
3031
const bool has_spi;
3132
const bool has_canfd;
3233
const uint16_t fan_max_rpm;
@@ -37,7 +38,6 @@ struct board {
3738
board_init init;
3839
board_init_bootloader init_bootloader;
3940
board_enable_can_transceiver enable_can_transceiver;
40-
board_set_led set_led;
4141
board_set_can_mode set_can_mode;
4242
board_check_ignition check_ignition;
4343
board_read_voltage_mV read_voltage_mV;
@@ -64,11 +64,6 @@ struct board {
6464
#define HW_TYPE_TRES 9U
6565
#define HW_TYPE_CUATRO 10U
6666

67-
// LED colors
68-
#define LED_RED 0U
69-
#define LED_GREEN 1U
70-
#define LED_BLUE 2U
71-
7267
// USB power modes (from cereal.log.health)
7368
#define USB_POWER_NONE 0U
7469
#define USB_POWER_CLIENT 1U

board/boards/cuatro.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@
66
// Cuatro (STM32H7) + Harness //
77
// ////////////////////////// //
88

9-
static void cuatro_set_led(uint8_t color, bool enabled) {
10-
switch (color) {
11-
case LED_RED:
12-
set_gpio_output(GPIOC, 6, !enabled);
13-
break;
14-
case LED_GREEN:
15-
set_gpio_output(GPIOC, 7, !enabled);
16-
break;
17-
case LED_BLUE:
18-
set_gpio_output(GPIOC, 9, !enabled);
19-
break;
20-
default:
21-
break;
22-
}
23-
}
24-
259
static void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
2610
switch (transceiver) {
2711
case 1U:
@@ -66,12 +50,7 @@ static void cuatro_set_amp_enabled(bool enabled){
6650
static void cuatro_init(void) {
6751
common_init_gpio();
6852

69-
// init LEDs as open drain
70-
set_gpio_output_type(GPIOC, 6, OUTPUT_TYPE_OPEN_DRAIN);
71-
set_gpio_output_type(GPIOC, 7, OUTPUT_TYPE_OPEN_DRAIN);
72-
set_gpio_output_type(GPIOC, 9, OUTPUT_TYPE_OPEN_DRAIN);
73-
74-
// more open drain
53+
// open drain
7554
set_gpio_output_type(GPIOD, 3, OUTPUT_TYPE_OPEN_DRAIN); // FAN_EN
7655
set_gpio_output_type(GPIOC, 12, OUTPUT_TYPE_OPEN_DRAIN); // VBAT_EN
7756

@@ -138,7 +117,8 @@ board board_cuatro = {
138117
.init = cuatro_init,
139118
.init_bootloader = unused_init_bootloader,
140119
.enable_can_transceiver = cuatro_enable_can_transceiver,
141-
.set_led = cuatro_set_led,
120+
.led_GPIO = {GPIOC, GPIOC, GPIOC},
121+
.led_pin = {6, 7, 9},
142122
.set_can_mode = tres_set_can_mode,
143123
.check_ignition = red_check_ignition,
144124
.read_voltage_mV = cuatro_read_voltage_mV,

board/boards/dos.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,6 @@ static void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
2626
}
2727
}
2828

29-
static void dos_set_led(uint8_t color, bool enabled) {
30-
switch (color){
31-
case LED_RED:
32-
set_gpio_output(GPIOC, 9, !enabled);
33-
break;
34-
case LED_GREEN:
35-
set_gpio_output(GPIOC, 7, !enabled);
36-
break;
37-
case LED_BLUE:
38-
set_gpio_output(GPIOC, 6, !enabled);
39-
break;
40-
default:
41-
break;
42-
}
43-
}
44-
4529
static void dos_set_bootkick(BootState state) {
4630
set_gpio_output(GPIOC, 4, state != BOOT_BOOTKICK);
4731
}
@@ -155,7 +139,8 @@ board board_dos = {
155139
.init = dos_init,
156140
.init_bootloader = unused_init_bootloader,
157141
.enable_can_transceiver = dos_enable_can_transceiver,
158-
.set_led = dos_set_led,
142+
.led_GPIO = {GPIOC, GPIOC, GPIOC},
143+
.led_pin = {9, 7, 6},
159144
.set_can_mode = dos_set_can_mode,
160145
.check_ignition = dos_check_ignition,
161146
.read_voltage_mV = white_read_voltage_mV,

board/boards/grey.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ board board_grey = {
2121
.init = white_grey_init,
2222
.init_bootloader = white_grey_init_bootloader,
2323
.enable_can_transceiver = white_enable_can_transceiver,
24-
.set_led = white_set_led,
24+
.led_GPIO = {GPIOC, GPIOC, GPIOC},
25+
.led_pin = {9, 7, 6},
2526
.set_can_mode = white_set_can_mode,
2627
.check_ignition = white_check_ignition,
2728
.read_voltage_mV = white_read_voltage_mV,

board/boards/red.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ static void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
2525
}
2626
}
2727

28-
static void red_set_led(uint8_t color, bool enabled) {
29-
switch (color) {
30-
case LED_RED:
31-
set_gpio_output(GPIOE, 4, !enabled);
32-
break;
33-
case LED_GREEN:
34-
set_gpio_output(GPIOE, 3, !enabled);
35-
break;
36-
case LED_BLUE:
37-
set_gpio_output(GPIOE, 2, !enabled);
38-
break;
39-
default:
40-
break;
41-
}
42-
}
43-
4428
static void red_set_can_mode(uint8_t mode) {
4529
red_enable_can_transceiver(2U, false);
4630
red_enable_can_transceiver(4U, false);
@@ -146,7 +130,8 @@ board board_red = {
146130
.init = red_init,
147131
.init_bootloader = unused_init_bootloader,
148132
.enable_can_transceiver = red_enable_can_transceiver,
149-
.set_led = red_set_led,
133+
.led_GPIO = {GPIOE, GPIOE, GPIOE},
134+
.led_pin = {4, 3, 2},
150135
.set_can_mode = red_set_can_mode,
151136
.check_ignition = red_check_ignition,
152137
.read_voltage_mV = red_read_voltage_mV,

board/boards/tres.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ board board_tres = {
158158
.init = tres_init,
159159
.init_bootloader = unused_init_bootloader,
160160
.enable_can_transceiver = tres_enable_can_transceiver,
161-
.set_led = red_set_led,
161+
.led_GPIO = {GPIOE, GPIOE, GPIOE},
162+
.led_pin = {4, 3, 2},
162163
.set_can_mode = tres_set_can_mode,
163164
.check_ignition = red_check_ignition,
164165
.read_voltage_mV = red_read_voltage_mV,

board/boards/uno.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,6 @@ static void uno_enable_can_transceiver(uint8_t transceiver, bool enabled) {
2626
}
2727
}
2828

29-
static void uno_set_led(uint8_t color, bool enabled) {
30-
switch (color){
31-
case LED_RED:
32-
set_gpio_output(GPIOC, 9, !enabled);
33-
break;
34-
case LED_GREEN:
35-
set_gpio_output(GPIOC, 7, !enabled);
36-
break;
37-
case LED_BLUE:
38-
set_gpio_output(GPIOC, 6, !enabled);
39-
break;
40-
default:
41-
break;
42-
}
43-
}
44-
4529
static void uno_set_bootkick(BootState state) {
4630
if (state == BOOT_BOOTKICK) {
4731
set_gpio_output(GPIOB, 14, false);
@@ -167,7 +151,8 @@ board board_uno = {
167151
.init = uno_init,
168152
.init_bootloader = uno_init_bootloader,
169153
.enable_can_transceiver = uno_enable_can_transceiver,
170-
.set_led = uno_set_led,
154+
.led_GPIO = {GPIOC, GPIOC, GPIOC},
155+
.led_pin = {9, 7, 6},
171156
.set_can_mode = uno_set_can_mode,
172157
.check_ignition = uno_check_ignition,
173158
.read_voltage_mV = white_read_voltage_mV,

board/boards/white.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,6 @@ static void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
2222
}
2323
}
2424

25-
static void white_set_led(uint8_t color, bool enabled) {
26-
switch (color){
27-
case LED_RED:
28-
set_gpio_output(GPIOC, 9, !enabled);
29-
break;
30-
case LED_GREEN:
31-
set_gpio_output(GPIOC, 7, !enabled);
32-
break;
33-
case LED_BLUE:
34-
set_gpio_output(GPIOC, 6, !enabled);
35-
break;
36-
default:
37-
break;
38-
}
39-
}
40-
4125
static void white_set_usb_power_mode(uint8_t mode){
4226
switch (mode) {
4327
case USB_POWER_CLIENT:
@@ -181,7 +165,8 @@ board board_white = {
181165
.init = white_grey_init,
182166
.init_bootloader = white_grey_init_bootloader,
183167
.enable_can_transceiver = white_enable_can_transceiver,
184-
.set_led = white_set_led,
168+
.led_GPIO = {GPIOC, GPIOC, GPIOC},
169+
.led_pin = {9, 7, 6},
185170
.set_can_mode = white_set_can_mode,
186171
.check_ignition = white_check_ignition,
187172
.read_voltage_mV = white_read_voltage_mV,

board/bootstub.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// ********************* Includes *********************
77
#include "config.h"
88

9+
#include "drivers/led.h"
910
#include "drivers/pwm.h"
1011
#include "drivers/usb.h"
1112

0 commit comments

Comments
 (0)