Skip to content

Commit 208c1e9

Browse files
committed
Rabbit Droppings
1 parent b1feafa commit 208c1e9

3 files changed

Lines changed: 29 additions & 16 deletions

File tree

pio-scripts/enable_lto_s3.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,17 @@ def enable_lto(env):
4444
# library archives carry IR that the linker can optimise across.
4545
cc = str(env.get("CC", ""))
4646
if cc:
47-
toolchain_prefix = cc.replace("gcc", "").replace("g++", "")
48-
# toolchain_prefix is something like "xtensa-esp32s3-elf-"
49-
new_ar = toolchain_prefix + "gcc-ar"
50-
new_ranlib = toolchain_prefix + "gcc-ranlib"
47+
cc_basename = os.path.basename(cc)
48+
# Strip trailing "gcc" or "g++" (with optional .exe suffix) from basename only
49+
if cc_basename.endswith(".exe"):
50+
cc_basename = cc_basename[:-4]
51+
if cc_basename.endswith("gcc"):
52+
cc_basename = cc_basename[:-3]
53+
elif cc_basename.endswith("g++"):
54+
cc_basename = cc_basename[:-3]
55+
# cc_basename is now something like "xtensa-esp32s3-elf"
56+
new_ar = cc_basename + "-gcc-ar"
57+
new_ranlib = cc_basename + "-gcc-ranlib"
5158

5259
# Resolve CC to its real path so we can search the same directory
5360
cc_resolved = shutil.which(cc) or cc

usermods/M5Stack_CoreS3_Display/readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Reset is controlled via the AW9523B GPIO expander (P1_1). Backlight is powered v
1919

2020
In `platformio_override.ini` for your M5Stack Core S3 environment:
2121

22-
```build_flags =
22+
```ini
23+
build_flags =
2324
-D USERMOD_M5STACK_CORE_S3_DISPLAY
2425
;; For the M5Stack ModuleAudio:
2526
-D SR_ENABLE_DEFAULT
@@ -32,7 +33,8 @@ In `platformio_override.ini` for your M5Stack Core S3 environment:
3233
-D HW_SCL_PIN=11
3334

3435
lib_deps =
35-
https://github.com/lovyan03/LovyanGFX```
36+
https://github.com/lovyan03/LovyanGFX
37+
```
3638

3739
## Features
3840

@@ -48,7 +50,7 @@ lib_deps =
4850

4951
- Uses LovyanGFX with `SPI3_HOST` (HSPI)
5052
- Native landscape 320x240 resolution
51-
- BGR color order, display inversion enabled
53+
- RGB color order, display inversion enabled
5254
- Backlight always on (controlled by AXP2101 DLDO1)
5355

5456
## TroyHacks Recommended AudioReactive Settings

usermods/M5Stack_CoreS3_Display/usermod_m5stack_s3_display.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ static LGFX_ILI9342_M5StackS3 tft;
7777
class M5StackCoreS3DisplayUsermod : public Usermod {
7878
private:
7979
bool enabled = true;
80+
bool _initOk = false;
8081

8182
// needRedraw marks if redraw is required to prevent often redrawing.
8283
bool needRedraw = true;
@@ -140,7 +141,7 @@ class M5StackCoreS3DisplayUsermod : public Usermod {
140141
Wire.write(0x90);
141142
Wire.endTransmission(false);
142143
Wire.requestFrom((uint8_t)AXP2101_ADDR, (uint8_t)1);
143-
byte pwr_orig = Wire.read();
144+
byte pwr_orig = Wire.available() ? Wire.read() : 0x00;
144145
Serial.printf("M5StackS3Display: 0x90 orig: 0x%02X\n", pwr_orig);
145146

146147
// Set DLDO1 voltage to 3.3V (voltage reg 0x99)
@@ -155,7 +156,7 @@ class M5StackCoreS3DisplayUsermod : public Usermod {
155156
Wire.write(0x99);
156157
Wire.endTransmission(false);
157158
Wire.requestFrom((uint8_t)AXP2101_ADDR, (uint8_t)1);
158-
byte dldo1_v = Wire.read();
159+
byte dldo1_v = Wire.available() ? Wire.read() : 0x00;
159160
Serial.printf("M5StackS3Display: DLDO1 0x99: 0x%02X\n", dldo1_v);
160161

161162
// Enable DLDO1 via bit 7 of 0x90
@@ -172,7 +173,7 @@ class M5StackCoreS3DisplayUsermod : public Usermod {
172173
Wire.write(0x90);
173174
Wire.endTransmission(false);
174175
Wire.requestFrom((uint8_t)AXP2101_ADDR, (uint8_t)1);
175-
byte pwr_after = Wire.read();
176+
byte pwr_after = Wire.available() ? Wire.read() : 0x00;
176177
Serial.printf("M5StackS3Display: 0x90 after: 0x%02X\n", pwr_after);
177178

178179
// AW9523 GPIO expander for LCD reset
@@ -209,7 +210,7 @@ class M5StackCoreS3DisplayUsermod : public Usermod {
209210
Wire.write(0x03); // P1 output register
210211
Wire.endTransmission(false);
211212
Wire.requestFrom((uint8_t)AW9523B_ADDR, (uint8_t)1);
212-
byte p1_state = Wire.read();
213+
byte p1_state = Wire.available() ? Wire.read() : 0x00;
213214
Serial.printf("M5StackS3Display: AW9523B P1 state: 0x%02X\n", p1_state);
214215

215216
Serial.println("M5StackS3Display: init TFT");
@@ -222,11 +223,13 @@ class M5StackCoreS3DisplayUsermod : public Usermod {
222223
{ (gpio_num_t)TFT_CS, true },
223224
{ (gpio_num_t)TFT_DC, true }
224225
};
225-
if (pinManager.allocateMultiplePins(pins, 4, PinOwner::UM_Unspecified)) {
226-
Serial.println("M5StackS3Display: SPI pins allocated");
227-
} else {
228-
Serial.println("M5StackS3Display: SPI pin allocation FAILED");
226+
if (!pinManager.allocateMultiplePins(pins, 4, PinOwner::UM_Unspecified)) {
227+
Serial.println("M5StackS3Display: SPI pin allocation FAILED — disabling usermod");
228+
enabled = false;
229+
_initOk = false;
230+
return;
229231
}
232+
Serial.println("M5StackS3Display: SPI pins allocated");
230233

231234
Serial.printf("M5StackS3Display: TFT width: %d, height: %d\n", tft.width(), tft.height());
232235

@@ -248,13 +251,14 @@ class M5StackCoreS3DisplayUsermod : public Usermod {
248251
tft.drawString("Loading...", tft.width() - 10, textY);
249252

250253
Serial.println("M5StackS3Display: setup complete");
254+
_initOk = true;
251255
}
252256

253257
/*
254258
* loop() is called continuously. Here you can check for events, read sensors, etc.
255259
*/
256260
void loop() {
257-
if (!enabled) return;
261+
if (!enabled || !_initOk) return;
258262

259263
unsigned long now = millis();
260264

0 commit comments

Comments
 (0)