# 0x1abin/multibutton architecture

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

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

## Overview

MultiButton is a compact embedded C library that turns sampled GPIO levels into debounced button events. The main workflow is application setup and callback registration, periodic timer-driven scanning, state-machine event detection, then callback handling or polling. The implementation confirms the scan, debounce, state transitions, linked-list management, and polling APIs; other documented capabilities such as configurable thresholds and optional RTOS locks are defined in the header.

Main entry points: [`multi_button.h`](https://github.com/0x1abin/multibutton/blob/master/multi_button.h) (Button state), [`multi_button.c`](https://github.com/0x1abin/multibutton/blob/master/multi_button.c) (Debounce and state machine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Application Setup"]
  node_init["Initialize button<br/>[multi_button.c]"]
  node_attach["Attach callbacks<br/>[multi_button.c]"]
  node_start["Start button<br/>[multi_button.c]"]
end

subgraph group_engine["Button Runtime"]
  node_button["Button state<br/>[multi_button.h]"]
  node_ticks["Tick dispatcher<br/>[multi_button.c]"]
  node_handler["Debounce and state machine<br/>[multi_button.c]"]
end

subgraph group_events["Event Consumption"]
  node_callbacks["Callback dispatch<br/>[multi_button.c]"]
  node_poll["Polling accessors<br/>[multi_button.c]"]
end

node_app(("Embedded application"))
node_timer(("Periodic timer"))
node_gpio(("GPIO reader"))
node_consumer(("Event consumer"))

node_app -->|"initializes"| node_init
node_init -->|"sets state"| node_button
node_app -->|"registers callbacks"| node_attach
node_attach -->|"stores callbacks"| node_button
node_app -->|"starts scanning"| node_start
node_start -->|"links handle"| node_button
node_timer -->|"invokes periodically"| node_ticks
node_ticks -->|"scans handles"| node_handler
node_handler -->|"reads pin level"| node_gpio
node_handler -->|"updates state"| node_button
node_handler -->|"dispatches events"| node_callbacks
node_callbacks -->|"invokes callback"| node_consumer
node_app -->|"requests event state"| node_poll
node_poll -->|"reads state"| node_button
node_poll -->|"returns event data"| node_consumer

click node_init "https://github.com/0x1abin/multibutton/blob/master/multi_button.c"
click node_attach "https://github.com/0x1abin/multibutton/blob/master/multi_button.c"
click node_start "https://github.com/0x1abin/multibutton/blob/master/multi_button.c"
click node_button "https://github.com/0x1abin/multibutton/blob/master/multi_button.h"
click node_ticks "https://github.com/0x1abin/multibutton/blob/master/multi_button.c"
click node_handler "https://github.com/0x1abin/multibutton/blob/master/multi_button.c"
click node_callbacks "https://github.com/0x1abin/multibutton/blob/master/multi_button.c"
click node_poll "https://github.com/0x1abin/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_init,node_attach,node_start toneBlue
class node_button,node_ticks,node_handler toneAmber
class node_callbacks,node_poll toneMint
class node_app,node_timer,node_gpio,node_consumer toneIndigo
```

## Components

### Application Setup

- [Initialize button](https://github.com/0x1abin/multibutton/blob/master/multi_button.c): `multi_button.c`
- [Attach callbacks](https://github.com/0x1abin/multibutton/blob/master/multi_button.c): `multi_button.c`
- [Start button](https://github.com/0x1abin/multibutton/blob/master/multi_button.c): `multi_button.c`

### Button Runtime

- [Button state](https://github.com/0x1abin/multibutton/blob/master/multi_button.h): `multi_button.h`
- [Tick dispatcher](https://github.com/0x1abin/multibutton/blob/master/multi_button.c): `multi_button.c`
- [Debounce and state machine](https://github.com/0x1abin/multibutton/blob/master/multi_button.c): `multi_button.c`

### Event Consumption

- [Callback dispatch](https://github.com/0x1abin/multibutton/blob/master/multi_button.c): `multi_button.c`
- [Polling accessors](https://github.com/0x1abin/multibutton/blob/master/multi_button.c): `multi_button.c`

### Other components

- **Embedded application**
- **Periodic timer**
- **GPIO reader**
- **Event consumer**

## Connections

- Embedded application → Initialize button: initializes
- Initialize button → Button state: sets state
- Embedded application → Attach callbacks: registers callbacks
- Attach callbacks → Button state: stores callbacks
- Embedded application → Start button: starts scanning
- Start button → Button state: links handle
- Periodic timer → Tick dispatcher: invokes periodically
- Tick dispatcher → Debounce and state machine: scans handles
- Debounce and state machine → GPIO reader: reads pin level
- Debounce and state machine → Button state: updates state
- Debounce and state machine → Callback dispatch: dispatches events
- Callback dispatch → Event consumer: invokes callback
- Embedded application → Polling accessors: requests event state
- Polling accessors → Button state: reads state
- Polling accessors → Event consumer: returns event data
