# eth-pbl/h-watch architecture

> Architecture diagram of the GitHub repository eth-pbl/h-watch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eth-pbl/h-watch
- Repository: https://github.com/eth-pbl/h-watch

## Overview

H-Watch is a low-power healthcare-monitoring wearable. Its intended user-to-result workflow is sensing physiological and motion/environmental signals, processing them on the watch, and providing tracked health information, with NB-IoT cloud connectivity documented by the README. The tree also contains two neural-network implementations: a TensorFlow Lite Micro STM32 template and FANN code. Firmware excerpts establish MCU initialization, while app excerpts show inference entry points are currently empty. Sensor-to-firmware and cloud data paths are therefore not asserted as verified calls.

Main entry points: [`Firmware/v1/Drivers`](https://github.com/eth-pbl/h-watch/tree/main/Firmware/v1/Drivers) (Sensor drivers), [`Firmware/v1/Core/Src/main.c`](https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Core/Src/main.c) (Watch control loop), [`ANN/FANN/FANN_test/main.c`](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/main.c) (FANN test inference), [`ANN/FANN/FANN_on_MCU/fann.c`](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_on_MCU/fann.c) (MCU FANN runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_watch["Watch firmware"]
  node_firmware["Watch control loop<br/>[main.c]"]
  node_display["Display output<br/>[Display.c]"]
end

subgraph group_sensing["Health sensing"]
  node_sensor_hub["Sensor drivers"]
  node_pulseox["Pulse oximeter<br/>[max3010x.c]"]
  node_spo2["SpO2 processing<br/>[spo2_algorithm.c]"]
  node_pressure["Pressure sensor<br/>[lps22hb_reg.c]"]
  node_compass["Compass sensor<br/>[lsm303agr_reg.c]"]
  node_imu["Motion sensor<br/>[lsm6dsm_reg.c]"]
end

subgraph group_inference["On-device inference"]
  node_tflite_main["Inference loop<br/>[app.cc]"]
  node_tflite_allocator["Tensor allocator<br/>[micro_allocator.cc]"]
end

subgraph group_fann["FANN networks"]
  node_fann_mcu["MCU FANN runtime<br/>[fann.c]"]
  node_fann_mcu_defs["MCU network model<br/>[fann_net.h]"]
  node_fann_mcu_types["MCU network types<br/>[fann_structs.h]"]
  node_fann_mcu_api["MCU FANN API<br/>[fann.h]"]
  node_fann_test_run["FANN test inference<br/>[main.c]"]
  node_fann_test_impl["Test FANN runtime<br/>[fann.c]"]
  node_fann_test_defs["Test network model<br/>[fann_net.h]"]
  node_fann_test_types["Test network types<br/>[fann_structs.h]"]
  node_fann_test_api["Test FANN API<br/>[fann.h]"]
end

subgraph group_platform["Cloud and hardware"]
  node_cloud(("NB-IoT cloud"))
end

node_user(("Watch user"))

node_user -.->|"uses"| node_firmware
node_firmware -.->|"updates"| node_display
node_firmware -.->|"reads sensors"| node_sensor_hub
node_sensor_hub -.->|"includes driver"| node_pulseox
node_sensor_hub -.->|"uses algorithm"| node_spo2
node_sensor_hub -.->|"includes driver"| node_pressure
node_sensor_hub -.->|"includes driver"| node_compass
node_sensor_hub -.->|"includes driver"| node_imu
node_firmware -.->|"uploads health data"| node_cloud
node_firmware -->|"calls setup and run"| node_tflite_main
node_tflite_main -.->|"uses interpreter"| node_tflite_allocator
node_fann_mcu -->|"reads model"| node_fann_mcu_defs
node_fann_mcu -->|"uses structures"| node_fann_mcu_types
node_fann_mcu -->|"includes API"| node_fann_mcu_api
node_fann_test_run -.->|"runs inference"| node_fann_test_impl
node_fann_test_run -->|"uses model"| node_fann_test_defs
node_fann_test_run -->|"uses structures"| node_fann_test_types
node_fann_test_run -->|"includes API"| node_fann_test_api

click node_firmware "https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Core/Src/main.c"
click node_display "https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Core/Src/Display.c"
click node_sensor_hub "https://github.com/eth-pbl/h-watch/tree/main/Firmware/v1/Drivers"
click node_pulseox "https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/max3010x/max3010x.c"
click node_spo2 "https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/max3010x/spo2_algorithm.c"
click node_pressure "https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/lps22hb_STdC/driver/lps22hb_reg.c"
click node_compass "https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/lsm303agr_STdC/driver/lsm303agr_reg.c"
click node_imu "https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/lsm6dsm_STdC/driver/lsm6dsm_reg.c"
click node_tflite_main "https://github.com/eth-pbl/h-watch/blob/main/ANN/tflite_micro_stm32wb55_template/App/app.cc"
click node_tflite_allocator "https://github.com/eth-pbl/h-watch/blob/main/ANN/tflite_micro_stm32wb55_template/TensorFlow/tensorflow/lite/micro/micro_allocator.cc"
click node_fann_mcu "https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_on_MCU/fann.c"
click node_fann_mcu_defs "https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_on_MCU/fann_net.h"
click node_fann_mcu_types "https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_on_MCU/fann_structs.h"
click node_fann_mcu_api "https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_on_MCU/fann.h"
click node_fann_test_run "https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/main.c"
click node_fann_test_impl "https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/fann.c"
click node_fann_test_defs "https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/fann_net.h"
click node_fann_test_types "https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/fann_structs.h"
click node_fann_test_api "https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/fann.h"

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_firmware,node_display,node_user toneBlue
class node_sensor_hub,node_pulseox,node_spo2,node_pressure,node_compass,node_imu toneAmber
class node_tflite_main,node_tflite_allocator toneMint
class node_fann_mcu,node_fann_mcu_defs,node_fann_mcu_types,node_fann_mcu_api,node_fann_test_run,node_fann_test_impl,node_fann_test_defs,node_fann_test_types,node_fann_test_api toneRose
class node_cloud toneIndigo
```

## Components

### Watch firmware

- [Watch control loop](https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Core/Src/main.c): `Firmware/v1/Core/Src/main.c`
- [Display output](https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Core/Src/Display.c): `Firmware/v1/Core/Src/Display.c`

### Health sensing

- [Sensor drivers](https://github.com/eth-pbl/h-watch/tree/main/Firmware/v1/Drivers): `Firmware/v1/Drivers`
- [Pulse oximeter](https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/max3010x/max3010x.c): `Firmware/v1/Drivers/max3010x/max3010x.c`
- [SpO2 processing](https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/max3010x/spo2_algorithm.c): `Firmware/v1/Drivers/max3010x/spo2_algorithm.c`
- [Pressure sensor](https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/lps22hb_STdC/driver/lps22hb_reg.c): `Firmware/v1/Drivers/lps22hb_STdC/driver/lps22hb_reg.c`
- [Compass sensor](https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/lsm303agr_STdC/driver/lsm303agr_reg.c): `Firmware/v1/Drivers/lsm303agr_STdC/driver/lsm303agr_reg.c`
- [Motion sensor](https://github.com/eth-pbl/h-watch/blob/main/Firmware/v1/Drivers/lsm6dsm_STdC/driver/lsm6dsm_reg.c): `Firmware/v1/Drivers/lsm6dsm_STdC/driver/lsm6dsm_reg.c`

### On-device inference

- [Inference loop](https://github.com/eth-pbl/h-watch/blob/main/ANN/tflite_micro_stm32wb55_template/App/app.cc): `ANN/tflite_micro_stm32wb55_template/App/app.cc`
- [Tensor allocator](https://github.com/eth-pbl/h-watch/blob/main/ANN/tflite_micro_stm32wb55_template/TensorFlow/tensorflow/lite/micro/micro_allocator.cc): `ANN/tflite_micro_stm32wb55_template/TensorFlow/tensorflow/lite/micro/micro_allocator.cc`

### FANN networks

- [MCU FANN runtime](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_on_MCU/fann.c): `ANN/FANN/FANN_on_MCU/fann.c`
- [MCU network model](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_on_MCU/fann_net.h): `ANN/FANN/FANN_on_MCU/fann_net.h`
- [MCU network types](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_on_MCU/fann_structs.h): `ANN/FANN/FANN_on_MCU/fann_structs.h`
- [MCU FANN API](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_on_MCU/fann.h): `ANN/FANN/FANN_on_MCU/fann.h`
- [FANN test inference](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/main.c): `ANN/FANN/FANN_test/main.c`
- [Test FANN runtime](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/fann.c): `ANN/FANN/FANN_test/fann.c`
- [Test network model](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/fann_net.h): `ANN/FANN/FANN_test/fann_net.h`
- [Test network types](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/fann_structs.h): `ANN/FANN/FANN_test/fann_structs.h`
- [Test FANN API](https://github.com/eth-pbl/h-watch/blob/main/ANN/FANN/FANN_test/fann.h): `ANN/FANN/FANN_test/fann.h`

### Cloud and hardware

- **NB-IoT cloud**

### Other components

- **Watch user**

## Connections

- Watch user → Watch control loop: uses (evidence: `README.md`)
- Watch control loop → Display output: updates
- Watch control loop → Sensor drivers: reads sensors
- Sensor drivers → Pulse oximeter: includes driver (evidence: `Firmware/v1/Drivers/max3010x/max3010x.c`)
- Sensor drivers → SpO2 processing: uses algorithm
- Sensor drivers → Pressure sensor: includes driver
- Sensor drivers → Compass sensor: includes driver (evidence: `Firmware/v1/Drivers/lsm303agr_STdC/driver/lsm303agr_reg.c`)
- Sensor drivers → Motion sensor: includes driver (evidence: `Firmware/v1/Drivers/lsm6dsm_STdC/driver/lsm6dsm_reg.c`)
- Watch control loop → NB-IoT cloud: uploads health data (evidence: `README.md`)
- Watch control loop → Inference loop: calls setup and run
- Inference loop → Tensor allocator: uses interpreter
- MCU FANN runtime → MCU network model: reads model (evidence: `ANN/FANN/FANN_on_MCU/fann.c`)
- MCU FANN runtime → MCU network types: uses structures (evidence: `ANN/FANN/FANN_on_MCU/fann.c`)
- MCU FANN runtime → MCU FANN API: includes API (evidence: `ANN/FANN/FANN_on_MCU/fann.c`)
- FANN test inference → Test FANN runtime: runs inference
- FANN test inference → Test network model: uses model (evidence: `ANN/FANN/FANN_test/main.c`)
- FANN test inference → Test network types: uses structures (evidence: `ANN/FANN/FANN_test/main.c`)
- FANN test inference → Test FANN API: includes API (evidence: `ANN/FANN/FANN_test/main.c`)
