aboutsummaryrefslogtreecommitdiffstats
path: root/source/usbserial.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2020-08-15 08:44:02 -0400
committerClyne Sullivan <clyne@bitgloo.com>2020-08-15 08:44:02 -0400
commitd060dce4ec03dad8bcde265ff5b5eb68cd009ea2 (patch)
tree8370b81f6f9afc561840d83b3cd9b8e9accea275 /source/usbserial.cpp
parent7f59ca704b6f3c0ad254d391a123961aa0a86284 (diff)
move drivers into namespaces
Diffstat (limited to 'source/usbserial.cpp')
-rw-r--r--source/usbserial.cpp61
1 files changed, 32 insertions, 29 deletions
diff --git a/source/usbserial.cpp b/source/usbserial.cpp
index 5d605e6..ec2fc5d 100644
--- a/source/usbserial.cpp
+++ b/source/usbserial.cpp
@@ -15,35 +15,38 @@
constexpr static const auto sdud = &SDU1;
-void usbserial_init()
+namespace usbserial
{
- palSetPadMode(GPIOA, 11, PAL_MODE_ALTERNATE(10));
- palSetPadMode(GPIOA, 12, PAL_MODE_ALTERNATE(10));
-
- sduObjectInit(sdud);
- sduStart(sdud, &serusbcfg);
-
- // Reconnect bus so device can re-enumerate on reset
- usbDisconnectBus(serusbcfg.usbp);
- chThdSleepMilliseconds(1500);
- usbStart(serusbcfg.usbp, &usbcfg);
- usbConnectBus(serusbcfg.usbp);
-}
-
-bool usbserial_is_active()
-{
- return sdud->config->usbp->state == USB_ACTIVE;
-}
-
-size_t usbserial_read(void *buffer, size_t count)
-{
- auto bss = reinterpret_cast<BaseSequentialStream *>(sdud);
- return streamRead(bss, static_cast<uint8_t *>(buffer), count);
-}
-
-size_t usbserial_write(const void *buffer, size_t count)
-{
- auto bss = reinterpret_cast<BaseSequentialStream *>(sdud);
- return streamWrite(bss, static_cast<const uint8_t *>(buffer), count);
+ void init()
+ {
+ palSetPadMode(GPIOA, 11, PAL_MODE_ALTERNATE(10));
+ palSetPadMode(GPIOA, 12, PAL_MODE_ALTERNATE(10));
+
+ sduObjectInit(sdud);
+ sduStart(sdud, &serusbcfg);
+
+ // Reconnect bus so device can re-enumerate on reset
+ usbDisconnectBus(serusbcfg.usbp);
+ chThdSleepMilliseconds(1500);
+ usbStart(serusbcfg.usbp, &usbcfg);
+ usbConnectBus(serusbcfg.usbp);
+ }
+
+ bool is_active()
+ {
+ return sdud->config->usbp->state == USB_ACTIVE;
+ }
+
+ size_t read(void *buffer, size_t count)
+ {
+ auto bss = reinterpret_cast<BaseSequentialStream *>(sdud);
+ return streamRead(bss, static_cast<uint8_t *>(buffer), count);
+ }
+
+ size_t write(const void *buffer, size_t count)
+ {
+ auto bss = reinterpret_cast<BaseSequentialStream *>(sdud);
+ return streamWrite(bss, static_cast<const uint8_t *>(buffer), count);
+ }
}