Skip to content

Commit 6cb751a

Browse files
committed
wip: revamp API names
1 parent 4a7e129 commit 6cb751a

10 files changed

Lines changed: 80 additions & 78 deletions

File tree

shared-bindings/storage/__init__.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,30 +158,33 @@ mp_obj_t storage_erase_filesystem(void) {
158158
}
159159
MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem);
160160

161-
//| def enable_usb(enabled: True) -> None:
162-
//| """Enable or disable presenting ``CIRCUITPY`` as a USB mass storage device.
163-
//| By default, ``CIRCUITPY`` is visible.
164-
//| Use ``storage.enable_usb(False)`` to hide CIRCUITPY from the host computer.
165-
//| Can be changed in ``boot.py``, before USB is connected."""
161+
//| def configure_usb(enabled: True) -> None:
162+
//| """Configure the USB mass storage device.
163+
//| Enable or disable presenting ``CIRCUITPY`` as a USB mass storage device.
164+
//| By default, the device is enabled and ``CIRCUITPY`` is visible.
165+
//| Can be called in ``boot.py``, before USB is connected.
166+
//|
167+
//| :param enabled bool: Enable or disable the USB mass storage device.
168+
//| True to enable; False to disable. Enabled by default."""
166169
//| ...
167170
//|
168-
STATIC mp_obj_t storage_enable_usb(mp_obj_t enabled) {
169-
if (!common_hal_storage_enable_usb(mp_obj_is_true(enabled))) {
171+
STATIC mp_obj_t storage_configure_usb(mp_obj_t enabled) {
172+
if (!common_hal_storage_configure_usb(mp_obj_is_true(enabled))) {
170173
mp_raise_RuntimeError(translate("Cannot change usb devices now"));
171174
}
172175
return mp_const_none;
173176
}
174-
MP_DEFINE_CONST_FUN_OBJ_1(storage_enable_usb_obj, storage_enable_usb);
177+
MP_DEFINE_CONST_FUN_OBJ_1(storage_configure_usb_obj, storage_configure_usb);
175178

176179
STATIC const mp_rom_map_elem_t storage_module_globals_table[] = {
177180
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_storage) },
178181

179-
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&storage_mount_obj) },
180-
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) },
181-
{ MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) },
182-
{ MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) },
182+
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&storage_mount_obj) },
183+
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) },
184+
{ MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) },
185+
{ MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) },
183186
{ MP_ROM_QSTR(MP_QSTR_erase_filesystem), MP_ROM_PTR(&storage_erase_filesystem_obj) },
184-
{ MP_ROM_QSTR(MP_QSTR_enable_usb), MP_ROM_PTR(&storage_enable_usb_obj) },
187+
{ MP_ROM_QSTR(MP_QSTR_configure_usb), MP_ROM_PTR(&storage_configure_usb_obj) },
185188

186189
//| class VfsFat:
187190
//| def __init__(self, block_device: str) -> None:

shared-bindings/storage/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ void common_hal_storage_umount_object(mp_obj_t vfs_obj);
3636
void common_hal_storage_remount(const char *path, bool readonly, bool disable_concurrent_write_protection);
3737
mp_obj_t common_hal_storage_getmount(const char *path);
3838
void common_hal_storage_erase_filesystem(void);
39-
bool common_hal_storage_enable_usb(bool enabled);
39+
bool common_hal_storage_configure_usb(bool enabled);
4040

4141
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_STORAGE___INIT___H

shared-bindings/usb_cdc/__init__.c

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,46 +60,33 @@
6060
//| the host.
6161
//| Note that `data` is *disabled* by default."""
6262

63-
64-
65-
66-
//| def enable_repl(enabled:bool) -> None:
67-
//| """Enable or disable the `repl` USB serial connection. The REPL
68-
//| is enabled by default.
69-
//| Can be changed in ``boot.py``, before USB is connected."""
70-
//| ...
63+
//| def configure_usb(repl_enabled: bool, data_enabled: bool) -> None:
64+
//| """Configure the USB CDC devices. Can be called in ``boot.py``, before USB is connected.
7165
//|
72-
STATIC mp_obj_t usb_cdc_enable_repl(mp_obj_t enabled) {
73-
if (!common_hal_usb_cdc_enable_repl(mp_obj_is_true(enabled))) {
74-
mp_raise_RuntimeError(translate("Cannot change USB devices now"));
75-
}
76-
return mp_const_none;
77-
}
78-
MP_DEFINE_CONST_FUN_OBJ_1(usb_cdc_enable_repl_obj, usb_cdc_enable_repl);
79-
80-
//| def enable_data(enabled: bool) -> None:
81-
//| """Enable or disable the `data` USB serial connection;n
82-
//| *disabled* by default.
83-
//| Can be changed in ``boot.py``, before USB is connected."""
66+
//| :param repl_enabled bool: Enable or disable the `repl` USB serial device.
67+
//| True to enable; False to disable. Enabled by default.
68+
//| :param data_enabled bool: Enable or disable the `data` USB serial device.
69+
//| True to enable; False to disable. *Disabled* by default."""
8470
//| ...
8571
//|
86-
STATIC mp_obj_t usb_cdc_enable_data(mp_obj_t enabled) {
87-
if (!common_hal_usb_cdc_enable_data(mp_obj_is_true(enabled))) {
72+
STATIC mp_obj_t usb_cdc_configure_usb(mp_obj_t repl_enabled, mp_obj_t data_enabled) {
73+
if (!common_hal_usb_cdc_configure_usb(
74+
mp_obj_is_true(repl_enabled),
75+
mp_obj_is_true(data_enabled))) {
8876
mp_raise_RuntimeError(translate("Cannot change USB devices now"));
8977
}
9078
return mp_const_none;
9179
}
92-
MP_DEFINE_CONST_FUN_OBJ_1(usb_cdc_enable_data_obj, usb_cdc_enable_data);
80+
MP_DEFINE_CONST_FUN_OBJ_2(usb_cdc_configure_usb_obj, usb_cdc_configure_usb);
9381

9482
// The usb_cdc module dict is mutable so that .repl and .data may
9583
// be set to a Serial or to None depending on whether they are enabled or not.
9684
static mp_map_elem_t usb_cdc_module_globals_table[] = {
97-
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) },
98-
{ MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) },
99-
{ MP_ROM_QSTR(MP_QSTR_repl), mp_const_none },
100-
{ MP_ROM_QSTR(MP_QSTR_data), mp_const_none },
101-
{ MP_ROM_QSTR(MP_QSTR_enable_repl), MP_OBJ_FROM_PTR(&usb_cdc_enable_repl_obj) },
102-
{ MP_ROM_QSTR(MP_QSTR_enable_data), MP_OBJ_FROM_PTR(&usb_cdc_enable_data_obj) },
85+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) },
86+
{ MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) },
87+
{ MP_ROM_QSTR(MP_QSTR_repl), mp_const_none },
88+
{ MP_ROM_QSTR(MP_QSTR_data), mp_const_none },
89+
{ MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_cdc_configure_usb_obj) },
10390
};
10491

10592
static MP_DEFINE_MUTABLE_DICT(usb_cdc_module_globals, usb_cdc_module_globals_table);
@@ -108,3 +95,18 @@ const mp_obj_module_t usb_cdc_module = {
10895
.base = { &mp_type_module },
10996
.globals = (mp_obj_dict_t *)&usb_cdc_module_globals,
11097
};
98+
99+
static void set_module_dict_entry(mp_obj_t key_qstr, mp_obj_t serial_obj) {
100+
mp_map_elem_t *elem = mp_map_lookup(&usb_cdc_module_globals.map, key_qstr, MP_MAP_LOOKUP);
101+
if (elem) {
102+
elem->value = serial_obj;
103+
}
104+
}
105+
106+
void usb_cdc_set_repl(mp_obj_t serial_obj) {
107+
set_module_dict_entry(MP_ROM_QSTR(MP_QSTR_repl), serial_obj);
108+
}
109+
110+
void usb_cdc_set_data(mp_obj_t serial_obj) {
111+
set_module_dict_entry(MP_ROM_QSTR(MP_QSTR_data), serial_obj);
112+
}

shared-bindings/usb_cdc/__init__.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929

3030
#include "shared-module/usb_cdc/__init__.h"
3131

32-
bool common_hal_usb_cdc_enable_repl(bool enabled);
33-
bool common_hal_usb_cdc_enable_data(bool enabled);
32+
// Set the module dict entries.
33+
void usb_cdc_set_repl(mp_obj_t serial_obj);
34+
void usb_cdc_set_data(mp_obj_t serial_obj);
35+
36+
extern bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled);
3437

3538
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H

shared-bindings/usb_midi/__init__.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,28 @@
4343
//| """Tuple of all MIDI ports. Each item is ether `PortIn` or `PortOut`."""
4444
//|
4545

46-
//| def enable(enabled: bool) -> None:
47-
//| """Enable or disable USB MIDI device. By default, MIDI is enabled.
48-
//| Can be changed in ``boot.py``, before USB is connected."""
46+
//| def configure_usb(enabled: True) -> None:
47+
//| """Configure the USB MIDI device.
48+
//| Can be called in ``boot.py``, before USB is connected.
49+
//|
50+
//| :param enabled bool: Enable or disable the USB MIDI Device.
51+
//| True to enable; False to disable. Enabled by default."""
4952
//| ...
5053
//|
51-
STATIC mp_obj_t usb_midi_enable(mp_obj_t enabled) {
52-
if (!common_hal_usb_midi_enable(mp_obj_is_true(enabled))) {
54+
STATIC mp_obj_t usb_midi_configure_usb(mp_obj_t enabled) {
55+
if (!common_hal_usb_midi_configure_usb(mp_obj_is_true(enabled))) {
5356
mp_raise_RuntimeError(translate("Cannot change USB devices now"));
5457
}
5558
return mp_const_none;
5659
}
57-
MP_DEFINE_CONST_FUN_OBJ_1(usb_midi_enable_obj, usb_midi_enable);
60+
MP_DEFINE_CONST_FUN_OBJ_1(usb_midi_configure_usb_obj, usb_midi_configure_usb);
5861

5962
mp_map_elem_t usb_midi_module_globals_table[] = {
60-
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_midi) },
61-
{ MP_ROM_QSTR(MP_QSTR_enable), MP_OBJ_FROM_PTR(&usb_midi_enable_obj) },
62-
{ MP_ROM_QSTR(MP_QSTR_ports), mp_const_empty_tuple },
63-
{ MP_ROM_QSTR(MP_QSTR_PortIn), MP_OBJ_FROM_PTR(&usb_midi_portin_type) },
64-
{ MP_ROM_QSTR(MP_QSTR_PortOut), MP_OBJ_FROM_PTR(&usb_midi_portout_type) },
63+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_midi) },
64+
{ MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_midi_configure_usb_obj) },
65+
{ MP_ROM_QSTR(MP_QSTR_ports), mp_const_empty_tuple },
66+
{ MP_ROM_QSTR(MP_QSTR_PortIn), MP_OBJ_FROM_PTR(&usb_midi_portin_type) },
67+
{ MP_ROM_QSTR(MP_QSTR_PortOut), MP_OBJ_FROM_PTR(&usb_midi_portout_type) },
6568
};
6669

6770
// This isn't const so we can set ports dynamically.

shared-bindings/usb_midi/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131

3232
extern mp_obj_dict_t usb_midi_module_globals;
3333

34-
bool common_hal_usb_midi_enable(bool enabled);
34+
bool common_hal_usb_midi_configure_usb(bool enabled);
3535

3636
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_MIDI___INIT___H

shared-module/storage/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ void common_hal_storage_erase_filesystem(void) {
175175
// We won't actually get here, since we're resetting.
176176
}
177177

178-
bool common_hal_storage_enable_usb(bool enabled) {
178+
bool common_hal_storage_configure_usb(bool enabled) {
179179
// We can't change the descriptors once we're connected.
180-
if (!tud_connected()) {
180+
if (tud_connected()) {
181181
return false;
182182
}
183183
usb_storage_enabled = enabled;

shared-module/usb_cdc/__init__.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,17 @@ void usb_cdc_init(void) {
6060
usb_cdc_data_enabled = false;
6161
}
6262

63-
bool common_hal_usb_cdc_enable_repl(bool enabled) {
63+
bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled) {
6464
// We can't change the descriptors once we're connected.
65-
if (!tud_connected()) {
66-
// TODO set entry in dict
65+
if (tud_connected()) {
6766
return false;
6867
}
69-
usb_cdc_repl_enabled = enabled;
70-
// TODO set entry in dict
71-
return true;
72-
}
7368

74-
bool common_hal_usb_cdc_enable_data(bool enabled) {
75-
// We can't change the descriptors once we're connected.
76-
if (!tud_connected()) {
77-
// TODO set entry in dict
78-
return false;
79-
}
80-
usb_cdc_data_enabled = enabled;
81-
// TODO set entry in dict
69+
usb_cdc_repl_enabled = repl_enabled;
70+
usb_cdc_set_repl(repl_enabled ? MP_OBJ_FROM_PTR(&usb_cdc_repl_obj) : mp_const_none);
71+
72+
usb_cdc_data_enabled = data_enabled;
73+
usb_cdc_set_data(data_enabled ? MP_OBJ_FROM_PTR(&usb_cdc_data_obj) : mp_const_none);
74+
8275
return true;
8376
}

shared-module/usb_cdc/__init__.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
#include "py/objtuple.h"
3131

32-
extern const mp_rom_obj_tuple_t usb_cdc_serials_tuple;
33-
3432
void usb_cdc_init(void);
3533

3634
#endif /* SHARED_MODULE_USB_CDC___INIT___H */

shared-module/usb_midi/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ void usb_midi_usb_init(void) {
7575
mp_map_lookup(&usb_midi_module_globals.map, MP_ROM_QSTR(MP_QSTR_ports), MP_MAP_LOOKUP)->value = MP_OBJ_FROM_PTR(ports);
7676
}
7777

78-
bool common_hal_usb_midi_enable(bool enabled) {
78+
bool common_hal_usb_midi_configure_usb(bool enabled) {
7979
// We can't change the descriptors once we're connected.
80-
if (!tud_connected()) {
80+
if (tud_connected()) {
8181
return false;
8282
}
8383
usb_midi_enabled = enabled;

0 commit comments

Comments
 (0)