@@ -34,15 +34,19 @@ namespace espp {
34
34
// / - Display
35
35
// / - Audio
36
36
// / - Interrupts
37
+ // / - Buttons (boot and mute)
37
38
// / - I2C
38
- // / - IMU (Inertial Measurement Unit)
39
+ // / - IMU (Inertial Measurement Unit), 6-axis ICM42607
39
40
// /
40
41
// / The class is a singleton and can be accessed using the get() method.
41
42
// /
42
43
// / \section esp_box_example Example
43
44
// / \snippet esp_box_example.cpp esp box example
44
45
class EspBox : public BaseComponent {
45
46
public:
47
+ // / Alias for the button callback function
48
+ using button_callback_t = espp::Interrupt::event_callback_fn;
49
+
46
50
// / Alias for the pixel type used by the ESP-Box display
47
51
using Pixel = lv_color16_t ;
48
52
@@ -233,6 +237,28 @@ class EspBox : public BaseComponent {
233
237
// / if there is an ongoing SPI transaction
234
238
void write_lcd_lines (int xs, int ys, int xe, int ye, const uint8_t *data, uint32_t user_data);
235
239
240
+ // ///////////////////////////////////////////////////////////////////////////
241
+ // Button
242
+ // ///////////////////////////////////////////////////////////////////////////
243
+
244
+ // / Initialize the boot button (side of the box)
245
+ // / \param callback The callback function to call when the button is pressed
246
+ // / \return true if the button was successfully initialized, false otherwise
247
+ bool initialize_boot_button (const button_callback_t &callback = nullptr );
248
+
249
+ // / Get the boot button state
250
+ // / \return The button state (true = button pressed, false = button released)
251
+ bool boot_button_state () const ;
252
+
253
+ // / Initialize the mute button (top of the box)
254
+ // / \param callback The callback function to call when the button is pressed
255
+ // / \return true if the button was successfully initialized, false otherwise
256
+ bool initialize_mute_button (const button_callback_t &callback = nullptr );
257
+
258
+ // / Get the mute button state
259
+ // / \return The button state (true = button pressed, false = button released)
260
+ bool mute_button_state () const ;
261
+
236
262
// ///////////////////////////////////////////////////////////////////////////
237
263
// Audio
238
264
// ///////////////////////////////////////////////////////////////////////////
@@ -351,6 +377,9 @@ class EspBox : public BaseComponent {
351
377
bool touch_interrupt_pullup_enabled;
352
378
353
379
// common:
380
+ // button (boot button)
381
+ static constexpr gpio_num_t boot_button_io = GPIO_NUM_0; // active low
382
+
354
383
// internal i2c (touchscreen, audio codec)
355
384
static constexpr auto internal_i2c_port = I2C_NUM_0;
356
385
static constexpr auto internal_i2c_clock_speed = 400 * 1000 ;
@@ -408,6 +437,29 @@ class EspBox : public BaseComponent {
408
437
.sda_pullup_en = GPIO_PULLUP_ENABLE,
409
438
.scl_pullup_en = GPIO_PULLUP_ENABLE}};
410
439
440
+ espp::Interrupt::PinConfig boot_button_interrupt_pin_{
441
+ .gpio_num = boot_button_io,
442
+ .callback =
443
+ [this ](const auto &event) {
444
+ if (boot_button_callback_) {
445
+ boot_button_callback_ (event);
446
+ }
447
+ },
448
+ .active_level = espp::Interrupt::ActiveLevel::LOW,
449
+ .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
450
+ .pullup_enabled = true };
451
+ espp::Interrupt::PinConfig mute_button_interrupt_pin_{
452
+ .gpio_num = mute_pin,
453
+ .callback =
454
+ [this ](const auto &event) {
455
+ mute (event.active );
456
+ if (mute_button_callback_) {
457
+ mute_button_callback_ (event);
458
+ }
459
+ },
460
+ .active_level = espp::Interrupt::ActiveLevel::LOW,
461
+ .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
462
+ .pullup_enabled = true };
411
463
// NOTE: the active level, interrupt type, and pullup configuration is set by
412
464
// detect(), since it depends on the box type
413
465
espp::Interrupt::PinConfig touch_interrupt_pin_{
@@ -430,6 +482,12 @@ class EspBox : public BaseComponent {
430
482
.task_config = {.name = " esp-box interrupts" ,
431
483
.stack_size_bytes = CONFIG_ESP_BOX_INTERRUPT_STACK_SIZE}}};
432
484
485
+ // button
486
+ std::atomic<bool > boot_button_initialized_{false };
487
+ button_callback_t boot_button_callback_{nullptr };
488
+ std::atomic<bool > mute_button_initialized_{false };
489
+ button_callback_t mute_button_callback_{nullptr };
490
+
433
491
// touch
434
492
std::shared_ptr<Gt911> gt911_; // only used on ESP32-S3-BOX-3
435
493
std::shared_ptr<Tt21100> tt21100_; // only used on ESP32-S3-BOX
@@ -451,6 +509,7 @@ class EspBox : public BaseComponent {
451
509
uint8_t *frame_buffer1_{nullptr };
452
510
453
511
// sound
512
+ std::atomic<bool > sound_initialized_{false };
454
513
std::atomic<float > volume_{50 .0f };
455
514
std::atomic<bool > mute_{false };
456
515
std::unique_ptr<espp::Task> audio_task_{nullptr };
0 commit comments