# joeycastillo/sensor-watch architecture

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

- Interactive diagram: https://gitdiagram.com/joeycastillo/sensor-watch
- Repository: https://github.com/joeycastillo/sensor-watch

## Overview

##### Main Components

a. Hardware Layer:
- SAM L22 Microcontroller (Core Component)
- LCD Display Interface
- Button Interface (3 interrupt-capable buttons)
- LED Backlight System (Red/Green PWM)
- Optional Buzzer Interface
- USB Interface
- Sensor Board Connector (9-pin flex PCB)
- Power Management (CR2016 coin cell)

b. Software Layer:
- UF2 Bootloader
- Watch Library
- Movement Framework
- Application Layer
- Hardware Abstraction Layer (HAL)

##### Component Relationships

**[Hardware Layer]**
**┌─────────────────────────────────────────┐**
- Power Supply (CR2016)                   │
- ┬─────────────────────┬─┘

**┌─────────────────┴─────────────────────┴─┐**
- SAM L22 Microcontroller                  │
- ┬────────────┬───────────────┤
- LCD        │ Buttons    │ LED           │
- Controller │ Interface  │ Controller    │
- ┴────────────┴───────────────┘

**┌───────┴──────────┴────────────┴─────────┐**
- Hardware Abstraction Layer               │
- ┤
- Watch Library                           │
- ┤
- Movement Framework                      │
- ┤
- Applications                            │
- ┘

##### Interface Details

**[Sensor Board Interface]**
**┌─────────────────────┐**
- 3V Power            │
- ┤
- I²C (SCL/SDA)      │
- ┤
- GPIO/Analog (5 pins)│
- SPI             │
- UART            │
- PWM             │
- Wake inputs     │
- ┘

##### Important Notes

a. Modular nature of the sensor board interface
b. Dual-boot capability (main firmware and UF2 bootloader)
c. Different clock domains (32KHz RTC vs. main CPU clock)
d. Interrupt paths from buttons and sensor interfaces
e. Power domains and sleep mode capabilities

##### Additional Details

- Signal types (digital, analog, power)
- Communication protocols (I²C, SPI, UART)
- Power states
- Interrupt capabilities
- Memory regions (Flash, RAM, EEPROM emulation)

##### Applications (top)

Bidirectional data flow where appropriate, and mark critical paths for interrupts and wake signals.

This system design should capture both the hardware complexity and software architecture while maintaining clarity about how the components interact. The emphasis should be on the modular nature of the sensor board interface and the flexibility of the software framework.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Hardware
        PS[Power Supply CR2016]:::power
        SAML22[SAM L22 Microcontroller]:::core
        click SAML22 "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/hardware/include/saml22.h"
        
        LCD[LCD Controller]:::hw
        click LCD "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/hardware/watch/watch_slcd.c"
        
        BTN[Button Interface]:::hw
        click BTN "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/hardware/watch/watch_extint.c"
        
        LED[LED Controller]:::hw
        click LED "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/hardware/watch/watch_led.c"
        
        BUZ[Buzzer Interface]:::hw
        click BUZ "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/hardware/watch/watch_buzzer.c"
        
        USB[USB Interface]:::hw
        click USB "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/hardware/watch/watch_private_cdc.c"
        
        GPIO[GPIO Interface]:::hw
        click GPIO "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/hardware/watch/watch_gpio.c"
        
        RTC[Real-Time Clock]:::hw
        click RTC "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/hardware/watch/watch_rtc.c"
    end

    subgraph "Sensor Board Interface"
        SBI[9-Pin Flex PCB]:::interface
        click SBI "https://github.com/joeycastillo/sensor-watch/tree/main/watch-library/shared/driver/"
        
        PWR[3V Power]:::power
        I2C["I²C (SCL/SDA)"]:::interface
        GPIO_AN["GPIO/Analog (5 pins)"]:::interface
        
        subgraph "GPIO Capabilities"
            SPI[SPI]:::protocol
            UART[UART]:::protocol
            PWM[PWM]:::protocol
            WAKE[Wake Inputs]:::protocol
        end
    end

    subgraph "Software Stack"
        HAL[Hardware Abstraction Layer]:::software
        click HAL "https://github.com/joeycastillo/sensor-watch/tree/main/watch-library/hardware/hal/"
        
        WL[Watch Library]:::software
        click WL "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/shared/watch/watch.h"
        
        MF[Movement Framework]:::software
        click MF "https://github.com/joeycastillo/sensor-watch/blob/main/movement/movement.c"
        
        APP[Applications]:::software
        click APP "https://github.com/joeycastillo/sensor-watch/tree/main/apps/"
        
        PM[Power Management]:::software
        click PM "https://github.com/joeycastillo/sensor-watch/blob/main/watch-library/hardware/watch/watch_deepsleep.c"
        
        HD[Hardware Drivers]:::software
        click HD "https://github.com/joeycastillo/sensor-watch/tree/main/watch-library/hardware/watch/"
    end

    PS --> SAML22
    SAML22 --> |controls| LCD
    SAML22 --> |monitors| BTN
    SAML22 --> |drives| LED
    SAML22 --> |drives| BUZ
    SAML22 --> |connects| USB
    SAML22 --> |manages| GPIO
    SAML22 --> |syncs| RTC

    SBI --> PWR
    SBI --> I2C
    SBI --> GPIO_AN
    GPIO_AN --> SPI
    GPIO_AN --> UART
    GPIO_AN --> PWM
    GPIO_AN --> WAKE

    SAML22 --> HAL
    HAL --> WL
    WL --> MF
    MF --> APP
    HAL --> PM
    HAL --> HD

    classDef power fill:#ff6b6b,stroke:#333,stroke-width:2px
    classDef core fill:#4ecdc4,stroke:#333,stroke-width:2px
    classDef hw fill:#45b7d1,stroke:#333,stroke-width:2px
    classDef interface fill:#f7d794,stroke:#333,stroke-width:2px
    classDef protocol fill:#96c3eb,stroke:#333,stroke-width:2px
    classDef software fill:#96d38c,stroke:#333,stroke-width:2px

    %% Legend
    classDef legendBox fill:none,stroke:#333,stroke-width:2px
    subgraph Legend
        L1[Power Components]:::power
        L2[Core Components]:::core
        L3[Hardware Interfaces]:::hw
        L4[Board Interfaces]:::interface
        L5[Protocols]:::protocol
        L6[Software Components]:::software
    end
```
