# aaronzhouciph/multibutton architecture

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

- Interactive diagram: https://gitdiagram.com/aaronzhouciph/multibutton
- Repository: https://github.com/aaronzhouciph/multibutton

## Overview

MultiButton is a small C library for debouncing button inputs and detecting press, click, repeat, and long-press events. The main workflow is: an application initializes and starts button instances, a periodic timer calls button_ticks(), and the library samples GPIO levels, filters changes, advances each instance’s state machine, and invokes registered callbacks. Applications can alternatively poll event and button state. The README documents these capabilities; the graph’s implementation links are limited to the sampled core source.

Main entry points: [`multi_button.c`](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c) (Tick Dispatcher), [`multi_button.h`](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.h) (Button Instance)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Instance Setup"]
  node_button["Button Instance<br/>[multi_button.h]"]
  node_init["Initialize Button<br/>[multi_button.c]"]
  node_callbacks["Callback Registry<br/>[multi_button.c]"]
end

subgraph group_runtime["Button Runtime"]
  node_worklist["Active Button List<br/>[multi_button.c]"]
  node_ticks["Tick Dispatcher<br/>[multi_button.c]"]
  node_fsm["Debounce And FSM<br/>[multi_button.c]"]
end

subgraph group_access["Events And Queries"]
  node_event_callbacks["Event Callbacks<br/>[multi_button.c]"]
  node_queries["Event And State Queries<br/>[multi_button.c]"]
end

node_app(("Application"))
node_gpio["GPIO Reader"]
node_timer(("Periodic Timer"))

node_app -->|"initializes"| node_init
node_init -->|"sets fields"| node_button
node_app -->|"registers handlers"| node_callbacks
node_app -->|"starts instance"| node_worklist
node_timer -->|"calls every 5ms"| node_ticks
node_ticks -->|"iterates"| node_worklist
node_ticks -->|"dispatches handler"| node_fsm
node_fsm -->|"reads level"| node_gpio
node_fsm -->|"invokes events"| node_event_callbacks
node_event_callbacks -->|"calls handler"| node_app
node_app -->|"polls state"| node_queries
node_queries -->|"reads fields"| node_button

click node_button "https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.h"
click node_init "https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c"
click node_callbacks "https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c"
click node_worklist "https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c"
click node_ticks "https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c"
click node_fsm "https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c"
click node_event_callbacks "https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c"
click node_queries "https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.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_button,node_init,node_callbacks toneBlue
class node_worklist,node_ticks,node_fsm toneAmber
class node_event_callbacks,node_queries toneMint
class node_app,node_gpio,node_timer toneIndigo
```

## Components

### Instance Setup

- [Button Instance](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.h): `multi_button.h`
- [Initialize Button](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c): `multi_button.c`
- [Callback Registry](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c): `multi_button.c`

### Button Runtime

- [Active Button List](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c): `multi_button.c`
- [Tick Dispatcher](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c): `multi_button.c`
- [Debounce And FSM](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c): `multi_button.c`

### Events And Queries

- [Event Callbacks](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c): `multi_button.c`
- [Event And State Queries](https://github.com/aaronzhouciph/multibutton/blob/master/multi_button.c): `multi_button.c`

### Other components

- **Application**
- **GPIO Reader**
- **Periodic Timer**

## Connections

- Application → Initialize Button: initializes (evidence: `README.md`)
- Initialize Button → Button Instance: sets fields (evidence: `multi_button.c`)
- Application → Callback Registry: registers handlers (evidence: `README.md`)
- Application → Active Button List: starts instance (evidence: `multi_button.c`)
- Periodic Timer → Tick Dispatcher: calls every 5ms (evidence: `README.md`)
- Tick Dispatcher → Active Button List: iterates (evidence: `multi_button.c`)
- Tick Dispatcher → Debounce And FSM: dispatches handler (evidence: `multi_button.c`)
- Debounce And FSM → GPIO Reader: reads level (evidence: `multi_button.c`)
- Debounce And FSM → Event Callbacks: invokes events (evidence: `multi_button.c`)
- Event Callbacks → Application: calls handler (evidence: `multi_button.c`)
- Application → Event And State Queries: polls state (evidence: `README.md`)
- Event And State Queries → Button Instance: reads fields (evidence: `multi_button.c`)
