circuitpython/supervisor/shared/usb/usb.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

312 lines
8.8 KiB
C
Raw Normal View History

/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 hathach for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/objstr.h"
#include "py/runtime.h"
#include "shared-bindings/microcontroller/Processor.h"
#include "supervisor/background_callback.h"
#include "supervisor/port.h"
#include "supervisor/serial.h"
#include "supervisor/usb.h"
2020-11-19 17:47:12 -05:00
#include "supervisor/shared/workflow.h"
#include "lib/utils/interrupt_char.h"
#include "lib/mp-readline/readline.h"
2021-04-27 23:53:23 -04:00
#if CIRCUITPY_STORAGE
#include "shared-module/storage/__init__.h"
#endif
#if CIRCUITPY_USB_CDC
#include "shared-module/usb_cdc/__init__.h"
#endif
2021-04-26 23:54:01 -04:00
#if CIRCUITPY_USB_HID
#include "shared-module/usb_hid/__init__.h"
#endif
2021-02-15 20:06:18 -05:00
#if CIRCUITPY_USB_MIDI
#include "shared-module/usb_midi/__init__.h"
#endif
#include "tusb.h"
#if CIRCUITPY_USB_VENDOR
feat: add Blues Swan R5 support complete pin mapping for Feather pins stubbed out files needed for complilation. still to be modified 0 out all CPY modules in mpconfigboard.mk until we get the build running add csv for pin generation for STM32L4R5 add F4R5 references in peripherals files refactored out board files BECAUSE I AM AN IDIOT; add L4 series system clocks file from CubeMX took a guess at the number of USB endpoint pairs to get the build done guess was close, but wrong. It is 8 clean up peripheral DEFs Fixes build error: ``` In file included from ../../py/mpstate.h:33, from ../../py/mpstate.c:27: ../../py/misc.h: In function 'vstr_str': ../../py/misc.h:196:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI static inline char *vstr_str(vstr_t *vstr) { ^~~~~~ ``` Sleuthing steps: * verify that the feather_stm32f4_express board builds correctly * put a `#error` at the bottom of the `mpstate.c` file. * build for the feather and swan boards, with V=2 to capture the build command for that file. * use a differencing tool to inspect the differences between the two invocations * inspecting the differences, I saw a missing `-mcpu=cortex-m4` I tested by adding that to the Swan build command. The file built fine (stopping at the hard error, but no other warnings.) A grep through the sources revealed where this flag was being set for the stm ports. With this commit, the build gets further, but does not complete. The next exciting episode in this unfolding coding saga is just a commit away! working build with minimal set of modules for the Blues Swan r5 chore:change header copyright name to Blues Wireless Contributors USB operational. Fixed up clocks to be hardwired for LSE no HSE case. (Trying to combine HSE in there made the code much more complex, and I don't have a board to test it out on.) USART working adds support for `ENABLE_3V3` and `DISCHARGE_3V3` pins. I am surprised that pin definitions are quite low-level and don't include default direction and state, so the code currently has to initialize `ENABLE_3V3` pin as output. The LED takes over a second to discharge, so I wonder if the board startup code is not having the desired affect. short circuit implementation of backup memory for the STM32L4 all the ports remove company name from board name to be consistent with the Arduino board definition. add default pins for I2C, SPI and UART, so that `board.I2C` et al. works as expected. Confirmed I2C timing. fix board name fix incorrect pin definition. add test to allow manual check of each output pin analog IO code changes for WebUSB. Doesn't appear to work, will revisit later. ensure that `sys.platform` is available checkin missing file feat: make room for a larger filesystem so the sensor tutorial will fit on the device. fix:(stm32l4r5zi.csv): merged AF0-7 and AF8-15 into single lines and removed extraneous headers mixed in with the data. fix(parse_af_csv.py): pin index in the csv is 0 not 1, and AF index made 1 larger chore(Swan R5): update peripherals pins from `parse_af_csv.py` output optimize flash sector access
2021-07-29 18:06:31 -04:00
#include "usb_vendor_descriptors.h"
// The WebUSB support being conditionally added to this file is based on the
// tinyusb demo examples/device/webusb_serial.
static bool web_serial_connected = false;
feat: add Blues Swan R5 support complete pin mapping for Feather pins stubbed out files needed for complilation. still to be modified 0 out all CPY modules in mpconfigboard.mk until we get the build running add csv for pin generation for STM32L4R5 add F4R5 references in peripherals files refactored out board files BECAUSE I AM AN IDIOT; add L4 series system clocks file from CubeMX took a guess at the number of USB endpoint pairs to get the build done guess was close, but wrong. It is 8 clean up peripheral DEFs Fixes build error: ``` In file included from ../../py/mpstate.h:33, from ../../py/mpstate.c:27: ../../py/misc.h: In function 'vstr_str': ../../py/misc.h:196:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI static inline char *vstr_str(vstr_t *vstr) { ^~~~~~ ``` Sleuthing steps: * verify that the feather_stm32f4_express board builds correctly * put a `#error` at the bottom of the `mpstate.c` file. * build for the feather and swan boards, with V=2 to capture the build command for that file. * use a differencing tool to inspect the differences between the two invocations * inspecting the differences, I saw a missing `-mcpu=cortex-m4` I tested by adding that to the Swan build command. The file built fine (stopping at the hard error, but no other warnings.) A grep through the sources revealed where this flag was being set for the stm ports. With this commit, the build gets further, but does not complete. The next exciting episode in this unfolding coding saga is just a commit away! working build with minimal set of modules for the Blues Swan r5 chore:change header copyright name to Blues Wireless Contributors USB operational. Fixed up clocks to be hardwired for LSE no HSE case. (Trying to combine HSE in there made the code much more complex, and I don't have a board to test it out on.) USART working adds support for `ENABLE_3V3` and `DISCHARGE_3V3` pins. I am surprised that pin definitions are quite low-level and don't include default direction and state, so the code currently has to initialize `ENABLE_3V3` pin as output. The LED takes over a second to discharge, so I wonder if the board startup code is not having the desired affect. short circuit implementation of backup memory for the STM32L4 all the ports remove company name from board name to be consistent with the Arduino board definition. add default pins for I2C, SPI and UART, so that `board.I2C` et al. works as expected. Confirmed I2C timing. fix board name fix incorrect pin definition. add test to allow manual check of each output pin analog IO code changes for WebUSB. Doesn't appear to work, will revisit later. ensure that `sys.platform` is available checkin missing file feat: make room for a larger filesystem so the sensor tutorial will fit on the device. fix:(stm32l4r5zi.csv): merged AF0-7 and AF8-15 into single lines and removed extraneous headers mixed in with the data. fix(parse_af_csv.py): pin index in the csv is 0 not 1, and AF index made 1 larger chore(Swan R5): update peripherals pins from `parse_af_csv.py` output optimize flash sector access
2021-07-29 18:06:31 -04:00
#define URL "www.tinyusb.org/examples/webusb-serial"
const tusb_desc_webusb_url_t desc_webusb_url =
{
.bLength = 3 + sizeof(URL) - 1,
.bDescriptorType = 3, // WEBUSB URL type
.bScheme = 1, // 0: http, 1: https
.url = URL
};
#endif
bool usb_enabled(void) {
2019-01-29 08:47:01 -05:00
return tusb_inited();
}
2018-08-23 03:00:54 -04:00
2021-03-15 09:57:36 -04:00
MP_WEAK void post_usb_init(void) {
}
2021-01-21 14:33:13 -05:00
void usb_init(void) {
init_usb_hardware();
2018-08-23 03:00:54 -04:00
tusb_init();
2021-01-21 14:33:13 -05:00
post_usb_init();
#if MICROPY_KBD_EXCEPTION && CIRCUITPY_USB_CDC
// Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() usb_callback will be invoked when Ctrl+C is received
// This usb_callback always got invoked regardless of mp_interrupt_char value since we only set it once here
// Don't watch for ctrl-C if there is no REPL.
if (usb_cdc_console_enabled()) {
// Console will always be itf 0.
tud_cdc_set_wanted_char(CHAR_CTRL_C);
}
2021-03-15 09:57:36 -04:00
#endif
2021-04-27 23:53:23 -04:00
}
2021-04-28 13:00:44 -04:00
// Set up USB defaults before any USB changes are made in boot.py
2021-04-28 23:48:26 -04:00
void usb_set_defaults(void) {
#if CIRCUITPY_STORAGE && CIRCUITPY_USB_MSC
2021-04-28 23:48:26 -04:00
storage_usb_set_defaults();
2021-04-27 23:53:23 -04:00
#endif
2021-04-26 23:54:01 -04:00
#if CIRCUITPY_USB_CDC
2021-04-28 23:48:26 -04:00
usb_cdc_set_defaults();
2021-04-27 23:53:23 -04:00
#endif
#if CIRCUITPY_USB_HID
2021-04-28 23:48:26 -04:00
usb_hid_set_defaults();
2021-04-26 23:54:01 -04:00
#endif
2021-03-15 09:57:36 -04:00
#if CIRCUITPY_USB_MIDI
2021-04-28 23:48:26 -04:00
usb_midi_set_defaults();
2021-03-15 09:57:36 -04:00
#endif
2021-04-27 23:53:23 -04:00
};
// Some dynamic USB data must be saved after boot.py. How much is needed?
2021-04-28 23:48:26 -04:00
size_t usb_boot_py_data_size(void) {
size_t size = 0;
#if CIRCUITPY_USB_HID
size += usb_hid_report_descriptor_length();
2021-04-28 13:00:44 -04:00
#endif
2021-04-28 23:48:26 -04:00
return size;
}
// Fill in the data to save.
void usb_get_boot_py_data(uint8_t *temp_storage, size_t temp_storage_size) {
#if CIRCUITPY_USB_HID
usb_hid_build_report_descriptor(temp_storage, temp_storage_size);
2021-04-28 13:00:44 -04:00
#endif
2021-04-28 23:48:26 -04:00
}
2021-04-28 13:00:44 -04:00
2021-04-28 23:48:26 -04:00
// After VM is gone, save data into non-heap storage (storage_allocations).
void usb_return_boot_py_data(uint8_t *temp_storage, size_t temp_storage_size) {
2021-04-28 13:00:44 -04:00
#if CIRCUITPY_USB_HID
2021-04-28 23:48:26 -04:00
usb_hid_save_report_descriptor(temp_storage, temp_storage_size);
2021-04-28 13:00:44 -04:00
#endif
2021-04-28 23:48:26 -04:00
// Now we can also build the rest of the descriptors and place them in storage_allocations.
usb_build_descriptors();
2021-04-25 23:17:41 -04:00
}
2021-04-28 23:48:26 -04:00
// Call this when ready to run code.py or a REPL, and a VM has been started.
void usb_setup_with_vm(void) {
#if CIRCUITPY_USB_HID
usb_hid_setup_devices();
#endif
2021-03-15 09:57:36 -04:00
#if CIRCUITPY_USB_MIDI
2021-04-28 23:48:26 -04:00
usb_midi_setup_ports();
2021-03-15 09:57:36 -04:00
#endif
}
void usb_disconnect(void) {
tud_disconnect();
}
void usb_background(void) {
if (usb_enabled()) {
#if CFG_TUSB_OS == OPT_OS_NONE
tud_task();
#endif
// No need to flush if there's no REPL.
#if CIRCUITPY_USB_CDC
if (usb_cdc_console_enabled()) {
// Console will always be itf 0.
tud_cdc_write_flush();
}
#endif
}
}
static background_callback_t usb_callback;
2021-03-15 09:57:36 -04:00
static void usb_background_do(void *unused) {
usb_background();
}
2021-03-15 09:57:36 -04:00
void usb_background_schedule(void) {
background_callback_add(&usb_callback, usb_background_do, NULL);
}
void usb_irq_handler(void) {
tud_int_handler(0);
usb_background_schedule();
}
2021-03-15 09:57:36 -04:00
// --------------------------------------------------------------------+
// tinyusb callbacks
2021-03-15 09:57:36 -04:00
// --------------------------------------------------------------------+
2018-08-21 04:15:44 -04:00
// Invoked when device is mounted
void tud_mount_cb(void) {
2021-03-15 09:57:36 -04:00
#if CIRCUITPY_USB_MSC
usb_msc_mount();
2021-03-15 09:57:36 -04:00
#endif
}
2018-08-21 04:15:44 -04:00
// Invoked when device is unmounted
void tud_umount_cb(void) {
2021-03-15 09:57:36 -04:00
#if CIRCUITPY_USB_MSC
usb_msc_umount();
2021-03-15 09:57:36 -04:00
#endif
}
// Invoked when usb bus is suspended
// remote_wakeup_en : if host allows us to perform remote wakeup
// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus
void tud_suspend_cb(bool remote_wakeup_en) {
}
// Invoked when usb bus is resumed
void tud_resume_cb(void) {
}
2018-08-21 04:15:44 -04:00
// Invoked when cdc when line state changed e.g connected/disconnected
// Use to reset to DFU when disconnect with 1200 bps
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
2021-03-15 09:57:36 -04:00
(void)itf; // interface ID, not used
2018-08-21 04:15:44 -04:00
// DTR = false is counted as disconnected
2021-03-15 09:57:36 -04:00
if (!dtr) {
2018-08-21 04:15:44 -04:00
cdc_line_coding_t coding;
// Use whichever CDC is itf 0.
2018-08-21 04:15:44 -04:00
tud_cdc_get_line_coding(&coding);
2021-03-15 09:57:36 -04:00
if (coding.bit_rate == 1200) {
reset_to_bootloader();
2018-08-21 04:15:44 -04:00
}
}
}
#if CIRCUITPY_USB_VENDOR
2021-03-15 09:57:36 -04:00
// --------------------------------------------------------------------+
// WebUSB use vendor class
2021-03-15 09:57:36 -04:00
// --------------------------------------------------------------------+
2021-03-15 09:57:36 -04:00
bool tud_vendor_connected(void) {
return web_serial_connected;
}
// Invoked when a control transfer occurred on an interface of this class
// Driver response accordingly to the request and the transfer stage (setup/data/ack)
// return false to stall control endpoint (e.g unsupported request)
2021-03-15 09:57:36 -04:00
bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) {
// nothing to with DATA & ACK stage
if (stage != CONTROL_STAGE_SETUP) {
return true;
}
switch (request->bRequest)
{
case VENDOR_REQUEST_WEBUSB:
// match vendor request in BOS descriptor
// Get landing page url
return tud_control_xfer(rhport, request, (void *)&desc_webusb_url, desc_webusb_url.bLength);
case VENDOR_REQUEST_MICROSOFT:
if (request->wIndex == 7) {
// Get Microsoft OS 2.0 compatible descriptor
feat: add Blues Swan R5 support complete pin mapping for Feather pins stubbed out files needed for complilation. still to be modified 0 out all CPY modules in mpconfigboard.mk until we get the build running add csv for pin generation for STM32L4R5 add F4R5 references in peripherals files refactored out board files BECAUSE I AM AN IDIOT; add L4 series system clocks file from CubeMX took a guess at the number of USB endpoint pairs to get the build done guess was close, but wrong. It is 8 clean up peripheral DEFs Fixes build error: ``` In file included from ../../py/mpstate.h:33, from ../../py/mpstate.c:27: ../../py/misc.h: In function 'vstr_str': ../../py/misc.h:196:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI static inline char *vstr_str(vstr_t *vstr) { ^~~~~~ ``` Sleuthing steps: * verify that the feather_stm32f4_express board builds correctly * put a `#error` at the bottom of the `mpstate.c` file. * build for the feather and swan boards, with V=2 to capture the build command for that file. * use a differencing tool to inspect the differences between the two invocations * inspecting the differences, I saw a missing `-mcpu=cortex-m4` I tested by adding that to the Swan build command. The file built fine (stopping at the hard error, but no other warnings.) A grep through the sources revealed where this flag was being set for the stm ports. With this commit, the build gets further, but does not complete. The next exciting episode in this unfolding coding saga is just a commit away! working build with minimal set of modules for the Blues Swan r5 chore:change header copyright name to Blues Wireless Contributors USB operational. Fixed up clocks to be hardwired for LSE no HSE case. (Trying to combine HSE in there made the code much more complex, and I don't have a board to test it out on.) USART working adds support for `ENABLE_3V3` and `DISCHARGE_3V3` pins. I am surprised that pin definitions are quite low-level and don't include default direction and state, so the code currently has to initialize `ENABLE_3V3` pin as output. The LED takes over a second to discharge, so I wonder if the board startup code is not having the desired affect. short circuit implementation of backup memory for the STM32L4 all the ports remove company name from board name to be consistent with the Arduino board definition. add default pins for I2C, SPI and UART, so that `board.I2C` et al. works as expected. Confirmed I2C timing. fix board name fix incorrect pin definition. add test to allow manual check of each output pin analog IO code changes for WebUSB. Doesn't appear to work, will revisit later. ensure that `sys.platform` is available checkin missing file feat: make room for a larger filesystem so the sensor tutorial will fit on the device. fix:(stm32l4r5zi.csv): merged AF0-7 and AF8-15 into single lines and removed extraneous headers mixed in with the data. fix(parse_af_csv.py): pin index in the csv is 0 not 1, and AF index made 1 larger chore(Swan R5): update peripherals pins from `parse_af_csv.py` output optimize flash sector access
2021-07-29 18:06:31 -04:00
// let's just hope the target architecture always has the same endianness
2021-03-15 09:57:36 -04:00
uint16_t total_len;
feat: add Blues Swan R5 support complete pin mapping for Feather pins stubbed out files needed for complilation. still to be modified 0 out all CPY modules in mpconfigboard.mk until we get the build running add csv for pin generation for STM32L4R5 add F4R5 references in peripherals files refactored out board files BECAUSE I AM AN IDIOT; add L4 series system clocks file from CubeMX took a guess at the number of USB endpoint pairs to get the build done guess was close, but wrong. It is 8 clean up peripheral DEFs Fixes build error: ``` In file included from ../../py/mpstate.h:33, from ../../py/mpstate.c:27: ../../py/misc.h: In function 'vstr_str': ../../py/misc.h:196:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI static inline char *vstr_str(vstr_t *vstr) { ^~~~~~ ``` Sleuthing steps: * verify that the feather_stm32f4_express board builds correctly * put a `#error` at the bottom of the `mpstate.c` file. * build for the feather and swan boards, with V=2 to capture the build command for that file. * use a differencing tool to inspect the differences between the two invocations * inspecting the differences, I saw a missing `-mcpu=cortex-m4` I tested by adding that to the Swan build command. The file built fine (stopping at the hard error, but no other warnings.) A grep through the sources revealed where this flag was being set for the stm ports. With this commit, the build gets further, but does not complete. The next exciting episode in this unfolding coding saga is just a commit away! working build with minimal set of modules for the Blues Swan r5 chore:change header copyright name to Blues Wireless Contributors USB operational. Fixed up clocks to be hardwired for LSE no HSE case. (Trying to combine HSE in there made the code much more complex, and I don't have a board to test it out on.) USART working adds support for `ENABLE_3V3` and `DISCHARGE_3V3` pins. I am surprised that pin definitions are quite low-level and don't include default direction and state, so the code currently has to initialize `ENABLE_3V3` pin as output. The LED takes over a second to discharge, so I wonder if the board startup code is not having the desired affect. short circuit implementation of backup memory for the STM32L4 all the ports remove company name from board name to be consistent with the Arduino board definition. add default pins for I2C, SPI and UART, so that `board.I2C` et al. works as expected. Confirmed I2C timing. fix board name fix incorrect pin definition. add test to allow manual check of each output pin analog IO code changes for WebUSB. Doesn't appear to work, will revisit later. ensure that `sys.platform` is available checkin missing file feat: make room for a larger filesystem so the sensor tutorial will fit on the device. fix:(stm32l4r5zi.csv): merged AF0-7 and AF8-15 into single lines and removed extraneous headers mixed in with the data. fix(parse_af_csv.py): pin index in the csv is 0 not 1, and AF index made 1 larger chore(Swan R5): update peripherals pins from `parse_af_csv.py` output optimize flash sector access
2021-07-29 18:06:31 -04:00
memcpy(&total_len, vendor_ms_os_20_descriptor() + 8, 2);
2021-03-15 09:57:36 -04:00
feat: add Blues Swan R5 support complete pin mapping for Feather pins stubbed out files needed for complilation. still to be modified 0 out all CPY modules in mpconfigboard.mk until we get the build running add csv for pin generation for STM32L4R5 add F4R5 references in peripherals files refactored out board files BECAUSE I AM AN IDIOT; add L4 series system clocks file from CubeMX took a guess at the number of USB endpoint pairs to get the build done guess was close, but wrong. It is 8 clean up peripheral DEFs Fixes build error: ``` In file included from ../../py/mpstate.h:33, from ../../py/mpstate.c:27: ../../py/misc.h: In function 'vstr_str': ../../py/misc.h:196:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI static inline char *vstr_str(vstr_t *vstr) { ^~~~~~ ``` Sleuthing steps: * verify that the feather_stm32f4_express board builds correctly * put a `#error` at the bottom of the `mpstate.c` file. * build for the feather and swan boards, with V=2 to capture the build command for that file. * use a differencing tool to inspect the differences between the two invocations * inspecting the differences, I saw a missing `-mcpu=cortex-m4` I tested by adding that to the Swan build command. The file built fine (stopping at the hard error, but no other warnings.) A grep through the sources revealed where this flag was being set for the stm ports. With this commit, the build gets further, but does not complete. The next exciting episode in this unfolding coding saga is just a commit away! working build with minimal set of modules for the Blues Swan r5 chore:change header copyright name to Blues Wireless Contributors USB operational. Fixed up clocks to be hardwired for LSE no HSE case. (Trying to combine HSE in there made the code much more complex, and I don't have a board to test it out on.) USART working adds support for `ENABLE_3V3` and `DISCHARGE_3V3` pins. I am surprised that pin definitions are quite low-level and don't include default direction and state, so the code currently has to initialize `ENABLE_3V3` pin as output. The LED takes over a second to discharge, so I wonder if the board startup code is not having the desired affect. short circuit implementation of backup memory for the STM32L4 all the ports remove company name from board name to be consistent with the Arduino board definition. add default pins for I2C, SPI and UART, so that `board.I2C` et al. works as expected. Confirmed I2C timing. fix board name fix incorrect pin definition. add test to allow manual check of each output pin analog IO code changes for WebUSB. Doesn't appear to work, will revisit later. ensure that `sys.platform` is available checkin missing file feat: make room for a larger filesystem so the sensor tutorial will fit on the device. fix:(stm32l4r5zi.csv): merged AF0-7 and AF8-15 into single lines and removed extraneous headers mixed in with the data. fix(parse_af_csv.py): pin index in the csv is 0 not 1, and AF index made 1 larger chore(Swan R5): update peripherals pins from `parse_af_csv.py` output optimize flash sector access
2021-07-29 18:06:31 -04:00
return tud_control_xfer(rhport, request, (void *)vendor_ms_os_20_descriptor(), total_len);
2021-03-15 09:57:36 -04:00
} else {
return false;
}
case 0x22:
// Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to
// connect and disconnect.
web_serial_connected = (request->wValue != 0);
// response with status OK
return tud_control_status(rhport, request);
default:
// stall unknown request
return false;
}
return true;
}
2021-02-18 14:24:58 -05:00
#endif // CIRCUITPY_USB_VENDOR
#if MICROPY_KBD_EXCEPTION
/**
* Callback invoked when received an "wanted" char.
* @param itf Interface index (for multiple cdc interfaces)
* @param wanted_char The wanted char (set previously)
*/
// Only called when console is enabled.
void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) {
// Workaround for using lib/utils/interrupt_char.c
// Compare mp_interrupt_char with wanted_char and ignore if not matched
if (mp_interrupt_char == wanted_char) {
tud_cdc_n_read_flush(itf); // flush read fifo
2021-06-18 12:15:51 -04:00
mp_sched_keyboard_interrupt();
}
}
#endif