2024-02-07 03:15:46 +08:00
|
|
|
// ///////////////////// //
|
|
|
|
// White Panda (STM32F4) //
|
|
|
|
// ///////////////////// //
|
2019-07-24 06:07:06 +08:00
|
|
|
|
2020-09-28 22:19:09 +08:00
|
|
|
void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
|
|
|
switch (transceiver){
|
2019-07-24 06:07:06 +08:00
|
|
|
case 1U:
|
|
|
|
set_gpio_output(GPIOC, 1, !enabled);
|
|
|
|
break;
|
|
|
|
case 2U:
|
|
|
|
set_gpio_output(GPIOC, 13, !enabled);
|
|
|
|
break;
|
|
|
|
case 3U:
|
|
|
|
set_gpio_output(GPIOA, 0, !enabled);
|
|
|
|
break;
|
|
|
|
default:
|
2022-11-30 14:55:10 +08:00
|
|
|
print("Invalid CAN transceiver ("); puth(transceiver); print("): enabling failed\n");
|
2019-07-24 06:07:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-28 22:19:09 +08:00
|
|
|
void white_enable_can_transceivers(bool enabled) {
|
|
|
|
uint8_t t1 = enabled ? 1U : 2U; // leave transceiver 1 enabled to detect CAN ignition
|
2019-10-23 06:10:43 +08:00
|
|
|
for(uint8_t i=t1; i<=3U; i++) {
|
2020-09-28 22:19:09 +08:00
|
|
|
white_enable_can_transceiver(i, enabled);
|
2019-10-23 06:10:43 +08:00
|
|
|
}
|
2019-07-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void white_set_led(uint8_t color, bool enabled) {
|
|
|
|
switch (color){
|
|
|
|
case LED_RED:
|
|
|
|
set_gpio_output(GPIOC, 9, !enabled);
|
|
|
|
break;
|
|
|
|
case LED_GREEN:
|
|
|
|
set_gpio_output(GPIOC, 7, !enabled);
|
|
|
|
break;
|
|
|
|
case LED_BLUE:
|
|
|
|
set_gpio_output(GPIOC, 6, !enabled);
|
2019-10-03 02:48:40 +08:00
|
|
|
break;
|
2019-07-24 06:07:06 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void white_set_usb_power_mode(uint8_t mode){
|
|
|
|
switch (mode) {
|
|
|
|
case USB_POWER_CLIENT:
|
|
|
|
// B2,A13: set client mode
|
|
|
|
set_gpio_output(GPIOB, 2, 0);
|
|
|
|
set_gpio_output(GPIOA, 13, 1);
|
|
|
|
break;
|
|
|
|
case USB_POWER_CDP:
|
|
|
|
// B2,A13: set CDP mode
|
|
|
|
set_gpio_output(GPIOB, 2, 1);
|
|
|
|
set_gpio_output(GPIOA, 13, 1);
|
|
|
|
break;
|
|
|
|
case USB_POWER_DCP:
|
|
|
|
// B2,A13: set DCP mode on the charger (breaks USB!)
|
|
|
|
set_gpio_output(GPIOB, 2, 0);
|
|
|
|
set_gpio_output(GPIOA, 13, 0);
|
|
|
|
break;
|
|
|
|
default:
|
2022-11-30 14:55:10 +08:00
|
|
|
print("Invalid usb power mode\n");
|
2019-07-24 06:07:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void white_set_can_mode(uint8_t mode){
|
2024-03-22 04:56:36 +08:00
|
|
|
if (mode == CAN_MODE_NORMAL) {
|
|
|
|
// B12,B13: disable GMLAN mode
|
|
|
|
set_gpio_mode(GPIOB, 12, MODE_INPUT);
|
|
|
|
set_gpio_mode(GPIOB, 13, MODE_INPUT);
|
|
|
|
|
|
|
|
// B3,B4: disable GMLAN mode
|
|
|
|
set_gpio_mode(GPIOB, 3, MODE_INPUT);
|
|
|
|
set_gpio_mode(GPIOB, 4, MODE_INPUT);
|
|
|
|
|
|
|
|
// B5,B6: normal CAN2 mode
|
|
|
|
set_gpio_alternate(GPIOB, 5, GPIO_AF9_CAN2);
|
|
|
|
set_gpio_alternate(GPIOB, 6, GPIO_AF9_CAN2);
|
|
|
|
|
|
|
|
// A8,A15: normal CAN3 mode
|
|
|
|
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
|
|
|
|
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
2019-07-24 06:07:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-16 05:49:06 +08:00
|
|
|
uint32_t white_read_voltage_mV(void){
|
|
|
|
return adc_get_mV(12) * 11U;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t white_read_current_mA(void){
|
|
|
|
// This isn't in mA, but we're keeping it for backwards compatibility
|
|
|
|
return adc_get_raw(13);
|
2019-10-26 07:22:42 +08:00
|
|
|
}
|
|
|
|
|
2019-07-24 06:07:06 +08:00
|
|
|
bool white_check_ignition(void){
|
|
|
|
// ignition is on PA1
|
|
|
|
return !get_gpio_input(GPIOA, 1);
|
|
|
|
}
|
|
|
|
|
2023-08-07 03:29:54 +08:00
|
|
|
void white_grey_init(void) {
|
2019-07-24 06:07:06 +08:00
|
|
|
common_init_gpio();
|
|
|
|
|
|
|
|
// C3: current sense
|
|
|
|
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
|
|
|
|
|
|
|
|
// A1: started_alt
|
|
|
|
set_gpio_pullup(GPIOA, 1, PULL_UP);
|
|
|
|
|
|
|
|
// A2, A3: USART 2 for debugging
|
|
|
|
set_gpio_alternate(GPIOA, 2, GPIO_AF7_USART2);
|
|
|
|
set_gpio_alternate(GPIOA, 3, GPIO_AF7_USART2);
|
|
|
|
|
|
|
|
// A4, A5, A6, A7: SPI
|
|
|
|
set_gpio_alternate(GPIOA, 4, GPIO_AF5_SPI1);
|
|
|
|
set_gpio_alternate(GPIOA, 5, GPIO_AF5_SPI1);
|
|
|
|
set_gpio_alternate(GPIOA, 6, GPIO_AF5_SPI1);
|
|
|
|
set_gpio_alternate(GPIOA, 7, GPIO_AF5_SPI1);
|
|
|
|
|
|
|
|
// B12: GMLAN, ignition sense, pull up
|
|
|
|
set_gpio_pullup(GPIOB, 12, PULL_UP);
|
|
|
|
|
|
|
|
/* GMLAN mode pins:
|
|
|
|
M0(B15) M1(B14) mode
|
|
|
|
=======================
|
|
|
|
0 0 sleep
|
|
|
|
1 0 100kbit
|
|
|
|
0 1 high voltage wakeup
|
|
|
|
1 1 33kbit (normal)
|
|
|
|
*/
|
2024-03-22 04:56:36 +08:00
|
|
|
set_gpio_output(GPIOB, 14, 0);
|
|
|
|
set_gpio_output(GPIOB, 15, 0);
|
2019-07-24 06:07:06 +08:00
|
|
|
|
|
|
|
// B7: K-line enable
|
|
|
|
set_gpio_output(GPIOB, 7, 1);
|
|
|
|
|
|
|
|
// C12, D2: Setup K-line (UART5)
|
|
|
|
set_gpio_alternate(GPIOC, 12, GPIO_AF8_UART5);
|
|
|
|
set_gpio_alternate(GPIOD, 2, GPIO_AF8_UART5);
|
|
|
|
set_gpio_pullup(GPIOD, 2, PULL_UP);
|
|
|
|
|
|
|
|
// L-line enable
|
|
|
|
set_gpio_output(GPIOA, 14, 1);
|
|
|
|
|
|
|
|
// C10, C11: L-Line setup (USART3)
|
|
|
|
set_gpio_alternate(GPIOC, 10, GPIO_AF7_USART3);
|
|
|
|
set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3);
|
|
|
|
set_gpio_pullup(GPIOC, 11, PULL_UP);
|
|
|
|
|
2022-02-10 07:36:37 +08:00
|
|
|
|
2020-09-28 22:19:09 +08:00
|
|
|
// Enable CAN transceivers
|
|
|
|
white_enable_can_transceivers(true);
|
2019-07-24 06:07:06 +08:00
|
|
|
|
|
|
|
// Disable LEDs
|
|
|
|
white_set_led(LED_RED, false);
|
|
|
|
white_set_led(LED_GREEN, false);
|
|
|
|
white_set_led(LED_BLUE, false);
|
|
|
|
|
|
|
|
// Set normal CAN mode
|
|
|
|
white_set_can_mode(CAN_MODE_NORMAL);
|
2019-08-29 03:57:42 +08:00
|
|
|
|
2019-10-06 11:34:20 +08:00
|
|
|
// Init usb power mode
|
|
|
|
// Init in CDP mode only if panda is powered by 12V.
|
2021-06-22 04:54:09 +08:00
|
|
|
// Otherwise a PC would not be able to flash a standalone panda
|
2024-02-16 05:49:06 +08:00
|
|
|
if (white_read_voltage_mV() > 8000U) { // 8V threshold
|
2019-10-06 11:34:20 +08:00
|
|
|
white_set_usb_power_mode(USB_POWER_CDP);
|
|
|
|
} else {
|
|
|
|
white_set_usb_power_mode(USB_POWER_CLIENT);
|
|
|
|
}
|
2019-07-24 06:07:06 +08:00
|
|
|
|
2023-08-07 03:29:54 +08:00
|
|
|
// ESP/GPS off
|
|
|
|
set_gpio_output(GPIOC, 5, 0);
|
|
|
|
set_gpio_output(GPIOC, 14, 0);
|
|
|
|
}
|
2019-11-20 10:41:59 +08:00
|
|
|
|
2023-08-07 03:29:54 +08:00
|
|
|
void white_grey_init_bootloader(void) {
|
|
|
|
// ESP/GPS off
|
|
|
|
set_gpio_output(GPIOC, 5, 0);
|
|
|
|
set_gpio_output(GPIOC, 14, 0);
|
2019-11-20 10:41:59 +08:00
|
|
|
}
|
|
|
|
|
2024-03-25 03:38:25 +08:00
|
|
|
harness_configuration white_harness_config = {
|
2019-07-24 06:07:06 +08:00
|
|
|
.has_harness = false
|
|
|
|
};
|
|
|
|
|
2024-03-25 03:38:25 +08:00
|
|
|
board board_white = {
|
2023-11-09 14:54:55 +08:00
|
|
|
.set_bootkick = unused_set_bootkick,
|
2019-07-24 06:07:06 +08:00
|
|
|
.harness_config = &white_harness_config,
|
2021-07-03 09:25:35 +08:00
|
|
|
.has_obd = false,
|
2022-11-14 11:57:20 +08:00
|
|
|
.has_spi = false,
|
2022-09-17 12:56:48 +08:00
|
|
|
.has_canfd = false,
|
2022-08-18 11:43:49 +08:00
|
|
|
.fan_max_rpm = 0U,
|
2023-05-04 19:22:01 +08:00
|
|
|
.avdd_mV = 3300U,
|
2023-03-16 21:15:43 +08:00
|
|
|
.fan_stall_recovery = false,
|
|
|
|
.fan_enable_cooldown_time = 0U,
|
2023-08-07 03:29:54 +08:00
|
|
|
.init = white_grey_init,
|
|
|
|
.init_bootloader = white_grey_init_bootloader,
|
2020-09-28 22:19:09 +08:00
|
|
|
.enable_can_transceiver = white_enable_can_transceiver,
|
|
|
|
.enable_can_transceivers = white_enable_can_transceivers,
|
2019-07-24 06:07:06 +08:00
|
|
|
.set_led = white_set_led,
|
|
|
|
.set_can_mode = white_set_can_mode,
|
2019-10-26 07:22:42 +08:00
|
|
|
.check_ignition = white_check_ignition,
|
2024-02-16 05:49:06 +08:00
|
|
|
.read_voltage_mV = white_read_voltage_mV,
|
|
|
|
.read_current_mA = white_read_current_mA,
|
2022-08-18 11:43:49 +08:00
|
|
|
.set_fan_enabled = unused_set_fan_enabled,
|
2021-08-04 01:55:10 +08:00
|
|
|
.set_ir_power = unused_set_ir_power,
|
2023-02-08 23:01:14 +08:00
|
|
|
.set_siren = unused_set_siren,
|
|
|
|
.read_som_gpio = unused_read_som_gpio
|
2019-10-03 02:48:40 +08:00
|
|
|
};
|