Skip to content

Commit 07f29ed

Browse files
committed
unrefactor harness configuration, fix lladc for jungle
1 parent aebe2d9 commit 07f29ed

File tree

7 files changed

+37
-44
lines changed

7 files changed

+37
-44
lines changed

SConscript

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,21 @@ def build_project(project_name, project, extra_flags):
155155
if _is_stm32h7:
156156
sources.extend([
157157
("drivers_fake_siren", f"{panda_root}/board/drivers/fake_siren.c"),
158-
("stm32h7_peripherals", f"{panda_root}/board/stm32h7/peripherals.c"),
159-
("stm32h7_llusb", f"{panda_root}/board/stm32h7/llusb.c"),
160158
("stm32h7_clock", f"{panda_root}/board/stm32h7/clock.c"),
161-
("stm32h7_lladc", f"{panda_root}/board/stm32h7/lladc.c"),
162159
("stm32h7_lldac", f"{panda_root}/board/stm32h7/lldac.c"),
163160
("stm32h7_llflash", f"{panda_root}/board/stm32h7/llflash.c"),
164161
("stm32h7_lli2c", f"{panda_root}/board/stm32h7/lli2c.c"),
165162
("stm32h7_llspi", f"{panda_root}/board/stm32h7/llspi.c"),
163+
("stm32h7_llusb", f"{panda_root}/board/stm32h7/llusb.c"),
164+
("stm32h7_peripherals", f"{panda_root}/board/stm32h7/peripherals.c"),
166165
])
167-
if not _is_panda_jungle:
166+
if _is_panda_jungle:
167+
sources.extend([
168+
("stm32h7_jungle_lladc", f"{panda_root}/board/jungle/stm32h7/lladc.c"),
169+
])
170+
else:
168171
sources.extend([
172+
("stm32h7_lladc", f"{panda_root}/board/stm32h7/lladc.c"),
169173
("stm32h7_llfan", f"{panda_root}/board/stm32h7/llfan.c"),
170174
("stm32h7_sound", f"{panda_root}/board/stm32h7/sound.c"),
171175
])
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
#pragma once
1+
#include "board/jungle/stm32h7/lladc.h"
22
#include "config.h"
33

4-
typedef struct {
5-
ADC_TypeDef *adc;
6-
uint8_t channel;
7-
} adc_channel_t;
8-
9-
static inline void adc_init(ADC_TypeDef *adc) {
4+
void adc_init(ADC_TypeDef *adc) {
105
adc->CR &= ~(ADC_CR_DEEPPWD); // Reset deep-power-down mode
116
adc->CR |= ADC_CR_ADVREGEN; // Enable ADC regulator
127
while(!(adc->ISR & ADC_ISR_LDORDY) && (adc != ADC3));
@@ -23,7 +18,7 @@ static inline void adc_init(ADC_TypeDef *adc) {
2318
while(!(adc->ISR & ADC_ISR_ADRDY));
2419
}
2520

26-
static inline uint16_t adc_get_raw(ADC_TypeDef *adc, uint8_t channel) {
21+
uint16_t adc_get_raw(ADC_TypeDef *adc, uint8_t channel) {
2722
adc->SQR1 &= ~(ADC_SQR1_L);
2823
adc->SQR1 = ((uint32_t) channel << 6U);
2924

@@ -45,7 +40,7 @@ static inline uint16_t adc_get_raw(ADC_TypeDef *adc, uint8_t channel) {
4540
return res;
4641
}
4742

48-
static inline uint16_t adc_get_mV(ADC_TypeDef *adc, uint8_t channel) {
43+
uint16_t adc_get_mV(ADC_TypeDef *adc, uint8_t channel) {
4944
uint16_t ret = 0;
5045
if ((adc == ADC1) || (adc == ADC2)) {
5146
ret = (adc_get_raw(adc, channel) * current_board->avdd_mV) / 65535U;

include/board/boards/board.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#include <stdint.h>
44
#include <stdbool.h>
55
#include "platform_definitions.h"
6-
#include "drivers/harness_configuration.h"
76

87
#ifdef PANDA_JUNGLE
98
#include "jungle/boards/board.h"
109
#else
1110

11+
#include "drivers/harness.h"
12+
1213
typedef enum {
1314
BOOT_STANDBY,
1415
BOOT_BOOTKICK,
@@ -31,7 +32,7 @@ typedef void (*board_set_bootkick)(BootState state);
3132
typedef bool (*board_read_som_gpio)(void);
3233
typedef void (*board_set_amp_enabled)(bool enabled);
3334

34-
typedef struct board {
35+
typedef struct board_t {
3536
harness_configuration *harness_config;
3637
GPIO_TypeDef * const led_GPIO[3];
3738
const uint8_t led_pin[3];
@@ -81,12 +82,12 @@ typedef struct board {
8182
#define CAN_MODE_NORMAL 0U
8283
#define CAN_MODE_OBD_CAN2 1U
8384

84-
extern struct board board_black;
85-
extern struct board board_dos;
86-
extern struct board board_uno;
87-
extern struct board board_tres;
88-
extern struct board board_grey;
89-
extern struct board board_white;
90-
extern struct board board_cuatro;
91-
extern struct board board_red;
85+
extern board board_black;
86+
extern board board_dos;
87+
extern board board_uno;
88+
extern board board_tres;
89+
extern board board_grey;
90+
extern board board_white;
91+
extern board board_cuatro;
92+
extern board board_red;
9293
#endif

include/board/drivers/harness.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
#include <stdbool.h>
33
#include <stdint.h>
4-
#include "drivers/harness_configuration.h"
4+
#include "platform_definitions.h"
55

66
extern uint16_t adc_get_mV(uint8_t channel);
77

@@ -18,6 +18,19 @@ struct harness_t {
1818
};
1919
extern struct harness_t harness;
2020

21+
typedef struct harness_configuration {
22+
const bool has_harness;
23+
GPIO_TypeDef * const GPIO_SBU1;
24+
GPIO_TypeDef * const GPIO_SBU2;
25+
GPIO_TypeDef * const GPIO_relay_SBU1;
26+
GPIO_TypeDef * const GPIO_relay_SBU2;
27+
const uint8_t pin_SBU1;
28+
const uint8_t pin_SBU2;
29+
const uint8_t pin_relay_SBU1;
30+
const uint8_t pin_relay_SBU2;
31+
const uint8_t adc_channel_SBU1;
32+
const uint8_t adc_channel_SBU2;
33+
} harness_configuration;
2134

2235
// The ignition relay is only used for testing purposes
2336
void set_intercept_relay(bool intercept, bool ignition_relay);

include/board/drivers/harness_configuration.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

include/board/stm32f4/board.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
// ///// Board definition and detection ///// //
99
#include "stm32f4/lladc.h"
10-
#include "drivers/harness.h"
1110
#include "drivers/fan.h"
1211
#include "stm32f4/llfan.h"
1312
#include "drivers/clock_source.h"

include/board/stm32h7/board.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
// ///// Board definition and detection ///// //
99
#include "stm32h7/lladc.h"
10-
#include "drivers/harness.h"
1110
#include "drivers/fan.h"
1211
#include "stm32h7/llfan.h"
1312
#include "stm32h7/lldac.h"

0 commit comments

Comments
 (0)