Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 663b93b

Browse files
committed
Disable RGBLED functionality with Makefile switch RGB_LED=disable
1 parent 0a38f88 commit 663b93b

File tree

10 files changed

+78
-4
lines changed

10 files changed

+78
-4
lines changed

esp32/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ RELEASE_DIR ?= build/
3737
COPY_IDF_LIB ?= 0
3838

3939
LTE_LOG_BUFF ?= 0
40+
RGB_LED ?= enable
4041

4142
# by default openthread over LoRa is enabled
4243
OPENTHREAD ?= on
@@ -127,6 +128,10 @@ ifeq ($(LTE_DEBUG_BUFF),1)
127128
CFLAGS += -DLTE_DEBUG_BUFF
128129
endif #ifeq ($(LTE_LOG_BUFF),1)
129130
endif #ifeq ($(BOARD), $(filter $(BOARD), GPY FIPY))
131+
# Enable or Disable RGB led
132+
ifeq ($(RGB_LED),disable)
133+
CFLAGS += -DRGB_LED_DISABLE
134+
endif #ifeq ($(LTE_LOG_BUFF),1)
130135

131136
B_LIBS = -Lbootloader/lib -Lbootloader -L$(BUILD)/bootloader -L$(ESP_IDF_COMP_PATH)/esp32/ld \
132137
-L$(ESP_IDF_COMP_PATH)/esp32/lib -llog -lcore -lbootloader_support \

esp32/bootloader/bootloader.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ static bool find_active_image(bootloader_state_t *bs, esp_partition_pos_t *parti
338338
memcpy(&_boot_info, boot_info, sizeof(boot_info_t));
339339
bootloader_munmap(boot_info);
340340
boot_info = &_boot_info;
341+
#ifndef RGB_LED_DISABLE
341342
mperror_init0();
343+
#endif
342344

343345
// // check the signature fot he bootloader first
344346
// uint8_t signature[16];
@@ -372,7 +374,9 @@ static bool find_active_image(bootloader_state_t *bs, esp_partition_pos_t *parti
372374
boot_info->safeboot = false;
373375
if (!ota_write_boot_info (boot_info, bs->ota_info.offset)) {
374376
ESP_LOGE(TAG, "Error writing boot info");
377+
#ifndef RGB_LED_DISABLE
375378
mperror_fatal_error();
379+
#endif
376380
return false;
377381
}
378382
return true;
@@ -504,7 +508,9 @@ static void bootloader_main()
504508
if (bootloader_state.ota_info.offset == 0 || !find_active_image(&bootloader_state, &partition)) {
505509
// nothing to load, bail out
506510
ESP_LOGE(TAG, "nothing to load");
511+
#ifndef RGB_LED_DISABLE
507512
mperror_fatal_error();
513+
#endif
508514
return;
509515
}
510516

esp32/bootloader/bootmgr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,20 @@ static void delay_ms (uint32_t delay) {
7070
//*****************************************************************************
7171
static bool wait_while_blinking (uint32_t wait_time, uint32_t period, bool force_wait) {
7272
uint32_t count;
73+
#ifndef RGB_LED_DISABLE
7374
static bool toggle = true;
75+
#endif
7476
for (count = 0; (force_wait || gpio_get_level(MICROPY_HW_SAFE_PIN_NUM)) &&
7577
((period * count) < wait_time); count++) {
78+
#ifndef RGB_LED_DISABLE
7679
// toggle the led
7780
if (toggle) {
7881
mperror_set_rgb_color(BOOTMGR_SAFEBOOT_COLOR);
7982
} else {
8083
mperror_set_rgb_color(0);
8184
}
8285
toggle = !toggle;
86+
#endif
8387
delay_ms(period);
8488
}
8589
return gpio_get_level(MICROPY_HW_SAFE_PIN_NUM) ? true : false;
@@ -116,8 +120,10 @@ uint32_t wait_for_safe_boot (const boot_info_t *boot_info, uint32_t *ActiveImg)
116120
wait_while_blinking(BOOTMGR_WAIT_SAFE_MODE_3_MS, BOOTMGR_WAIT_SAFE_MODE_3_BLINK_MS, true);
117121
}
118122
}
123+
#ifndef RGB_LED_DISABLE
119124
// turn off the heartbeat led
120125
mperror_set_rgb_color(0);
126+
#endif
121127
// request a HW safe boot
122128
ret = SAFE_BOOT_HW;
123129
}

esp32/bootloader/mperror.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* see the Pycom Licence v1.0 document supplied with this file, or
77
* available at https://www.pycom.io/opensource/licensing
88
*/
9-
9+
#ifndef RGB_LED_DISABLE
1010
#include <stdbool.h>
1111
#include <stdio.h>
1212
#include <stdint.h>
@@ -146,3 +146,11 @@ void IRAM_ATTR mperror_set_rgb_color (uint32_t rgbcolor) {
146146
XTOS_RESTORE_INTLEVEL(ilevel);
147147
ets_delay_us(RESET_TIME_US);
148148
}
149+
150+
#else
151+
152+
__attribute__((noreturn)) void mperror_fatal_error (void) {
153+
for ( ; ; );
154+
}
155+
156+
#endif //RGB_LED_DISABLE

esp32/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ void app_main(void) {
120120
nvs_flash_erase();
121121
nvs_flash_init();
122122
}
123-
123+
#ifndef RGB_LED_DISABLE
124124
// initialise heartbeat on Core 0
125125
mperror_pre_init();
126+
#endif
126127

127128
// differentiate the Flash Size (either 8MB or 4MB) based on ESP32 rev id
128129
micropy_hw_flash_size = (esp_get_revision() > 0 ? 0x800000 : 0x400000);

esp32/mods/machpin.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ void pin_init0(void) {
138138
{
139139
continue;
140140
}
141+
#ifndef RGB_LED_DISABLE
141142
/* exclude RGB led from initialization as it is already initialized by mperror */
142143
if (self == &PIN_MODULE_P2)
143144
{
144145
continue;
145146
}
147+
#endif
146148
pin_config(self, -1, -1, GPIO_MODE_INPUT, MACHPIN_PULL_DOWN, 0);
147149
}
148150
}

esp32/mods/modmachine.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ STATIC mp_obj_t machine_sleep (uint n_args, const mp_obj_t *arg) {
239239
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_sleep_obj,0, 2, machine_sleep);
240240

241241
STATIC mp_obj_t machine_deepsleep (uint n_args, const mp_obj_t *arg) {
242+
#ifndef RGB_LED_DISABLE
242243
mperror_enable_heartbeat(false);
244+
#endif
243245
bt_deinit(NULL);
244246
wlan_deinit(NULL);
245247
#if defined(FIPY) || defined(GPY)

esp32/mods/modpycom.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ static void modpycom_bootmgr(uint8_t boot_partition, uint8_t fs_type, uint8_t sa
124124

125125

126126
STATIC mp_obj_t mod_pycom_heartbeat (mp_uint_t n_args, const mp_obj_t *args) {
127+
#ifndef RGB_LED_DISABLE
127128
if (n_args) {
128129
mperror_enable_heartbeat (mp_obj_is_true(args[0]));
129130
if (!mp_obj_is_true(args[0])) {
@@ -134,19 +135,25 @@ STATIC mp_obj_t mod_pycom_heartbeat (mp_uint_t n_args, const mp_obj_t *args) {
134135
} else {
135136
return mp_obj_new_bool(mperror_is_heartbeat_enabled());
136137
}
138+
#else
139+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "RGB Led Interface Disabled"));
140+
#endif
137141
return mp_const_none;
138142
}
139143
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_pycom_heartbeat_obj, 0, 1, mod_pycom_heartbeat);
140144

141145
STATIC mp_obj_t mod_pycom_rgb_led (mp_obj_t o_color) {
142-
146+
#ifndef RGB_LED_DISABLE
143147
if (mperror_is_heartbeat_enabled()) {
144148
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible));
145149
}
146150

147151
uint32_t color = mp_obj_get_int(o_color);
148152
led_info.color.value = color;
149153
led_set_color(&led_info, true, false);
154+
#else
155+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "RGB Led Interface Disabled"));
156+
#endif
150157

151158
return mp_const_none;
152159
}

esp32/mptask.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ void TASK_Micropython (void *pvParameters) {
212212
mp_irq_init0();
213213
#endif
214214
uart_init0();
215+
#ifndef RGB_LED_DISABLE
215216
mperror_init0();
217+
#endif
216218
rng_init0();
217219
mp_hal_init(soft_reset);
218220
readline_init0();
@@ -295,8 +297,10 @@ void TASK_Micropython (void *pvParameters) {
295297
goto soft_reset_exit;
296298
}
297299
if (!ret) {
300+
#ifndef RGB_LED_DISABLE
298301
// flash the system led
299302
mperror_signal_error();
303+
#endif
300304
}
301305
}
302306

@@ -317,8 +321,10 @@ void TASK_Micropython (void *pvParameters) {
317321
goto soft_reset_exit;
318322
}
319323
if (!ret) {
324+
#ifndef RGB_LED_DISABLE
320325
// flash the system led
321326
mperror_signal_error();
327+
#endif
322328
}
323329
}
324330
}

esp32/util/mperror.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* see the Pycom Licence v1.0 document supplied with this file, or
77
* available at https://www.pycom.io/opensource/licensing
88
*/
9-
9+
#ifndef RGB_LED_DISABLE
1010
#include <stdio.h>
1111
#include <stdint.h>
1212
#include <string.h>
@@ -37,6 +37,7 @@
3737

3838
#include "esp_freertos_hooks.h"
3939

40+
4041
/******************************************************************************
4142
DEFINE CONSTANTS
4243
******************************************************************************/
@@ -219,3 +220,33 @@ static void disable_and_wait (void) {
219220
mp_hal_delay_ms(2);
220221
}
221222
}
223+
224+
#else
225+
#include "py/mpconfig.h"
226+
#ifndef BOOTLOADER_BUILD
227+
void NORETURN __fatal_error(const char *msg) {
228+
#ifdef DEBUG
229+
if (msg != NULL) {
230+
// wait for 20ms
231+
mp_hal_delay_ms(20);
232+
mp_hal_stdout_tx_str("\r\nFATAL ERROR:");
233+
mp_hal_stdout_tx_str(msg);
234+
mp_hal_stdout_tx_str("\r\n");
235+
}
236+
#endif
237+
238+
for ( ;; ); //{__WFI();}
239+
}
240+
241+
void nlr_jump_fail(void *val) {
242+
#ifdef DEBUG
243+
char msg[64];
244+
snprintf(msg, sizeof(msg), "uncaught exception %p\n", val);
245+
__fatal_error(msg);
246+
#else
247+
__fatal_error(NULL);
248+
#endif
249+
}
250+
#endif
251+
252+
#endif // RGB_LED_DISABLE

0 commit comments

Comments
 (0)