diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2020-11-12 09:45:16 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2020-11-12 09:45:16 -0500 |
commit | 0fde1b98eee06eda8333ae4099a6731a05a14482 (patch) | |
tree | 263826f916da816b0d7f8bf92b16f34fcc4aeaf6 /source/usbserial.cpp | |
parent | 1ade2969fb22c6bab4152f5e157f09e3675e8da1 (diff) |
firmware reorganize; added more sample rates
Diffstat (limited to 'source/usbserial.cpp')
-rw-r--r-- | source/usbserial.cpp | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/source/usbserial.cpp b/source/usbserial.cpp index ec2fc5d..c24be2f 100644 --- a/source/usbserial.cpp +++ b/source/usbserial.cpp @@ -11,42 +11,42 @@ #include "usbserial.hpp" -#include "usbcfg.h" +SerialUSBDriver *USBSerial::m_driver = &SDU1; -constexpr static const auto sdud = &SDU1; +void USBSerial::begin() +{ + palSetPadMode(GPIOA, 11, PAL_MODE_ALTERNATE(10)); + palSetPadMode(GPIOA, 12, PAL_MODE_ALTERNATE(10)); + + sduObjectInit(m_driver); + sduStart(m_driver, &serusbcfg); + + // Reconnect bus so device can re-enumerate on reset + usbDisconnectBus(serusbcfg.usbp); + chThdSleepMilliseconds(1500); + usbStart(serusbcfg.usbp, &usbcfg); + usbConnectBus(serusbcfg.usbp); +} -namespace usbserial +bool USBSerial::isActive() { - 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); + if (auto config = m_driver->config; config != nullptr) { + if (auto usbp = config->usbp; usbp != nullptr) + return usbp->state == USB_ACTIVE; } + + return false; +} + +size_t USBSerial::read(unsigned char *buffer, size_t count) +{ + auto bss = reinterpret_cast<BaseSequentialStream *>(m_driver); + return streamRead(bss, buffer, count); +} + +size_t USBSerial::write(const unsigned char *buffer, size_t count) +{ + auto bss = reinterpret_cast<BaseSequentialStream *>(m_driver); + return streamWrite(bss, buffer, count); } |