# pvvx/zigbeetlc architecture

> Architecture diagram of the GitHub repository pvvx/zigbeetlc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pvvx/zigbeetlc
- Repository: https://github.com/pvvx/zigbeetlc

## Overview

This repository provides Telink-based Zigbee 3.0 sensor firmware, with optional BLE support, device-specific displays and sensors, and Zigbee OTA. The principal device workflow samples sensor and battery state, exposes measurements and settings through Zigbee clusters, and reports data to a coordinator; button actions and BLE commands provide local control and configuration. The graph also preserves documented display, reporting, persistence, and OTA capabilities. Evidence is limited to the supplied excerpts and README; links to unsampled firmware subsystems use documented relationships only.

Main entry points: [`src/app_EpCfg.c`](https://github.com/pvvx/zigbeetlc/blob/master/src/app_EpCfg.c) (Endpoint and clusters), [`src/app_main.c`](https://github.com/pvvx/zigbeetlc/blob/master/src/app_main.c) (Application loop), [`src/main.c`](https://github.com/pvvx/zigbeetlc/blob/master/src/main.c) (Firmware entry), [`src/sensor_th.c`](https://github.com/pvvx/zigbeetlc/blob/master/src/sensor_th.c) (Sensor drivers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Device runtime"]
  node_entry["Firmware entry<br/>[main.c]"]
  node_app["Application loop<br/>[app_main.c]"]
  node_inputs["Button handling<br/>[app_ui.c]"]
end

subgraph group_sensing["Sensing and display"]
  node_sensor["Sensor drivers<br/>[sensor_th.c]"]
  node_battery["Battery readings<br/>[battery.c]"]
  node_display["Device displays<br/>[lcd.h]"]
end

subgraph group_zigbee["Zigbee application"]
  node_zcl["Endpoint and clusters<br/>[app_EpCfg.c]"]
  node_callbacks["Zigbee callbacks<br/>[zcl_appCb.c]"]
  node_reporting["Measurement reporting<br/>[reporting.c]"]
  node_custom["Custom clusters"]
end

subgraph group_config["Configuration and updates"]
  node_ble["BLE command interface<br/>[cmd_parser.c]"]
  node_settings["Device settings<br/>[app_EpCfg.c]"]
  node_nv[("Nonvolatile settings<br/>[drv_nv.c]")]
  node_flash["Flash operations<br/>[flash.c]"]
  node_ota["Zigbee OTA handling<br/>[main.c]"]
  node_quirk["ZHA device quirk<br/>[zigbeetlc.py]"]
end

node_user(("Device user"))
node_coordinator(("Zigbee coordinator"))

node_entry -->|"runs"| node_app
node_entry -->|"converts OTA image"| node_ota
node_app -.->|"samples sensors"| node_sensor
node_app -.->|"reads battery"| node_battery
node_app -->|"polls buttons"| node_inputs
node_app -.->|"updates display"| node_display
node_sensor -.->|"supplies measurements"| node_zcl
node_battery -.->|"supplies battery state"| node_zcl
node_zcl -.->|"dispatches callbacks"| node_callbacks
node_zcl -->|"registers settings cluster"| node_custom
node_zcl -.->|"reports measurements"| node_reporting
node_reporting -->|"sends reports"| node_coordinator
node_coordinator -->|"configures attributes"| node_zcl
node_user -->|"presses button"| node_inputs
node_user -->|"sends commands"| node_ble
node_ble -->|"updates settings"| node_settings
node_settings -.->|"persists settings"| node_nv
node_nv -->|"reads and writes"| node_flash
node_coordinator -->|"delivers firmware"| node_ota
node_coordinator -.->|"uses device quirk"| node_quirk

click node_entry "https://github.com/pvvx/zigbeetlc/blob/master/src/main.c"
click node_app "https://github.com/pvvx/zigbeetlc/blob/master/src/app_main.c"
click node_inputs "https://github.com/pvvx/zigbeetlc/blob/master/src/app_ui.c"
click node_sensor "https://github.com/pvvx/zigbeetlc/blob/master/src/sensor_th.c"
click node_battery "https://github.com/pvvx/zigbeetlc/blob/master/src/battery.c"
click node_display "https://github.com/pvvx/zigbeetlc/blob/master/src/lcd.h"
click node_zcl "https://github.com/pvvx/zigbeetlc/blob/master/src/app_EpCfg.c"
click node_callbacks "https://github.com/pvvx/zigbeetlc/blob/master/src/zcl_appCb.c"
click node_reporting "https://github.com/pvvx/zigbeetlc/blob/master/src/reporting.c"
click node_custom "https://github.com/pvvx/zigbeetlc/blob/master/src/custom_zcl/zcl_thermostat_ui_cfg.c"
click node_ble "https://github.com/pvvx/zigbeetlc/blob/master/src/cmd_parser.c"
click node_settings "https://github.com/pvvx/zigbeetlc/blob/master/src/app_EpCfg.c"
click node_nv "https://github.com/pvvx/zigbeetlc/blob/master/src/patch_zb_sdk/drv_nv.c"
click node_flash "https://github.com/pvvx/zigbeetlc/blob/master/src/patch_zb_sdk/flash.c"
click node_ota "https://github.com/pvvx/zigbeetlc/blob/master/src/main.c"
click node_quirk "https://github.com/pvvx/zigbeetlc/blob/master/zhaquirks/custom/zigbeetlc.py"

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_entry,node_app,node_inputs,node_user toneBlue
class node_sensor,node_battery,node_display toneAmber
class node_zcl,node_callbacks,node_reporting,node_custom toneMint
class node_ble,node_settings,node_nv,node_flash,node_ota,node_quirk toneRose
class node_coordinator toneIndigo
```

## Components

### Device runtime

- [Firmware entry](https://github.com/pvvx/zigbeetlc/blob/master/src/main.c): `src/main.c`
- [Application loop](https://github.com/pvvx/zigbeetlc/blob/master/src/app_main.c): `src/app_main.c`
- [Button handling](https://github.com/pvvx/zigbeetlc/blob/master/src/app_ui.c): `src/app_ui.c`

### Sensing and display

- [Sensor drivers](https://github.com/pvvx/zigbeetlc/blob/master/src/sensor_th.c): `src/sensor_th.c`
- [Battery readings](https://github.com/pvvx/zigbeetlc/blob/master/src/battery.c): `src/battery.c`
- [Device displays](https://github.com/pvvx/zigbeetlc/blob/master/src/lcd.h): `src/lcd.h`

### Zigbee application

- [Endpoint and clusters](https://github.com/pvvx/zigbeetlc/blob/master/src/app_EpCfg.c): `src/app_EpCfg.c`
- [Zigbee callbacks](https://github.com/pvvx/zigbeetlc/blob/master/src/zcl_appCb.c): `src/zcl_appCb.c`
- [Measurement reporting](https://github.com/pvvx/zigbeetlc/blob/master/src/reporting.c): `src/reporting.c`
- [Custom clusters](https://github.com/pvvx/zigbeetlc/blob/master/src/custom_zcl/zcl_thermostat_ui_cfg.c): `src/custom_zcl/zcl_thermostat_ui_cfg.c`

### Configuration and updates

- [BLE command interface](https://github.com/pvvx/zigbeetlc/blob/master/src/cmd_parser.c): `src/cmd_parser.c`
- [Device settings](https://github.com/pvvx/zigbeetlc/blob/master/src/app_EpCfg.c): `src/app_EpCfg.c`
- [Nonvolatile settings](https://github.com/pvvx/zigbeetlc/blob/master/src/patch_zb_sdk/drv_nv.c): `src/patch_zb_sdk/drv_nv.c`
- [Flash operations](https://github.com/pvvx/zigbeetlc/blob/master/src/patch_zb_sdk/flash.c): `src/patch_zb_sdk/flash.c`
- [Zigbee OTA handling](https://github.com/pvvx/zigbeetlc/blob/master/src/main.c): `src/main.c`
- [ZHA device quirk](https://github.com/pvvx/zigbeetlc/blob/master/zhaquirks/custom/zigbeetlc.py): `zhaquirks/custom/zigbeetlc.py`

### Other components

- **Device user**
- **Zigbee coordinator**

## Connections

- Firmware entry → Application loop: runs (evidence: `src/main.c`)
- Firmware entry → Zigbee OTA handling: converts OTA image (evidence: `src/main.c`)
- Application loop → Sensor drivers: samples sensors
- Application loop → Battery readings: reads battery
- Application loop → Button handling: polls buttons
- Application loop → Device displays: updates display
- Sensor drivers → Endpoint and clusters: supplies measurements
- Battery readings → Endpoint and clusters: supplies battery state
- Endpoint and clusters → Zigbee callbacks: dispatches callbacks
- Endpoint and clusters → Custom clusters: registers settings cluster (evidence: `src/app_EpCfg.c`)
- Endpoint and clusters → Measurement reporting: reports measurements
- Measurement reporting → Zigbee coordinator: sends reports (evidence: `README.md`)
- Zigbee coordinator → Endpoint and clusters: configures attributes (evidence: `README.md`)
- Device user → Button handling: presses button (evidence: `README.md`)
- Device user → BLE command interface: sends commands (evidence: `src/cmd_parser.c`)
- BLE command interface → Device settings: updates settings (evidence: `src/cmd_parser.c`)
- Device settings → Nonvolatile settings: persists settings
- Nonvolatile settings → Flash operations: reads and writes (evidence: `src/patch_zb_sdk/drv_nv.c`)
- Zigbee coordinator → Zigbee OTA handling: delivers firmware (evidence: `README.md`)
- Zigbee coordinator → ZHA device quirk: uses device quirk
