9
9
#include < hal/spi_types.h>
10
10
11
11
#include " base_component.hpp"
12
+ #include " interrupt.hpp"
12
13
#include " led_strip.hpp"
13
14
#include " st7789.hpp"
14
15
@@ -17,6 +18,7 @@ namespace espp {
17
18
// / development board.
18
19
// /
19
20
// / The class provides access to the following features:
21
+ // / - Button (boot button)
20
22
// / - Display
21
23
// / - RGB LED
22
24
// /
@@ -26,6 +28,9 @@ namespace espp {
26
28
// / \snippet t_dongle_s3_example.cpp t-dongle-s3 example
27
29
class TDongleS3 : public BaseComponent {
28
30
public:
31
+ // / Alias for the button callback function
32
+ using button_callback_t = espp::Interrupt::event_callback_fn;
33
+
29
34
// / Alias for the pixel type used by the T-Dongle-S3 display
30
35
using Pixel = lv_color16_t ;
31
36
@@ -41,6 +46,23 @@ class TDongleS3 : public BaseComponent {
41
46
TDongleS3 (TDongleS3 &&) = delete ;
42
47
TDongleS3 &operator =(TDongleS3 &&) = delete ;
43
48
49
+ // / Get a reference to the interrupts
50
+ // / \return A reference to the interrupts
51
+ espp::Interrupt &interrupts ();
52
+
53
+ // ///////////////////////////////////////////////////////////////////////////
54
+ // Button
55
+ // ///////////////////////////////////////////////////////////////////////////
56
+
57
+ // / Initialize the button
58
+ // / \param callback The callback function to call when the button is pressed
59
+ // / \return true if the button was successfully initialized, false otherwise
60
+ bool initialize_button (const button_callback_t &callback = nullptr );
61
+
62
+ // / Get the button state
63
+ // / \return The button state (true = button pressed, false = button released)
64
+ bool button_state () const ;
65
+
44
66
// ///////////////////////////////////////////////////////////////////////////
45
67
// RGB LED
46
68
// ///////////////////////////////////////////////////////////////////////////
@@ -208,6 +230,32 @@ class TDongleS3 : public BaseComponent {
208
230
static constexpr gpio_num_t backlight_io = GPIO_NUM_38;
209
231
using DisplayDriver = espp::St7789;
210
232
233
+ // button (boot button)
234
+ static constexpr gpio_num_t button_io = GPIO_NUM_0; // active low
235
+
236
+ // Interrupts
237
+ espp::Interrupt::PinConfig button_interrupt_pin_{
238
+ .gpio_num = button_io,
239
+ .callback =
240
+ [this ](const auto &event) {
241
+ if (button_callback_) {
242
+ button_callback_ (event);
243
+ }
244
+ },
245
+ .active_level = espp::Interrupt::ActiveLevel::LOW,
246
+ .interrupt_type = espp::Interrupt::Type::ANY_EDGE,
247
+ .pullup_enabled = true };
248
+
249
+ // we'll only add each interrupt pin if the initialize method is called
250
+ espp::Interrupt interrupts_{
251
+ {.interrupts = {},
252
+ .task_config = {.name = " t-dongle-s3 interrupts" ,
253
+ .stack_size_bytes = CONFIG_T_DONGLE_S3_INTERRUPT_STACK_SIZE}}};
254
+
255
+ // button
256
+ std::atomic<bool > button_initialized_{false };
257
+ button_callback_t button_callback_{nullptr };
258
+
211
259
// led
212
260
std::shared_ptr<LedStrip> led_;
213
261
spi_bus_config_t led_spi_bus_config_;
0 commit comments