VersaMCU/doc/01_matrix.md
2026-03-30 19:52:37 +02:00

46 lines
1.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Tasten-Matrix
**Dateien:** `hal/matrix.h`, `hal/matrix.cpp`, `config/pins.h`
## Hardware
5×5-Matrix mit externer 10-kΩ-Pullup-Beschaltung auf den COL-Leitungen (immer HIGH im Ruhezustand). Dioden zwischen Schalter-DO und ROW-Leitung (Anode = Schalter, Kathode = ROW) verhindern Geistertasten bei Mehrfachdrücken.
Scan-Prinzip: ROW LOW treiben → gedrückter Schalter zieht zugehörige COL durch Diode auf LOW.
## Scan-Logik
```
für jede ROW r:
ROW r → OUTPUT LOW
warte 10 µs (Einschwingen)
für jede COL c:
raw = (digitalRead(COL[c]) == LOW)
Debounce prüfen
ROW r → INPUT (hochohmig, Pullup-Freigabe)
```
ROW-Pins wechseln zwischen OUTPUT-LOW (während Scan) und INPUT (hochohmig) kein dauerhaftes LOW.
## Debounce
- **10 ms**, Software-seitig pro Taste
- Flanken-Erkennung: Zustandsänderung (raw) wird mit Timestamp notiert
- Erst nach 10 ms stabiler neuer Zustand wird `s_debounced` aktualisiert und der Callback aufgerufen
- Callback: `matrix_cb(key_id, pressed)``CEventQueue::push(KEY_DOWN / KEY_UP)`
## Key-ID-Berechnung
```cpp
key_id = col * MATRIX_ROWS + row
// col 04, row 04
// key_id 04: Encoder-SW (COL_0)
// key_id 524: MX-Buttons (COL_14)
```
## Kontext
- Läuft im Loop-Kontext (kein ISR)
- Encoder-SW-Tasten gehen durch denselben Matrix-Pfad (COL_0)
- `matrix_scan()` wird einmal pro `loop()` aufgerufen