Skip to content

Commit 4e3c1d4

Browse files
committed
[build] Allow USB to be set to 0
Unify USB-related makefile var and C def as CIRCUITPY_USB. Always define it as 0 or 1, same as all other settings. USB_AVAILABLE was conditionally defined in supervisor.mk, but never actually used to #ifdef USB-related code. Loosely related to adafruit#4546
1 parent 346740e commit 4e3c1d4

15 files changed

Lines changed: 32 additions & 10 deletions

File tree

main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "supervisor/shared/translate.h"
6161
#include "supervisor/shared/workflow.h"
6262
#include "supervisor/usb.h"
63+
#include "supervisor/workflow.h"
6364

6465
#include "shared-bindings/microcontroller/__init__.h"
6566
#include "shared-bindings/microcontroller/Processor.h"
@@ -188,7 +189,10 @@ STATIC void stop_mp(void) {
188189
#endif
189190

190191
background_callback_reset();
192+
193+
#if CIRCUITPY_USB
191194
usb_background();
195+
#endif
192196

193197
gc_deinit();
194198
}

ports/esp32s2/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ SRC_C += \
201201
peripherals/rmt.c \
202202
supervisor/shared/memory.c
203203

204-
ifneq ($(USB),FALSE)
204+
ifneq ($(CIRCUITPY_USB),0)
205205
SRC_C += lib/tinyusb/src/portable/espressif/esp32s2/dcd_esp32s2.c
206206
endif
207207

ports/litex/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ SRC_C += \
136136
lib/utils/sys_stdio_mphal.c \
137137
supervisor/shared/memory.c
138138

139-
ifneq ($(USB),FALSE)
139+
ifneq ($(CIRCUITPY_USB),0)
140140
SRC_C += lib/tinyusb/src/portable/valentyusb/eptri/dcd_eptri.c
141141
endif
142142

ports/litex/supervisor/internal_flash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n
310310
uint32_t src = lba2addr(block);
311311
memcpy(dest, (uint8_t *)src, FILESYSTEM_BLOCK_SIZE * num_blocks);
312312

313-
#if USB_AVAILABLE
313+
#if CIRCUITPY_USB
314314
usb_background();
315315
#endif
316316

@@ -347,7 +347,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
347347
src += count * FILESYSTEM_BLOCK_SIZE;
348348
num_blocks -= count;
349349

350-
#if USB_AVAILABLE
350+
#if CIRCUITPY_USB
351351
usb_background();
352352
#endif
353353
}

ports/nrf/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ SRC_C += \
177177
sd_mutex.c \
178178
supervisor/shared/memory.c
179179

180+
ifneq ($(CIRCUITPY_USB),0)
180181
# USB source files for nrf52840
181182
ifeq ($(MCU_SUB_VARIANT),nrf52840)
182183
SRC_C += \
@@ -187,6 +188,7 @@ ifeq ($(MCU_SUB_VARIANT),nrf52833)
187188
SRC_C += \
188189
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c
189190
endif
191+
endif # CIRCUITPY_USB
190192

191193
ifeq ($(CIRCUITPY_NETWORK),1)
192194
CFLAGS += -DMICROPY_PY_NETWORK=1

ports/nrf/bluetooth/ble_drv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void SD_EVT_IRQHandler(void) {
9898
uint32_t evt_id;
9999
while (sd_evt_get(&evt_id) != NRF_ERROR_NOT_FOUND) {
100100
switch (evt_id) {
101+
#if CIRCUITPY_USB
101102
// usb power event
102103
case NRF_EVT_POWER_USB_DETECTED:
103104
case NRF_EVT_POWER_USB_POWER_READY:
@@ -109,6 +110,7 @@ void SD_EVT_IRQHandler(void) {
109110
tusb_hal_nrf_power_event(usbevt);
110111
}
111112
break;
113+
#endif
112114

113115
// Set flag indicating that a flash operation has finished.
114116
case NRF_EVT_FLASH_OPERATION_SUCCESS:

ports/nrf/common-hal/_bleio/Adapter.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,11 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable
351351
} else {
352352
err_code = sd_softdevice_disable();
353353
}
354+
355+
#if CIRCUITPY_USB
354356
// Re-init USB hardware
355357
init_usb_hardware();
358+
#endif
356359

357360
check_nrf_error(err_code);
358361

ports/stm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ SRC_C += \
238238
lib/utils/sys_stdio_mphal.c \
239239
supervisor/shared/memory.c
240240

241-
ifneq ($(USB),FALSE)
241+
ifneq ($(CIRCUITPY_USB),0)
242242
SRC_C += lib/tinyusb/src/portable/st/synopsys/dcd_synopsys.c
243243
endif
244244

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ CFLAGS += -DCIRCUITPY_TOUCHIO=$(CIRCUITPY_TOUCHIO)
331331
CIRCUITPY_UHEAP ?= 0
332332
CFLAGS += -DCIRCUITPY_UHEAP=$(CIRCUITPY_UHEAP)
333333

334+
CIRCUITPY_USB ?= 1
335+
CFLAGS += -DCIRCUITPY_USB=$(CIRCUITPY_USB)
336+
334337
# Disable by default for now, until we have dynamic enabling.
335338
CIRCUITPY_USB_CDC ?= 0
336339
# Secondary CDC is usually available if there are at least 8 endpoints.

shared-bindings/supervisor/Runtime.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ STATIC supervisor_run_reason_t _run_reason;
5959
//| """Returns the USB enumeration status (read-only)."""
6060
//|
6161
STATIC mp_obj_t supervisor_runtime_get_usb_connected(mp_obj_t self) {
62+
#if CIRCUITPY_USB
6263
return mp_obj_new_bool(tud_ready());
64+
#else
65+
return mp_const_false;
66+
#endif
6367
}
6468
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_usb_connected_obj, supervisor_runtime_get_usb_connected);
6569

0 commit comments

Comments
 (0)