diff --git a/esp32/Makefile b/esp32/Makefile index 10ca433cca..5826d20992 100644 --- a/esp32/Makefile +++ b/esp32/Makefile @@ -32,8 +32,19 @@ PYGATE_ENABLED ?= 0 # COAP is enabled by default MOD_COAP_ENABLED ?= 1 -# SIGFOX is enabled by default. It will only be built for supported boards. +# LORA is enabled by default for supported boards +ifeq ($(BOARD), $(filter $(BOARD), LOPY LOPY4 FIPY)) +MOD_LORA_ENABLED ?= 1 +else +MOD_LORA_ENABLED ?= 0 +endif + +# SIGFOX is enabled by default for supported boards +ifeq ($(BOARD), $(filter $(BOARD), SIPY LOPY4 FIPY)) MOD_SIGFOX_ENABLED ?= 1 +else +MOD_SIGFOX_ENABLED ?= 0 +endif # Pybytes disabled by default PYBYTES_ENABLED ?= 0 @@ -55,6 +66,7 @@ ifeq ($(VARIANT),PYGATE) endif PYBYTES_ENABLED=1 PYETH_ENABLED=1 + MOD_LORA_ENABLED=0 # ETH and LORA are mutually exclusive PYGATE_ENABLED=1 endif @@ -121,6 +133,7 @@ CFLAGS_XTENSA_OPT = -Os CFLAGS_XTENSA_PSRAM = -mfix-esp32-psram-cache-issue CFLAGS = $(CFLAGS_XTENSA) $(CFLAGS_XTENSA_PSRAM) $(CFLAGS_XTENSA_OPT) -nostdlib -std=gnu99 -g3 -ggdb -fstrict-volatile-bitfields -Iboards/$(BOARD) +CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA) CFLAGS_SIGFOX = $(CFLAGS_XTENSA) -O2 -nostdlib -std=gnu99 -g3 -ggdb -fstrict-volatile-bitfields -Iboards/$(BOARD) # Configure floating point support @@ -156,6 +169,11 @@ ifeq ($(MOD_COAP_ENABLED), 1) CFLAGS += -DMOD_COAP_ENABLED endif +ifeq ($(MOD_LORA_ENABLED), 1) + $(info LORA Module Enabled) + CFLAGS += -DMOD_LORA_ENABLED +endif + ifeq ($(DIFF_UPDATE_ENABLED), 1) $(info Differential Update Enabled) CFLAGS += -DDIFF_UPDATE_ENABLED -DBZ_NO_STDIO @@ -163,12 +181,9 @@ endif ifeq ($(MOD_SIGFOX_ENABLED), 1) $(info SIGFOX Module Enabled) - - ifeq ($(BOARD), $(filter $(BOARD), SIPY LOPY4 FIPY)) - CFLAGS += -DMOD_SIGFOX_ENABLED - LIBS += sigfox/modsigfox_$(BOARD).a -lsigfox - $(BUILD)/application.elf: sigfox/modsigfox_$(BOARD).a - endif + CFLAGS += -DMOD_SIGFOX_ENABLED + LIBS += sigfox/modsigfox_$(BOARD).a -lsigfox + $(BUILD)/application.elf: sigfox/modsigfox_$(BOARD).a endif ifeq ($(OPENTHREAD), on) diff --git a/esp32/application.mk b/esp32/application.mk index 7fdd0c8256..299e96f87b 100644 --- a/esp32/application.mk +++ b/esp32/application.mk @@ -388,13 +388,30 @@ BOOT_SRC_C = $(addprefix bootloader/,\ SFX_OBJ = OBJ = $(PY_O) +ifeq ($(MOD_LORA_ENABLED), 1) + ifeq ($(BOARD), $(filter $(BOARD), LOPY FIPY)) OBJ += $(addprefix $(BUILD)/, $(APP_LORA_SRC_C:.c=.o) $(APP_LIB_LORA_SRC_C:.c=.o) $(APP_SX1272_SRC_C:.c=.o) $(APP_MODS_LORA_SRC_C:.c=.o)) endif + ifeq ($(BOARD), $(filter $(BOARD), LOPY4)) OBJ += $(addprefix $(BUILD)/, $(APP_LORA_SRC_C:.c=.o) $(APP_LIB_LORA_SRC_C:.c=.o) $(APP_SX1276_SRC_C:.c=.o) $(APP_MODS_LORA_SRC_C:.c=.o)) endif +endif + +ifeq ($(MOD_SIGFOX_ENABLED), 1) + +ifeq ($(BOARD), $(filter $(BOARD), LOPY FIPY)) +OBJ += $(addprefix $(BUILD)/, $(APP_LORA_SRC_C:.c=.o) $(APP_LIB_LORA_SRC_C:.c=.o) $(APP_SX1272_SRC_C:.c=.o) $(APP_MODS_LORA_SRC_C:.c=.o)) +endif + +ifeq ($(BOARD), $(filter $(BOARD), LOPY4)) +OBJ += $(addprefix $(BUILD)/, $(APP_LORA_SRC_C:.c=.o) $(APP_LIB_LORA_SRC_C:.c=.o) $(APP_SX1276_SRC_C:.c=.o) $(APP_MODS_LORA_SRC_C:.c=.o)) +endif + +endif + ifeq ($(MOD_SIGFOX_ENABLED), 1) ifeq ($(BOARD), $(filter $(BOARD), SIPY)) OBJ += $(addprefix $(BUILD)/, $(APP_SIGFOX_MOD_SRC_C:.c=.o)) @@ -416,7 +433,7 @@ endif endif # ifeq ($(OPENTHREAD), on) OBJ += $(addprefix $(BUILD)/, $(APP_MAIN_SRC_C:.c=.o) $(APP_HAL_SRC_C:.c=.o) $(APP_LIB_SRC_C:.c=.o)) -OBJ += $(addprefix $(BUILD)/, $(APP_MODS_SRC_C:.c=.o) $(APP_STM_SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(APP_MODS_SRC_C:.c=.o) $(APP_STM_SRC_C:.c=.o) $(SRC_MOD:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(APP_FATFS_SRC_C:.c=.o) $(APP_LITTLEFS_SRC_C:.c=.o) $(APP_UTIL_SRC_C:.c=.o) $(APP_TELNET_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(APP_FTP_SRC_C:.c=.o) $(APP_CAN_SRC_C:.c=.o)) ifeq ($(PYGATE_ENABLED), 1) @@ -436,7 +453,7 @@ OBJ += $(BUILD)/pins.o BOOT_OBJ = $(addprefix $(BUILD)/, $(BOOT_SRC_C:.c=.o)) # List of sources for qstr extraction -SRC_QSTR += $(APP_MODS_SRC_C) $(APP_UTIL_SRC_C) $(APP_STM_SRC_C) $(APP_LIB_SRC_C) +SRC_QSTR += $(APP_MODS_SRC_C) $(APP_UTIL_SRC_C) $(APP_STM_SRC_C) $(APP_LIB_SRC_C) $(SRC_MOD) ifeq ($(BOARD), $(filter $(BOARD), LOPY LOPY4 FIPY)) SRC_QSTR += $(APP_MODS_LORA_SRC_C) endif @@ -463,7 +480,7 @@ BOOT_LDFLAGS = $(LDFLAGS) -T esp32.bootloader.ld -T esp32.rom.ld -T esp32.periph # add the application linker script(s) APP_LDFLAGS += $(LDFLAGS) -T esp32_out.ld -T esp32.project.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.libgcc.ld -T esp32.extram.bss.ld - +APP_LDFLAGS += $(LDFLAGS_MOD) # add the application specific CFLAGS CFLAGS += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM -DFFCONF_H=\"lib/oofatfs/ffconf.h\" -DWITH_POSIX CFLAGS_SIGFOX += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM diff --git a/esp32/lte/lteppp.c b/esp32/lte/lteppp.c index ad7f70c28b..01035c1d74 100644 --- a/esp32/lte/lteppp.c +++ b/esp32/lte/lteppp.c @@ -174,7 +174,7 @@ void lteppp_init(void) { lteppp_pcb = pppapi_pppos_create(<eppp_netif, lteppp_output_callback, lteppp_status_cb, NULL); //wait on connecting modem until it is allowed - lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED; + lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED); xTaskCreatePinnedToCore(TASK_LTE, "LTE", LTE_TASK_STACK_SIZE / sizeof(StackType_t), NULL, LTE_TASK_PRIORITY, &xLTETaskHndl, 1); @@ -211,15 +211,26 @@ char* lteppp_get_log_buff(void) } #endif -lte_modem_conn_state_t lteppp_modem_state(void) +lte_modem_conn_state_t lteppp_get_modem_conn_state(void) { lte_modem_conn_state_t state; + if (!xLTESem){ + // lte task hasn't been initialized yet, so we don't need to (and can't) protect this read + return lteppp_modem_conn_state; + } xSemaphoreTake(xLTESem, portMAX_DELAY); state = lteppp_modem_conn_state; xSemaphoreGive(xLTESem); return state; } +void lteppp_set_modem_conn_state(lte_modem_conn_state_t state) +{ + xSemaphoreTake(xLTESem, portMAX_DELAY); + lteppp_modem_conn_state = state; + xSemaphoreGive(xLTESem); +} + void lteppp_set_state(lte_state_t state) { xSemaphoreTake(xLTESem, portMAX_DELAY); lteppp_lte_state = state; @@ -382,6 +393,10 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m lte_state_t lteppp_get_state(void) { lte_state_t state; + if (!xLTESem){ + // lte task hasn't been initialized yet, so we don't need to (and can't) protect this read + return lteppp_lte_state; + } xSemaphoreTake(xLTESem, portMAX_DELAY); state = lteppp_lte_state; xSemaphoreGive(xLTESem); @@ -429,6 +444,35 @@ void lteppp_resume(void) { /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ +bool trx_is_ok_or_error(){ + if (strstr(lteppp_trx_buffer, "ERROR\r\n") != NULL){ + // printf("ok\n"); + return true; + } else if (strstr(lteppp_trx_buffer, "OK\r\n") != NULL) { + // printf("error\n"); + return true; + } + return false; +} + +/** check whether modem is responding at 115200 + * this means it is in FFH or RECOVYER mode + */ +bool lteppp_check_ffh_mode(){ + uart_set_baudrate(LTE_UART_ID, 115200); + uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_CTS_RTS, 64); + uart_set_rts(LTE_UART_ID, true); + + for ( uint8_t attempt = 0 ; attempt < 3 ; attempt++ ){ + lteppp_send_at_cmd("AT", LTE_PPP_BACK_OFF_TIME_MS); + if ( trx_is_ok_or_error() ){ + // we could check for AT+SMOD / AT+BMOD to get more details + return true; + } + } + return false; +} + static void TASK_LTE (void *pvParameters) { MSG("\n"); bool sim_present; @@ -447,9 +491,7 @@ static void TASK_LTE (void *pvParameters) { { MSG("notif\n"); xSemaphoreTake(xLTE_modem_Conn_Sem, portMAX_DELAY); - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_CONNECTING; - xSemaphoreGive(xLTESem); + lteppp_set_modem_conn_state(E_LTE_MODEM_CONNECTING); uart_set_rts(LTE_UART_ID, true); vTaskDelay(500/portTICK_PERIOD_MS); uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_CTS_RTS, 64); @@ -463,9 +505,7 @@ static void TASK_LTE (void *pvParameters) { if (at_trials >= LTE_AT_CMD_TRIALS) { uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0); uart_set_rts(LTE_UART_ID, false); - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED; - xSemaphoreGive(xLTESem); + lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED); xSemaphoreGive(xLTE_modem_Conn_Sem); at_trials = 0; goto modem_init; @@ -486,9 +526,7 @@ static void TASK_LTE (void *pvParameters) { if (at_trials >= LTE_AT_CMD_TRIALS) { uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0); uart_set_rts(LTE_UART_ID, false); - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED; - xSemaphoreGive(xLTESem); + lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED); xSemaphoreGive(xLTE_modem_Conn_Sem); at_trials = 0; goto modem_init; @@ -501,11 +539,14 @@ static void TASK_LTE (void *pvParameters) { while(!lteppp_send_at_cmd("AT", LTE_RX_TIMEOUT_MIN_MS)) { if (at_trials >= LTE_AT_CMD_TRIALS) { - uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0); - uart_set_rts(LTE_UART_ID, false); - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED; - xSemaphoreGive(xLTESem); + if ( lteppp_check_ffh_mode() ){ + lteppp_set_modem_conn_state(E_LTE_MODEM_RECOVERY); + } else { + uart_set_baudrate(LTE_UART_ID, MICROPY_LTE_UART_BAUDRATE); + uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0); + uart_set_rts(LTE_UART_ID, false); + lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED); + } xSemaphoreGive(xLTE_modem_Conn_Sem); at_trials = 0; goto modem_init; @@ -547,22 +588,16 @@ static void TASK_LTE (void *pvParameters) { { lteppp_send_at_cmd("AT+SQNIBRCFG=1,100", LTE_RX_TIMEOUT_MAX_MS); } - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_CONNECTED; - xSemaphoreGive(xLTESem); + lteppp_set_modem_conn_state(E_LTE_MODEM_CONNECTED); xSemaphoreGive(xLTE_modem_Conn_Sem); MSG("forever\n"); lte_state_t state; for (;;) { vTaskDelay(LTE_TASK_PERIOD_MS); - xSemaphoreTake(xLTESem, portMAX_DELAY); - if(E_LTE_MODEM_DISCONNECTED == lteppp_modem_conn_state) - { - xSemaphoreGive(xLTESem); + if(lteppp_get_modem_conn_state() == E_LTE_MODEM_DISCONNECTED ){ // restart the task goto modem_init; } - xSemaphoreGive(xLTESem); state = lteppp_get_state(); if (xQueueReceive(xCmdQueue, lteppp_trx_buffer, 0)) { MSG("cmd\n"); @@ -860,7 +895,7 @@ static void lteppp_print_states(){ if (!xLTESem) return; static lte_modem_conn_state_t last_c = 0xff; - lte_modem_conn_state_t c = lteppp_modem_state(); + lte_modem_conn_state_t c = lteppp_get_modem_conn_state(); static lte_state_t last_s = 0xff; lte_state_t s = lteppp_get_state(); static bool last_u = false; diff --git a/esp32/lte/lteppp.h b/esp32/lte/lteppp.h index 8ca52c5d7b..64b260e80e 100644 --- a/esp32/lte/lteppp.h +++ b/esp32/lte/lteppp.h @@ -61,7 +61,8 @@ typedef enum { typedef enum { E_LTE_MODEM_CONNECTED = 0, E_LTE_MODEM_CONNECTING, - E_LTE_MODEM_DISCONNECTED + E_LTE_MODEM_DISCONNECTED, + E_LTE_MODEM_RECOVERY } lte_modem_conn_state_t; #ifdef LTE_DEBUG_BUFF @@ -119,7 +120,8 @@ extern void lteppp_send_at_command (lte_task_cmd_data_t *cmd, lte_task_rsp_data_ extern bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_mp, void* data_rem); -lte_modem_conn_state_t lteppp_modem_state(void); +lte_modem_conn_state_t lteppp_get_modem_conn_state(void); +void lteppp_set_modem_conn_state(lte_modem_conn_state_t state); extern void connect_lte_uart (void); diff --git a/esp32/mods/modbt.c b/esp32/mods/modbt.c index 99a79a6570..8b8ae40d1d 100644 --- a/esp32/mods/modbt.c +++ b/esp32/mods/modbt.c @@ -2268,6 +2268,7 @@ STATIC const mp_map_elem_t bt_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_CHAR_SUBSCRIBE_EVENT), MP_OBJ_NEW_SMALL_INT(MOD_BT_GATTS_SUBSCRIBE_EVT) }, // { MP_OBJ_NEW_QSTR(MP_QSTR_CHAR_INDICATE_EVENT), MP_OBJ_NEW_SMALL_INT(MOD_BT_GATTC_INDICATE_EVT) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MAN_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_MANUAL) }, { MP_OBJ_NEW_QSTR(MP_QSTR_INT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_INTERNAL) }, { MP_OBJ_NEW_QSTR(MP_QSTR_EXT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_EXTERNAL) }, diff --git a/esp32/mods/modlte.c b/esp32/mods/modlte.c index 1372c679c8..b823883ef9 100644 --- a/esp32/mods/modlte.c +++ b/esp32/mods/modlte.c @@ -454,7 +454,7 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) { //printf("All done since we were already initialised.\n"); return mp_const_none; } - modem_state = lteppp_modem_state(); + modem_state = lteppp_get_modem_conn_state(); switch(modem_state) { case E_LTE_MODEM_DISCONNECTED: @@ -463,15 +463,19 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) { MP_THREAD_GIL_EXIT(); xSemaphoreTake(xLTE_modem_Conn_Sem, portMAX_DELAY); MP_THREAD_GIL_ENTER(); - if (E_LTE_MODEM_DISCONNECTED == lteppp_modem_state()) { + lte_modem_conn_state_t modem_state = lteppp_get_modem_conn_state(); + if (E_LTE_MODEM_DISCONNECTED == modem_state) { xSemaphoreGive(xLTE_modem_Conn_Sem); - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=disconnected)")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't start connection to Modem (modem_state=disconnected)")); + } else if (E_LTE_MODEM_RECOVERY == modem_state){ + xSemaphoreGive(xLTE_modem_Conn_Sem); + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't start connection to Modem (modem_state=recovery). Perform a modem firmware update.")); } break; case E_LTE_MODEM_CONNECTING: // Block till modem is connected xSemaphoreTake(xLTE_modem_Conn_Sem, portMAX_DELAY); - if (E_LTE_MODEM_DISCONNECTED == lteppp_modem_state()) { + if (E_LTE_MODEM_DISCONNECTED == lteppp_get_modem_conn_state()) { xSemaphoreGive(xLTE_modem_Conn_Sem); nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=connecting)")); } @@ -479,8 +483,11 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) { case E_LTE_MODEM_CONNECTED: //continue break; + case E_LTE_MODEM_RECOVERY: + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=recovery). Perform a modem firmware update.")); + break; default: - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=default)")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state - default)")); break; } lte_obj.cid = args[1].u_int; diff --git a/esp32/mods/modmachine.c b/esp32/mods/modmachine.c index b5d07bfd3c..28f4f4b9e0 100644 --- a/esp32/mods/modmachine.c +++ b/esp32/mods/modmachine.c @@ -405,12 +405,12 @@ STATIC mp_obj_t machine_sleep (uint n_args, const mp_obj_t *arg) { bool reconnect = false; #if defined(FIPY) || defined(GPY) - if (lteppp_modem_state() < E_LTE_MODEM_DISCONNECTED) { + if (lteppp_get_modem_conn_state() < E_LTE_MODEM_DISCONNECTED) { lteppp_deinit(); } #endif -#if defined(LOPY) || defined(LOPY4) || defined(FIPY) +#ifdef MOD_LORA_ENABLED /* Send LoRa module to Sleep Mode */ modlora_sleep_module(); while(!modlora_is_module_sleep()) @@ -466,7 +466,7 @@ STATIC mp_obj_t machine_deepsleep (uint n_args, const mp_obj_t *arg) { modbt_deinit(false); wlan_deinit(NULL); #if defined(FIPY) || defined(GPY) - if (lteppp_modem_state() < E_LTE_MODEM_DISCONNECTED) { + if (lteppp_get_modem_conn_state() < E_LTE_MODEM_DISCONNECTED) { lteppp_deinit(); } #endif diff --git a/esp32/mods/modnetwork.c b/esp32/mods/modnetwork.c index ae96e8375e..26e52323b3 100644 --- a/esp32/mods/modnetwork.c +++ b/esp32/mods/modnetwork.c @@ -112,11 +112,11 @@ mp_obj_t mod_network_find_nic(const mod_network_socket_obj_t *s, const uint8_t * mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i]; // we want a raw network card if (ip == NULL) { - #if defined (LOPY) || defined(LOPY4) || defined (FIPY) +#ifdef MOD_LORA_ENABLED if (mp_obj_get_type(nic) == (mp_obj_type_t *)&mod_network_nic_type_lora && s->sock_base.u.u_param.domain == AF_LORA) { return nic; } - #endif +#endif #if defined (SIPY) || defined (LOPY4) || defined (FIPY) #if defined (MOD_SIGFOX_ENABLED) if (mp_obj_get_type(nic) == (mp_obj_type_t *)&mod_network_nic_type_sigfox && s->sock_base.u.u_param.domain == AF_SIGFOX) { @@ -371,7 +371,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = { #ifdef PYETH_ENABLED { MP_OBJ_NEW_QSTR(MP_QSTR_ETH), (mp_obj_t)&mod_network_nic_type_eth }, #endif -#if defined (LOPY) || defined(LOPY4) || defined (FIPY) +#ifdef MOD_LORA_ENABLED { MP_OBJ_NEW_QSTR(MP_QSTR_LoRa), (mp_obj_t)&mod_network_nic_type_lora }, #endif #if defined (SIPY) || defined (LOPY4) || defined (FIPY) diff --git a/esp32/mods/modpycom.c b/esp32/mods/modpycom.c index 44551e1e08..a4007622f0 100644 --- a/esp32/mods/modpycom.c +++ b/esp32/mods/modpycom.c @@ -156,22 +156,25 @@ STATIC mp_obj_t mod_pycom_heartbeat (mp_uint_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_pycom_heartbeat_obj, 0, 1, mod_pycom_heartbeat); -STATIC mp_obj_t mod_pycom_rgb_led (mp_obj_t o_color) { +STATIC mp_obj_t mod_pycom_rgb_led (mp_uint_t n_args, const mp_obj_t *args) { #ifndef RGB_LED_DISABLE if (mperror_is_heartbeat_enabled()) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible)); } - - uint32_t color = mp_obj_get_int(o_color); - led_info.color.value = color; - led_set_color(&led_info, true, false); + if(n_args > 0){ + uint32_t color = mp_obj_get_int(args[0]); + led_info.color.value = color; + led_set_color(&led_info, true, false); + } else { + return mp_obj_new_int(led_info.color.value); + } #else nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "RGB Led Interface Disabled")); #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_pycom_rgb_led_obj, mod_pycom_rgb_led); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_pycom_rgb_led_obj, 0,1,mod_pycom_rgb_led); STATIC mp_obj_t mod_pycom_ota_start (void) { if (!updater_start()) { diff --git a/esp32/mods/moduos.c b/esp32/mods/moduos.c index d928eaa37d..cb1b548e49 100644 --- a/esp32/mods/moduos.c +++ b/esp32/mods/moduos.c @@ -81,7 +81,7 @@ STATIC const qstr os_uname_info_fields[] = { #if defined(LOPY) || defined(LOPY4) || defined(FIPY) ,MP_QSTR_lorawan #endif -#if defined(SIPY) || defined(FIPY) || defined(LOPY4) +#ifdef MOD_SIGFOX_ENABLED ,MP_QSTR_sigfox #endif #if (VARIANT == PYBYTES) @@ -100,7 +100,7 @@ STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME #if defined(LOPY) || defined(LOPY4) || defined(FIPY) STATIC const MP_DEFINE_STR_OBJ(os_uname_info_lorawan_obj, LORAWAN_VERSION_NUMBER); #endif -#if defined(SIPY) || defined (LOPY4) || defined (FIPY) +#ifdef MOD_SIGFOX_ENABLED STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sigfox_obj, SIGFOX_VERSION_NUMBER); #endif #if (VARIANT == PYBYTES) @@ -117,7 +117,7 @@ STATIC MP_DEFINE_ATTRTUPLE( #if defined(LOPY) || defined(LOPY4) || defined(FIPY) +1 #endif -#if defined(SIPY) || defined (LOPY4) || defined(FIPY) +#ifdef MOD_SIGFOX_ENABLED +1 #endif #if (VARIANT == PYBYTES) @@ -134,7 +134,7 @@ STATIC MP_DEFINE_ATTRTUPLE( #if defined(LOPY) || defined(LOPY4) || defined(FIPY) ,(mp_obj_t)&os_uname_info_lorawan_obj #endif -#if defined(SIPY) || defined (LOPY4) || defined(FIPY) +#ifdef MOD_SIGFOX_ENABLED ,(mp_obj_t)&os_uname_info_sigfox_obj #endif #if (VARIANT == PYBYTES) diff --git a/esp32/mods/modusocket.c b/esp32/mods/modusocket.c index afb5daaee2..cd660932b2 100644 --- a/esp32/mods/modusocket.c +++ b/esp32/mods/modusocket.c @@ -272,7 +272,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { mod_network_socket_obj_t *self = self_in; int _errno; -#if defined (LOPY) || defined(LOPY4) || defined(FIPY) +#ifdef MOD_LORA_ENABLED if (self->sock_base.nic_type == &mod_network_nic_type_lora) { if (MP_OBJ_IS_INT(addr_in)) { mp_uint_t port = mp_obj_get_int(addr_in); @@ -301,7 +301,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { if (self->sock_base.nic_type->n_bind(self, ip, port, &_errno) != 0) { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno))); } -#if defined (LOPY) || defined(LOPY4) || defined(FIPY) +#ifdef MOD_LORA_ENABLED } #endif return mp_const_none; @@ -521,7 +521,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_ uint8_t ip[MOD_USOCKET_IPV6_CHARS_MAX]; mp_uint_t port = 0; -#if defined (LOPY) || defined(LOPY4) || defined(FIPY) +#ifdef MOD_LORA_ENABLED if (self->sock_base.nic_type == &mod_network_nic_type_lora) { mp_obj_t *addr_items; mp_obj_get_array_fixed_n(addr_in, 2, &addr_items); @@ -579,7 +579,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) { vstr.buf[vstr.len] = '\0'; tuple[0] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); } -#if defined (LOPY) || defined(LOPY4) || defined(FIPY) +#ifdef MOD_LORA_ENABLED // check if lora NIC and IP is not set (so Lora Raw or LoraWAN, but no Lora Mesh) if (self->sock_base.nic_type == &mod_network_nic_type_lora) { if (ip[0] == 0) { diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index 81efbd1818..55d5b793ea 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -2735,6 +2735,7 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_WPA2_ENT), MP_OBJ_NEW_SMALL_INT(WIFI_AUTH_WPA2_ENTERPRISE) }, { MP_OBJ_NEW_QSTR(MP_QSTR_INT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_INTERNAL) }, { MP_OBJ_NEW_QSTR(MP_QSTR_EXT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_EXTERNAL) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MAN_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_MANUAL) }, { MP_OBJ_NEW_QSTR(MP_QSTR_HT20), MP_OBJ_NEW_SMALL_INT(WIFI_BW_HT20) }, { MP_OBJ_NEW_QSTR(MP_QSTR_HT40), MP_OBJ_NEW_SMALL_INT(WIFI_BW_HT40) }, { MP_OBJ_NEW_QSTR(MP_QSTR_PHY_11_B), MP_OBJ_NEW_SMALL_INT(WLAN_PHY_11_B) }, diff --git a/esp32/mptask.c b/esp32/mptask.c index 1e792db0d9..e5e89919d7 100644 --- a/esp32/mptask.c +++ b/esp32/mptask.c @@ -52,14 +52,12 @@ #include "esp_log.h" #include "mods/pybflash.h" -#if defined (LOPY) || defined (LOPY4) || defined (FIPY) +#ifdef MOD_LORA_ENABLED #include "modlora.h" #endif -#if defined (SIPY) || defined(LOPY4) || defined (FIPY) -#if defined (MOD_SIGFOX_ENABLED) +#ifdef MOD_SIGFOX_ENABLED #include "sigfox/modsigfox.h" #endif -#endif #if defined (GPY) || defined (FIPY) #include "modlte.h" #endif @@ -260,35 +258,27 @@ void TASK_Micropython (void *pvParameters) { // Config Wifi as per Pycom config mptask_config_wifi(false); // these ones are special because they need uPy running and they launch tasks -#ifndef PYETH_ENABLED -// PyEth and LoRa module are both connected via SPI 3, -// so with PyEth enabled, we disable th LoRa module -#if defined(LOPY) || defined (LOPY4) || defined (FIPY) +#ifdef MOD_LORA_ENABLED modlora_init0(); #endif -#if defined(SIPY) || defined(LOPY4) || defined (FIPY) -#if defined (MOD_SIGFOX_ENABLED) +#ifdef MOD_SIGFOX_ENABLED modsigfox_init0(); -#endif -#endif #endif } // initialize the serial flash file system mptask_init_sflash_filesystem(); -#if defined(LOPY) || defined(SIPY) || defined (LOPY4) || defined(FIPY) +#if defined(MOD_LORA_ENABLED) || defined(MOD_SIGFOX_ENABLED) // must be done after initializing the file system mptask_update_lpwan_mac_address(); #endif -#if defined(SIPY) || defined(LOPY4) || defined(FIPY) -#if defined (MOD_SIGFOX_ENABLED) +#ifdef MOD_SIGFOX_ENABLED sigfox_update_id(); sigfox_update_pac(); sigfox_update_private_key(); sigfox_update_public_key(); -#endif #endif // append the flash paths to the system path diff --git a/esp32/pycom_version.h b/esp32/pycom_version.h index 55b3ed1ca3..b85d758bb1 100644 --- a/esp32/pycom_version.h +++ b/esp32/pycom_version.h @@ -10,7 +10,7 @@ #ifndef VERSION_H_ #define VERSION_H_ -#define SW_VERSION_NUMBER "1.20.2.r2" +#define SW_VERSION_NUMBER "1.20.2.r3" #define LORAWAN_VERSION_NUMBER "1.0.2"