From 9d91111b1b6a1eee77a88b13faf695ee0c5caea3 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 19 Oct 2018 18:46:22 -0700 Subject: Move atmel-samd to tinyusb and support nRF flash. This started while adding USB MIDI support (and descriptor support is in this change.) When seeing that I'd have to implement the MIDI class logic twice, once for atmel-samd and once for nrf, I decided to refactor the USB stack so its shared across ports. This has led to a number of changes that remove items from the ports folder and move them into supervisor. Furthermore, we had external SPI flash support for nrf pending so I factored out the connection between the usb stack and the flash API as well. This PR also includes the QSPI support for nRF. --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/tinyusb') diff --git a/lib/tinyusb b/lib/tinyusb index 33c61bfda..30e3c6413 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 33c61bfda2c3aada3cb06d36e12d7cf57da02037 +Subproject commit 30e3c64134789416e10ed867fa12c210b808e98f -- cgit v1.2.3 From 168e23e466737fd25d6c7a524231781e35d1d49a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 9 Nov 2018 00:11:43 -0800 Subject: Build refinement to handle warnings and quiet output --- lib/tinyusb | 2 +- py/py.mk | 4 ++-- shared-module/usb_hid/__init__.c | 12 ++++++------ supervisor/shared/usb/tusb_config.h | 1 + supervisor/supervisor.mk | 8 ++++++-- 5 files changed, 16 insertions(+), 11 deletions(-) (limited to 'lib/tinyusb') diff --git a/lib/tinyusb b/lib/tinyusb index 30e3c6413..537a29273 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 30e3c64134789416e10ed867fa12c210b808e98f +Subproject commit 537a29273c08b1e047004e1bd71c37af82937dd4 diff --git a/py/py.mk b/py/py.mk index 9874dde4d..c640e6cff 100644 --- a/py/py.mk +++ b/py/py.mk @@ -307,7 +307,7 @@ $(HEADER_BUILD)/qstrdefs.preprocessed.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEF # qstr data $(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h $(STEPECHO) "GEN $@" - $(PYTHON3) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ + $(Q)$(PYTHON3) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ # Adding an order only dependency on $(HEADER_BUILD) causes $(HEADER_BUILD) to get # created before we run the script to generate the .h @@ -315,7 +315,7 @@ $(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrd # the lines in "" and then unwrap after the preprocessor is finished. $(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h $(STEPECHO) "GEN $@" - $(PYTHON3) $(PY_SRC)/makeqstrdata.py --compression_filename $(HEADER_BUILD)/compression.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ + $(Q)$(PYTHON3) $(PY_SRC)/makeqstrdata.py --compression_filename $(HEADER_BUILD)/compression.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ $(PY_BUILD)/qstr.o: $(HEADER_BUILD)/qstrdefs.generated.h diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index c0f9c897c..f14fdd41e 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -58,7 +58,7 @@ static uint8_t digitizer_report_buffer[USB_HID_REPORT_LENGTH_DIGITIZER]; #endif usb_hid_device_obj_t usb_hid_devices[] = { -#if USB_HID_REPORT_ID_KEYBOARD +#ifdef USB_HID_REPORT_ID_KEYBOARD { .base = { .type = &usb_hid_device_type } , .report_buffer = keyboard_report_buffer , @@ -69,7 +69,7 @@ usb_hid_device_obj_t usb_hid_devices[] = { }, #endif -#if USB_HID_REPORT_ID_MOUSE +#ifdef USB_HID_REPORT_ID_MOUSE { .base = { .type = &usb_hid_device_type } , .report_buffer = mouse_report_buffer , @@ -80,7 +80,7 @@ usb_hid_device_obj_t usb_hid_devices[] = { }, #endif -#if USB_HID_REPORT_ID_CONSUMER +#ifdef USB_HID_REPORT_ID_CONSUMER { .base = { .type = &usb_hid_device_type } , .report_buffer = consumer_report_buffer , @@ -91,7 +91,7 @@ usb_hid_device_obj_t usb_hid_devices[] = { }, #endif -#if USB_HID_REPORT_ID_SYS_CONTROL +#ifdef USB_HID_REPORT_ID_SYS_CONTROL { .base = { .type = &usb_hid_device_type } , .report_buffer = sys_control_report_buffer , @@ -102,7 +102,7 @@ usb_hid_device_obj_t usb_hid_devices[] = { }, #endif -#if USB_HID_REPORT_ID_GAMEPAD +#ifdef USB_HID_REPORT_ID_GAMEPAD { .base = { .type = &usb_hid_device_type } , .report_buffer = gamepad_report_buffer , @@ -113,7 +113,7 @@ usb_hid_device_obj_t usb_hid_devices[] = { }, #endif -#if USB_HID_REPORT_ID_DIGITIZER +#ifdef USB_HID_REPORT_ID_DIGITIZER { .base = { .type = &usb_hid_device_type } , .report_buffer = digitizer_report_buffer , diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index 4693bfced..649c390ac 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -75,6 +75,7 @@ #define CFG_TUD_CDC 1 #define CFG_TUD_MSC 1 #define CFG_TUD_HID 1 +#define CFG_TUD_CUSTOM_CLASS 0 /*------------------------------------------------------------------*/ /* CLASS DRIVER diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index d870f799f..ac982d277 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -66,10 +66,14 @@ SUPERVISOR_O = $(addprefix $(BUILD)/, $(SRC_SUPERVISOR:.c=.o)) $(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h -$(BUILD)/autogen_usb_descriptor.c $(BUILD)/genhdr/autogen_usb_descriptor.h: ../../tools/gen_usb_descriptor.py Makefile | $(HEADER_BUILD) +$(BUILD)/autogen_usb_descriptor.c $(BUILD)/genhdr/autogen_usb_descriptor.h: autogen_usb_descriptor.intermediate + +.INTERMEDIATE: autogen_usb_descriptor.intermediate + +autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile | $(HEADER_BUILD) $(STEPECHO) "GEN $@" $(Q)install -d $(BUILD)/genhdr - $(PYTHON3) ../../tools/gen_usb_descriptor.py \ + $(Q)$(PYTHON3) ../../tools/gen_usb_descriptor.py \ --manufacturer $(USB_MANUFACTURER)\ --product $(USB_PRODUCT)\ --vid $(USB_VID)\ -- cgit v1.2.3 From 43f7ca7985768c974b6881957b21d687c34413ba Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 9 Nov 2018 11:33:56 -0800 Subject: Incorporate feedback: * Clean up board defines. * Add flush on eject and stay ejected. * Swith back to NONE protocol for CDC. --- lib/tinyusb | 2 +- ports/atmel-samd/boards/arduino_zero/mpconfigboard.h | 2 +- .../boards/circuitplayground_express/mpconfigboard.h | 1 - ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h | 2 ++ ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h | 7 ++++--- ports/atmel-samd/boards/trinket_m0/mpconfigboard.h | 2 +- ports/atmel-samd/common-hal/microcontroller/Pin.c | 5 ----- supervisor/shared/external_flash/external_flash.h | 2 +- supervisor/shared/usb/usb_msc_flash.c | 12 +++++++++++- tools/gen_usb_descriptor.py | 4 ++-- 10 files changed, 23 insertions(+), 16 deletions(-) (limited to 'lib/tinyusb') diff --git a/lib/tinyusb b/lib/tinyusb index 537a29273..299a2f12d 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 537a29273c08b1e047004e1bd71c37af82937dd4 +Subproject commit 299a2f12de2ddb76b9a488b23e7e562058faee90 diff --git a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h index 56e4dbcec..9a6256c68 100644 --- a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h +++ b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.h @@ -5,7 +5,7 @@ #define MICROPY_HW_LED_TX &pin_PA27 #define MICROPY_HW_LED_RX &pin_PB03 -#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25 | PORT_PA27) +#define MICROPY_PORT_A (PORT_PA27) #define MICROPY_PORT_B (PORT_PB03) #define MICROPY_PORT_C (0) diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h index 6dfaf87e9..2ad13e81c 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h @@ -14,7 +14,6 @@ #define SPI_FLASH_CS_PIN &pin_PB22 // These are pins not to reset. -// PA24 and PA25 are USB. #define MICROPY_PORT_A (0) #define MICROPY_PORT_B (0) #define MICROPY_PORT_C (0) diff --git a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h index 7dd4bf7c4..5869c01ff 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.h @@ -9,7 +9,9 @@ #define SPI_FLASH_CS_PIN &pin_PA07 // These are pins not to reset. +// NeoPixel and for the display: Reset, Command or data, and Chip select #define MICROPY_PORT_A ( PORT_PA01 | PORT_PA12 | PORT_PA27 | PORT_PA28) +// Data and Clock for the display #define MICROPY_PORT_B ( PORT_PB22 | PORT_PB23 ) #define MICROPY_PORT_C ( 0 ) diff --git a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h index 28bb1f293..f08d129dc 100644 --- a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h @@ -1,8 +1,9 @@ #define MICROPY_HW_BOARD_NAME "Adafruit Metro M0 Express" #define MICROPY_HW_MCU_NAME "samd21g18" -//#define MICROPY_HW_LED_TX &pin_PA27 -//#define MICROPY_HW_LED_RX &pin_PA31 +#define MICROPY_HW_LED_TX &pin_PA27 +// Comment this out if you have trouble connecting over SWD. It's one of the SWD pins. +#define MICROPY_HW_LED_RX &pin_PA31 #define MICROPY_HW_NEOPIXEL (&pin_PA30) @@ -15,7 +16,7 @@ #define SPI_FLASH_CS_PIN &pin_PA13 // These are pins not to reset. -#define MICROPY_PORT_A (PORT_PA24 | PORT_PA25 | PORT_PA30 | PORT_PA31) +#define MICROPY_PORT_A (0) #define MICROPY_PORT_B (0) #define MICROPY_PORT_C (0) diff --git a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h index 24f3004e9..c311f540c 100644 --- a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h +++ b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.h @@ -5,7 +5,7 @@ #define MICROPY_HW_APA102_MOSI (&pin_PA00) #define MICROPY_HW_APA102_SCK (&pin_PA01) -#define MICROPY_PORT_A (PORT_PA00 | PORT_PA01 | PORT_PA24 | PORT_PA25) +#define MICROPY_PORT_A (PORT_PA00 | PORT_PA01) #define MICROPY_PORT_B (0) #define MICROPY_PORT_C (0) diff --git a/ports/atmel-samd/common-hal/microcontroller/Pin.c b/ports/atmel-samd/common-hal/microcontroller/Pin.c index 9af5aeaf7..7dd9c6b09 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Pin.c +++ b/ports/atmel-samd/common-hal/microcontroller/Pin.c @@ -53,12 +53,7 @@ void reset_all_pins(void) { // Do not full reset USB or SWD lines. pin_mask[0] &= ~(PORT_PA24 | PORT_PA25 | PORT_PA30 | PORT_PA31); - #ifdef SAMD21 - pin_mask[0] &= ~(PORT_PA31); - #endif - for (uint32_t i = 0; i < PORT_COUNT; i++) { - pin_mask[i] &= ~(PORT_PA31); pin_mask[i] &= ~never_reset_pins[i]; } diff --git a/supervisor/shared/external_flash/external_flash.h b/supervisor/shared/external_flash/external_flash.h index 852d183a7..72b619a2a 100644 --- a/supervisor/shared/external_flash/external_flash.h +++ b/supervisor/shared/external_flash/external_flash.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c index 72dc40204..13b5c3966 100644 --- a/supervisor/shared/usb/usb_msc_flash.c +++ b/supervisor/shared/usb/usb_msc_flash.c @@ -38,6 +38,8 @@ #define MSC_FLASH_BLOCK_SIZE 512 +static bool ejected[1]; + // The root FS is always at the end of the list. static fs_user_mount_t* get_vfs(int lun) { // TODO(tannewt): Return the mount which matches the lun where 0 is the end @@ -60,7 +62,7 @@ static fs_user_mount_t* get_vfs(int lun) { // - READ10 and WRITE10 have their own callbacks int32_t tud_msc_scsi_cb (uint8_t lun, const uint8_t scsi_cmd[16], void* buffer, uint16_t bufsize) { const void* response = NULL; - uint16_t resplen = 0; + int32_t resplen = 0; switch ( scsi_cmd[0] ) { case SCSI_CMD_TEST_UNIT_READY: @@ -73,6 +75,9 @@ int32_t tud_msc_scsi_cb (uint8_t lun, const uint8_t scsi_cmd[16], void* buffer, if (current_mount == NULL) { resplen = -1; } + if (ejected[lun]) { + resplen = -1; + } } break; @@ -96,6 +101,11 @@ int32_t tud_msc_scsi_cb (uint8_t lun, const uint8_t scsi_cmd[16], void* buffer, if (current_mount == NULL) { resplen = -1; } + if (disk_ioctl(current_mount, CTRL_SYNC, NULL) != RES_OK) { + resplen = -1; + } else { + ejected[lun] = true; + } } } } diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index b50c0798f..2cb06ec2f 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -80,7 +80,7 @@ cdc_comm_interface = standard.InterfaceDescriptor( description="CDC comm", bInterfaceClass=cdc.CDC_CLASS_COMM, # Communications Device Class bInterfaceSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model - bInterfaceProtocol=cdc.CDC_PROTOCOL_V25TER, + bInterfaceProtocol=cdc.CDC_PROTOCOL_NONE, iInterface=StringIndex.index("CircuitPython CDC control"), subdescriptors=[ cdc.Header( @@ -254,7 +254,7 @@ cdc_iad = standard.InterfaceAssociationDescriptor( bInterfaceCount=len(cdc_interfaces), bFunctionClass=cdc.CDC_CLASS_COMM, # Communications Device Class bFunctionSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model - bFunctionProtocol=cdc.CDC_PROTOCOL_V25TER) # TODO(tannewt): can this be NONE (aka 0)? + bFunctionProtocol=cdc.CDC_PROTOCOL_NONE) # audio_iad = standard.InterfaceAssociationDescriptor( # description="Audio IAD", -- cgit v1.2.3