Misc

Data Storage

Handling of internal or external EEPROM to store device configuration.

Functions

void data_storage_write()

Store current charge controller data to EEPROM

void data_storage_read()

Restore charge controller data from EEPROM and write to variables in RAM

void data_storage_update()

Stores data to EEPROM every 6 hours (can be called regularly)

Hardware

Hardware-specific functions like timers, watchdog, bootloader.

Functions

void system_control()

DC/DC or PWM control loop (implemented in main.cpp)

void start_stm32_bootloader()

Reset device and start STM32 internal bootloader

void reset_device()

Reset device

void task_wdt_callback(int channel_id, void *user_data)

Callback for task watchdogs used in multiple threads

Helper

General helper functions.

Functions

static inline uint32_t uptime()

Framework-independent system uptime

Returns:

seconds since the system booted

inline void flags_set(uint32_t *field, uint32_t mask)

Sets one or more flags in given field

Parameters:
  • field – pointer to the field that will be manipulated

  • mask – a single flag or bitwise OR-ed flags

inline void flags_clear(uint32_t *field, uint32_t mask)

Clears one or more flags in the bit field

Parameters:
  • field – pointer to the field that will be manipulated

  • mask – a single flag or bitwise OR-ed flags

inline bool flags_check(uint32_t *field, uint32_t mask)

Queries one or more flags in the bit field

Parameters:
  • field – pointer to the field that will be manipulated

  • mask – a single flag or bitwise OR-ed

Returns:

true if any of the flags given in mask are set in the bit field

LEDs

Control of status LEDs with charlieplexing.

Provides higher-level access to different LEDs (e.g. blinking and flickering). Internally, charlieplexing is used for some boards to optimize power consumption and needed pin numbers.

Enums

enum [anonymous]

Values:

enumerator DT_FOREACH_CHILD
enum LedState

LED states

Values:

enumerator LED_STATE_OFF
enumerator LED_STATE_ON
enumerator LED_STATE_BLINK
enumerator LED_STATE_FLICKER
enum PinState

Pin states

Values:

enumerator PIN_LOW
enumerator PIN_HIGH
enumerator PIN_FLOAT

Functions

void leds_init(bool enabled)

Initialize LEDs (called at the beginning of leds_update_thread)

void leds_update_thread()

Main thread for LED control. Performs pin initializations and charlieplexing at 60 Hz

void leds_set_charging(bool enabled)

Enables/disables dedicated charging LED if existing or blinks SOC LED when solar power is coming in.

void leds_set(unsigned int led, bool enabled, int timeout)

Enables/disables LED

Parameters:
  • led – Number of LED in array defined in PCB configuration

  • enabled – LED is switched on if enabled is set to true

  • timeout – Defines for how long this state should be set (-1 for permanent setting)

void leds_on(unsigned int led, int timeout)

Enable LED

Parameters:
  • led – Number of LED in array defined in PCB configuration

  • timeout – Defines for how long this state should be set (-1 for permanent setting)

void leds_off(unsigned int led)

Disable LED

Parameters:

led – Number of LED in array defined in PCB configuration

void leds_blink(unsigned int led, int timeout)

Blink LED

Parameters:
  • led – Number of LED in array defined in PCB configuration

  • timeout – Defines for how long this state should be set (-1 for permanent setting)

void leds_flicker(unsigned int led, int timeout)

Flicker LED

Parameters:
  • led – Number of LED in array defined in PCB configuration

  • timeout – Defines for how long this state should be set (-1 for permanent setting)

void leds_update_1s()

Updates LED blink and timeout states, must be called every second

void leds_update_soc(int soc, bool load_off_low_soc)

Update SOC LED bar (if existing)

Parameters:
  • soc – SOC in percent

  • load_off_low_soc – Prevents showing two SOC LEDs if load is switched off because of low SOC

void leds_toggle_error()

Toggle between even and uneven LEDs switched on/off to create annoying flashing in case of an error.

Setup

Functions

void setup()

Perform some device setup tasks (currently only used in Zephyr)

Variables

DcBus lv_bus
PowerPort lv_terminal
DcBus hv_bus
PowerPort hv_terminal
Dcdc dcdc
PwmSwitch pwm_switch
PowerPort &bat_terminal
PowerPort &solar_terminal
PowerPort &grid_terminal
DeviceStatus dev_stat
Charger charger
BatConf bat_conf
BatConf bat_conf_user
LoadOutput load
LoadOutput usb_pwr
ThingSet ts
uint32_t timestamp