Fix merge bugs; remove shared/tinyusb/*

This commit is contained in:
Dan Halbert 2023-10-19 16:02:42 -04:00
parent a8fb081166
commit c0a4abc03c
22 changed files with 82 additions and 427 deletions

View File

@ -32,7 +32,7 @@
#include "py/binary.h"
#include "py/objstr.h"
#include "lib/uzlib/tinf.h"
//#include "lib/uzlib/tinf.h"
#if MICROPY_PY_BINASCII
@ -219,7 +219,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b
*/
#if MICROPY_PY_UBINASCII_CRC32
#include "lib/uzlib/tinf.h"
//#include "lib/uzlib/uzlib.h"
STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) {
mp_buffer_info_t bufinfo;

View File

@ -31,10 +31,10 @@
#include "py/stream.h"
#include "py/mperrno.h"
#if MICROPY_PY_UZLIB
#if MICROPY_PY_ZLIB
#define UZLIB_CONF_PARANOID_CHECKS (1)
#include "lib/uzlib/tinf.h"
#include "lib/uzlib/uzlib.h"
#if 0 // print debugging info
#define DEBUG_printf DEBUG_printf
@ -243,4 +243,4 @@ MP_REGISTER_MODULE(MP_QSTR_zlib, mp_module_uzlib);
#include "lib/uzlib/adler32.c"
#include "lib/uzlib/crc32.c"
#endif // MICROPY_PY_UZLIB
#endif // MICROPY_PY_ZLIB

View File

@ -59,8 +59,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
cyw43_pin_type,
MP_QSTR_CywPin,
MP_TYPE_FLAG_NONE,
print, shared_bindings_microcontroller_pin_print,
unary_op, mp_generic_unary_op
print, shared_bindings_microcontroller_pin_print
);
//| PM_STANDARD: int

View File

@ -31,6 +31,8 @@
#include <assert.h>
#include "py/compile.h"
// CIRCUITPY: for gc_collect() after each import
#include "py/gc.h"
#include "py/objmodule.h"
#include "py/persistentcode.h"
#include "py/runtime.h"
@ -136,7 +138,6 @@ STATIC mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) {
return stat;
}
}
#endif
// sys.path was empty or no matches, do not search the filesystem or
// frozen code.

View File

@ -255,7 +255,7 @@ STATIC void compile_error_set_line(compiler_t *comp, mp_parse_node_t pn) {
}
}
STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, mp_rom_error_text_t msg) {
STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, const compressed_string_t *msg) {
// only register the error if there has been no other error
if (comp->compile_error == MP_OBJ_NULL) {
comp->compile_error = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg);

17
py/gc.c
View File

@ -260,14 +260,6 @@ void gc_add(void *start, void *end) {
prev_area->next = area;
}
// CIRCUITPY
// TODO FOR MERGE: fix this for multiple areas??
void gc_deinit(void) {
// Run any finalisers before we stop using the heap.
gc_sweep_all();
MP_STATIC_ASSERT(!MICROPY_GC_SPLIT_HEAP);
memset(&MP_STATE_MEM(area), 0, sizeof(MP_STATE_MEM(area)));
#if MICROPY_GC_SPLIT_HEAP_AUTO
// Try to automatically add a heap area large enough to fulfill 'failed_alloc'.
STATIC bool gc_try_add_heap(size_t failed_alloc) {
@ -346,6 +338,15 @@ STATIC bool gc_try_add_heap(size_t failed_alloc) {
#endif
// CIRCUITPY
// TODO FOR MERGE: fix this for multiple areas??
void gc_deinit(void) {
// Run any finalisers before we stop using the heap.
gc_sweep_all();
MP_STATIC_ASSERT(!MICROPY_GC_SPLIT_HEAP);
memset(&MP_STATE_MEM(area), 0, sizeof(MP_STATE_MEM(area)));
}
void gc_lock(void) {
// This does not need to be atomic or have the GC mutex because:
// - each thread has its own gc_lock_depth so there are no races between threads;

View File

@ -26,6 +26,11 @@
#ifndef MICROPY_INCLUDED_PY_MPCONFIG_H
#define MICROPY_INCLUDED_PY_MPCONFIG_H
// Is this a CircuitPython build?
#ifndef CIRCUITPY
#define CIRCUITPY 0
#endif
// In CircuitPython, version info is in genhdr/mpversion.h.
#if CIRCUITPY
#include "genhdr/mpversion.h"
@ -53,11 +58,6 @@
// You can override any of the options below using mpconfigport.h file
// located in a directory of your port.
// Is this a CircuitPython build?
#ifndef CIRCUITPY
#define CIRCUITPY 0
#endif
// mpconfigport.h is a file containing configuration settings for a
// particular port. mpconfigport.h is actually a default name for
// such config, and it can be overridden using MP_CONFIGFILE preprocessor
@ -540,6 +540,15 @@
#define MICROPY_OPT_COMPUTED_GOTO (0)
#endif
// CIRCUITPY
// Whether to save trade flash space for speed in MICROPY_OPT_COMPUTED_GOTO.
// Costs about 3% speed, saves about 1500 bytes space. In addition to the assumptions
// of MICROPY_OPT_COMPUTED_GOTO, also assumes that mp_execute_bytecode is less than
// 32kB in size.
#ifndef MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE
#define MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE (0)
#endif
// Optimise the fast path for loading attributes from instance types. Increases
// Thumb2 code size by about 48 bytes.
#ifndef MICROPY_OPT_LOAD_ATTR_FAST_PATH
@ -597,6 +606,12 @@
#define MICROPY_HAS_FILE_READER (MICROPY_READER_POSIX || MICROPY_READER_VFS)
#endif
// CIRCUITPY
// Number of VFS mounts to persist across soft-reset.
#ifndef MICROPY_FATFS_NUM_PERSISTENT
#define MICROPY_FATFS_NUM_PERSISTENT (0)
#endif
// Hook for the VM at the start of the opcode loop (can contain variable
// definitions usable by the other hook functions)
#ifndef MICROPY_VM_HOOK_INIT
@ -1595,6 +1610,7 @@ typedef double mp_float_t;
// TODO? CIRCUITPY_ZLIB instead
#ifndef MICROPY_PY_ZLIB
#define MICROPY_PY_ZLIB (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
#endif
// Whether to provide "deflate" module (decompression-only by default)
#ifndef MICROPY_PY_DEFLATE
@ -1977,6 +1993,19 @@ typedef double mp_float_t;
#define MP_WEAK __attribute__((weak))
#endif
// CIRCUITPY
// Modifier for functions which should not be instrumented when tracing with
// -finstrument-functions
#ifndef MP_NO_INSTRUMENT
#define MP_NO_INSTRUMENT __attribute__((no_instrument_function))
#endif
// CIRCUITPY
// Modifier for functions which should ideally inlined
#ifndef MP_INLINE
#define MP_INLINE inline MP_NO_INSTRUMENT
#endif
// Modifier for functions which should be never inlined
#ifndef MP_NOINLINE
#define MP_NOINLINE __attribute__((noinline))
@ -1997,6 +2026,13 @@ typedef double mp_float_t;
#define MP_UNLIKELY(x) __builtin_expect((x), 0)
#endif
// CIRCUITPY
// Modifier for functions which aren't often used. Calls will also be considered
// unlikely. Section names are `.text.unlikely` for use in linker scripts.
#ifndef MP_COLD
#define MP_COLD __attribute__((cold))
#endif
// To annotate that code is unreachable
#ifndef MP_UNREACHABLE
#if defined(__GNUC__)

View File

@ -1057,7 +1057,7 @@ mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items);
const mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in);
const char *mp_obj_get_type_str(mp_const_obj_t o_in);
CIRCUITPY
// CIRCUITPY
#define mp_obj_get_type_qstr(o_in) (mp_obj_get_type((o_in))->name)
bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo); // arguments should be type objects
mp_obj_t mp_obj_cast_to_native_base(mp_obj_t self_in, mp_const_obj_t native_type);

View File

@ -103,8 +103,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
MP_QSTR_coroutine,
MP_TYPE_FLAG_BINDS_SELF,
GEN_WRAP_TYPE_ATTR
call, gen_wrap_call,
unary_op, mp_generic_unary_op
call, gen_wrap_call
);
#endif
@ -191,8 +190,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
MP_QSTR_coroutine,
MP_TYPE_FLAG_BINDS_SELF,
GEN_WRAP_TYPE_ATTR
call, native_gen_wrap_call,
unary_op, mp_generic_unary_op
call, native_gen_wrap_call
);
#endif
@ -475,7 +473,6 @@ MP_DEFINE_CONST_OBJ_TYPE(
MP_QSTR_coroutine,
MP_TYPE_FLAG_ITER_IS_ITERNEXT,
print, coro_instance_print,
unary_op, mp_generic_unary_op,
iter, gen_instance_iternext,
locals_dict, &coro_instance_locals_dict
);

View File

@ -653,20 +653,11 @@ STATIC const mp_rom_map_elem_t mp_constants_table[] = {
STATIC MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table);
#endif
STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args);
#if MICROPY_COMP_CONST_FOLDING
// CIRCUITPY: The compilers mentioned below are esp-2020r3. We are using minimum esp-2021r3 (ESP-IDF v4.4).
// See https://github.com/micropython/micropython/commit/f63b4f85aae1e0ade7a7c9f908debb5905cc144d
// and https://github.com/espressif/esp-idf/issues/9130
// So disable this for CircuitPython.
/*
#if MICROPY_COMP_CONST_FOLDING_COMPILER_WORKAROUND
#if defined(MICROPY_COMP_CONST_FOLDING_COMPILER_WORKAROUND) && MICROPY_COMP_CONST_FOLDING_COMPILER_WORKAROUND
// Some versions of the xtensa-esp32-elf-gcc compiler generate wrong code if this
// function is static, so provide a hook for them to work around this problem.
MP_NOINLINE
#endif
*/
STATIC bool fold_logical_constants(parser_t *parser, uint8_t rule_id, size_t *num_args) {
if (rule_id == RULE_or_test
|| rule_id == RULE_and_test) {

View File

@ -1393,7 +1393,8 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
STATIC mp_fun_1_t type_get_iternext(const mp_obj_type_t *type) {
if ((type->flags & MP_TYPE_FLAG_ITER_IS_STREAM) == MP_TYPE_FLAG_ITER_IS_STREAM) {
mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self);
// CIRCUITPY: unneeded declaration
// mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self);
return mp_stream_unbuffered_iter;
} else if (type->flags & MP_TYPE_FLAG_ITER_IS_ITERNEXT) {
return (mp_fun_1_t)MP_OBJ_TYPE_GET_SLOT(type, iter);

View File

@ -163,6 +163,9 @@ static inline void mp_globals_set(mp_obj_dict_t *d) {
MP_STATE_THREAD(dict_globals) = d;
}
void mp_globals_locals_set_from_nlr_jump_callback(void *ctx_in);
void mp_call_function_1_from_nlr_jump_callback(void *ctx_in);
mp_obj_t mp_load_name(qstr qst);
mp_obj_t mp_load_global(qstr qst);
mp_obj_t mp_load_build_class(void);

View File

@ -248,6 +248,5 @@ MP_DEFINE_CONST_OBJ_TYPE(
bleio_connection_type,
MP_QSTR_Connection,
MP_TYPE_FLAG_NONE,
locals_dict, &bleio_connection_locals_dict,
unary_op, mp_generic_unary_op
locals_dict, &bleio_connection_locals_dict
);

View File

@ -45,7 +45,9 @@
//| """Returns a hash for the Pin."""
//| ...
//|
// Provided by mp_generic_unary_op().
// Provided inherently.
// See https://github.com/micropython/micropython/pull/10348.
static void get_pin_name(const mcu_pin_obj_t *self, qstr *package, qstr *module, qstr *name) {
const mp_map_t *board_map = &board_module_globals.map;
@ -86,8 +88,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
mcu_pin_type,
MP_QSTR_Pin,
MP_TYPE_FLAG_NONE,
print, shared_bindings_microcontroller_pin_print,
unary_op, mp_generic_unary_op
print, shared_bindings_microcontroller_pin_print
);
const mcu_pin_obj_t *validate_obj_is_pin(mp_obj_t obj, qstr arg_name) {

View File

@ -51,7 +51,8 @@
//| def __hash__(self) -> int:
//| """Returns a hash for the Socket."""
//| ...
// Provided by mp_generic_unary_op().
// Provided inherently.
// See https://github.com/micropython/micropython/pull/10348.
//| def __enter__(self) -> Socket:
//| """No-op used by Context Managers."""
@ -452,6 +453,5 @@ MP_DEFINE_CONST_OBJ_TYPE(
MP_QSTR_Socket,
MP_TYPE_FLAG_NONE,
locals_dict, &socketpool_socket_locals_dict,
unary_op, mp_generic_unary_op,
protocol, &socket_stream_p
);

View File

@ -48,7 +48,8 @@
//| def __hash__(self) -> int:
//| """Returns a hash for the Socket."""
//| ...
// Provided by mp_generic_unary_op().
// Provided by automatic inclusion of hash()
// https://github.com/micropython/micropython/pull/10348
//| def __enter__(self) -> SSLSocket:
//| """No-op used by Context Managers."""
@ -301,7 +302,5 @@ MP_DEFINE_CONST_OBJ_TYPE(
ssl_sslsocket_type,
MP_QSTR_SSLSocket,
MP_TYPE_FLAG_NONE,
locals_dict, &ssl_sslsocket_locals_dict,
unary_op, mp_generic_unary_op
locals_dict, &ssl_sslsocket_locals_dict
);

View File

@ -63,6 +63,5 @@ MP_DEFINE_CONST_OBJ_TYPE(
MP_QSTR_Packet,
MP_TYPE_FLAG_NONE,
print, wifi_packet_print,
locals_dict, &wifi_packet_locals_dict,
unary_op, mp_generic_unary_op
locals_dict, &wifi_packet_locals_dict
);

View File

@ -29,13 +29,14 @@
#include <stdint.h>
#include <string.h>
#include "py/mphal.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/repl.h"
#include "py/gc.h"
#include "py/frozenmod.h"
#include "py/mphal.h"
#if MICROPY_HW_ENABLE_USB
#if defined(MICROPY_HW_ENABLE_USB) && MICROPY_HW_ENABLE_USB
#include "irq.h"
#include "usb.h"
#endif
@ -638,7 +639,7 @@ friendly_repl_reset:
for (;;) {
input_restart:
#if MICROPY_HW_ENABLE_USB
#if defined(MICROPY_HW_ENABLE_USB) && MICROPY_HW_ENABLE_USB
if (usb_vcp_is_enabled()) {
// If the user gets to here and interrupts are disabled then
// they'll never see the prompt, traceback etc. The USB REPL needs

View File

@ -1,60 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 Ibrahim Abdelkader <iabdalkader@openmv.io>
*
* 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/runtime.h"
#include "py/mphal.h"
#include "modmachine.h"
#if MICROPY_HW_USB_CDC_1200BPS_TOUCH && MICROPY_HW_ENABLE_USBDEV
#include "tusb.h"
static mp_sched_node_t mp_bootloader_sched_node;
STATIC void usbd_cdc_run_bootloader_task(mp_sched_node_t *node) {
mp_hal_delay_ms(250);
machine_bootloader(0, NULL);
}
void
#if MICROPY_HW_USB_EXTERNAL_TINYUSB
mp_usbd_line_state_cb
#else
tud_cdc_line_state_cb
#endif
(uint8_t itf, bool dtr, bool rts) {
if (dtr == false && rts == false) {
// Device is disconnected.
cdc_line_coding_t line_coding;
tud_cdc_n_get_line_coding(itf, &line_coding);
if (line_coding.bit_rate == 1200) {
// Delay bootloader jump to allow the USB stack to service endpoints.
mp_sched_schedule_node(&mp_bootloader_sched_node, usbd_cdc_run_bootloader_task);
}
}
}
#endif

View File

@ -1,133 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Damien P. George
* Copyright (c) 2022 Blake W. Felt & Angus Gratton
*
* 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/mpconfig.h"
#if MICROPY_HW_ENABLE_USBDEV
#include "tusb.h"
#include "mp_usbd.h"
#include "mp_usbd_internal.h"
#define USBD_CDC_CMD_MAX_SIZE (8)
#define USBD_CDC_IN_OUT_MAX_SIZE ((CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED) ? 512 : 64)
const tusb_desc_device_t mp_usbd_desc_device_static = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_MISC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.idVendor = MICROPY_HW_USB_VID,
.idProduct = MICROPY_HW_USB_PID,
.bcdDevice = 0x0100,
.iManufacturer = USBD_STR_MANUF,
.iProduct = USBD_STR_PRODUCT,
.iSerialNumber = USBD_STR_SERIAL,
.bNumConfigurations = 1,
};
const uint8_t mp_usbd_desc_cfg_static[USBD_STATIC_DESC_LEN] = {
TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_STATIC_MAX, USBD_STR_0, USBD_STATIC_DESC_LEN,
0, USBD_MAX_POWER_MA),
#if CFG_TUD_CDC
TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD,
USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE),
#endif
#if CFG_TUD_MSC
TUD_MSC_DESCRIPTOR(USBD_ITF_MSC, 5, EPNUM_MSC_OUT, EPNUM_MSC_IN, 64),
#endif
};
const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
char serial_buf[MICROPY_HW_USB_DESC_STR_MAX + 1]; // Includes terminating NUL byte
static uint16_t desc_wstr[MICROPY_HW_USB_DESC_STR_MAX + 1]; // Includes prefix uint16_t
const char *desc_str;
uint16_t desc_len;
switch (index) {
case 0:
desc_wstr[1] = 0x0409; // supported language is English
desc_len = 4;
break;
case USBD_STR_SERIAL:
// TODO: make a port-specific serial number callback
mp_usbd_port_get_serial_number(serial_buf);
desc_str = serial_buf;
break;
case USBD_STR_MANUF:
desc_str = MICROPY_HW_USB_MANUFACTURER_STRING;
break;
case USBD_STR_PRODUCT:
desc_str = MICROPY_HW_USB_PRODUCT_FS_STRING;
break;
#if CFG_TUD_CDC
case USBD_STR_CDC:
desc_str = MICROPY_HW_USB_CDC_INTERFACE_STRING;
break;
#endif
#if CFG_TUD_MSC
case USBD_STR_MSC:
desc_str = MICROPY_HW_USB_MSC_INTERFACE_STRING;
break;
#endif
default:
desc_str = NULL;
}
if (index != 0) {
if (desc_str == NULL) {
return NULL; // Will STALL the endpoint
}
// Convert from narrow string to wide string
desc_len = 2;
for (int i = 0; i < MICROPY_HW_USB_DESC_STR_MAX && desc_str[i] != 0; i++) {
desc_wstr[1 + i] = desc_str[i];
desc_len += 2;
}
}
// first byte is length (including header), second byte is string type
desc_wstr[0] = (TUSB_DESC_STRING << 8) | desc_len;
return desc_wstr;
}
const uint8_t *tud_descriptor_device_cb(void) {
return (const void *)&mp_usbd_desc_device_static;
}
const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
(void)index;
return mp_usbd_desc_cfg_static;
}
#endif

View File

@ -1,34 +0,0 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 Angus Gratton
*
* 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.
*/
#ifndef MICROPY_INCLUDED_SHARED_TINYUSB_MP_USBD_INTERNAL_H
#define MICROPY_INCLUDED_SHARED_TINYUSB_MP_USBD_INTERNAL_H
#include "tusb.h"
// Static USB device descriptor values
extern const tusb_desc_device_t mp_usbd_desc_device_static;
extern const uint8_t mp_usbd_desc_cfg_static[USBD_STATIC_DESC_LEN];
#endif // MICROPY_INCLUDED_SHARED_TINYUSB_MP_USBD_INTERNAL_H

View File

@ -1,146 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020-2021 Damien P. George
* Copyright (c) 2022 Angus Gratton
*
* 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.
*
*/
#ifndef MICROPY_INCLUDED_SHARED_TINYUSB_TUSB_CONFIG_H
#define MICROPY_INCLUDED_SHARED_TINYUSB_TUSB_CONFIG_H
#include "py/mpconfig.h"
#if MICROPY_HW_ENABLE_USBDEV
#ifndef MICROPY_HW_USB_MANUFACTURER_STRING
#define MICROPY_HW_USB_MANUFACTURER_STRING "MicroPython"
#endif
#ifndef MICROPY_HW_USB_PRODUCT_FS_STRING
#define MICROPY_HW_USB_PRODUCT_FS_STRING "Board in FS mode"
#endif
#ifndef MICROPY_HW_USB_CDC_INTERFACE_STRING
#define MICROPY_HW_USB_CDC_INTERFACE_STRING "Board CDC"
#endif
#ifndef MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING
#define MICROPY_HW_USB_MSC_INQUIRY_VENDOR_STRING "MicroPy"
#endif
#ifndef MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING
#define MICROPY_HW_USB_MSC_INQUIRY_PRODUCT_STRING "Mass Storage"
#endif
#ifndef MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING
#define MICROPY_HW_USB_MSC_INQUIRY_REVISION_STRING "1.00"
#endif
#ifndef CFG_TUSB_RHPORT0_MODE
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE)
#endif
#if MICROPY_HW_USB_CDC
#define CFG_TUD_CDC (1)
#else
#define CFG_TUD_CDC (0)
#endif
#if MICROPY_HW_USB_MSC
#define CFG_TUD_MSC (1)
#else
#define CFG_TUD_MSC (0)
#endif
// CDC Configuration
#if CFG_TUD_CDC
#define CFG_TUD_CDC_RX_BUFSIZE ((CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED) ? 512 : 256)
#define CFG_TUD_CDC_TX_BUFSIZE ((CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED) ? 512 : 256)
#endif
// MSC Configuration
#if CFG_TUD_MSC
#ifndef MICROPY_HW_USB_MSC_INTERFACE_STRING
#define MICROPY_HW_USB_MSC_INTERFACE_STRING "Board MSC"
#endif
// Set MSC EP buffer size to FatFS block size to avoid partial read/writes (offset arg).
#define CFG_TUD_MSC_BUFSIZE (MICROPY_FATFS_MAX_SS)
#endif
// Define static descriptor size and interface count based on the above config
#define USBD_STATIC_DESC_LEN (TUD_CONFIG_DESC_LEN + \
(CFG_TUD_CDC ? (TUD_CDC_DESC_LEN) : 0) + \
(CFG_TUD_MSC ? (TUD_MSC_DESC_LEN) : 0) \
)
#define USBD_STR_0 (0x00)
#define USBD_STR_MANUF (0x01)
#define USBD_STR_PRODUCT (0x02)
#define USBD_STR_SERIAL (0x03)
#define USBD_STR_CDC (0x04)
#define USBD_STR_MSC (0x05)
#define USBD_MAX_POWER_MA (250)
#ifndef MICROPY_HW_USB_DESC_STR_MAX
#define MICROPY_HW_USB_DESC_STR_MAX (20)
#endif
#if CFG_TUD_CDC
#define USBD_ITF_CDC (0) // needs 2 interfaces
#define USBD_CDC_EP_CMD (0x81)
#define USBD_CDC_EP_OUT (0x02)
#define USBD_CDC_EP_IN (0x82)
#endif // CFG_TUD_CDC
#if CFG_TUD_MSC
// Interface & Endpoint numbers for MSC come after CDC, if it is enabled
#if CFG_TUD_CDC
#define USBD_ITF_MSC (2)
#define EPNUM_MSC_OUT (0x03)
#define EPNUM_MSC_IN (0x83)
#else
#define USBD_ITF_MSC (0)
#define EPNUM_MSC_OUT (0x01)
#define EPNUM_MSC_IN (0x81)
#endif // CFG_TUD_CDC
#endif // CFG_TUD_MSC
/* Limits of statically defined USB interfaces, endpoints, strings */
#if CFG_TUD_MSC
#define USBD_ITF_STATIC_MAX (USBD_ITF_MSC + 1)
#define USBD_STR_STATIC_MAX (USBD_STR_MSC + 1)
#define USBD_EP_STATIC_MAX (EPNUM_MSC_OUT + 1)
#elif CFG_TUD_CDC
#define USBD_ITF_STATIC_MAX (USBD_ITF_CDC + 2)
#define USBD_STR_STATIC_MAX (USBD_STR_CDC + 1)
#define USBD_EP_STATIC_MAX (((EPNUM_CDC_EP_IN)&~TUSB_DIR_IN_MASK) + 1)
#else // !CFG_TUD_MSC && !CFG_TUD_CDC
#define USBD_ITF_STATIC_MAX (0)
#define USBD_STR_STATIC_MAX (0)
#define USBD_EP_STATIC_MAX (0)
#endif
#endif // MICROPY_HW_ENABLE_USBDEV
#endif // MICROPY_INCLUDED_SHARED_TINYUSB_TUSB_CONFIG_H