Skip to content

Commit

Permalink
Merge pull request #4215 from dhalbert/secondary-cdc
Browse files Browse the repository at this point in the history
Second USB CDC (serial) channel
  • Loading branch information
tannewt authored Feb 20, 2021
2 parents 220f86f + 985e020 commit 7b6f89a
Show file tree
Hide file tree
Showing 53 changed files with 1,797 additions and 684 deletions.
26 changes: 15 additions & 11 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@
#include "shared-bindings/alarm/__init__.h"
#endif

#if CIRCUITPY_BLEIO
#include "shared-bindings/_bleio/__init__.h"
#include "supervisor/shared/bluetooth.h"
#endif

#if CIRCUITPY_BOARD
#include "shared-module/board/__init__.h"
#endif

#if CIRCUITPY_CANIO
#include "common-hal/canio/CAN.h"
#endif

#if CIRCUITPY_DISPLAYIO
#include "shared-module/displayio/__init__.h"
#endif
Expand All @@ -81,17 +94,8 @@
#include "shared-module/network/__init__.h"
#endif

#if CIRCUITPY_BOARD
#include "shared-module/board/__init__.h"
#endif

#if CIRCUITPY_BLEIO
#include "shared-bindings/_bleio/__init__.h"
#include "supervisor/shared/bluetooth.h"
#endif

#if CIRCUITPY_CANIO
#include "common-hal/canio/CAN.h"
#if CIRCUITPY_USB_CDC
#include "shared-module/usb_cdc/__init__.h"
#endif

#if CIRCUITPY_WIFI
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ CFLAGS += -ftree-vrp
$(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY))
#Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -ggdb3 -Og
CFLAGS += -ggdb3 -Og -Os
# You may want to disable -flto if it interferes with debugging.
CFLAGS += -flto -flto-partition=none
# You may want to enable these flags to make setting breakpoints easier.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0

SUPEROPT_GC = 0
SUPEROPT_VM = 0
4 changes: 2 additions & 2 deletions ports/atmel-samd/common-hal/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "shared-bindings/supervisor/Runtime.h"
#include "supervisor/serial.h"

bool common_hal_get_serial_connected(void) {
bool common_hal_supervisor_runtime_get_serial_connected(void) {
return (bool) serial_connected();
}

bool common_hal_get_serial_bytes_available(void) {
bool common_hal_supervisor_runtime_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
}
22 changes: 16 additions & 6 deletions ports/atmel-samd/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ ifeq ($(LONGINT_IMPL),LONGLONG)
MPY_TOOL_LONGINT_IMPL = -mlongint-impl=longlong
endif

INTERNAL_LIBM = 1

USB_SERIAL_NUMBER_LENGTH = 32

# Number of USB endpoint pairs.
USB_NUM_EP = 8

######################################################################
# Put samd21-only choices here.

ifeq ($(CHIP_FAMILY),samd21)

# The ?='s allow overriding in mpconfigboard.mk.
Expand All @@ -40,7 +49,9 @@ CIRCUITPY_SDCARDIO ?= 0
CIRCUITPY_FRAMEBUFFERIO ?= 0

# SAMD21 needs separate endpoint pairs for MSC BULK IN and BULK OUT, otherwise it's erratic.
# Because of that, there aren't enough endpoints for a secondary CDC serial connection.
USB_MSC_EP_NUM_OUT = 1
CIRCUITPY_USB_CDC = 0

CIRCUITPY_ULAB = 0

Expand All @@ -55,9 +66,13 @@ CIRCUITPY_TERMINALIO = 0
endif

endif # samd21
######################################################################

######################################################################
# Put samd51-only choices here.

ifeq ($(CHIP_FAMILY),samd51)

# No native touchio on SAMD51.
CIRCUITPY_TOUCHIO_USE_NATIVE = 0

Expand All @@ -70,9 +85,4 @@ CIRCUITPY_RGBMATRIX ?= $(CIRCUITPY_FULL_BUILD)
CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD)

endif # samd51

INTERNAL_LIBM = 1

USB_SERIAL_NUMBER_LENGTH = 32

USB_NUM_EP = 8
######################################################################
4 changes: 2 additions & 2 deletions ports/cxd56/common-hal/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#include "shared-bindings/supervisor/Runtime.h"
#include "supervisor/serial.h"

bool common_hal_get_serial_connected(void) {
bool common_hal_supervisor_runtime_get_serial_connected(void) {
return (bool) serial_connected();
}

bool common_hal_get_serial_bytes_available(void) {
bool common_hal_supervisor_runtime_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
}
3 changes: 3 additions & 0 deletions ports/cxd56/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ USB_CDC_EP_NUM_DATA_IN = 1
USB_MSC_EP_NUM_OUT = 5
USB_MSC_EP_NUM_IN = 4

# Number of USB endpoint pairs.
USB_NUM_EP = 6

MPY_TOOL_LONGINT_IMPL = -mlongint-impl=mpz

CIRCUITPY_AUDIOBUSIO = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ USB_VID = 0x303a
USB_PID = 0x8007
USB_PRODUCT = "TTGO T8 ESP32-S2"
USB_MANUFACTURER = "LILYGO"
USB_DEVICES = "CDC,MSC,HID"

INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = MPZ
Expand Down
1 change: 0 additions & 1 deletion ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ USB_VID = 0x239A
USB_PID = 0x80C6
USB_PRODUCT = "microS2"
USB_MANUFACTURER = "microDev"
USB_DEVICES = "CDC,MSC,HID"

INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = MPZ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ USB_VID = 0x239A
USB_PID = 0x80AC
USB_PRODUCT = "FeatherS2"
USB_MANUFACTURER = "UnexpectedMaker"
USB_DEVICES = "CDC,MSC,HID"

INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = MPZ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ USB_VID = 0x239A
USB_PID = 0x80AC
USB_PRODUCT = "FeatherS2"
USB_MANUFACTURER = "UnexpectedMaker"
USB_DEVICES = "CDC,MSC,HID"

INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = MPZ
Expand Down
6 changes: 3 additions & 3 deletions ports/esp32s2/common-hal/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "shared-bindings/supervisor/Runtime.h"
#include "supervisor/serial.h"

bool common_hal_get_serial_connected(void) {
bool common_hal_supervisor_runtime_get_serial_connected(void) {
return (bool) serial_connected();
}

bool common_hal_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
bool common_hal_supervisor_runtime_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
}
13 changes: 5 additions & 8 deletions ports/esp32s2/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@ CIRCUITPY_FREQUENCYIO = 1
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_ROTARYIO = 1
CIRCUITPY_NVM = 1
CIRCUITPY_PS2IO ?= 1
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1
# We don't have enough endpoints to include MIDI.
CIRCUITPY_USB_MIDI ?= 0
CIRCUITPY_USB_HID ?= 1
# We have borrowed the VENDOR nomenclature from tinyusb. VENDOR AKA WEBUSB
CIRCUITPY_USB_VENDOR ?= 0
CIRCUITPY_WIFI = 1
CIRCUITPY_WATCHDOG ?= 1
CIRCUITPY_ESPIDF = 1

ifndef CIRCUITPY_PS2IO
CIRCUITPY_PS2IO = 1
endif

ifndef CIRCUITPY_TOUCHIO_USE_NATIVE
CIRCUITPY_TOUCHIO_USE_NATIVE = 1
endif
CIRCUITPY_ESPIDF = 1

CIRCUITPY_MODULE ?= none

USB_NUM_EP = 5
6 changes: 3 additions & 3 deletions ports/litex/common-hal/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "shared-bindings/supervisor/Runtime.h"
#include "supervisor/serial.h"

bool common_hal_get_serial_connected(void) {
bool common_hal_supervisor_runtime_get_serial_connected(void) {
return (bool) serial_connected();
}

bool common_hal_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
bool common_hal_supervisor_runtime_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
}
3 changes: 3 additions & 0 deletions ports/litex/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ MPY_TOOL_LONGINT_IMPL = -mlongint-impl=mpz
# Internal math library is substantially smaller than toolchain one
INTERNAL_LIBM = 1

# Number of USB endpoint pairs.
USB_NUM_EP = 16

# Chip supplied serial number, in bytes
USB_SERIAL_NUMBER_LENGTH = 30

Expand Down
4 changes: 2 additions & 2 deletions ports/mimxrt10xx/common-hal/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "shared-bindings/supervisor/Runtime.h"
#include "supervisor/serial.h"

bool common_hal_get_serial_connected(void) {
bool common_hal_supervisor_runtime_get_serial_connected(void) {
return (bool) serial_connected();
}

bool common_hal_get_serial_bytes_available(void) {
bool common_hal_supervisor_runtime_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
}
3 changes: 3 additions & 0 deletions ports/mimxrt10xx/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ INTERNAL_LIBM = 1
USB_SERIAL_NUMBER_LENGTH = 32
USB_HIGHSPEED = 1

# Number of USB endpoint pairs.
USB_NUM_EP = 8

INTERNAL_FLASH_FILESYSTEM = 1

CIRCUITPY_AUDIOIO = 0
Expand Down
4 changes: 2 additions & 2 deletions ports/nrf/bluetooth/ble_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "shared-bindings/_bleio/Service.h"
#include "shared-bindings/_bleio/UUID.h"

#if CIRCUITPY_SERIAL_BLE
#if CIRCUITPY_REPL_BLE

static const char default_name[] = "CP-REPL"; // max 8 chars or uuid won't fit in adv data
static const char NUS_UUID[] = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
Expand Down Expand Up @@ -190,4 +190,4 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
}
}

#endif // CIRCUITPY_SERIAL_BLE
#endif // CIRCUITPY_REPL_BLE
1 change: 1 addition & 0 deletions ports/nrf/boards/pca10100/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ CIRCUITPY_BUSDEVICE = 0
MICROPY_PY_ASYNC_AWAIT = 0

SUPEROPT_GC = 0
SUPEROPT_VM = 0

# Override optimization to keep binary small
OPTIMIZATION_FLAGS = -Os
3 changes: 1 addition & 2 deletions ports/nrf/boards/simmel/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ USB_PID = 0xc051
USB_PRODUCT = "Simmel"
USB_MANUFACTURER = "Betrusted"

CIRCUITPY_DEVICES="CDC,MSC,HID"

MCU_CHIP = nrf52833

# SPI_FLASH_FILESYSTEM = 1
Expand All @@ -31,6 +29,7 @@ CIRCUITPY_RTC = 1
CIRCUITPY_SDCARDIO = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_ULAB = 0
CIRCUITPY_USB_CDC = 0
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_WATCHDOG = 1

Expand Down
4 changes: 2 additions & 2 deletions ports/nrf/common-hal/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "shared-bindings/supervisor/Runtime.h"
#include "supervisor/serial.h"

bool common_hal_get_serial_connected(void) {
bool common_hal_supervisor_runtime_get_serial_connected(void) {
return (bool) serial_connected();
}

bool common_hal_get_serial_bytes_available(void) {
bool common_hal_supervisor_runtime_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
}
3 changes: 3 additions & 0 deletions ports/nrf/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ INTERNAL_LIBM = 1

USB_SERIAL_NUMBER_LENGTH = 16

# Number of USB endpoint pairs.
USB_NUM_EP = 8

# All nRF ports have longints.
LONGINT_IMPL = MPZ

Expand Down
10 changes: 5 additions & 5 deletions ports/nrf/supervisor/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@

#include "supervisor/serial.h"

#if CIRCUITPY_SERIAL_BLE
#if CIRCUITPY_REPL_BLE
#include "ble_uart.h"
#elif CIRCUITPY_SERIAL_UART
#elif CIRCUITPY_REPL_UART
#include <string.h>
#include "nrf_gpio.h"
#include "nrfx_uarte.h"
#endif

#if CIRCUITPY_SERIAL_BLE
#if CIRCUITPY_REPL_BLE

void serial_init(void) {
ble_uart_init();
Expand All @@ -58,7 +58,7 @@ void serial_write(const char *text) {
ble_uart_stdout_tx_str(text);
}

#elif CIRCUITPY_SERIAL_UART
#elif CIRCUITPY_REPL_UART

uint8_t serial_received_char;
nrfx_uarte_t serial_instance = NRFX_UARTE_INSTANCE(0);
Expand Down Expand Up @@ -124,4 +124,4 @@ void serial_write_substring(const char *text, uint32_t len) {
}
}

#endif // CIRCUITPY_SERIAL_UART
#endif // CIRCUITPY_REPL_UART
4 changes: 2 additions & 2 deletions ports/raspberrypi/common-hal/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#include "shared-bindings/supervisor/Runtime.h"
#include "supervisor/serial.h"

bool common_hal_get_serial_connected(void) {
bool common_hal_supervisor_runtime_get_serial_connected(void) {
return (bool) serial_connected();
}

bool common_hal_get_serial_bytes_available(void) {
bool common_hal_supervisor_runtime_get_serial_bytes_available(void) {
return (bool) serial_bytes_available();
}
1 change: 1 addition & 0 deletions ports/raspberrypi/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ INTERNAL_LIBM = 1

USB_SERIAL_NUMBER_LENGTH = 16

# Number of USB endpoint pairs.
USB_NUM_EP = 8
2 changes: 0 additions & 2 deletions ports/stm/boards/stm32f412zg_discovery/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ MCU_PACKAGE = LQFP144

LD_COMMON = boards/common_default.ld
LD_FILE = boards/STM32F412_fs.ld

CIRCUITPY_USB_HID = 1
4 changes: 3 additions & 1 deletion ports/stm/boards/thunderpack_v12/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ USB_VID = 0x239A
USB_PID = 0x8071
USB_PRODUCT = "Thunderpack STM32F411"
USB_MANUFACTURER = "Jeremy Gillick"
USB_DEVICES = "CDC,MSC"

# Turn off HID devices
CIRCUITPY_USB_HID = 0

LONGINT_IMPL = NONE

Expand Down
Loading

0 comments on commit 7b6f89a

Please sign in to comment.