@geastack/targets 0.1.91 → 0.1.92
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 +32 -0
- package/package.json +1 -1
- package/targets/cmake/geatsc_generated_archive.cmake +18 -2
- package/targets/esp32/chip_bindings/audio/es8311.cpp +10 -1
- package/targets/esp32/chip_bindings/displays/co5300.cpp +40 -0
- package/targets/esp32/chip_bindings/imu/bmi270.cpp +6 -1
- package/targets/esp32/chip_bindings/touch/cst9217.cpp +67 -3
- package/targets/esp32/display.cpp +35 -32
- package/targets/esp32/render_worker_join.h +32 -0
- package/targets/esp32/services/device_control.cpp +130 -0
- package/targets/esp32-s3-touch-amoled-1.8/main/CMakeLists.txt +8 -1
- package/targets/esp32-s3-touch-amoled-1.8/main/app_main.cpp +8 -0
- package/targets/esp32-s3-touch-amoled-1.8/main/launcher_button.cpp +6 -1
- package/targets/esp32-s31-espressif-mosaico/CMakeLists.txt +10 -0
- package/targets/esp32-s31-espressif-mosaico/README.md +65 -0
- package/targets/esp32-s31-espressif-mosaico/dependencies.lock +141 -0
- package/targets/esp32-s31-espressif-mosaico/main/CMakeLists.txt +77 -0
- package/targets/esp32-s31-espressif-mosaico/main/Kconfig.projbuild +12 -0
- package/targets/esp32-s31-espressif-mosaico/main/board_power.cpp +440 -0
- package/targets/esp32-s31-espressif-mosaico/main/idf_component.yml +37 -0
- package/targets/esp32-s31-espressif-mosaico/main/include/board.h +147 -0
- package/targets/esp32-s31-espressif-mosaico/main/include/wifi_config.h.example +5 -0
- package/targets/esp32-s31-espressif-mosaico/main/touch.cpp +45 -0
- package/targets/esp32-s31-espressif-mosaico/partitions.csv +10 -0
- package/targets/esp32-s31-espressif-mosaico/sdkconfig.defaults +200 -0
- package/targets.json +12 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
// ESP-Mosaico board bring-up: the VCC_3V3 rail and the USB console.
|
|
2
|
+
//
|
|
3
|
+
// Everything on the panel side -- the CO5300, its touch controller, the codec
|
|
4
|
+
// supply on V1.0 and the expansion slots' 3V3 -- hangs off VCC_3V3, a high-side
|
|
5
|
+
// switch whose enable is GPIO60, active low. Until that rail is open the panel
|
|
6
|
+
// does not answer, and a QSPI write reports success either way, so a board that
|
|
7
|
+
// skips this boots with every log line saying the display came up and a dark
|
|
8
|
+
// screen. The BSP soft-starts the rail by fading the enable through LEDC over
|
|
9
|
+
// 50 ms (the switch's gate follows the average of the pin), which bounds the
|
|
10
|
+
// inrush when the board runs from its 65 mAh cell; this does the same.
|
|
11
|
+
//
|
|
12
|
+
// GPIO57 is the power-off request to the board's SAM8108 power controller:
|
|
13
|
+
// open drain, asserted low. It must be released for the board to stay on.
|
|
14
|
+
//
|
|
15
|
+
// The USB-C port is the S31's high-speed OTG controller, not USB-Serial/JTAG
|
|
16
|
+
// (that sits on GPIO33/34, routed to the left expansion header), so there is no
|
|
17
|
+
// ROM console on it: logs reach the host through a TinyUSB CDC interface that
|
|
18
|
+
// reports the chip's MAC as its USB serial -- the same "AA:BB:CC:DD:EE:FF"
|
|
19
|
+
// spelling the S3 boards' USB-Serial/JTAG uses, so `--board` resolves a
|
|
20
|
+
// Mosaico by serial exactly as it does every other board. UART0 keeps the
|
|
21
|
+
// early boot output and remains the fallback when USB does not come up.
|
|
22
|
+
//
|
|
23
|
+
// That console is also how apps are installed: `gea flash` streams the image to
|
|
24
|
+
// the running app (GEADEV OTA, `usbAppUpdate: "geadev-ota"` in targets.json),
|
|
25
|
+
// which writes the next OTA slot and restarts into it. The OTG port has no reset
|
|
26
|
+
// lines and V1.2 ships with automatic download disabled, so the ROM downloader
|
|
27
|
+
// is for first flash and recovery only (BOOT held through a power cycle). A new
|
|
28
|
+
// app confirms itself after it has run for a few seconds; one that crashes
|
|
29
|
+
// first is rolled back by the bootloader, and the app that comes back reports
|
|
30
|
+
// the crash on the console.
|
|
31
|
+
|
|
32
|
+
#include "board.h"
|
|
33
|
+
|
|
34
|
+
#include <algorithm>
|
|
35
|
+
#include <cstddef>
|
|
36
|
+
#include <cstdint>
|
|
37
|
+
#include <cstdio>
|
|
38
|
+
|
|
39
|
+
#include "driver/gpio.h"
|
|
40
|
+
#include "driver/ledc.h"
|
|
41
|
+
#include "esp_attr.h"
|
|
42
|
+
#include "esp_check.h"
|
|
43
|
+
#include "esp_err.h"
|
|
44
|
+
#include "esp_heap_caps.h"
|
|
45
|
+
#include "esp_log.h"
|
|
46
|
+
#include "esp_mac.h"
|
|
47
|
+
#include "esp_ota_ops.h"
|
|
48
|
+
#include "esp_private/panic_internal.h"
|
|
49
|
+
#include "esp_private/startup_internal.h"
|
|
50
|
+
#include "esp_rom_sys.h"
|
|
51
|
+
#include "esp_system.h"
|
|
52
|
+
#include "freertos/FreeRTOS.h"
|
|
53
|
+
#include "freertos/semphr.h"
|
|
54
|
+
#include "freertos/task.h"
|
|
55
|
+
#include "hal/uart_hal.h"
|
|
56
|
+
#include "riscv/rvruntime-frames.h"
|
|
57
|
+
#include "soc/lp_system_reg.h"
|
|
58
|
+
#include "soc/soc.h"
|
|
59
|
+
|
|
60
|
+
#if GEA_BOARD_USB_CONSOLE
|
|
61
|
+
#include "tinyusb.h"
|
|
62
|
+
#include "tinyusb_cdc_acm.h"
|
|
63
|
+
#include "tinyusb_console.h"
|
|
64
|
+
#include "tinyusb_default_config.h"
|
|
65
|
+
#include "vfs_tinyusb.h"
|
|
66
|
+
#endif
|
|
67
|
+
|
|
68
|
+
namespace
|
|
69
|
+
{
|
|
70
|
+
constexpr char kTag[] = "mosaico";
|
|
71
|
+
|
|
72
|
+
constexpr int kVccOnLevel = 0;
|
|
73
|
+
constexpr int kVccOffLevel = 1;
|
|
74
|
+
constexpr int kVccRampMs = 50;
|
|
75
|
+
// Settling after the ramp before anything talks to the panel. The BSP's
|
|
76
|
+
// codec path waits 10 ms; the panel takes its own 600 ms sleep-out later.
|
|
77
|
+
constexpr int kVccSettleMs = 10;
|
|
78
|
+
|
|
79
|
+
constexpr ledc_mode_t kRampMode = LEDC_LOW_SPEED_MODE;
|
|
80
|
+
constexpr ledc_timer_t kRampTimer = LEDC_TIMER_1;
|
|
81
|
+
constexpr ledc_channel_t kRampChannel = LEDC_CHANNEL_1;
|
|
82
|
+
// 8-bit keeps the carrier well above the gate RC pole (the BSP's choice).
|
|
83
|
+
constexpr ledc_timer_bit_t kRampResolution = LEDC_TIMER_8_BIT;
|
|
84
|
+
constexpr std::uint32_t kRampFrequencyHz = 100000;
|
|
85
|
+
|
|
86
|
+
StaticSemaphore_t powerLockStorage;
|
|
87
|
+
SemaphoreHandle_t powerLock = nullptr;
|
|
88
|
+
bool railsOn = false;
|
|
89
|
+
|
|
90
|
+
esp_err_t configureOutput(gpio_num_t pin, gpio_mode_t mode, int level)
|
|
91
|
+
{
|
|
92
|
+
gpio_config_t config = {};
|
|
93
|
+
config.pin_bit_mask = 1ULL << pin;
|
|
94
|
+
config.mode = mode;
|
|
95
|
+
config.pull_up_en = GPIO_PULLUP_DISABLE;
|
|
96
|
+
config.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
|
97
|
+
config.intr_type = GPIO_INTR_DISABLE;
|
|
98
|
+
// Preset the level so the pad never glitches through the wrong state.
|
|
99
|
+
ESP_RETURN_ON_ERROR(gpio_set_level(pin, level), kTag, "preset GPIO%d", pin);
|
|
100
|
+
return gpio_config(&config);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
esp_err_t rampVccOn()
|
|
104
|
+
{
|
|
105
|
+
constexpr gpio_num_t pin = gea::platform::board::power.vcc3v3Enable;
|
|
106
|
+
ledc_timer_config_t timer = {};
|
|
107
|
+
timer.speed_mode = kRampMode;
|
|
108
|
+
timer.duty_resolution = kRampResolution;
|
|
109
|
+
timer.timer_num = kRampTimer;
|
|
110
|
+
timer.freq_hz = kRampFrequencyHz;
|
|
111
|
+
timer.clk_cfg = LEDC_AUTO_CLK;
|
|
112
|
+
ESP_RETURN_ON_ERROR(ledc_timer_config(&timer), kTag, "ramp timer");
|
|
113
|
+
|
|
114
|
+
constexpr std::uint32_t maxDuty = (1U << kRampResolution) - 1U;
|
|
115
|
+
ledc_channel_config_t channel = {};
|
|
116
|
+
channel.gpio_num = pin;
|
|
117
|
+
channel.speed_mode = kRampMode;
|
|
118
|
+
channel.channel = kRampChannel;
|
|
119
|
+
channel.timer_sel = kRampTimer;
|
|
120
|
+
channel.duty = kVccOffLevel ? maxDuty : 0;
|
|
121
|
+
channel.hpoint = 0;
|
|
122
|
+
ESP_RETURN_ON_ERROR(ledc_channel_config(&channel), kTag, "ramp channel");
|
|
123
|
+
|
|
124
|
+
const esp_err_t installed = ledc_fade_func_install(0);
|
|
125
|
+
esp_err_t err = installed == ESP_ERR_INVALID_STATE ? ESP_OK : installed;
|
|
126
|
+
if (err == ESP_OK)
|
|
127
|
+
err = ledc_set_fade_with_time(kRampMode, kRampChannel, kVccOnLevel ? maxDuty : 0, kVccRampMs);
|
|
128
|
+
if (err == ESP_OK)
|
|
129
|
+
err = ledc_fade_start(kRampMode, kRampChannel, LEDC_FADE_WAIT_DONE);
|
|
130
|
+
if (installed == ESP_OK)
|
|
131
|
+
ledc_fade_func_uninstall();
|
|
132
|
+
|
|
133
|
+
// Hand the pad back to plain GPIO at its final level; a failed ramp leaves
|
|
134
|
+
// the rail off rather than half driven.
|
|
135
|
+
const int level = err == ESP_OK ? kVccOnLevel : kVccOffLevel;
|
|
136
|
+
ledc_stop(kRampMode, kRampChannel, level);
|
|
137
|
+
const esp_err_t restored = configureOutput(pin, GPIO_MODE_OUTPUT, level);
|
|
138
|
+
return err != ESP_OK ? err : restored;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
void powerOnRailsLocked()
|
|
142
|
+
{
|
|
143
|
+
using gea::platform::board::power;
|
|
144
|
+
// Keep the board on before anything else: release the power-off request.
|
|
145
|
+
gpio_hold_dis(power.powerOffRequest);
|
|
146
|
+
esp_err_t err = configureOutput(power.powerOffRequest, GPIO_MODE_OUTPUT_OD, 1);
|
|
147
|
+
if (err != ESP_OK)
|
|
148
|
+
ESP_LOGE(kTag, "PWR_SW GPIO%d release failed: %s", power.powerOffRequest, esp_err_to_name(err));
|
|
149
|
+
|
|
150
|
+
gpio_hold_dis(power.vcc3v3Enable);
|
|
151
|
+
err = rampVccOn();
|
|
152
|
+
if (err != ESP_OK)
|
|
153
|
+
{
|
|
154
|
+
// Better a hard switch-on than a dark panel: the ramp only bounds inrush.
|
|
155
|
+
ESP_LOGW(kTag, "VCC_3V3 soft start failed (%s); switching it on directly", esp_err_to_name(err));
|
|
156
|
+
err = configureOutput(power.vcc3v3Enable, GPIO_MODE_OUTPUT, kVccOnLevel);
|
|
157
|
+
}
|
|
158
|
+
if (err != ESP_OK)
|
|
159
|
+
{
|
|
160
|
+
ESP_LOGE(kTag, "VCC_3V3 enable GPIO%d failed: %s", power.vcc3v3Enable, esp_err_to_name(err));
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
vTaskDelay(pdMS_TO_TICKS(kVccSettleMs));
|
|
164
|
+
railsOn = true;
|
|
165
|
+
ESP_LOGI(kTag, "VCC_3V3 on (GPIO%d ramped low over %d ms), PWR_SW GPIO%d released",
|
|
166
|
+
power.vcc3v3Enable, kVccRampMs, power.powerOffRequest);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#if GEA_BOARD_USB_CONSOLE
|
|
170
|
+
char usbSerial[18] = "000000000000";
|
|
171
|
+
const char *usbStrings[] = {
|
|
172
|
+
"\x09\x04", // 0: English (0x0409)
|
|
173
|
+
"Espressif", // 1: Manufacturer
|
|
174
|
+
"ESP-Mosaico", // 2: Product
|
|
175
|
+
usbSerial, // 3: Serial -- the chip MAC, filled in at start
|
|
176
|
+
"ESP-Mosaico Console", // 4: CDC interface
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
void startUsbConsole()
|
|
180
|
+
{
|
|
181
|
+
std::uint8_t mac[6] = {};
|
|
182
|
+
if (esp_read_mac(mac, ESP_MAC_BASE) == ESP_OK)
|
|
183
|
+
{
|
|
184
|
+
std::snprintf(usbSerial, sizeof(usbSerial), "%02X:%02X:%02X:%02X:%02X:%02X",
|
|
185
|
+
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
tinyusb_config_t config = TINYUSB_DEFAULT_CONFIG();
|
|
189
|
+
config.descriptor.string = usbStrings;
|
|
190
|
+
config.descriptor.string_count = sizeof(usbStrings) / sizeof(usbStrings[0]);
|
|
191
|
+
esp_err_t err = tinyusb_driver_install(&config);
|
|
192
|
+
if (err != ESP_OK)
|
|
193
|
+
{
|
|
194
|
+
ESP_LOGE(kTag, "TinyUSB install failed: %s; console stays on UART0", esp_err_to_name(err));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
tinyusb_config_cdcacm_t cdc = {};
|
|
199
|
+
cdc.cdc_port = TINYUSB_CDC_ACM_0;
|
|
200
|
+
err = tinyusb_cdcacm_init(&cdc);
|
|
201
|
+
if (err != ESP_OK)
|
|
202
|
+
{
|
|
203
|
+
ESP_LOGE(kTag, "USB CDC init failed: %s; console stays on UART0", esp_err_to_name(err));
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
err = tinyusb_console_init(TINYUSB_CDC_ACM_0);
|
|
208
|
+
if (err != ESP_OK)
|
|
209
|
+
{
|
|
210
|
+
ESP_LOGE(kTag, "USB console redirect failed: %s; console stays on UART0", esp_err_to_name(err));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// Pass console input through untouched. The libc default (CR -> LF) is for
|
|
214
|
+
// a typed terminal; GEADEV's parser takes either line ending, and GEADEV
|
|
215
|
+
// OTA/PUSH stream raw binary that the conversion would corrupt.
|
|
216
|
+
esp_vfs_tusb_cdc_set_rx_line_endings(ESP_LINE_ENDINGS_LF);
|
|
217
|
+
ESP_LOGI(kTag, "USB CDC console up (serial %s)", usbSerial);
|
|
218
|
+
}
|
|
219
|
+
#endif
|
|
220
|
+
|
|
221
|
+
// The panic dump only reaches UART0, which nothing on this board exposes, and
|
|
222
|
+
// a crash on boot comes before the USB console. The panic handler is wrapped
|
|
223
|
+
// (-Wl,--wrap=esp_panic_handler) to leave the crash registers in LP_STORE10-14,
|
|
224
|
+
// and the dump itself plus esp_rom_printf output land in an LP RAM ring; both
|
|
225
|
+
// survive the reset. The next app to boot -- after a rollback, the previous
|
|
226
|
+
// one -- prints them (GEADEV:CRASH, GEADEV:CRASHLOG) when a host opens the
|
|
227
|
+
// console.
|
|
228
|
+
constexpr std::uint32_t kPanicMagic = 0x9EA0DEADU;
|
|
229
|
+
constexpr std::uint32_t kCrashLogMagic = 0x9EA01060U;
|
|
230
|
+
constexpr std::size_t kCrashLogBytes = 12 * 1024;
|
|
231
|
+
RTC_NOINIT_ATTR std::uint32_t crashLogMagic;
|
|
232
|
+
RTC_NOINIT_ATTR std::uint32_t crashLogHead;
|
|
233
|
+
RTC_NOINIT_ATTR char crashLog[kCrashLogBytes];
|
|
234
|
+
char *previousCrashLog = nullptr;
|
|
235
|
+
std::size_t previousCrashLogBytes = 0;
|
|
236
|
+
|
|
237
|
+
IRAM_ATTR void crashLogPutc(char c)
|
|
238
|
+
{
|
|
239
|
+
crashLog[crashLogHead % kCrashLogBytes] = c;
|
|
240
|
+
crashLogHead = crashLogHead + 1;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
bool previousBootCrashed()
|
|
244
|
+
{
|
|
245
|
+
const esp_reset_reason_t reason = esp_reset_reason();
|
|
246
|
+
return REG_READ(LP_SYSTEM_REG_LP_STORE10_REG) == kPanicMagic || reason == ESP_RST_PANIC ||
|
|
247
|
+
reason == ESP_RST_INT_WDT || reason == ESP_RST_TASK_WDT || reason == ESP_RST_WDT ||
|
|
248
|
+
reason == ESP_RST_BROWNOUT;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
__attribute__((constructor)) void startCrashLog()
|
|
252
|
+
{
|
|
253
|
+
if (crashLogMagic == kCrashLogMagic && previousBootCrashed())
|
|
254
|
+
{
|
|
255
|
+
const std::size_t bytes = crashLogHead < kCrashLogBytes ? crashLogHead : kCrashLogBytes;
|
|
256
|
+
previousCrashLog = static_cast<char *>(heap_caps_malloc(bytes + 1, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
|
|
257
|
+
if (previousCrashLog)
|
|
258
|
+
{
|
|
259
|
+
const std::size_t start = crashLogHead < kCrashLogBytes ? 0 : crashLogHead % kCrashLogBytes;
|
|
260
|
+
for (std::size_t i = 0; i < bytes; ++i)
|
|
261
|
+
previousCrashLog[i] = crashLog[(start + i) % kCrashLogBytes];
|
|
262
|
+
previousCrashLog[bytes] = 0;
|
|
263
|
+
previousCrashLogBytes = bytes;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
crashLogMagic = kCrashLogMagic;
|
|
267
|
+
crashLogHead = 0;
|
|
268
|
+
esp_rom_install_channel_putc(2, crashLogPutc);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
#if GEA_BOARD_USB_CONSOLE
|
|
272
|
+
void reportPreviousPanic()
|
|
273
|
+
{
|
|
274
|
+
const bool captured = REG_READ(LP_SYSTEM_REG_LP_STORE10_REG) == kPanicMagic;
|
|
275
|
+
const std::uint32_t mepc = REG_READ(LP_SYSTEM_REG_LP_STORE11_REG);
|
|
276
|
+
const std::uint32_t ra = REG_READ(LP_SYSTEM_REG_LP_STORE12_REG);
|
|
277
|
+
const std::uint32_t mcause = REG_READ(LP_SYSTEM_REG_LP_STORE13_REG);
|
|
278
|
+
const std::uint32_t mtval = REG_READ(LP_SYSTEM_REG_LP_STORE14_REG);
|
|
279
|
+
REG_WRITE(LP_SYSTEM_REG_LP_STORE10_REG, 0);
|
|
280
|
+
// Shown each time a host opens the console, for three minutes.
|
|
281
|
+
const TickType_t until = xTaskGetTickCount() + pdMS_TO_TICKS(180000);
|
|
282
|
+
while (xTaskGetTickCount() < until)
|
|
283
|
+
{
|
|
284
|
+
if (!tud_cdc_n_connected(0))
|
|
285
|
+
{
|
|
286
|
+
vTaskDelay(pdMS_TO_TICKS(100));
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
vTaskDelay(pdMS_TO_TICKS(1500));
|
|
290
|
+
if (captured)
|
|
291
|
+
std::printf("GEADEV:CRASH reset=%d mepc=0x%08lx ra=0x%08lx mcause=0x%08lx mtval=0x%08lx\n",
|
|
292
|
+
static_cast<int>(esp_reset_reason()), static_cast<unsigned long>(mepc),
|
|
293
|
+
static_cast<unsigned long>(ra), static_cast<unsigned long>(mcause),
|
|
294
|
+
static_cast<unsigned long>(mtval));
|
|
295
|
+
else
|
|
296
|
+
std::printf("GEADEV:CRASH reset=%d (no panic)\n", static_cast<int>(esp_reset_reason()));
|
|
297
|
+
std::printf("GEADEV:CRASHLOG BEGIN bytes=%u\n", static_cast<unsigned>(previousCrashLogBytes));
|
|
298
|
+
for (std::size_t off = 0; off < previousCrashLogBytes; off += 256)
|
|
299
|
+
{
|
|
300
|
+
std::fwrite(previousCrashLog + off, 1, std::min<std::size_t>(256, previousCrashLogBytes - off), stdout);
|
|
301
|
+
std::fflush(stdout);
|
|
302
|
+
}
|
|
303
|
+
std::printf("\nGEADEV:CRASHLOG END\n");
|
|
304
|
+
std::fflush(stdout);
|
|
305
|
+
while (tud_cdc_n_connected(0) && xTaskGetTickCount() < until)
|
|
306
|
+
vTaskDelay(pdMS_TO_TICKS(100));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
void panicReportTask(void *)
|
|
311
|
+
{
|
|
312
|
+
reportPreviousPanic();
|
|
313
|
+
vTaskDelete(nullptr);
|
|
314
|
+
}
|
|
315
|
+
#endif
|
|
316
|
+
|
|
317
|
+
#if CONFIG_BOOTLOADER_APP_ROLLBACK_CONFIRM_BY_APP
|
|
318
|
+
// A new app (installed over USB into the other OTA slot) is confirmed once it
|
|
319
|
+
// has run this long. One that crashes or hangs-and-resets first is rolled
|
|
320
|
+
// back by the bootloader on the next boot, and the board stays reachable.
|
|
321
|
+
constexpr std::uint32_t kConfirmAfterMs = 8000;
|
|
322
|
+
|
|
323
|
+
void confirmRunningApp()
|
|
324
|
+
{
|
|
325
|
+
esp_ota_img_states_t state;
|
|
326
|
+
if (esp_ota_get_state_partition(esp_ota_get_running_partition(), &state) != ESP_OK ||
|
|
327
|
+
(state != ESP_OTA_IMG_PENDING_VERIFY && state != ESP_OTA_IMG_NEW))
|
|
328
|
+
return;
|
|
329
|
+
vTaskDelay(pdMS_TO_TICKS(kConfirmAfterMs));
|
|
330
|
+
const esp_err_t err = esp_ota_mark_app_valid_cancel_rollback();
|
|
331
|
+
if (err == ESP_OK)
|
|
332
|
+
ESP_LOGI(kTag, "app confirmed after %u ms; rollback cancelled", static_cast<unsigned>(kConfirmAfterMs));
|
|
333
|
+
else
|
|
334
|
+
ESP_LOGE(kTag, "app confirm failed: %s", esp_err_to_name(err));
|
|
335
|
+
}
|
|
336
|
+
#endif
|
|
337
|
+
|
|
338
|
+
void boardStartTask(void *)
|
|
339
|
+
{
|
|
340
|
+
gea::platform::board::powerOnRails();
|
|
341
|
+
#if GEA_BOARD_USB_CONSOLE
|
|
342
|
+
startUsbConsole();
|
|
343
|
+
if (previousBootCrashed())
|
|
344
|
+
xTaskCreatePinnedToCore(panicReportTask, "mosaico_panic", 3072, nullptr, 5, nullptr, 0);
|
|
345
|
+
#endif
|
|
346
|
+
#if CONFIG_BOOTLOADER_APP_ROLLBACK_CONFIRM_BY_APP
|
|
347
|
+
confirmRunningApp();
|
|
348
|
+
#endif
|
|
349
|
+
vTaskDelete(nullptr);
|
|
350
|
+
}
|
|
351
|
+
} // namespace
|
|
352
|
+
|
|
353
|
+
namespace gea::platform::board
|
|
354
|
+
{
|
|
355
|
+
void powerOnRails()
|
|
356
|
+
{
|
|
357
|
+
// Either the start task or display init gets here first; the other waits
|
|
358
|
+
// for the rail rather than talking to a panel that is still unpowered.
|
|
359
|
+
xSemaphoreTake(powerLock, portMAX_DELAY);
|
|
360
|
+
if (!railsOn)
|
|
361
|
+
powerOnRailsLocked();
|
|
362
|
+
xSemaphoreGive(powerLock);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Display init calls this just before the panel takes its init sequence
|
|
366
|
+
// (GEA_BOARD_PREPARE_DISPLAY_PANEL). Referencing it from display.cpp is also
|
|
367
|
+
// what keeps this translation unit -- and the start hook below -- linked.
|
|
368
|
+
void prepareDisplayPanel()
|
|
369
|
+
{
|
|
370
|
+
powerOnRails();
|
|
371
|
+
}
|
|
372
|
+
} // namespace gea::platform::board
|
|
373
|
+
|
|
374
|
+
// Runs before app_main, before the scheduler. It only creates the start task:
|
|
375
|
+
// the LEDC fade and TinyUSB both need a running scheduler.
|
|
376
|
+
ESP_SYSTEM_INIT_FN(gea_mosaico_board_start, SECONDARY, BIT(0), 999)
|
|
377
|
+
{
|
|
378
|
+
powerLock = xSemaphoreCreateMutexStatic(&powerLockStorage);
|
|
379
|
+
if (xTaskCreatePinnedToCore(boardStartTask, "mosaico_start", 4096, nullptr, 10, nullptr, 0) != pdPASS)
|
|
380
|
+
ESP_EARLY_LOGW(kTag, "board start task not created; display init will open VCC_3V3");
|
|
381
|
+
return ESP_OK;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
extern "C" void __real_esp_panic_handler(panic_info_t *info);
|
|
385
|
+
|
|
386
|
+
extern "C" void __wrap_esp_panic_handler(panic_info_t *info)
|
|
387
|
+
{
|
|
388
|
+
const auto *frame = info ? static_cast<const RvExcFrame *>(info->frame) : nullptr;
|
|
389
|
+
REG_WRITE(LP_SYSTEM_REG_LP_STORE11_REG, frame ? static_cast<std::uint32_t>(frame->mepc) : 0);
|
|
390
|
+
REG_WRITE(LP_SYSTEM_REG_LP_STORE12_REG, frame ? static_cast<std::uint32_t>(frame->ra) : 0);
|
|
391
|
+
REG_WRITE(LP_SYSTEM_REG_LP_STORE13_REG, frame ? static_cast<std::uint32_t>(frame->mcause) : 0);
|
|
392
|
+
REG_WRITE(LP_SYSTEM_REG_LP_STORE14_REG, frame ? static_cast<std::uint32_t>(frame->mtval) : 0);
|
|
393
|
+
REG_WRITE(LP_SYSTEM_REG_LP_STORE10_REG, kPanicMagic);
|
|
394
|
+
__real_esp_panic_handler(info);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
#if GEA_BOARD_USB_CONSOLE
|
|
398
|
+
// The TinyUSB console drops whatever does not fit the TX FIFO, so under a log
|
|
399
|
+
// flood a GEADEV reply (OTA READY, PONG) is lost and `gea flash` times out.
|
|
400
|
+
// Wait for the host to drain the FIFO instead, while a host is reading; give up
|
|
401
|
+
// after 100 ms and stop waiting until the FIFO takes a byte again, so a host
|
|
402
|
+
// that holds the port open without reading cannot stall the app.
|
|
403
|
+
extern "C" size_t __real_tinyusb_cdcacm_write_queue_char(tinyusb_cdcacm_itf_t itf, char ch);
|
|
404
|
+
|
|
405
|
+
extern "C" size_t __wrap_tinyusb_cdcacm_write_queue_char(tinyusb_cdcacm_itf_t itf, char ch)
|
|
406
|
+
{
|
|
407
|
+
static bool txStalled = false;
|
|
408
|
+
size_t queued = __real_tinyusb_cdcacm_write_queue_char(itf, ch);
|
|
409
|
+
if (queued || txStalled || xPortInIsrContext() || xTaskGetSchedulerState() != taskSCHEDULER_RUNNING ||
|
|
410
|
+
!tud_cdc_n_connected(itf))
|
|
411
|
+
{
|
|
412
|
+
if (queued)
|
|
413
|
+
txStalled = false;
|
|
414
|
+
return queued;
|
|
415
|
+
}
|
|
416
|
+
const TickType_t start = xTaskGetTickCount();
|
|
417
|
+
while (xTaskGetTickCount() - start < pdMS_TO_TICKS(100))
|
|
418
|
+
{
|
|
419
|
+
tud_cdc_n_write_flush(itf);
|
|
420
|
+
vTaskDelay(1);
|
|
421
|
+
queued = __real_tinyusb_cdcacm_write_queue_char(itf, ch);
|
|
422
|
+
if (queued)
|
|
423
|
+
return queued;
|
|
424
|
+
}
|
|
425
|
+
txStalled = true;
|
|
426
|
+
return 0;
|
|
427
|
+
}
|
|
428
|
+
#endif
|
|
429
|
+
|
|
430
|
+
// The panic dump goes out through the UART HAL; keep a copy in the crash log.
|
|
431
|
+
extern "C" void __real_uart_hal_write_txfifo(uart_hal_context_t *hal, const uint8_t *buf, uint32_t size,
|
|
432
|
+
uint32_t *written);
|
|
433
|
+
|
|
434
|
+
extern "C" IRAM_ATTR void __wrap_uart_hal_write_txfifo(uart_hal_context_t *hal, const uint8_t *buf,
|
|
435
|
+
uint32_t size, uint32_t *written)
|
|
436
|
+
{
|
|
437
|
+
__real_uart_hal_write_txfifo(hal, buf, size, written);
|
|
438
|
+
for (uint32_t i = 0; i < *written; ++i)
|
|
439
|
+
crashLogPutc(static_cast<char>(buf[i]));
|
|
440
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# A managed dependency is a requirement of `main` the moment it is listed here,
|
|
2
|
+
# so each network-only component carries the same capability rule the other
|
|
3
|
+
# targets use (GEA_EMBEDDED_CAPABILITY_* comes from the gea CLI's app analysis).
|
|
4
|
+
#
|
|
5
|
+
# Not here, unlike the S3 AMOLED targets: esp_audio_codec and esp-sr ship
|
|
6
|
+
# prebuilt per-chip libraries; the portable Opus build below stands in for the
|
|
7
|
+
# former, and an app that asks for echo cancellation is not supported yet.
|
|
8
|
+
dependencies:
|
|
9
|
+
espressif/esp_lcd_co5300: '^2.0.3'
|
|
10
|
+
# The board's touch controller is a CST9220 (Espressif's board definition,
|
|
11
|
+
# esp-brookesia esp_mosaico_v1_2). It may run the HYN212 protocol, which the
|
|
12
|
+
# CST9217 driver does not speak: touch then initializes and never reports.
|
|
13
|
+
espressif/esp_lcd_touch_cst9220: '^0.1.1'
|
|
14
|
+
espressif/esp_codec_dev: '^1.4.0'
|
|
15
|
+
esp_lcd_panel_io_additions: '^1'
|
|
16
|
+
# board_power.cpp: the USB-C port is the S31's high-speed OTG controller, so
|
|
17
|
+
# the console is a TinyUSB CDC interface.
|
|
18
|
+
espressif/esp_tinyusb: '^2.2.1'
|
|
19
|
+
espressif/esp_h264:
|
|
20
|
+
version: '^1.4.1'
|
|
21
|
+
rules:
|
|
22
|
+
- if: '$GEA_EMBEDDED_CAPABILITY_NETWORK == 1'
|
|
23
|
+
78/esp-opus:
|
|
24
|
+
version: '^1.0.5'
|
|
25
|
+
rules:
|
|
26
|
+
- if: '$GEA_EMBEDDED_CAPABILITY_NETWORK == 1'
|
|
27
|
+
espressif/esp_websocket_client:
|
|
28
|
+
version: '^1.4'
|
|
29
|
+
rules:
|
|
30
|
+
- if: '$GEA_EMBEDDED_CAPABILITY_NETWORK == 1'
|
|
31
|
+
espressif/esp_peer:
|
|
32
|
+
version: '^1.4'
|
|
33
|
+
rules:
|
|
34
|
+
- if: '$GEA_EMBEDDED_CAPABILITY_NETWORK == 1'
|
|
35
|
+
idf:
|
|
36
|
+
# ESP32-S31 exists only in ESP-IDF master (6.2-dev), as a preview target.
|
|
37
|
+
version: '>=6.2.0-dev'
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "driver/gpio.h"
|
|
4
|
+
#include "driver/i2s_types.h"
|
|
5
|
+
#include "driver/spi_master.h"
|
|
6
|
+
|
|
7
|
+
// Espressif ESP-Mosaico, hardware V1.2 (V1.1 shares the mapping).
|
|
8
|
+
//
|
|
9
|
+
// ESP32-S31 (dual-core RISC-V, 320 MHz) with 16 MB in-package octal PSRAM,
|
|
10
|
+
// 16 MB quad NOR flash, a 480x480 CO5300 QSPI AMOLED with a CST9220 touch
|
|
11
|
+
// controller, ES8311 codec + NS4150B amplifier, BMI270 IMU, two BMM150
|
|
12
|
+
// magnetometers, a BQ27220 fuel gauge and 128 MB SPI NAND.
|
|
13
|
+
//
|
|
14
|
+
// Pins come from the board's own BSP (esp-mosaico-bsp, bsp/esp_mosaico.h) and
|
|
15
|
+
// the esp-dev-kits V1.2 user guide. V1.0 is NOT interchangeable: it swaps the
|
|
16
|
+
// LCD clock and reset (GPIO44/42) and puts the onboard I2C on GPIO0/1. Getting
|
|
17
|
+
// the swap wrong is silent -- every QSPI write reports success into a panel
|
|
18
|
+
// still held in reset.
|
|
19
|
+
//
|
|
20
|
+
// Everything on the panel side sits behind VCC_3V3, a high-side switch whose
|
|
21
|
+
// enable (GPIO60) is ACTIVE LOW. Nothing on that rail answers until the board
|
|
22
|
+
// power code has opened it; see board_power.cpp.
|
|
23
|
+
|
|
24
|
+
namespace gea::platform::board {
|
|
25
|
+
|
|
26
|
+
struct I2cBusConfig {
|
|
27
|
+
gpio_num_t sda;
|
|
28
|
+
gpio_num_t scl;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
struct Co5300DisplayConfig {
|
|
32
|
+
spi_host_device_t spiHost;
|
|
33
|
+
gpio_num_t cs;
|
|
34
|
+
gpio_num_t pclk;
|
|
35
|
+
gpio_num_t data0;
|
|
36
|
+
gpio_num_t data1;
|
|
37
|
+
gpio_num_t data2;
|
|
38
|
+
gpio_num_t data3;
|
|
39
|
+
gpio_num_t reset;
|
|
40
|
+
gpio_num_t te; // VBlank/tearing-effect line; GPIO_NUM_NC = vsync disabled
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
struct Cst9217TouchConfig {
|
|
44
|
+
gpio_num_t reset;
|
|
45
|
+
gpio_num_t interrupt;
|
|
46
|
+
bool swapXy;
|
|
47
|
+
bool mirrorX;
|
|
48
|
+
bool mirrorY;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
struct Es8311AudioConfig {
|
|
52
|
+
int i2sPort;
|
|
53
|
+
gpio_num_t mclk;
|
|
54
|
+
gpio_num_t bclk;
|
|
55
|
+
gpio_num_t ws;
|
|
56
|
+
gpio_num_t dout;
|
|
57
|
+
gpio_num_t din;
|
|
58
|
+
gpio_num_t powerAmplifier;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
struct PowerConfig {
|
|
62
|
+
// VCC_3V3 high-side switch enable, active low.
|
|
63
|
+
gpio_num_t vcc3v3Enable;
|
|
64
|
+
// Power-off request to the SAM8108 controller, open drain, asserted low.
|
|
65
|
+
// Released (high impedance) for as long as the board should stay on.
|
|
66
|
+
gpio_num_t powerOffRequest;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
struct LauncherButtonConfig {
|
|
70
|
+
gpio_num_t pin;
|
|
71
|
+
int activeLevel;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
class EspMosaicoV12 {
|
|
75
|
+
public:
|
|
76
|
+
// Onboard bus: touch (0x5A), ES8311 (0x19), BMI270 (0x69), BMM150 (0x11,
|
|
77
|
+
// 0x12) and BQ27220 (0x55). The expansion slots have their own bus on
|
|
78
|
+
// GPIO0/GPIO1, which nothing here drives.
|
|
79
|
+
static constexpr I2cBusConfig i2c{
|
|
80
|
+
.sda = GPIO_NUM_56,
|
|
81
|
+
.scl = GPIO_NUM_3,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// SPI3 carries the NAND; SPI2 is the panel's.
|
|
85
|
+
static constexpr Co5300DisplayConfig display{
|
|
86
|
+
.spiHost = SPI2_HOST,
|
|
87
|
+
.cs = GPIO_NUM_50,
|
|
88
|
+
.pclk = GPIO_NUM_42,
|
|
89
|
+
.data0 = GPIO_NUM_36,
|
|
90
|
+
.data1 = GPIO_NUM_51,
|
|
91
|
+
.data2 = GPIO_NUM_35,
|
|
92
|
+
.data3 = GPIO_NUM_9,
|
|
93
|
+
.reset = GPIO_NUM_44,
|
|
94
|
+
// The panel drives TE on GPIO43 (TEON in the init sequence). An app that
|
|
95
|
+
// calls Display.setVSync(true) frames off it, locked to the ~60 Hz scanout.
|
|
96
|
+
.te = GPIO_NUM_43,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// Touch reset is not wired; the controller comes out of power-on reset
|
|
100
|
+
// with the VCC_3V3 rail. The panel and touch share orientation, and the
|
|
101
|
+
// BSP applies no base swap or mirror to either.
|
|
102
|
+
static constexpr Cst9217TouchConfig touch{
|
|
103
|
+
.reset = GPIO_NUM_NC,
|
|
104
|
+
.interrupt = GPIO_NUM_6,
|
|
105
|
+
.swapXy = false,
|
|
106
|
+
.mirrorX = false,
|
|
107
|
+
.mirrorY = false,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// The codec's I2S pins double as right-slot expansion pins; a module
|
|
111
|
+
// there and audio cannot be used at the same time.
|
|
112
|
+
static constexpr Es8311AudioConfig audio{
|
|
113
|
+
.i2sPort = I2S_NUM_AUTO,
|
|
114
|
+
.mclk = GPIO_NUM_54,
|
|
115
|
+
.bclk = GPIO_NUM_37,
|
|
116
|
+
.ws = GPIO_NUM_49,
|
|
117
|
+
.dout = GPIO_NUM_52,
|
|
118
|
+
.din = GPIO_NUM_40,
|
|
119
|
+
.powerAmplifier = GPIO_NUM_45,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
static constexpr PowerConfig power{
|
|
123
|
+
.vcc3v3Enable = GPIO_NUM_60,
|
|
124
|
+
.powerOffRequest = GPIO_NUM_57,
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
using Board = EspMosaicoV12;
|
|
129
|
+
|
|
130
|
+
inline constexpr auto i2c = Board::i2c;
|
|
131
|
+
inline constexpr auto display = Board::display;
|
|
132
|
+
inline constexpr auto touch = Board::touch;
|
|
133
|
+
inline constexpr auto audio = Board::audio;
|
|
134
|
+
inline constexpr auto power = Board::power;
|
|
135
|
+
|
|
136
|
+
// The "AI" button on the side, active low. BOOT (GPIO61) stays the ROM's
|
|
137
|
+
// download strap and is left alone.
|
|
138
|
+
inline constexpr LauncherButtonConfig launcherButton{
|
|
139
|
+
.pin = GPIO_NUM_7,
|
|
140
|
+
.activeLevel = 0,
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// Opens VCC_3V3 (soft-started) and releases the power-off request. Safe to
|
|
144
|
+
// call more than once; display init calls it through prepareDisplayPanel().
|
|
145
|
+
void powerOnRails();
|
|
146
|
+
|
|
147
|
+
} // namespace gea::platform::board
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#include "touch.h"
|
|
2
|
+
#include "chip_bindings/touch/cst9217_controller.h"
|
|
3
|
+
|
|
4
|
+
namespace {
|
|
5
|
+
|
|
6
|
+
gea::platform::esp32::chip_bindings::cst9217::TouchController &touchController() {
|
|
7
|
+
return gea::platform::esp32::chip_bindings::cst9217::TouchController::instance();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
} // namespace
|
|
11
|
+
|
|
12
|
+
void gea::platform::touch::Touchscreen::setObserver(Observer observer) {
|
|
13
|
+
touchController().setObserver(observer);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
void gea::platform::touch::Touchscreen::setPointerObserver(PointerObserver observer) {
|
|
17
|
+
touchController().setPointerObserver(observer);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
bool gea::platform::touch::Touchscreen::init() {
|
|
21
|
+
return touchController().begin() == ESP_OK;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
int gea::platform::touch::Touchscreen::read(int *x, int *y) {
|
|
25
|
+
gea::platform::esp32::chip_bindings::cst9217::TouchSample sample;
|
|
26
|
+
const bool touching = touchController().read(sample);
|
|
27
|
+
if (x) *x = sample.x;
|
|
28
|
+
if (y) *y = sample.y;
|
|
29
|
+
return touching ? 1 : 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
int gea::platform::touch::Touchscreen::readCached(int *x, int *y) {
|
|
33
|
+
const auto sample = touchController().cached();
|
|
34
|
+
if (x) *x = sample.x;
|
|
35
|
+
if (y) *y = sample.y;
|
|
36
|
+
return sample.touching ? 1 : 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void gea::platform::touch::Touchscreen::consumeLatestMove(int *x, int *y) {
|
|
40
|
+
touchController().consumeLatestMove(x, y);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
void gea::platform::touch::Touchscreen::injectEvent(Phase phase, bool touching, int x, int y) {
|
|
44
|
+
touchController().injectEvent(phase, touching, x, y);
|
|
45
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Espressif ESP-Mosaico V1.2, 16 MB quad NOR flash (GD25Q128E).
|
|
2
|
+
# The S31 bootloader sits at 0x2000 (the first two sectors are reserved), which
|
|
3
|
+
# leaves it 24 KB below the partition table at 0x8000.
|
|
4
|
+
# Name, Type, SubType, Offset, Size
|
|
5
|
+
nvs, data, nvs, 0x9000, 0x6000
|
|
6
|
+
otadata, data, ota, 0xf000, 0x2000
|
|
7
|
+
phy_init, data, phy, 0x11000, 0x1000
|
|
8
|
+
ota_0, app, ota_0, 0x20000, 0x700000
|
|
9
|
+
ota_1, app, ota_1, 0x720000, 0x700000
|
|
10
|
+
storage, data, spiffs, 0xe20000, 0x1c0000
|