# yectoprogirls-debug/emkiwear architecture

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

- Interactive diagram: https://gitdiagram.com/yectoprogirls-debug/emkiwear
- Repository: https://github.com/yectoprogirls-debug/emkiwear

## Overview

EMKIWEAR is ESP32-C6 watch firmware for detecting and classifying Parkinsonian resting tremor. Its main workflow samples the BMI270, calibrates and analyzes motion on-device, then presents the classification and sends results to a mobile app over BLE; the app synchronizes data to Firebase for clinician review. The graph also includes local five-minute summaries, controls, charging behavior, and raw FIFO streaming. Links between unsampled runtime modules rely on README descriptions; firmware-source excerpts do not expose the complete sampling task or all data handoffs.

Main entry points: [`main/main.c`](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/main.c) (Firmware startup), [`main/test_bmi270.c`](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/test_bmi270.c) (IMU monitoring task), [`main/ble_stream.c`](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/ble_stream.c) (BLE GATT streams), [`main/bmi270_esp32.c`](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/bmi270_esp32.c) (ESP32 sensor adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sensing["Sensing"]
  node_sensor_adapter["ESP32 sensor adapter<br/>[bmi270_esp32.c]"]
  node_bmi270_driver["BMI270 driver<br/>[bmi270.c]"]
  node_bmi2_core["BMI2 core API<br/>[bmi2.c]"]
  node_sampling_task["IMU monitoring task<br/>[test_bmi270.c]"]
  node_raw_fifo["Raw FIFO export<br/>[bmi270_esp32.c]"]
end

subgraph group_analysis["Signal analysis"]
  node_signal_blocks["Signal processing blocks<br/>[signal_proc.c]"]
  node_filter_coeffs["Filter coefficients"]
  node_tremor_analyzer["Tremor classifier<br/>[tremor.c]"]
end

subgraph group_device["Watch interface"]
  node_app_init["Firmware startup<br/>[main.c]"]
  node_display["Watch display<br/>[display.c]"]
  node_graphics["Display graphics<br/>[display_gfx.c]"]
  node_buttons["Screen button<br/>[buttons.c]"]
  node_charge["Charge detection<br/>[charge.c]"]
end

subgraph group_connectivity["Connectivity and records"]
  node_summary_store[("Periodic summaries<br/>[hourly_summary.c]")]
  node_ble_service["BLE GATT streams<br/>[ble_stream.c]"]
end

node_wearer(("Wearer"))
node_imu{{"BMI270 IMU"}}
node_app["Mobile app"]
node_firebase[("Firebase")]
node_clinician["Clinician dashboard"]

node_wearer -->|"wears"| node_imu
node_imu -->|"I2C samples"| node_sensor_adapter
node_sensor_adapter -->|"uses driver"| node_bmi270_driver
node_bmi270_driver -->|"uses core API"| node_bmi2_core
node_app_init -->|"initializes"| node_summary_store
node_app_init -->|"initializes"| node_display
node_app_init -->|"initializes"| node_buttons
node_app_init -->|"initializes"| node_charge
node_app_init -->|"starts"| node_ble_service
node_app_init -->|"starts task"| node_sampling_task
node_sampling_task -.->|"reads samples"| node_sensor_adapter
node_sampling_task -.->|"calibrates bias"| node_signal_blocks
node_sampling_task -.->|"analyzes windows"| node_tremor_analyzer
node_signal_blocks -->|"provides filters"| node_tremor_analyzer
node_filter_coeffs -->|"configures filters"| node_tremor_analyzer
node_sampling_task -.->|"feeds results"| node_summary_store
node_sampling_task -.->|"updates class"| node_display
node_display -->|"uses graphics"| node_graphics
node_buttons -->|"toggles power"| node_display
node_charge -->|"gates transmission"| node_ble_service
node_sensor_adapter -->|"reads FIFO"| node_raw_fifo
node_raw_fifo -.->|"streams raw batches"| node_ble_service
node_tremor_analyzer -.->|"publishes classification"| node_ble_service
node_summary_store -->|"serves pending records"| node_ble_service
node_ble_service -->|"sends BLE data"| node_app
node_app -->|"syncs records"| node_firebase
node_firebase -->|"provides records"| node_clinician

click node_app_init "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/main.c"
click node_sensor_adapter "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/bmi270_esp32.c"
click node_bmi270_driver "https://github.com/yectoprogirls-debug/emkiwear/blob/main/components/bmi270_api/bmi270.c"
click node_bmi2_core "https://github.com/yectoprogirls-debug/emkiwear/blob/main/components/bmi270_api/bmi2.c"
click node_sampling_task "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/test_bmi270.c"
click node_signal_blocks "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/signal_proc.c"
click node_filter_coeffs "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/emkiwear_filtros_coef.h"
click node_tremor_analyzer "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/tremor.c"
click node_summary_store "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/hourly_summary.c"
click node_ble_service "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/ble_stream.c"
click node_display "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/display.c"
click node_graphics "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/display_gfx.c"
click node_buttons "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/buttons.c"
click node_charge "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/charge.c"
click node_raw_fifo "https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/bmi270_esp32.c"

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_sensor_adapter,node_bmi270_driver,node_bmi2_core,node_sampling_task,node_raw_fifo toneBlue
class node_signal_blocks,node_filter_coeffs,node_tremor_analyzer,node_firebase toneAmber
class node_app_init,node_display,node_graphics,node_buttons,node_charge toneMint
class node_summary_store,node_ble_service toneRose
class node_wearer,node_imu,node_app,node_clinician toneIndigo
```

## Components

### Sensing

- [ESP32 sensor adapter](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/bmi270_esp32.c): `main/bmi270_esp32.c`
- [BMI270 driver](https://github.com/yectoprogirls-debug/emkiwear/blob/main/components/bmi270_api/bmi270.c): `components/bmi270_api/bmi270.c`
- [BMI2 core API](https://github.com/yectoprogirls-debug/emkiwear/blob/main/components/bmi270_api/bmi2.c): `components/bmi270_api/bmi2.c`
- [IMU monitoring task](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/test_bmi270.c): `main/test_bmi270.c`
- [Raw FIFO export](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/bmi270_esp32.c): `main/bmi270_esp32.c`

### Signal analysis

- [Signal processing blocks](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/signal_proc.c): `main/signal_proc.c`
- [Filter coefficients](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/emkiwear_filtros_coef.h): `main/emkiwear_filtros_coef.h`
- [Tremor classifier](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/tremor.c): `main/tremor.c`

### Watch interface

- [Firmware startup](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/main.c): `main/main.c`
- [Watch display](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/display.c): `main/display.c`
- [Display graphics](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/display_gfx.c): `main/display_gfx.c`
- [Screen button](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/buttons.c): `main/buttons.c`
- [Charge detection](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/charge.c): `main/charge.c`

### Connectivity and records

- [Periodic summaries](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/hourly_summary.c): `main/hourly_summary.c`
- [BLE GATT streams](https://github.com/yectoprogirls-debug/emkiwear/blob/main/main/ble_stream.c): `main/ble_stream.c`

### Other components

- **Wearer**
- **BMI270 IMU**
- **Mobile app**
- **Firebase**
- **Clinician dashboard**

## Connections

- Wearer → BMI270 IMU: wears (evidence: `README.md`)
- BMI270 IMU → ESP32 sensor adapter: I2C samples (evidence: `README.md`)
- ESP32 sensor adapter → BMI270 driver: uses driver (evidence: `main/bmi270_esp32.c`)
- BMI270 driver → BMI2 core API: uses core API
- Firmware startup → Periodic summaries: initializes (evidence: `main/main.c`)
- Firmware startup → Watch display: initializes (evidence: `main/main.c`)
- Firmware startup → Screen button: initializes (evidence: `main/main.c`)
- Firmware startup → Charge detection: initializes (evidence: `main/main.c`)
- Firmware startup → BLE GATT streams: starts (evidence: `main/main.c`)
- Firmware startup → IMU monitoring task: starts task (evidence: `main/main.c`)
- IMU monitoring task → ESP32 sensor adapter: reads samples
- IMU monitoring task → Signal processing blocks: calibrates bias
- IMU monitoring task → Tremor classifier: analyzes windows
- Signal processing blocks → Tremor classifier: provides filters (evidence: `main/tremor.c`)
- Filter coefficients → Tremor classifier: configures filters (evidence: `main/tremor.c`)
- IMU monitoring task → Periodic summaries: feeds results
- IMU monitoring task → Watch display: updates class
- Watch display → Display graphics: uses graphics (evidence: `main/display.c`)
- Screen button → Watch display: toggles power (evidence: `main/buttons.c`)
- Charge detection → BLE GATT streams: gates transmission (evidence: `main/charge.c`)
- ESP32 sensor adapter → Raw FIFO export: reads FIFO (evidence: `main/bmi270_esp32.c`)
- Raw FIFO export → BLE GATT streams: streams raw batches
- Tremor classifier → BLE GATT streams: publishes classification
- Periodic summaries → BLE GATT streams: serves pending records (evidence: `main/ble_stream.c`)
- BLE GATT streams → Mobile app: sends BLE data (evidence: `README.md`)
- Mobile app → Firebase: syncs records (evidence: `README.md`)
- Firebase → Clinician dashboard: provides records (evidence: `README.md`)
