From d060dce4ec03dad8bcde265ff5b5eb68cd009ea2 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 15 Aug 2020 08:44:02 -0400 Subject: move drivers into namespaces --- source/usbserial.cpp | 61 +++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'source/usbserial.cpp') 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(sdud); - return streamRead(bss, static_cast(buffer), count); -} - -size_t usbserial_write(const void *buffer, size_t count) -{ - auto bss = reinterpret_cast(sdud); - return streamWrite(bss, static_cast(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(sdud); + return streamRead(bss, static_cast(buffer), count); + } + + size_t write(const void *buffer, size_t count) + { + auto bss = reinterpret_cast(sdud); + return streamWrite(bss, static_cast(buffer), count); + } } -- cgit v1.2.3