diff options
| author | Angus Gratton <angus@redyak.com.au> | 2025-11-21 16:28:11 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-11-30 23:18:57 +1100 |
| commit | 604cda5d545564523c4deaedb2e93a464e3dcf8f (patch) | |
| tree | 41a2a459b44a45e351db21e06fa7e10fe3e9f7ff | |
| parent | 521b2f86bede90f5f30b6c9ce6a75e987a5f021d (diff) | |
esp32: Support building with network and/or bluetooth disabled.
(and a smaller binary size as a result)
Signed-off-by: Angus Gratton <angus@redyak.com.au>
| -rw-r--r-- | ports/esp32/main.c | 6 | ||||
| -rw-r--r-- | ports/esp32/modsocket.c | 5 | ||||
| -rw-r--r-- | ports/esp32/mpconfigport.h | 16 |
3 files changed, 21 insertions, 6 deletions
diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 41eea29b0..7460bf359 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -90,7 +90,8 @@ int vprintf_null(const char *format, va_list ap) { return 0; } -time_t platform_mbedtls_time(time_t *timer) { +#if MICROPY_SSL_MBEDTLS +static time_t platform_mbedtls_time(time_t *timer) { // mbedtls_time requires time in seconds from EPOCH 1970 struct timeval tv; @@ -98,6 +99,7 @@ time_t platform_mbedtls_time(time_t *timer) { return tv.tv_sec + TIMEUTILS_SECONDS_1970_TO_2000; } +#endif void mp_task(void *pvParameter) { volatile uint32_t sp = (uint32_t)esp_cpu_get_sp(); @@ -114,8 +116,10 @@ void mp_task(void *pvParameter) { #endif machine_init(); + #if MICROPY_SSL_MBEDTLS // Configure time function, for mbedtls certificate time validation. mbedtls_platform_set_time(platform_mbedtls_time); + #endif esp_err_t err = esp_event_loop_create_default(); if (err != ESP_OK) { diff --git a/ports/esp32/modsocket.c b/ports/esp32/modsocket.c index 2050d1d04..d8ebd3a89 100644 --- a/ports/esp32/modsocket.c +++ b/ports/esp32/modsocket.c @@ -55,6 +55,9 @@ #include "lwip/igmp.h" #include "esp_log.h" +// See note at bottom of file about why this isn't MICROPY_PY_SOCKET +#if MICROPY_PY_NETWORK + #define SOCKET_POLL_US (100000) #define MDNS_QUERY_TIMEOUT_MS (5000) #define MDNS_LOCAL_SUFFIX ".local" @@ -1028,3 +1031,5 @@ const mp_obj_module_t mp_module_socket = { // this will not conflict with the common implementation provided by // extmod/mod{lwip,socket}.c. MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_socket, mp_module_socket); + +#endif // MICROPY_PY_NETWORK diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index 7b973ebb9..c0bd4516e 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -92,6 +92,9 @@ #endif #ifndef MICROPY_PY_BLUETOOTH #define MICROPY_PY_BLUETOOTH (1) +#endif + +#if MICROPY_PY_BLUETOOTH #define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS (1) #define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK (1) // Event stack size is the RTOS stack size minus an allowance for the stack used @@ -102,7 +105,8 @@ #define MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING (1) #define MICROPY_BLUETOOTH_NIMBLE (1) #define MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY (1) -#endif +#endif // MICROPY_PY_BLUETOOTH + #define MICROPY_PY_RANDOM_SEED_INIT_FUNC (esp_random()) #define MICROPY_PY_OS_INCLUDEFILE "ports/esp32/modos.c" #define MICROPY_PY_OS_DUPTERM (1) @@ -158,7 +162,9 @@ #define MICROPY_PY_MACHINE_UART_IRQ (1) #define MICROPY_PY_MACHINE_WDT (1) #define MICROPY_PY_MACHINE_WDT_INCLUDEFILE "ports/esp32/machine_wdt.c" +#ifndef MICROPY_PY_NETWORK #define MICROPY_PY_NETWORK (1) +#endif #ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT #if CONFIG_IDF_TARGET_ESP32 #define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-esp32" @@ -189,10 +195,10 @@ #ifndef MICROPY_HW_ESP_NEW_I2C_DRIVER #define MICROPY_HW_ESP_NEW_I2C_DRIVER (0) #endif -#define MICROPY_PY_SSL (1) -#define MICROPY_SSL_MBEDTLS (1) -#define MICROPY_PY_WEBSOCKET (1) -#define MICROPY_PY_WEBREPL (1) +#define MICROPY_PY_SSL (MICROPY_PY_NETWORK) +#define MICROPY_SSL_MBEDTLS (MICROPY_PY_SSL) +#define MICROPY_PY_WEBSOCKET (MICROPY_PY_NETWORK) +#define MICROPY_PY_WEBREPL (MICROPY_PY_NETWORK) #define MICROPY_PY_ONEWIRE (1) #define MICROPY_PY_SOCKET_EVENTS (MICROPY_PY_WEBREPL) #define MICROPY_PY_BLUETOOTH_RANDOM_ADDR (1) |
