wip: usb_cdc.serials
This commit is contained in:
parent
93d788543c
commit
0b8f1b9a90
26
main.c
26
main.c
|
@ -69,6 +69,19 @@
|
||||||
#include "shared-bindings/alarm/__init__.h"
|
#include "shared-bindings/alarm/__init__.h"
|
||||||
#endif
|
#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
|
#if CIRCUITPY_DISPLAYIO
|
||||||
#include "shared-module/displayio/__init__.h"
|
#include "shared-module/displayio/__init__.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,17 +94,8 @@
|
||||||
#include "shared-module/network/__init__.h"
|
#include "shared-module/network/__init__.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_BOARD
|
#if CIRCUITPY_USB_CDC
|
||||||
#include "shared-module/board/__init__.h"
|
#include "shared-module/usb_cdc/__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"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_WIFI
|
#if CIRCUITPY_WIFI
|
||||||
|
|
|
@ -122,7 +122,7 @@ CFLAGS += -ftree-vrp
|
||||||
$(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY))
|
$(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY))
|
||||||
#Debugging/Optimization
|
#Debugging/Optimization
|
||||||
ifeq ($(DEBUG), 1)
|
ifeq ($(DEBUG), 1)
|
||||||
CFLAGS += -ggdb3 -Og
|
CFLAGS += -ggdb3 -Og -Os
|
||||||
# You may want to disable -flto if it interferes with debugging.
|
# You may want to disable -flto if it interferes with debugging.
|
||||||
CFLAGS += -flto -flto-partition=none
|
CFLAGS += -flto -flto-partition=none
|
||||||
# You may want to enable these flags to make setting breakpoints easier.
|
# You may want to enable these flags to make setting breakpoints easier.
|
||||||
|
|
|
@ -165,7 +165,6 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) {
|
||||||
extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty) {
|
extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty) {
|
||||||
self->duty_cycle = duty;
|
self->duty_cycle = duty;
|
||||||
uint16_t actual_duty = duty * self->top / ((1 << 16) - 1);
|
uint16_t actual_duty = duty * self->top / ((1 << 16) - 1);
|
||||||
mp_printf(&mp_plat_print, "actual_duty: %d, self->top: %d\n", actual_duty, top); /// ***
|
|
||||||
pwm_set_chan_level(self->slice, self->channel, actual_duty);
|
pwm_set_chan_level(self->slice, self->channel, actual_duty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +208,6 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, uint32_t fr
|
||||||
} else {
|
} else {
|
||||||
uint32_t top = common_hal_mcu_processor_get_frequency() / frequency;
|
uint32_t top = common_hal_mcu_processor_get_frequency() / frequency;
|
||||||
self->actual_frequency = common_hal_mcu_processor_get_frequency() / top;
|
self->actual_frequency = common_hal_mcu_processor_get_frequency() / top;
|
||||||
mp_printf(&mp_plat_print, "high speed self->top: %d\n", top); /// ***
|
|
||||||
self->top = top;
|
self->top = top;
|
||||||
pwm_set_clkdiv_int_frac(self->slice, 1, 0);
|
pwm_set_clkdiv_int_frac(self->slice, 1, 0);
|
||||||
pwm_set_wrap(self->slice, self->top - 1);
|
pwm_set_wrap(self->slice, self->top - 1);
|
||||||
|
|
|
@ -38,18 +38,17 @@
|
||||||
//|
|
//|
|
||||||
//| The `usb_cdc` module allows access to USB CDC (serial) communications.
|
//| The `usb_cdc` module allows access to USB CDC (serial) communications.
|
||||||
//|
|
//|
|
||||||
//| serial: Tuple[Serial, ...]
|
//| serials: Tuple[Serial, ...]
|
||||||
//| """Tuple of all CDC streams. Each item is a `Serial`."""
|
//| """Tuple of all CDC streams. Each item is a `Serial`."""
|
||||||
//|
|
//|
|
||||||
|
|
||||||
mp_map_elem_t usb_cdc_module_globals_table[] = {
|
static const mp_map_elem_t usb_cdc_module_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) },
|
{ MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_serial), mp_const_empty_tuple },
|
{ MP_ROM_QSTR(MP_QSTR_serials), MP_OBJ_FROM_PTR(&usb_cdc_serials_tuple) },
|
||||||
};
|
};
|
||||||
|
|
||||||
// This isn't const so we can set the streams dynamically.
|
static MP_DEFINE_CONST_DICT(usb_cdc_module_globals, usb_cdc_module_globals_table);
|
||||||
MP_DEFINE_MUTABLE_DICT(usb_cdc_module_globals, usb_cdc_module_globals_table);
|
|
||||||
|
|
||||||
const mp_obj_module_t usb_cdc_module = {
|
const mp_obj_module_t usb_cdc_module = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H
|
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H
|
||||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H
|
#define MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H
|
||||||
|
|
||||||
#include "py/obj.h"
|
#include "shared-module/usb_cdc/__init__.h"
|
||||||
|
|
||||||
extern mp_obj_dict_t usb_cdc_module_globals;
|
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H
|
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
|
* Copyright (c) 2021 Dan Halbert for Adafruit Industries
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
*
|
*
|
||||||
* Copyright (c) 2018 hathach for Adafruit Industries
|
* Copyright (c) 2021 Dan Halbert for Adafruit Industries
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -24,32 +24,34 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "shared-bindings/usb_cdc/__init__.h"
|
|
||||||
|
|
||||||
#include "genhdr/autogen_usb_descriptor.h"
|
#include "genhdr/autogen_usb_descriptor.h"
|
||||||
|
#include "py/gc.h"
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/objtuple.h"
|
#include "py/objtuple.h"
|
||||||
|
#include "shared-bindings/usb_cdc/__init__.h"
|
||||||
#include "shared-bindings/usb_cdc/Serial.h"
|
#include "shared-bindings/usb_cdc/Serial.h"
|
||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
|
|
||||||
supervisor_allocation* usb_cdc_allocation;
|
#if CFG_TUD_CDC != 2
|
||||||
|
#error CFG_TUD_CDC must be exactly 2
|
||||||
|
#endif
|
||||||
|
|
||||||
static usb_cdc_serial_obj_t serial_objs[CFG_TUD_CDC];
|
static const usb_cdc_serial_obj_t serial_objs[CFG_TUD_CDC] = {
|
||||||
|
{ .base.type = &usb_cdc_serial_type,
|
||||||
void usb_cdc_init(void) {
|
.idx = 0,
|
||||||
|
}, {
|
||||||
serial_obj_ptrs *usb_cdc_serial_obj_t[CFG_TUD_CDC];
|
.base.type = &usb_cdc_serial_type,
|
||||||
|
.idx = 1,
|
||||||
for (size_t i = 0; i < CFG_TUD_CDC; i++) {
|
|
||||||
serial_objs[i].base.type = &usb_cdc_serial_type;
|
|
||||||
serial_objs[i].idx = i;
|
|
||||||
serial_obj_ptrs[i] = &serial_objs[i];
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
serials_tuple->base.type = mp_obj_new_tuple(CFG_TUD_CDC, serials);
|
const mp_rom_obj_tuple_t usb_cdc_serials_tuple = {
|
||||||
|
.base.type = &mp_type_tuple,
|
||||||
repl->base.type =
|
.len = CFG_TUD_CDC,
|
||||||
repl->idx = 0; mp_map_lookup(&usb_cdc_module_globals.map, MP_ROM_QSTR(MP_QSTR_serial), MP_MAP_LOOKUP)->value = MP_OBJ_FROM_PTR(serials_tuple);
|
.items = {
|
||||||
}
|
&serial_objs[0],
|
||||||
|
&serial_objs[1],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#ifndef SHARED_MODULE_USB_CDC___INIT___H
|
#ifndef SHARED_MODULE_USB_CDC___INIT___H
|
||||||
#define SHARED_MODULE_USB_CDC___INIT___H
|
#define SHARED_MODULE_USB_CDC___INIT___H
|
||||||
|
|
||||||
void usb_cdc_init(void);
|
#include "py/objtuple.h"
|
||||||
|
|
||||||
|
extern const mp_rom_obj_tuple_t usb_cdc_serials_tuple;
|
||||||
|
|
||||||
#endif /* SHARED_MODULE_USB_CDC___INIT___H */
|
#endif /* SHARED_MODULE_USB_CDC___INIT___H */
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
#include "py/objstr.h"
|
#include "py/objstr.h"
|
||||||
#include "shared-bindings/microcontroller/Processor.h"
|
#include "shared-bindings/microcontroller/Processor.h"
|
||||||
#include "shared-module/usb_midi/__init__.h"
|
|
||||||
#include "supervisor/background_callback.h"
|
#include "supervisor/background_callback.h"
|
||||||
#include "supervisor/port.h"
|
#include "supervisor/port.h"
|
||||||
#include "supervisor/serial.h"
|
#include "supervisor/serial.h"
|
||||||
|
@ -35,6 +34,10 @@
|
||||||
#include "lib/utils/interrupt_char.h"
|
#include "lib/utils/interrupt_char.h"
|
||||||
#include "lib/mp-readline/readline.h"
|
#include "lib/mp-readline/readline.h"
|
||||||
|
|
||||||
|
#if CIRCUITPY_USB_MIDI
|
||||||
|
#include "shared-module/usb_midi/__init__.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
|
|
||||||
#if CIRCUITPY_USB_VENDOR
|
#if CIRCUITPY_USB_VENDOR
|
||||||
|
|
Loading…
Reference in New Issue