@geastack/targets 0.1.106 → 0.1.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-config.json +73 -0
- package/package.json +7 -7
- package/targets/esp32/chip_bindings/displays/sh8601.cpp +12 -2
- package/targets/esp32/chip_bindings/imu/qmi8658.cpp +10 -3
- package/targets/esp32/chip_bindings/power/axp2101.cpp +58 -0
- package/targets/esp32/chip_bindings/touch/cst9217.cpp +26 -23
- package/targets/esp32/connectivity/wifi.cpp +30 -2
- package/targets/esp32/gea_board_buttons.cmake +13 -0
- package/targets/esp32/gpio.cpp +124 -1
- package/targets/esp32/gpio_pins.h +17 -0
- package/targets/esp32/services/buttons.cpp +185 -0
- package/targets/esp32/services/buttons.h +46 -0
- package/targets/esp32/services/device_control.cpp +28 -0
- package/targets/esp32-s3-touch-amoled-1.75c/CMakeLists.txt +11 -0
- package/targets/esp32-s3-touch-amoled-1.75c/main/CMakeLists.txt +54 -0
- package/targets/esp32-s3-touch-amoled-1.75c/main/Kconfig.projbuild +12 -0
- package/targets/esp32-s3-touch-amoled-1.75c/main/gea-dependencies.json +42 -0
- package/targets/esp32-s3-touch-amoled-1.75c/main/idf_component.yml +10 -0
- package/targets/esp32-s3-touch-amoled-1.75c/main/include/board.h +113 -0
- package/targets/esp32-s3-touch-amoled-1.75c/partitions.csv +9 -0
- package/targets/esp32-s3-touch-amoled-1.75c/sdkconfig.defaults +279 -0
- package/targets/esp32-s3-touch-amoled-1.8/main/CMakeLists.txt +10 -1
- package/targets/esp32-s3-touch-amoled-1.8/main/app_main.cpp +2 -0
- package/targets/esp32-s3-touch-amoled-2.06/main/CMakeLists.txt +13 -0
- package/targets/esp32-s3-touch-amoled-2.06/main/app_main.cpp +2 -0
- package/targets/esp32-s3-touch-amoled-2.06/sdkconfig.defaults +5 -3
- package/targets/esp32-s3-touch-lcd-3.49/CMakeLists.txt +11 -0
- package/targets/esp32-s3-touch-lcd-3.49/main/CMakeLists.txt +82 -0
- package/targets/esp32-s3-touch-lcd-3.49/main/Kconfig.projbuild +12 -0
- package/targets/esp32-s3-touch-lcd-3.49/main/gea-dependencies.json +42 -0
- package/targets/esp32-s3-touch-lcd-3.49/main/idf_component.yml +8 -0
- package/targets/esp32-s3-touch-lcd-3.49/main/include/axs15231b_panel_init.h +9 -0
- package/targets/esp32-s3-touch-lcd-3.49/main/include/board.h +160 -0
- package/targets/esp32-s3-touch-lcd-3.49/main/panel_reset.cpp +93 -0
- package/targets/esp32-s3-touch-lcd-3.49/main/power.cpp +60 -0
- package/targets/esp32-s3-touch-lcd-3.49/main/touch.cpp +327 -0
- package/targets/esp32-s3-touch-lcd-3.49/partitions.csv +7 -0
- package/targets/esp32-s3-touch-lcd-3.49/sdkconfig.defaults +279 -0
- package/targets.json +60 -1
package/build-config.json
CHANGED
|
@@ -458,6 +458,39 @@
|
|
|
458
458
|
},
|
|
459
459
|
"supported": []
|
|
460
460
|
},
|
|
461
|
+
"esp32-s3-touch-amoled-1.75c": {
|
|
462
|
+
"supported": [
|
|
463
|
+
"compiler.generatedCodeOptimization",
|
|
464
|
+
"renderer.fuseReplayFlush",
|
|
465
|
+
"renderer.adaptiveCoalescing",
|
|
466
|
+
"renderer.broadDirtyBounds",
|
|
467
|
+
"display.framebufferStream",
|
|
468
|
+
"display.presentStream"
|
|
469
|
+
],
|
|
470
|
+
"defaults": {
|
|
471
|
+
"compiler": {
|
|
472
|
+
"generatedCodeOptimization": "Os",
|
|
473
|
+
"numberPrecision": "float64"
|
|
474
|
+
},
|
|
475
|
+
"renderer": {
|
|
476
|
+
"fuseReplayFlush": false,
|
|
477
|
+
"subtreeRevealChecks": true,
|
|
478
|
+
"recordInlinePositions": true,
|
|
479
|
+
"adaptiveCoalescing": false,
|
|
480
|
+
"broadDirtyBounds": false
|
|
481
|
+
},
|
|
482
|
+
"display": {
|
|
483
|
+
"framebufferStream": "independent",
|
|
484
|
+
"presentStream": "independent"
|
|
485
|
+
},
|
|
486
|
+
"diagnostics": {
|
|
487
|
+
"performanceCounters": true,
|
|
488
|
+
"frameTiming": true
|
|
489
|
+
}
|
|
490
|
+
},
|
|
491
|
+
"cssDevicePixelRatio": 1.5,
|
|
492
|
+
"constraints": {}
|
|
493
|
+
},
|
|
461
494
|
"esp32-s3-epaper-1.54": {
|
|
462
495
|
"cssDevicePixelRatio": 1,
|
|
463
496
|
"supported": []
|
|
@@ -549,6 +582,46 @@
|
|
|
549
582
|
]
|
|
550
583
|
}
|
|
551
584
|
},
|
|
585
|
+
"esp32-s3-touch-lcd-3.49": {
|
|
586
|
+
"supported": [
|
|
587
|
+
"compiler.generatedCodeOptimization",
|
|
588
|
+
"renderer.fuseReplayFlush",
|
|
589
|
+
"renderer.adaptiveCoalescing",
|
|
590
|
+
"renderer.broadDirtyBounds",
|
|
591
|
+
"display.framebufferStream",
|
|
592
|
+
"display.presentStream"
|
|
593
|
+
],
|
|
594
|
+
"defaults": {
|
|
595
|
+
"compiler": {
|
|
596
|
+
"generatedCodeOptimization": "Os",
|
|
597
|
+
"numberPrecision": "float64"
|
|
598
|
+
},
|
|
599
|
+
"renderer": {
|
|
600
|
+
"fuseReplayFlush": false,
|
|
601
|
+
"subtreeRevealChecks": true,
|
|
602
|
+
"recordInlinePositions": true,
|
|
603
|
+
"adaptiveCoalescing": false,
|
|
604
|
+
"broadDirtyBounds": false
|
|
605
|
+
},
|
|
606
|
+
"display": {
|
|
607
|
+
"framebufferStream": "independent",
|
|
608
|
+
"presentStream": "independent"
|
|
609
|
+
},
|
|
610
|
+
"diagnostics": {
|
|
611
|
+
"performanceCounters": true,
|
|
612
|
+
"frameTiming": true
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
"cssDevicePixelRatio": 1,
|
|
616
|
+
"constraints": {
|
|
617
|
+
"display.framebufferStream": [
|
|
618
|
+
"independent"
|
|
619
|
+
],
|
|
620
|
+
"renderer.fuseReplayFlush": [
|
|
621
|
+
false
|
|
622
|
+
]
|
|
623
|
+
}
|
|
624
|
+
},
|
|
552
625
|
"esp32-s31-espressif-mosaico": {
|
|
553
626
|
"supported": [
|
|
554
627
|
"compiler.generatedCodeOptimization",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/targets",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.108",
|
|
4
4
|
"description": "Native embedded build targets (ESP32-IDF, RP2350) for geastack apps: board sources, target catalog, and CMake glue driven by the gea CLI.",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@geastack/chips": "^0.1.
|
|
40
|
-
"@geastack/compiler": "^1.0.
|
|
41
|
-
"@geastack/core": "0.1.
|
|
39
|
+
"@geastack/chips": "^0.1.7",
|
|
40
|
+
"@geastack/compiler": "^1.0.41",
|
|
41
|
+
"@geastack/core": "0.1.49",
|
|
42
42
|
"@geastack/elements": "^0.1.6",
|
|
43
|
-
"@geastack/engine": "^0.1.
|
|
43
|
+
"@geastack/engine": "^0.1.20",
|
|
44
44
|
"@geastack/geaos": "^0.1.3",
|
|
45
|
-
"@geastack/geatsc-plugin-gea": "0.1.
|
|
46
|
-
"@geastack/host": "0.1.
|
|
45
|
+
"@geastack/geatsc-plugin-gea": "0.1.26",
|
|
46
|
+
"@geastack/host": "0.1.22"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"test": "for f in $(git ls-files | grep -E '(^|/)(test[-_][^/]*|[^/]*\\.test)\\.mjs$'); do echo \"==> $f\"; node \"$f\" || exit 1; done"
|
|
@@ -87,7 +87,10 @@ namespace gea::platform::esp32::chip_bindings::sh8601
|
|
|
87
87
|
timer.speed_mode = kBacklightSpeedMode;
|
|
88
88
|
timer.duty_resolution = LEDC_TIMER_8_BIT;
|
|
89
89
|
timer.timer_num = kBacklightTimer;
|
|
90
|
-
|
|
90
|
+
// Waveshare's own AXS15231B boards run the backlight at 50 kHz. At a
|
|
91
|
+
// low kHz rate the switching edges couple into the touch sensor, which
|
|
92
|
+
// then reports phantom contacts along one sense line.
|
|
93
|
+
timer.freq_hz = 50000;
|
|
91
94
|
timer.clk_cfg = LEDC_AUTO_CLK;
|
|
92
95
|
ESP_RETURN_ON_ERROR(ledc_timer_config(&timer), kTag, "configure backlight timer failed");
|
|
93
96
|
|
|
@@ -98,12 +101,19 @@ namespace gea::platform::esp32::chip_bindings::sh8601
|
|
|
98
101
|
channel.timer_sel = kBacklightTimer;
|
|
99
102
|
channel.duty = 0;
|
|
100
103
|
channel.hpoint = 0;
|
|
104
|
+
#if GEA_EMBEDDED_AXS15231B_BACKLIGHT_ACTIVE_LOW
|
|
105
|
+
// Driven through a PMOS high-side switch (Waveshare 3.49): duty counts
|
|
106
|
+
// the low time, so invert the output to keep duty 0 = dark.
|
|
107
|
+
channel.flags.output_invert = 1;
|
|
108
|
+
#endif
|
|
101
109
|
return ledc_channel_config(&channel);
|
|
102
110
|
}
|
|
103
111
|
|
|
104
112
|
esp_err_t setBacklightDuty(int brightnessPercent)
|
|
105
113
|
{
|
|
106
|
-
|
|
114
|
+
// An 8-bit channel's full scale is 256, not 255: 255 still leaves one
|
|
115
|
+
// switching edge per period, so full brightness would never be steady.
|
|
116
|
+
const std::uint32_t duty = static_cast<std::uint32_t>((brightnessPercent * 256) / 100);
|
|
107
117
|
ESP_RETURN_ON_ERROR(ledc_set_duty(kBacklightSpeedMode, kBacklightChannel, duty), kTag, "set backlight duty failed");
|
|
108
118
|
return ledc_update_duty(kBacklightSpeedMode, kBacklightChannel);
|
|
109
119
|
}
|
|
@@ -20,6 +20,10 @@ constexpr char kTag[] = "qmi8658";
|
|
|
20
20
|
constexpr int kI2cTimeoutMs = 100;
|
|
21
21
|
constexpr int64_t kRetryIntervalUs = 30000000;
|
|
22
22
|
constexpr double kStandardGravity = 9.80665;
|
|
23
|
+
#ifndef GEA_EMBEDDED_IMU_INVERT_X
|
|
24
|
+
#define GEA_EMBEDDED_IMU_INVERT_X 0
|
|
25
|
+
#endif
|
|
26
|
+
constexpr int kXSign = GEA_EMBEDDED_IMU_INVERT_X ? -1 : 1;
|
|
23
27
|
constexpr std::uint8_t kProbeAddresses[] = {
|
|
24
28
|
gea::chips::qmi8658::kI2cAddress,
|
|
25
29
|
0x6A,
|
|
@@ -114,12 +118,15 @@ public:
|
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
void calibrateBias() { std::lock_guard<std::mutex> lock(mutex_); if (ensureInitialized()) driver_.calibrateBias(); }
|
|
117
|
-
|
|
121
|
+
// A board whose QMI8658 sits mirrored along the screen's horizontal axis
|
|
122
|
+
// (the AMOLED 1.75C) sets GEA_EMBEDDED_IMU_INVERT_X, which flips every
|
|
123
|
+
// X-axis reading -- tilt, acceleration and rotation -- into screen terms.
|
|
124
|
+
int tiltX() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? kXSign * driver_.tiltX() : 0; }
|
|
118
125
|
int tiltY() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? driver_.tiltY() : 0; }
|
|
119
|
-
double accelerationX() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? driver_.accelerationX() : 0.0; }
|
|
126
|
+
double accelerationX() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? kXSign * driver_.accelerationX() : 0.0; }
|
|
120
127
|
double accelerationY() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? driver_.accelerationY() : 0.0; }
|
|
121
128
|
double accelerationZ() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? driver_.accelerationZ() : kStandardGravity; }
|
|
122
|
-
double gyroscopeX() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? driver_.gyroscopeX() : 0.0; }
|
|
129
|
+
double gyroscopeX() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? kXSign * driver_.gyroscopeX() : 0.0; }
|
|
123
130
|
double gyroscopeY() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? driver_.gyroscopeY() : 0.0; }
|
|
124
131
|
double gyroscopeZ() { std::lock_guard<std::mutex> lock(mutex_); return ensureInitialized() ? driver_.gyroscopeZ() : 0.0; }
|
|
125
132
|
|
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
#include "driver/i2c_master.h"
|
|
17
17
|
#include "esp_err.h"
|
|
18
18
|
#include "esp_log.h"
|
|
19
|
+
#include "freertos/FreeRTOS.h"
|
|
20
|
+
#include "freertos/task.h"
|
|
21
|
+
#if GEA_BOARD_HAS_BUTTONS
|
|
22
|
+
#include "input.h"
|
|
23
|
+
#include "services/buttons.h"
|
|
24
|
+
#endif
|
|
19
25
|
|
|
20
26
|
namespace {
|
|
21
27
|
|
|
@@ -155,6 +161,9 @@ public:
|
|
|
155
161
|
initialized_ = pmu_.begin();
|
|
156
162
|
if (initialized_) ESP_LOGI(kTag, "measurement channels enabled");
|
|
157
163
|
else ESP_LOGE(kTag, "measurement channel enable failed");
|
|
164
|
+
#if GEA_BOARD_HAS_BUTTONS
|
|
165
|
+
if (initialized_) startPowerKey();
|
|
166
|
+
#endif
|
|
158
167
|
return initialized_;
|
|
159
168
|
}
|
|
160
169
|
|
|
@@ -166,6 +175,55 @@ public:
|
|
|
166
175
|
private:
|
|
167
176
|
Axp2101Binding() : pmu_(bus_) {}
|
|
168
177
|
|
|
178
|
+
#if GEA_BOARD_HAS_BUTTONS
|
|
179
|
+
// The power key is the board's Source::Pmu button, when it declares one.
|
|
180
|
+
// The PMU's interrupt line is not wired to the ESP32 on these boards (the
|
|
181
|
+
// vendor's own example polls it too), so its latched edge bits are read on
|
|
182
|
+
// an interval -- the one button with no interrupt to wait on.
|
|
183
|
+
static constexpr int kPowerKeyPollMs = 30;
|
|
184
|
+
|
|
185
|
+
void startPowerKey() {
|
|
186
|
+
if (powerKeyTask_) return;
|
|
187
|
+
powerKeyButton_ = gea::platform::esp32::buttons::pmuButton();
|
|
188
|
+
if (powerKeyButton_ < 0 || !pmu_.enablePowerKeyEdges()) return;
|
|
189
|
+
if (xTaskCreate(powerKeyTask, "pmu_key", 2560, this, 4, &powerKeyTask_) != pdPASS) {
|
|
190
|
+
powerKeyTask_ = nullptr;
|
|
191
|
+
ESP_LOGE(kTag, "power key task unavailable");
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
ESP_LOGI(kTag, "PWR key is button %s (polled)", gea::framework::input::buttonCode(powerKeyButton_));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
static void powerKeyTask(void *arg) {
|
|
198
|
+
auto *self = static_cast<Axp2101Binding *>(arg);
|
|
199
|
+
bool pressed = false;
|
|
200
|
+
while (true) {
|
|
201
|
+
vTaskDelay(pdMS_TO_TICKS(kPowerKeyPollMs));
|
|
202
|
+
bool fell = false;
|
|
203
|
+
bool rose = false;
|
|
204
|
+
if (!self->pmu_.takePowerKeyEdges(fell, rose) || (!fell && !rose)) continue;
|
|
205
|
+
// Both latched means a whole edge pair fit between two reads: replay
|
|
206
|
+
// them in the order the current state allows.
|
|
207
|
+
for (int step = 0; step < 2; ++step) {
|
|
208
|
+
if (!pressed && fell) {
|
|
209
|
+
fell = false;
|
|
210
|
+
pressed = true;
|
|
211
|
+
} else if (pressed && rose) {
|
|
212
|
+
rose = false;
|
|
213
|
+
pressed = false;
|
|
214
|
+
} else {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
gea::framework::input::queueButton(self->powerKeyButton_, pressed);
|
|
218
|
+
ESP_LOGI(kTag, "PWR %s", pressed ? "down" : "up");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
int powerKeyButton_ = -1;
|
|
224
|
+
TaskHandle_t powerKeyTask_ = nullptr;
|
|
225
|
+
#endif
|
|
226
|
+
|
|
169
227
|
EspI2cRegisterBus bus_;
|
|
170
228
|
gea::chips::axp2101::PowerManagementUnit pmu_;
|
|
171
229
|
bool initialized_ = false;
|
|
@@ -69,12 +69,16 @@ constexpr gpio_num_t kInterruptPin = gea::platform::board::touch.interrupt;
|
|
|
69
69
|
constexpr int kPollIntervalMs = 10;
|
|
70
70
|
constexpr int kTaskPriority = 10;
|
|
71
71
|
|
|
72
|
-
#
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
72
|
+
#ifndef GEA_EMBEDDED_TOUCH_POLL
|
|
73
|
+
#define GEA_EMBEDDED_TOUCH_POLL 0
|
|
74
|
+
#endif
|
|
75
|
+
// The controller raises INT (low) once per report. Reading between reports
|
|
76
|
+
// finds a frame the driver already acknowledged (the CST9220 logs "Malformed
|
|
77
|
+
// report header" and drops it), so a board that wires INT reads on it instead
|
|
78
|
+
// of on a timer. While a finger is down it still re-reads after kLiftTimeoutMs
|
|
79
|
+
// of silence, so a missed final report cannot leave a finger stuck down. Only a
|
|
80
|
+
// board without INT, or one that sets GEA_EMBEDDED_TOUCH_POLL, polls.
|
|
81
|
+
constexpr bool kInterruptDriven = kInterruptPin != GPIO_NUM_NC && !GEA_EMBEDDED_TOUCH_POLL;
|
|
78
82
|
constexpr int kLiftTimeoutMs = 60;
|
|
79
83
|
|
|
80
84
|
void IRAM_ATTR touchInterrupt(void *arg)
|
|
@@ -84,7 +88,6 @@ void IRAM_ATTR touchInterrupt(void *arg)
|
|
|
84
88
|
if (*task) vTaskNotifyGiveFromISR(*task, &woken);
|
|
85
89
|
portYIELD_FROM_ISR(woken);
|
|
86
90
|
}
|
|
87
|
-
#endif
|
|
88
91
|
|
|
89
92
|
} // namespace
|
|
90
93
|
|
|
@@ -129,7 +132,7 @@ esp_err_t TouchController::begin()
|
|
|
129
132
|
if (err != ESP_OK) return err;
|
|
130
133
|
|
|
131
134
|
initialized_ = true;
|
|
132
|
-
ESP_LOGI(kTag, "Touch controller ready (
|
|
135
|
+
ESP_LOGI(kTag, "Touch controller ready (%s)", kInterruptDriven ? "interrupt" : "polling");
|
|
133
136
|
return ESP_OK;
|
|
134
137
|
}
|
|
135
138
|
|
|
@@ -189,14 +192,14 @@ esp_err_t TouchController::attachTouchDevice()
|
|
|
189
192
|
ESP_LOGE(kTag, "Failed to create CST92xx touch device: %s", esp_err_to_name(err));
|
|
190
193
|
return err;
|
|
191
194
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
195
|
+
if constexpr (kInterruptDriven) {
|
|
196
|
+
// The driver configured INT as a falling-edge input; hook it to the task.
|
|
197
|
+
err = gpio_install_isr_service(0);
|
|
198
|
+
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) return err;
|
|
199
|
+
err = gpio_isr_handler_add(kInterruptPin, touchInterrupt, &task_);
|
|
200
|
+
if (err == ESP_OK) err = gpio_intr_enable(kInterruptPin);
|
|
201
|
+
if (err != ESP_OK) ESP_LOGE(kTag, "Touch INT GPIO%d hook failed: %s", static_cast<int>(kInterruptPin), esp_err_to_name(err));
|
|
202
|
+
}
|
|
200
203
|
return err;
|
|
201
204
|
}
|
|
202
205
|
|
|
@@ -255,13 +258,13 @@ void TouchController::pollLoop()
|
|
|
255
258
|
int slotY[kMaxFingers] = {0, 0};
|
|
256
259
|
|
|
257
260
|
while (true) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
if constexpr (kInterruptDriven) {
|
|
262
|
+
const bool anyActive = slotActive[0] || slotActive[1];
|
|
263
|
+
if (ulTaskNotifyTake(pdTRUE, anyActive ? pdMS_TO_TICKS(kLiftTimeoutMs) : portMAX_DELAY) == 0 && !anyActive)
|
|
264
|
+
continue;
|
|
265
|
+
} else {
|
|
266
|
+
vTaskDelay(pdMS_TO_TICKS(kPollIntervalMs));
|
|
267
|
+
}
|
|
265
268
|
|
|
266
269
|
const MultiSample multi = readMulti();
|
|
267
270
|
if (multi.count > 0) {
|
|
@@ -133,6 +133,8 @@ public:
|
|
|
133
133
|
enabled_ = enabled;
|
|
134
134
|
|
|
135
135
|
if (!enabled_) {
|
|
136
|
+
scanPending_ = false;
|
|
137
|
+
connectAfterScan_ = false;
|
|
136
138
|
if (apNetif_ || apOwnsRadio_)
|
|
137
139
|
stopAccessPoint();
|
|
138
140
|
if (!initialized_)
|
|
@@ -420,8 +422,16 @@ public:
|
|
|
420
422
|
}
|
|
421
423
|
|
|
422
424
|
void scan() override {
|
|
423
|
-
if (!
|
|
425
|
+
if (!enabled_ || scanning_)
|
|
424
426
|
return;
|
|
427
|
+
// Opt-in radio: enabled() is already true before the first bring-up, so a
|
|
428
|
+
// scan request is what starts it. Run the scan once the station starts.
|
|
429
|
+
if (!initialized_ || !started_) {
|
|
430
|
+
scanPending_ = true;
|
|
431
|
+
if (!initialized_)
|
|
432
|
+
ensureBringUp();
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
425
435
|
|
|
426
436
|
wifi_scan_config_t scanConfig = {};
|
|
427
437
|
scanConfig.scan_type = WIFI_SCAN_TYPE_ACTIVE;
|
|
@@ -432,7 +442,7 @@ public:
|
|
|
432
442
|
scanning_ = true;
|
|
433
443
|
}
|
|
434
444
|
|
|
435
|
-
bool scanning() const override { return scanning_; }
|
|
445
|
+
bool scanning() const override { return scanning_ || scanPending_; }
|
|
436
446
|
int scanCount() const override { return scanCount_; }
|
|
437
447
|
|
|
438
448
|
gea::framework::network::WifiNetwork networkAt(int index) const override {
|
|
@@ -486,6 +496,16 @@ private:
|
|
|
486
496
|
void handleEvent(esp_event_base_t eventBase, std::int32_t eventId,
|
|
487
497
|
void *eventData) {
|
|
488
498
|
if (eventBase == WIFI_EVENT && eventId == WIFI_EVENT_STA_START) {
|
|
499
|
+
// A scan requested before the radio was up runs first; the connect
|
|
500
|
+
// follows from SCAN_DONE so the two do not contend for the radio.
|
|
501
|
+
if (scanPending_) {
|
|
502
|
+
scanPending_ = false;
|
|
503
|
+
scan();
|
|
504
|
+
if (scanning_) {
|
|
505
|
+
connectAfterScan_ = true;
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
489
509
|
if (enabled_ && ssid_[0] != '\0')
|
|
490
510
|
esp_wifi_connect();
|
|
491
511
|
} else if (eventBase == WIFI_EVENT &&
|
|
@@ -508,6 +528,11 @@ private:
|
|
|
508
528
|
gea::framework::services::NetworkServices::startDeferredServers();
|
|
509
529
|
} else if (eventBase == WIFI_EVENT && eventId == WIFI_EVENT_SCAN_DONE) {
|
|
510
530
|
handleScanDone();
|
|
531
|
+
if (connectAfterScan_) {
|
|
532
|
+
connectAfterScan_ = false;
|
|
533
|
+
if (enabled_ && ssid_[0] != '\0')
|
|
534
|
+
esp_wifi_connect();
|
|
535
|
+
}
|
|
511
536
|
}
|
|
512
537
|
}
|
|
513
538
|
|
|
@@ -618,6 +643,7 @@ private:
|
|
|
618
643
|
debugState_.store(4, std::memory_order_relaxed);
|
|
619
644
|
ESP_LOGE(kTag, "esp_wifi_init failed (%s); continuing without WiFi",
|
|
620
645
|
esp_err_to_name(err));
|
|
646
|
+
scanPending_ = false;
|
|
621
647
|
return false;
|
|
622
648
|
}
|
|
623
649
|
initialized_ = true;
|
|
@@ -856,6 +882,8 @@ private:
|
|
|
856
882
|
char ip_[16] = "0.0.0.0";
|
|
857
883
|
char mac_[18] = "";
|
|
858
884
|
bool scanning_ = false;
|
|
885
|
+
bool scanPending_ = false;
|
|
886
|
+
bool connectAfterScan_ = false;
|
|
859
887
|
int scanCount_ = 0;
|
|
860
888
|
char scanSsids_[kScanMax][33]{};
|
|
861
889
|
int scanRssi_[kScanMax]{};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# The board's physical buttons come from JSON (the board's "buttons" plus the
|
|
2
|
+
# app's changes); the CLI generates gea_board_buttons.h and passes its
|
|
3
|
+
# directory. With none, the button service compiles to nothing.
|
|
4
|
+
function(gea_board_buttons target)
|
|
5
|
+
set(_dir "${GEA_BOARD_BUTTONS_DIR}")
|
|
6
|
+
if(NOT _dir AND DEFINED ENV{GEA_BOARD_BUTTONS_DIR})
|
|
7
|
+
set(_dir "$ENV{GEA_BOARD_BUTTONS_DIR}")
|
|
8
|
+
endif()
|
|
9
|
+
if(_dir)
|
|
10
|
+
target_include_directories(${target} PRIVATE "${_dir}")
|
|
11
|
+
target_compile_definitions(${target} PRIVATE GEA_BOARD_HAS_BUTTONS=1)
|
|
12
|
+
endif()
|
|
13
|
+
endfunction()
|
package/targets/esp32/gpio.cpp
CHANGED
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
// of them to light one diode on the boards that have one.
|
|
7
7
|
|
|
8
8
|
#include "gpio.h"
|
|
9
|
+
#include "gpio_pins.h"
|
|
9
10
|
|
|
11
|
+
#include <atomic>
|
|
10
12
|
#include <cstdint>
|
|
11
13
|
#include <cstring>
|
|
12
14
|
|
|
13
15
|
#include "driver/gpio.h"
|
|
16
|
+
#include "esp_attr.h"
|
|
14
17
|
#include "driver/rmt_tx.h"
|
|
15
18
|
#include "esp_err.h"
|
|
16
19
|
#include "esp_log.h"
|
|
@@ -25,6 +28,19 @@ bool validPin(int pin)
|
|
|
25
28
|
return pin >= 0 && pin < GPIO_NUM_MAX && GPIO_IS_VALID_GPIO(static_cast<gpio_num_t>(pin));
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
// One bit per open Gpio slot, set from an edge interrupt and taken by the app
|
|
32
|
+
// thread. The interrupt does nothing else: the callback the edge stands for
|
|
33
|
+
// runs on the app thread, where TS code may run.
|
|
34
|
+
std::atomic<unsigned> gEdges{0};
|
|
35
|
+
|
|
36
|
+
// gpio_pins.h: the pins another driver owns, whether it takes their edge
|
|
37
|
+
// interrupts, and the Gpio slot an open owned pin reports to (-1 for none).
|
|
38
|
+
std::atomic<bool> gClaimed[GPIO_NUM_MAX];
|
|
39
|
+
std::atomic<bool> gClaimedInterrupt[GPIO_NUM_MAX];
|
|
40
|
+
std::atomic<std::int8_t> gOwnedSlot[GPIO_NUM_MAX];
|
|
41
|
+
|
|
42
|
+
bool claimed(int pin) { return gClaimed[pin].load(std::memory_order_acquire); }
|
|
43
|
+
|
|
28
44
|
// WS2812 is a single-wire protocol where a bit is a fixed-length pulse and only
|
|
29
45
|
// the high/low split says whether it is a 0 or a 1. At the 10 MHz resolution
|
|
30
46
|
// below one tick is 100 ns, so these are the datasheet's T0H/T0L/T1H/T1L.
|
|
@@ -78,7 +94,7 @@ namespace gea::platform::gpio {
|
|
|
78
94
|
|
|
79
95
|
bool Gpio::configureOutput(int pin)
|
|
80
96
|
{
|
|
81
|
-
if (!validPin(pin)) return false;
|
|
97
|
+
if (!validPin(pin) || claimed(pin)) return false;
|
|
82
98
|
const gpio_num_t num = static_cast<gpio_num_t>(pin);
|
|
83
99
|
gpio_reset_pin(num);
|
|
84
100
|
gpio_config_t config = {};
|
|
@@ -93,6 +109,8 @@ bool Gpio::configureOutput(int pin)
|
|
|
93
109
|
bool Gpio::configureInput(int pin, bool pull_up)
|
|
94
110
|
{
|
|
95
111
|
if (!validPin(pin)) return false;
|
|
112
|
+
// An owned pin is already an input, set up by its owner.
|
|
113
|
+
if (claimed(pin)) return true;
|
|
96
114
|
const gpio_num_t num = static_cast<gpio_num_t>(pin);
|
|
97
115
|
// A strapping pin (GPIO0 among them) can still be muxed to a boot function;
|
|
98
116
|
// resetting forces it back to a plain GPIO matrix entry, which is why
|
|
@@ -119,6 +137,111 @@ bool Gpio::read(int pin)
|
|
|
119
137
|
return gpio_get_level(static_cast<gpio_num_t>(pin)) != 0;
|
|
120
138
|
}
|
|
121
139
|
|
|
140
|
+
namespace {
|
|
141
|
+
|
|
142
|
+
void IRAM_ATTR edgeInterrupt(void *arg)
|
|
143
|
+
{
|
|
144
|
+
gEdges.fetch_or(1u << reinterpret_cast<std::uintptr_t>(arg), std::memory_order_relaxed);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
} // namespace
|
|
148
|
+
|
|
149
|
+
bool Gpio::configure(int pin, int mode)
|
|
150
|
+
{
|
|
151
|
+
if (!validPin(pin)) return false;
|
|
152
|
+
if (claimed(pin)) return mode == Input || mode == InputPullUp || mode == InputPullDown || mode == InputPullUpDown;
|
|
153
|
+
const gpio_num_t num = static_cast<gpio_num_t>(pin);
|
|
154
|
+
gpio_config_t config = {};
|
|
155
|
+
config.pin_bit_mask = 1ULL << pin;
|
|
156
|
+
config.intr_type = GPIO_INTR_DISABLE;
|
|
157
|
+
switch (mode) {
|
|
158
|
+
case Input:
|
|
159
|
+
case InputPullUp:
|
|
160
|
+
case InputPullDown:
|
|
161
|
+
case InputPullUpDown:
|
|
162
|
+
config.mode = GPIO_MODE_INPUT;
|
|
163
|
+
config.pull_up_en = (mode & InputPullUp) ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
|
|
164
|
+
config.pull_down_en = (mode & InputPullDown) ? GPIO_PULLDOWN_ENABLE : GPIO_PULLDOWN_DISABLE;
|
|
165
|
+
break;
|
|
166
|
+
case Output:
|
|
167
|
+
if (!GPIO_IS_VALID_OUTPUT_GPIO(num)) return false;
|
|
168
|
+
config.mode = GPIO_MODE_OUTPUT;
|
|
169
|
+
break;
|
|
170
|
+
case OutputOpenDrain:
|
|
171
|
+
if (!GPIO_IS_VALID_OUTPUT_GPIO(num)) return false;
|
|
172
|
+
config.mode = GPIO_MODE_INPUT_OUTPUT_OD;
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
// Strapping pins (GPIO0 among them) can be left muxed to a boot function;
|
|
178
|
+
// resetting returns the pin to a plain GPIO matrix entry.
|
|
179
|
+
gpio_reset_pin(num);
|
|
180
|
+
return gpio_config(&config) == ESP_OK;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
bool Gpio::watch(int pin, int edges, int slot)
|
|
184
|
+
{
|
|
185
|
+
if (!validPin(pin) || slot < 0 || slot > 31) return false;
|
|
186
|
+
if (claimed(pin)) {
|
|
187
|
+
if (!gClaimedInterrupt[pin].load(std::memory_order_acquire)) return false;
|
|
188
|
+
gOwnedSlot[pin].store(static_cast<std::int8_t>(slot), std::memory_order_release);
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
gpio_int_type_t type = GPIO_INTR_ANYEDGE;
|
|
192
|
+
if (edges == kRising) type = GPIO_INTR_POSEDGE;
|
|
193
|
+
else if (edges == kFalling) type = GPIO_INTR_NEGEDGE;
|
|
194
|
+
else if (edges != (kRising | kFalling)) return false;
|
|
195
|
+
// Shared with the board's buttons; whichever starts first installs it.
|
|
196
|
+
const esp_err_t service = gpio_install_isr_service(0);
|
|
197
|
+
if (service != ESP_OK && service != ESP_ERR_INVALID_STATE) {
|
|
198
|
+
ESP_LOGE(kTag, "GPIO interrupt service unavailable: %s", esp_err_to_name(service));
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const gpio_num_t num = static_cast<gpio_num_t>(pin);
|
|
202
|
+
if (gpio_set_intr_type(num, type) != ESP_OK) return false;
|
|
203
|
+
if (gpio_isr_handler_add(num, edgeInterrupt, reinterpret_cast<void *>(static_cast<std::uintptr_t>(slot))) != ESP_OK)
|
|
204
|
+
return false;
|
|
205
|
+
return gpio_intr_enable(num) == ESP_OK;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
void Gpio::unwatch(int pin)
|
|
209
|
+
{
|
|
210
|
+
if (!validPin(pin)) return;
|
|
211
|
+
if (claimed(pin)) {
|
|
212
|
+
gOwnedSlot[pin].store(-1, std::memory_order_release);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const gpio_num_t num = static_cast<gpio_num_t>(pin);
|
|
216
|
+
gpio_intr_disable(num);
|
|
217
|
+
gpio_isr_handler_remove(num);
|
|
218
|
+
gpio_set_intr_type(num, GPIO_INTR_DISABLE);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
unsigned Gpio::takeEdges() { return gEdges.exchange(0, std::memory_order_acquire); }
|
|
222
|
+
|
|
223
|
+
} // namespace gea::platform::gpio
|
|
224
|
+
|
|
225
|
+
namespace gea::platform::esp32::gpio {
|
|
226
|
+
|
|
227
|
+
void claimPin(int pin, bool interrupt)
|
|
228
|
+
{
|
|
229
|
+
if (!validPin(pin)) return;
|
|
230
|
+
gOwnedSlot[pin].store(-1, std::memory_order_relaxed);
|
|
231
|
+
gClaimedInterrupt[pin].store(interrupt, std::memory_order_relaxed);
|
|
232
|
+
gClaimed[pin].store(true, std::memory_order_release);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
void IRAM_ATTR ownedPinEdge(int pin)
|
|
236
|
+
{
|
|
237
|
+
const int slot = gOwnedSlot[pin].load(std::memory_order_acquire);
|
|
238
|
+
if (slot >= 0) gEdges.fetch_or(1u << slot, std::memory_order_relaxed);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
} // namespace gea::platform::esp32::gpio
|
|
242
|
+
|
|
243
|
+
namespace gea::platform::gpio {
|
|
244
|
+
|
|
122
245
|
bool AddressableLed::attach(int pin, int count)
|
|
123
246
|
{
|
|
124
247
|
if (!validPin(pin) || count <= 0 || count > kMaxPixels) return false;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
// Pins whose interrupt another ESP32 driver owns: the board's buttons
|
|
4
|
+
// (services/buttons.cpp). The Gpio and Digital classes can still open such a
|
|
5
|
+
// pin as an input. Gpio::configure() then leaves the owner's setup alone, and
|
|
6
|
+
// Gpio::watch() rides on the owner's interrupt, which reports each edge
|
|
7
|
+
// through ownedPinEdge(). Without this, opening the pin would reset it and
|
|
8
|
+
// replace the owner's interrupt handler.
|
|
9
|
+
namespace gea::platform::esp32::gpio {
|
|
10
|
+
|
|
11
|
+
// `interrupt`: the owner takes edge interrupts on the pin (false for a polled
|
|
12
|
+
// button, which Gpio then polls too).
|
|
13
|
+
void claimPin(int pin, bool interrupt);
|
|
14
|
+
// Interrupt context; IRAM-safe.
|
|
15
|
+
void ownedPinEdge(int pin);
|
|
16
|
+
|
|
17
|
+
} // namespace gea::platform::esp32::gpio
|