summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2021-02-15 20:06:18 -0500
committerDan Halbert <halbert@halwitz.org>2021-02-15 20:06:18 -0500
commit0b8f1b9a9039ab2ad4d43cc1d9bc388518ab0d38 (patch)
treeadabc14dbcae2f63e37b913f0d2b9bb83a7efbfe /shared-module
parent93d788543c2f1f688a9e74d9984f63948e76a598 (diff)
wip: usb_cdc.serials
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/usb_cdc/Serial.h2
-rw-r--r--shared-module/usb_cdc/__init__.c42
-rw-r--r--shared-module/usb_cdc/__init__.h4
3 files changed, 26 insertions, 22 deletions
diff --git a/shared-module/usb_cdc/Serial.h b/shared-module/usb_cdc/Serial.h
index 7e3c53e8a..60a1d1922 100644
--- a/shared-module/usb_cdc/Serial.h
+++ b/shared-module/usb_cdc/Serial.h
@@ -3,7 +3,7 @@
*
* 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
* of this software and associated documentation files (the "Software"), to deal
diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c
index ae2412cdd..ecb5777b2 100644
--- a/shared-module/usb_cdc/__init__.c
+++ b/shared-module/usb_cdc/__init__.c
@@ -3,7 +3,7 @@
*
* 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
* of this software and associated documentation files (the "Software"), to deal
@@ -24,32 +24,34 @@
* THE SOFTWARE.
*/
-#include "shared-bindings/usb_cdc/__init__.h"
-
#include "genhdr/autogen_usb_descriptor.h"
+#include "py/gc.h"
#include "py/obj.h"
#include "py/mphal.h"
#include "py/runtime.h"
#include "py/objtuple.h"
+#include "shared-bindings/usb_cdc/__init__.h"
#include "shared-bindings/usb_cdc/Serial.h"
#include "tusb.h"
-supervisor_allocation* usb_cdc_allocation;
-
-static usb_cdc_serial_obj_t serial_objs[CFG_TUD_CDC];
+#if CFG_TUD_CDC != 2
+#error CFG_TUD_CDC must be exactly 2
+#endif
-void usb_cdc_init(void) {
-
- serial_obj_ptrs *usb_cdc_serial_obj_t[CFG_TUD_CDC];
-
- 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];
+static const usb_cdc_serial_obj_t serial_objs[CFG_TUD_CDC] = {
+ { .base.type = &usb_cdc_serial_type,
+ .idx = 0,
+ }, {
+ .base.type = &usb_cdc_serial_type,
+ .idx = 1,
}
-
- serials_tuple->base.type = mp_obj_new_tuple(CFG_TUD_CDC, serials);
-
- repl->base.type =
- 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);
-}
+};
+
+const mp_rom_obj_tuple_t usb_cdc_serials_tuple = {
+ .base.type = &mp_type_tuple,
+ .len = CFG_TUD_CDC,
+ .items = {
+ &serial_objs[0],
+ &serial_objs[1],
+ },
+};
diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h
index 02b48e116..9de3eb2fa 100644
--- a/shared-module/usb_cdc/__init__.h
+++ b/shared-module/usb_cdc/__init__.h
@@ -27,6 +27,8 @@
#ifndef 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 */