# libresolar/charge-controller-firmware architecture

> Architecture diagram of the GitHub repository libresolar/charge-controller-firmware, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/libresolar/charge-controller-firmware
- Repository: https://github.com/libresolar/charge-controller-firmware

## Overview

Libre Solar Charge Controller Firmware is Zephyr-based embedded firmware for solar charging, battery protection, and DC power conversion. Its principal runtime workflow acquires electrical measurements, applies charger and converter control, and actuates power outputs while tracking device status and indicating state. README confirms the firmware product, while the sampled headers describe the DAQ and domain responsibilities. The source index shows the main runtime modules, but excerpts do not establish most call sites, so unverified runtime links are dashed.

Main entry points: [`app/src/main.cpp`](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/main.cpp) (Firmware runtime), [`app/src/daq.cpp`](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/daq.cpp) (Data acquisition), [`app/src/bat_charger.cpp`](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/bat_charger.cpp) (Battery charger), [`app/src/dcdc.cpp`](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/dcdc.cpp) (DC/DC control)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime coordination"]
  node_main["Firmware runtime<br/>[main.cpp]"]
  node_setup["Device setup<br/>[setup.cpp]"]
end

subgraph group_power["Power management"]
  node_charger["Battery charger<br/>[bat_charger.cpp]"]
  node_dcdc["DC/DC control<br/>[dcdc.cpp]"]
  node_port["Power ports<br/>[power_port.cpp]"]
  node_load["Load output<br/>[load.cpp]"]
  node_pwm["PWM switch<br/>[pwm_switch.cpp]"]
end

subgraph group_sensing["Sensing and actuation"]
  node_daq["Data acquisition<br/>[daq.cpp]"]
  node_bridge["Half bridge<br/>[half_bridge.c]"]
  node_daqdriver["DAQ driver<br/>[daq_driver.c]"]
  node_load_driver["Load driver<br/>[load_driver.c]"]
  node_pwm_driver["PWM driver"]
  node_hardware["Board hardware<br/>[hardware.cpp]"]
end

subgraph group_state["Status and interface"]
  node_objects["Data objects<br/>[data_objects.cpp]"]
  node_status["Device status<br/>[device_status.cpp]"]
  node_leds["Status LEDs<br/>[leds.cpp]"]
  node_display["OLED display<br/>[oled.cpp]"]
end

node_sun(("Solar input"))

node_sun -.->|"supplies measurements"| node_daq
node_main -.->|"initializes runtime"| node_setup
node_main -.->|"updates measurements"| node_daq
node_daq -.->|"provides measurements"| node_charger
node_daq -.->|"provides measurements"| node_dcdc
node_main -.->|"runs charge control"| node_charger
node_charger -.->|"controls battery port"| node_port
node_main -.->|"runs converter control"| node_dcdc
node_dcdc -.->|"sets PWM"| node_bridge
node_main -.->|"runs load control"| node_load
node_load -.->|"switches output"| node_load_driver
node_main -.->|"runs switch control"| node_pwm
node_pwm -.->|"drives switch"| node_pwm_driver
node_main -.->|"updates data objects"| node_objects
node_main -.->|"updates status"| node_status
node_main -.->|"initializes hardware"| node_hardware
node_main -.->|"updates indicators"| node_leds
node_main -.->|"updates display"| node_display

click node_main "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/main.cpp"
click node_setup "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/setup.cpp"
click node_daq "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/daq.cpp"
click node_charger "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/bat_charger.cpp"
click node_dcdc "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/dcdc.cpp"
click node_port "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/power_port.cpp"
click node_load "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/load.cpp"
click node_pwm "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/pwm_switch.cpp"
click node_bridge "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/half_bridge.c"
click node_daqdriver "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/daq_driver.c"
click node_load_driver "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/load_driver.c"
click node_pwm_driver "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/pwm_switch_driver.c"
click node_hardware "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/hardware.cpp"
click node_objects "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/data_objects.cpp"
click node_status "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/device_status.cpp"
click node_leds "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/leds.cpp"
click node_display "https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/oled.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_setup toneBlue
class node_charger,node_dcdc,node_port,node_load,node_pwm toneAmber
class node_daq,node_bridge,node_daqdriver,node_load_driver,node_pwm_driver,node_hardware toneMint
class node_objects,node_status,node_leds,node_display toneRose
class node_sun toneIndigo
```

## Components

### Runtime coordination

- [Firmware runtime](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/main.cpp): `app/src/main.cpp`
- [Device setup](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/setup.cpp): `app/src/setup.cpp`

### Power management

- [Battery charger](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/bat_charger.cpp): `app/src/bat_charger.cpp`
- [DC/DC control](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/dcdc.cpp): `app/src/dcdc.cpp`
- [Power ports](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/power_port.cpp): `app/src/power_port.cpp`
- [Load output](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/load.cpp): `app/src/load.cpp`
- [PWM switch](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/pwm_switch.cpp): `app/src/pwm_switch.cpp`

### Sensing and actuation

- [Data acquisition](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/daq.cpp): `app/src/daq.cpp`
- [Half bridge](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/half_bridge.c): `app/src/half_bridge.c`
- [DAQ driver](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/daq_driver.c): `app/src/daq_driver.c`
- [Load driver](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/load_driver.c): `app/src/load_driver.c`
- [PWM driver](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/pwm_switch_driver.c): `app/src/pwm_switch_driver.c`
- [Board hardware](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/hardware.cpp): `app/src/hardware.cpp`

### Status and interface

- [Data objects](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/data_objects.cpp): `app/src/data_objects.cpp`
- [Device status](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/device_status.cpp): `app/src/device_status.cpp`
- [Status LEDs](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/leds.cpp): `app/src/leds.cpp`
- [OLED display](https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/oled.cpp): `app/src/oled.cpp`

### Other components

- **Solar input**

## Connections

- Solar input → Data acquisition: supplies measurements
- Firmware runtime → Device setup: initializes runtime
- Firmware runtime → Data acquisition: updates measurements
- Data acquisition → Battery charger: provides measurements
- Data acquisition → DC/DC control: provides measurements
- Firmware runtime → Battery charger: runs charge control
- Battery charger → Power ports: controls battery port
- Firmware runtime → DC/DC control: runs converter control
- DC/DC control → Half bridge: sets PWM
- Firmware runtime → Load output: runs load control
- Load output → Load driver: switches output
- Firmware runtime → PWM switch: runs switch control
- PWM switch → PWM driver: drives switch
- Firmware runtime → Data objects: updates data objects
- Firmware runtime → Device status: updates status
- Firmware runtime → Board hardware: initializes hardware
- Firmware runtime → Status LEDs: updates indicators
- Firmware runtime → OLED display: updates display
