Skip to content

Commit

Permalink
Board config yaml & refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dzurikmiroslav committed Nov 22, 2024
1 parent e41fcb6 commit cab740f
Show file tree
Hide file tree
Showing 28 changed files with 1,755 additions and 602 deletions.
71 changes: 71 additions & 0 deletions cfg/esp32devkitc/board.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
deviceName: ESP32-DevKitC EVSE

ledChargingGpio: 19
ledErrorGpio: 18
ledWifiGpio: 17

buttonWifiGpio: 0

pilot:
gpio: 28
adcChannel: 0
levels: [2405, 2099, 1792, 1484, 728]

proximity:
adcChannel: 3
levels: [1650, 820, 430]

acRelayGpio: 26

socketLock:
aGpio:
bGpio:
detectionGpio:
detectionDelay:
minBreakTime:

rcm:
gpio:
testGpio:

energyMeter:
currentAdcChannels: [7,8,9]
currentScale: 0.090909091
voltageAdcChannels: [10,11,12]
voltageScale: 0.090909091

# Max 4 items
auxIn:
- name: Test
gpio: 60

# Max 4 items
auxOut:
- name: Test
gpio: 60

# Max 4 items
aixAIn:
- name: Test
adcChannel: 1

serial:
- type: uart
name: UART via USB
rxdGpio: 3
txdGpio: 1
rtsGpio:
- type: rs485
name: RS485
rxdGpio: 32
txdGpio: 25
rtsGpio: 33
- type: uart
name: UART
rxdGpio: 2
txdGpio: 15
rtsGpio:

onewire:
gpio: 16
tempSensor: true
8 changes: 3 additions & 5 deletions components/config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
set(srcs
"src/board_config.c")

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "include")
idf_component_register(SRC_DIRS "src"
INCLUDE_DIRS "include"
PRIV_REQUIRES yaml)
226 changes: 107 additions & 119 deletions components/config/include/board_config.h
Original file line number Diff line number Diff line change
@@ -1,138 +1,126 @@
#ifndef BOARD_CONFIG_H_
#define BOARD_CONFIG_H_
#ifndef CONFIG_H_
#define CONFIG_H_

#include <hal/adc_types.h>
#include <hal/gpio_types.h>
#include <soc/soc_caps.h>
#include <stdbool.h>
#include <stdint.h>

#define BOARD_CFG_DEVICE_NAME_LEN 32
#define BOARD_CFG_AUX_NAME_LEN 8
#define BOARD_CFG_AUX_IN_COUNT 4
#define BOARD_CFG_AUX_OUT_COUNT 4
#define BOARD_CFG_AUX_ANALOG_IN_COUNT 2
#define BOARD_CFG_SERIAL_NAME_LEN 16
#define BOARD_CFG_SERIAL_COUNT SOC_UART_NUM

#define board_cfg_is_proximity(config) (config.proximity_adc_channel != -1)
#define board_cfg_is_socket_lock(config) (config.socket_lock_a_gpio != -1 && config.socket_lock_b_gpio != -1 && config.socket_lock_detection_gpio != -1)
#define board_cfg_is_rcm(config) (config.rcm_gpio != -1 && config.rcm_test_gpio != -1)
#define board_cfg_is_aux_in(config, idx) (config.aux_in[idx].gpio != -1)
#define board_cfg_is_aux_out(config, idx) (config.aux_out[idx].gpio != -1)
#define board_cfg_is_aux_analog_in(config, idx) (config.aux_analog_in[idx].adc_channel != -1)
#define board_cfg_is_onewire(config) (config.onewire_gpio != -1)
#define board_cfg_is_energy_meter_cur(config) (config.energy_meter_cur_adc_channel[BOARD_CFG_ENERGY_METER_ADC_CHANNEL_L1] != -1)
#define board_cfg_is_energy_meter_vlt(config) (config.energy_meter_vlt_adc_channel[BOARD_CFG_ENERGY_METER_ADC_CHANNEL_L1] != -1)
#define board_cfg_is_energy_meter_cur_3p(config) \
(config.energy_meter_cur_adc_channel[BOARD_CFG_ENERGY_METER_ADC_CHANNEL_L2] != -1 && config.energy_meter_cur_adc_channel[BOARD_CFG_ENERGY_METER_ADC_CHANNEL_L3] != -1)
#define board_cfg_is_energy_meter_vlt_3p(config) \
(config.energy_meter_vlt_adc_channel[BOARD_CFG_ENERGY_METER_ADC_CHANNEL_L2] != -1 && config.energy_meter_vlt_adc_channel[BOARD_CFG_ENERGY_METER_ADC_CHANNEL_L3] != -1)

typedef enum {
BOARD_CONFIG_ENERGY_METER_NONE,
BOARD_CONFIG_ENERGY_METER_CUR,
BOARD_CONFIG_ENERGY_METER_CUR_VLT
} board_config_energy_meter_t;
BOARD_CFG_PILOT_LEVEL_12,
BOARD_CFG_PILOT_LEVEL_9,
BOARD_CFG_PILOT_LEVEL_6,
BOARD_CFG_PILOT_LEVEL_3,
BOARD_CFG_PILOT_LEVEL_N12,
BOARD_CFG_PILOT_LEVEL_MAX
} board_cfg_pilot_level_t;

typedef enum {
BOARD_CONFIG_SERIAL_NONE,
BOARD_CONFIG_SERIAL_UART,
BOARD_CONFIG_SERIAL_RS485
} board_config_serial_t;
BOARD_CFG_PROXIMITY_LEVEL_13,
BOARD_CFG_PROXIMITY_LEVEL_20,
BOARD_CFG_PROXIMITY_LEVEL_32,
BOARD_CFG_PROXIMITY_LEVEL_MAX
} board_cfg_proximity_level_t;

typedef struct {
char device_name[32];

bool led_charging : 1;
gpio_num_t led_charging_gpio;
bool led_error : 1;
gpio_num_t led_error_gpio;
bool led_wifi : 1;
gpio_num_t led_wifi_gpio;

gpio_num_t button_wifi_gpio;

gpio_num_t pilot_pwm_gpio;
adc_channel_t pilot_adc_channel;
uint16_t pilot_down_threshold_12;
uint16_t pilot_down_threshold_9;
uint16_t pilot_down_threshold_6;
uint16_t pilot_down_threshold_3;
uint16_t pilot_down_threshold_n12;

bool proximity : 1;
adc_channel_t proximity_adc_channel;
uint16_t proximity_down_threshold_13;
uint16_t proximity_down_threshold_20;
uint16_t proximity_down_threshold_32;

gpio_num_t ac_relay_gpio;

bool socket_lock : 1;
gpio_num_t socket_lock_a_gpio;
gpio_num_t socket_lock_b_gpio;
gpio_num_t socket_lock_detection_gpio;
char name[BOARD_CFG_AUX_NAME_LEN];
int8_t gpio;
} board_cfg_aux_in_out_t;

typedef struct {
char name[BOARD_CFG_AUX_NAME_LEN];
int8_t adc_channel;
} board_cfg_aux_analog_in_t;

typedef enum {
BOARD_CFG_SERIAL_TYPE_NONE,
BOARD_CFG_SERIAL_TYPE_UART,
BOARD_CFG_SERIAL_TYPE_RS485
} board_cfg_serial_type_t;

typedef struct {
board_cfg_serial_type_t type;
char name[BOARD_CFG_SERIAL_NAME_LEN];
int8_t rxd_gpio;
int8_t txd_gpio;
int8_t rts_gpio;
} board_cfg_serial_t;

typedef enum {
BOARD_CFG_ENERGY_METER_ADC_CHANNEL_L1,
BOARD_CFG_ENERGY_METER_ADC_CHANNEL_L2,
BOARD_CFG_ENERGY_METER_ADC_CHANNEL_L3,
BOARD_CFG_ENERGY_METER_ADC_CHANNEL_MAX
} board_cfg_energy_meter_adc_channel_t;

typedef struct {
char device_name[BOARD_CFG_DEVICE_NAME_LEN];

int8_t led_charging_gpio;
int8_t led_error_gpio;
int8_t led_wifi_gpio;

int8_t button_gpio;

int8_t pilot_gpio;
int8_t pilot_adc_channel;
uint16_t pilot_levels[BOARD_CFG_PILOT_LEVEL_MAX];

int8_t proximity_adc_channel;
uint16_t proximity_levels[BOARD_CFG_PROXIMITY_LEVEL_MAX];

int8_t ac_relay_gpio;

int8_t socket_lock_a_gpio;
int8_t socket_lock_b_gpio;
int8_t socket_lock_detection_gpio;
uint16_t socket_lock_detection_delay;
uint16_t socket_lock_min_break_time;

bool rcm : 1;
gpio_num_t rcm_gpio;
gpio_num_t rcm_test_gpio;

board_config_energy_meter_t energy_meter;
bool energy_meter_three_phases : 1;
int8_t rcm_gpio;
int8_t rcm_test_gpio;

adc_channel_t energy_meter_l1_cur_adc_channel;
adc_channel_t energy_meter_l2_cur_adc_channel;
adc_channel_t energy_meter_l3_cur_adc_channel;
int8_t energy_meter_cur_adc_channel[BOARD_CFG_ENERGY_METER_ADC_CHANNEL_MAX];
float energy_meter_cur_scale;
adc_channel_t energy_meter_l1_vlt_adc_channel;
adc_channel_t energy_meter_l2_vlt_adc_channel;
adc_channel_t energy_meter_l3_vlt_adc_channel;

int8_t energy_meter_vlt_adc_channel[BOARD_CFG_ENERGY_METER_ADC_CHANNEL_MAX];
float energy_meter_vlt_scale;

bool aux_in_1 : 1;
char aux_in_1_name[8];
gpio_num_t aux_in_1_gpio;

bool aux_in_2 : 1;
char aux_in_2_name[8];
gpio_num_t aux_in_2_gpio;

bool aux_in_3 : 1;
char aux_in_3_name[8];
gpio_num_t aux_in_3_gpio;

bool aux_in_4 : 1;
char aux_in_4_name[8];
gpio_num_t aux_in_4_gpio;

bool aux_out_1 : 1;
char aux_out_1_name[8];
gpio_num_t aux_out_1_gpio;

bool aux_out_2 : 1;
char aux_out_2_name[8];
gpio_num_t aux_out_2_gpio;

bool aux_out_3 : 1;
char aux_out_3_name[8];
gpio_num_t aux_out_3_gpio;

bool aux_out_4 : 1;
char aux_out_4_name[8];
gpio_num_t aux_out_4_gpio;

bool aux_ain_1 : 1;
char aux_ain_1_name[8];
adc_channel_t aux_ain_1_adc_channel;

bool aux_ain_2 : 1;
char aux_ain_2_name[8];
adc_channel_t aux_ain_2_adc_channel;

board_config_serial_t serial_1;
char serial_1_name[16];
gpio_num_t serial_1_rxd_gpio;
gpio_num_t serial_1_txd_gpio;
gpio_num_t serial_1_rts_gpio;
board_config_serial_t serial_2;
char serial_2_name[16];
gpio_num_t serial_2_rxd_gpio;
gpio_num_t serial_2_txd_gpio;
gpio_num_t serial_2_rts_gpio;
#if SOC_UART_NUM > 2
board_config_serial_t serial_3;
char serial_3_name[16];
gpio_num_t serial_3_rxd_gpio;
gpio_num_t serial_3_txd_gpio;
gpio_num_t serial_3_rts_gpio;
#endif /* SOC_UART_NUM > 2 */

bool onewire : 1;
gpio_num_t onewire_gpio;
board_cfg_aux_in_out_t aux_in[BOARD_CFG_AUX_IN_COUNT];

board_cfg_aux_in_out_t aux_out[BOARD_CFG_AUX_OUT_COUNT];

board_cfg_aux_analog_in_t aux_analog_in[BOARD_CFG_AUX_ANALOG_IN_COUNT];

board_cfg_serial_t serial[BOARD_CFG_SERIAL_COUNT];

int8_t onewire_gpio;
bool onewire_temp_sensor : 1;
} board_config_t;
} board_cfg_t;

extern board_config_t board_config;
extern board_cfg_t board_config;

void board_config_load();
void board_config_load(void);

#endif /* BOARD_CONFIG_H_ */
#endif /* CONFIG_H_ */
Loading

0 comments on commit cab740f

Please sign in to comment.