Skip to content

Commit 0b8f1b9

Browse files
committed
wip: usb_cdc.serials
1 parent 93d7885 commit 0b8f1b9

File tree

9 files changed

+51
-45
lines changed

9 files changed

+51
-45
lines changed

main.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@
6969
#include "shared-bindings/alarm/__init__.h"
7070
#endif
7171

72+
#if CIRCUITPY_BLEIO
73+
#include "shared-bindings/_bleio/__init__.h"
74+
#include "supervisor/shared/bluetooth.h"
75+
#endif
76+
77+
#if CIRCUITPY_BOARD
78+
#include "shared-module/board/__init__.h"
79+
#endif
80+
81+
#if CIRCUITPY_CANIO
82+
#include "common-hal/canio/CAN.h"
83+
#endif
84+
7285
#if CIRCUITPY_DISPLAYIO
7386
#include "shared-module/displayio/__init__.h"
7487
#endif
@@ -81,17 +94,8 @@
8194
#include "shared-module/network/__init__.h"
8295
#endif
8396

84-
#if CIRCUITPY_BOARD
85-
#include "shared-module/board/__init__.h"
86-
#endif
87-
88-
#if CIRCUITPY_BLEIO
89-
#include "shared-bindings/_bleio/__init__.h"
90-
#include "supervisor/shared/bluetooth.h"
91-
#endif
92-
93-
#if CIRCUITPY_CANIO
94-
#include "common-hal/canio/CAN.h"
97+
#if CIRCUITPY_USB_CDC
98+
#include "shared-module/usb_cdc/__init__.h"
9599
#endif
96100

97101
#if CIRCUITPY_WIFI

ports/atmel-samd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ CFLAGS += -ftree-vrp
122122
$(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY))
123123
#Debugging/Optimization
124124
ifeq ($(DEBUG), 1)
125-
CFLAGS += -ggdb3 -Og
125+
CFLAGS += -ggdb3 -Og -Os
126126
# You may want to disable -flto if it interferes with debugging.
127127
CFLAGS += -flto -flto-partition=none
128128
# You may want to enable these flags to make setting breakpoints easier.

ports/raspberrypi/common-hal/pwmio/PWMOut.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) {
165165
extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty) {
166166
self->duty_cycle = duty;
167167
uint16_t actual_duty = duty * self->top / ((1 << 16) - 1);
168-
mp_printf(&mp_plat_print, "actual_duty: %d, self->top: %d\n", actual_duty, top); /// ***
169168
pwm_set_chan_level(self->slice, self->channel, actual_duty);
170169
}
171170

@@ -209,7 +208,6 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, uint32_t fr
209208
} else {
210209
uint32_t top = common_hal_mcu_processor_get_frequency() / frequency;
211210
self->actual_frequency = common_hal_mcu_processor_get_frequency() / top;
212-
mp_printf(&mp_plat_print, "high speed self->top: %d\n", top); /// ***
213211
self->top = top;
214212
pwm_set_clkdiv_int_frac(self->slice, 1, 0);
215213
pwm_set_wrap(self->slice, self->top - 1);

shared-bindings/usb_cdc/__init__.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,17 @@
3838
//|
3939
//| The `usb_cdc` module allows access to USB CDC (serial) communications.
4040
//|
41-
//| serial: Tuple[Serial, ...]
41+
//| serials: Tuple[Serial, ...]
4242
//| """Tuple of all CDC streams. Each item is a `Serial`."""
4343
//|
4444

45-
mp_map_elem_t usb_cdc_module_globals_table[] = {
45+
static const mp_map_elem_t usb_cdc_module_globals_table[] = {
4646
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) },
4747
{ MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) },
48-
{ MP_ROM_QSTR(MP_QSTR_serial), mp_const_empty_tuple },
48+
{ MP_ROM_QSTR(MP_QSTR_serials), MP_OBJ_FROM_PTR(&usb_cdc_serials_tuple) },
4949
};
5050

51-
// This isn't const so we can set the streams dynamically.
52-
MP_DEFINE_MUTABLE_DICT(usb_cdc_module_globals, usb_cdc_module_globals_table);
51+
static MP_DEFINE_CONST_DICT(usb_cdc_module_globals, usb_cdc_module_globals_table);
5352

5453
const mp_obj_module_t usb_cdc_module = {
5554
.base = { &mp_type_module },

shared-bindings/usb_cdc/__init__.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H
2828
#define MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H
2929

30-
#include "py/obj.h"
31-
32-
extern mp_obj_dict_t usb_cdc_module_globals;
30+
#include "shared-module/usb_cdc/__init__.h"
3331

3432
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H

shared-module/usb_cdc/Serial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
6+
* Copyright (c) 2021 Dan Halbert for Adafruit Industries
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal

shared-module/usb_cdc/__init__.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* The MIT License (MIT)
55
*
6-
* Copyright (c) 2018 hathach for Adafruit Industries
6+
* Copyright (c) 2021 Dan Halbert for Adafruit Industries
77
*
88
* Permission is hereby granted, free of charge, to any person obtaining a copy
99
* of this software and associated documentation files (the "Software"), to deal
@@ -24,32 +24,34 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#include "shared-bindings/usb_cdc/__init__.h"
28-
2927
#include "genhdr/autogen_usb_descriptor.h"
28+
#include "py/gc.h"
3029
#include "py/obj.h"
3130
#include "py/mphal.h"
3231
#include "py/runtime.h"
3332
#include "py/objtuple.h"
33+
#include "shared-bindings/usb_cdc/__init__.h"
3434
#include "shared-bindings/usb_cdc/Serial.h"
3535
#include "tusb.h"
3636

37-
supervisor_allocation* usb_cdc_allocation;
38-
39-
static usb_cdc_serial_obj_t serial_objs[CFG_TUD_CDC];
37+
#if CFG_TUD_CDC != 2
38+
#error CFG_TUD_CDC must be exactly 2
39+
#endif
4040

41-
void usb_cdc_init(void) {
42-
43-
serial_obj_ptrs *usb_cdc_serial_obj_t[CFG_TUD_CDC];
44-
45-
for (size_t i = 0; i < CFG_TUD_CDC; i++) {
46-
serial_objs[i].base.type = &usb_cdc_serial_type;
47-
serial_objs[i].idx = i;
48-
serial_obj_ptrs[i] = &serial_objs[i];
41+
static const usb_cdc_serial_obj_t serial_objs[CFG_TUD_CDC] = {
42+
{ .base.type = &usb_cdc_serial_type,
43+
.idx = 0,
44+
}, {
45+
.base.type = &usb_cdc_serial_type,
46+
.idx = 1,
4947
}
50-
51-
serials_tuple->base.type = mp_obj_new_tuple(CFG_TUD_CDC, serials);
52-
53-
repl->base.type =
54-
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);
55-
}
48+
};
49+
50+
const mp_rom_obj_tuple_t usb_cdc_serials_tuple = {
51+
.base.type = &mp_type_tuple,
52+
.len = CFG_TUD_CDC,
53+
.items = {
54+
&serial_objs[0],
55+
&serial_objs[1],
56+
},
57+
};

shared-module/usb_cdc/__init__.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#ifndef SHARED_MODULE_USB_CDC___INIT___H
2828
#define SHARED_MODULE_USB_CDC___INIT___H
2929

30-
void usb_cdc_init(void);
30+
#include "py/objtuple.h"
31+
32+
extern const mp_rom_obj_tuple_t usb_cdc_serials_tuple;
3133

3234
#endif /* SHARED_MODULE_USB_CDC___INIT___H */

supervisor/shared/usb/usb.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include "py/objstr.h"
2828
#include "shared-bindings/microcontroller/Processor.h"
29-
#include "shared-module/usb_midi/__init__.h"
3029
#include "supervisor/background_callback.h"
3130
#include "supervisor/port.h"
3231
#include "supervisor/serial.h"
@@ -35,6 +34,10 @@
3534
#include "lib/utils/interrupt_char.h"
3635
#include "lib/mp-readline/readline.h"
3736

37+
#if CIRCUITPY_USB_MIDI
38+
#include "shared-module/usb_midi/__init__.h"
39+
#endif
40+
3841
#include "tusb.h"
3942

4043
#if CIRCUITPY_USB_VENDOR

0 commit comments

Comments
 (0)