working!
This commit is contained in:
parent
abfb020d41
commit
71a8cadb09
|
@ -659,7 +659,7 @@ msgid "Cannot record to a file"
|
|||
msgstr ""
|
||||
|
||||
#: shared-module/storage/__init__.c
|
||||
msgid "Cannot remount '/' when USB is active."
|
||||
msgid "Cannot remount '/' when visible via USB."
|
||||
msgstr ""
|
||||
|
||||
#: ports/atmel-samd/common-hal/microcontroller/__init__.c
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
//| the host.
|
||||
//| Note that `data` is *disabled* by default."""
|
||||
|
||||
//| def configure_usb(repl_enabled: bool, data_enabled: bool) -> None:
|
||||
//| def configure_usb(*, repl_enabled: bool = True, data_enabled: bool = False) -> None:
|
||||
//| """Configure the USB CDC devices. Can be called in ``boot.py``, before USB is connected.
|
||||
//|
|
||||
//| :param repl_enabled bool: Enable or disable the `repl` USB serial device.
|
||||
|
@ -69,15 +69,21 @@
|
|||
//| True to enable; False to disable. *Disabled* by default."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t usb_cdc_configure_usb(mp_obj_t repl_enabled, mp_obj_t data_enabled) {
|
||||
if (!common_hal_usb_cdc_configure_usb(
|
||||
mp_obj_is_true(repl_enabled),
|
||||
mp_obj_is_true(data_enabled))) {
|
||||
STATIC mp_obj_t usb_cdc_configure_usb(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_repl_enabled, ARG_data_enabled };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_repl_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true } },
|
||||
{ MP_QSTR_data_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } },
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if (!common_hal_usb_cdc_configure_usb(args[ARG_repl_enabled].u_bool, args[ARG_data_enabled].u_bool)) {
|
||||
mp_raise_RuntimeError(translate("Cannot change USB devices now"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(usb_cdc_configure_usb_obj, usb_cdc_configure_usb);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(usb_cdc_configure_usb_obj, 0, usb_cdc_configure_usb);
|
||||
|
||||
// The usb_cdc module dict is mutable so that .repl and .data may
|
||||
// be set to a Serial or to None depending on whether they are enabled or not.
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
usb_hid_device_obj_t *self = m_new_obj(usb_hid_device_obj_t);
|
||||
self->base.type = &usb_hid_device_type;
|
||||
enum { ARG_report_descriptor, ARG_usage, ARG_usage_page, ARG_in_report_length, ARG_out_report_length, ARG_report_id_index };
|
||||
enum { ARG_report_descriptor, ARG_usage_page, ARG_usage, ARG_in_report_length, ARG_out_report_length, ARG_report_id_index };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_report_descriptor, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
{ MP_QSTR_usage_page, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT },
|
||||
|
|
|
@ -229,8 +229,8 @@ void common_hal_storage_remount(const char *mount_path, bool readonly, bool disa
|
|||
}
|
||||
|
||||
#if CIRCUITPY_USB_MSC
|
||||
if (!usb_msc_ejected()) {
|
||||
mp_raise_RuntimeError(translate("Cannot remount '/' when USB is active."));
|
||||
if (!usb_msc_ejected() && storage_usb_is_enabled) {
|
||||
mp_raise_RuntimeError(translate("Cannot remount '/' when visible via USB."));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "supervisor/serial.h"
|
||||
#include "supervisor/usb.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-module/usb_cdc/__init__.h"
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
|
@ -92,6 +93,8 @@ bool serial_connected(void) {
|
|||
|
||||
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
|
||||
return true;
|
||||
#elif CIRCUITPY_USB_CDC
|
||||
return usb_cdc_repl_enabled() && tud_cdc_connected();
|
||||
#else
|
||||
return tud_cdc_connected();
|
||||
#endif
|
||||
|
@ -114,9 +117,12 @@ char serial_read(void) {
|
|||
char text;
|
||||
common_hal_busio_uart_read(&debug_uart, (uint8_t *)&text, 1, &uart_errcode);
|
||||
return text;
|
||||
#else
|
||||
return (char)tud_cdc_read_char();
|
||||
#elif CIRCUITPY_USB_CDC
|
||||
if (!usb_cdc_repl_enabled()) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return (char)tud_cdc_read_char();
|
||||
}
|
||||
|
||||
bool serial_bytes_available(void) {
|
||||
|
@ -128,9 +134,12 @@ bool serial_bytes_available(void) {
|
|||
|
||||
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
|
||||
return common_hal_busio_uart_rx_characters_available(&debug_uart) || (tud_cdc_available() > 0);
|
||||
#else
|
||||
return tud_cdc_available() > 0;
|
||||
#elif CIRCUITPY_USB_CDC
|
||||
if (!usb_cdc_repl_enabled()) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return tud_cdc_available() > 0;
|
||||
}
|
||||
void serial_write_substring(const char *text, uint32_t length) {
|
||||
if (length == 0) {
|
||||
|
@ -147,6 +156,12 @@ void serial_write_substring(const char *text, uint32_t length) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_USB_CDC
|
||||
if (!usb_cdc_repl_enabled()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t count = 0;
|
||||
while (count < length && tud_cdc_connected()) {
|
||||
count += tud_cdc_write(text + count, length - count);
|
||||
|
|
|
@ -74,7 +74,7 @@ extern "C" {
|
|||
|
||||
// ------------- CLASS -------------//
|
||||
|
||||
// Could be 2 if secondary CDC channel requested.
|
||||
// Will be set to 2 in supervisor.mk if CIRCUITPY_USB_CDC is set.
|
||||
#ifndef CFG_TUD_CDC
|
||||
#define CFG_TUD_CDC 1
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue