Refactor main loop touch flow and update docs
This commit is contained in:
24
README.md
24
README.md
@@ -21,13 +21,13 @@ The project now uses a **clean, event-driven architecture** perfect for building
|
||||
- ⚡ **Event-Driven**: Display only updates when input is received
|
||||
- 🔋 **Power Efficient**: Uses `__wfi()` to sleep between inputs (< 1mA idle)
|
||||
- 📄 **E-ink Optimized**: Minimizes screen refreshes for e-paper displays
|
||||
- 🎯 **Interrupt-Driven**: Touch and button handling via hardware interrupts
|
||||
- 🎯 **Hybrid Input**: IRQ wake-up plus active-touch sampling for smoother drag/move handling
|
||||
- 🧩 **Modular**: Clear separation of input processing, game logic, and rendering
|
||||
|
||||
### Architecture Highlights
|
||||
|
||||
```
|
||||
Interrupt → Set Flag → Wake CPU → Process Input → Update Game → Draw → Refresh → Sleep
|
||||
IRQ/Timer → Set Flag → Wake CPU → Process Input → Update Game → Draw → Refresh → Sleep
|
||||
```
|
||||
|
||||
**Before (Polling Loop):**
|
||||
@@ -45,14 +45,18 @@ while(1) {
|
||||
|
||||
**After (Reactive Template):**
|
||||
```cpp
|
||||
while(1) {
|
||||
__wfi(); // Sleep until interrupt
|
||||
|
||||
while (1) {
|
||||
bool stay_awake = pending_refresh || touch_event_down || (last_touch_time != 0);
|
||||
if (!stay_awake) {
|
||||
__wfi(); // Sleep until interrupt
|
||||
if (!has_pending_wake_source()) continue; // Ignore unrelated wake-ups
|
||||
}
|
||||
|
||||
InputEvent input = process_button_input(config);
|
||||
if (!input.valid) {
|
||||
input = process_touch_input(config, &last_touch_time);
|
||||
}
|
||||
|
||||
|
||||
if (input.valid && game_update(&game_state, input, config, &renderer)) {
|
||||
game_draw(&game_state, &renderer, &gui);
|
||||
refresh_screen(bit_buffer, display);
|
||||
@@ -534,7 +538,8 @@ The typical development workflow:
|
||||
**Interrupt not triggering:**
|
||||
- Verify `TOUCH_INT_PIN` is correctly defined
|
||||
- Check INT pin is pulled high (internal pull-up or external resistor)
|
||||
- Confirm touch controller is configured for interrupt mode
|
||||
- Confirm touch controller is configured for trigger/interrupt mode
|
||||
- Touch processing uses hybrid mode: IRQ wake-up plus active-session sampling while touch is down
|
||||
|
||||
### SD Card Issues
|
||||
|
||||
@@ -579,7 +584,7 @@ The code includes `printf()` statements for debugging touch, display, and SD car
|
||||
|
||||
For battery-powered projects:
|
||||
- E-Paper displays use almost no power when idle
|
||||
- Use `__wfi()` (Wait For Interrupt) to sleep between inputs
|
||||
- Use `__wfi()` (Wait For Interrupt) to sleep between event bursts
|
||||
- Disable TFT backlight when idle
|
||||
- Lower SPI/I2C baud rates to reduce power consumption
|
||||
|
||||
@@ -607,7 +612,8 @@ For battery-powered projects:
|
||||
### Touch Features
|
||||
- Multi-touch support (up to 2 points)
|
||||
- Coordinate transformation
|
||||
- Touch debouncing
|
||||
- Hybrid IRQ + active-session sampling
|
||||
- Touch debouncing with release hysteresis
|
||||
- Event types (press, lift, contact)
|
||||
|
||||
### SD Card Features
|
||||
|
||||
Reference in New Issue
Block a user