diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2020-06-11 10:15:31 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2020-06-11 10:15:31 -0400 |
commit | 7f0a54a8ee175106254982dc12c184d7c25849b4 (patch) | |
tree | 4415a7f58bdb2d17266c9bfa267f5f903e5177a6 /source/usbserial.cpp | |
parent | 14eb7970debdafdd7e8486eced64d4b718a821a7 (diff) |
made classes for drivers
Diffstat (limited to 'source/usbserial.cpp')
-rw-r--r-- | source/usbserial.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/source/usbserial.cpp b/source/usbserial.cpp new file mode 100644 index 0000000..cead28a --- /dev/null +++ b/source/usbserial.cpp @@ -0,0 +1,41 @@ +#include "usbserial.hpp" + +#include "hal.h" + +void USBSeriald::start() +{ + initPins(); + + 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); +} + +bool USBSeriald::active() const +{ + return m_driver->config->usbp->state == USB_ACTIVE; +} + +std::size_t USBSeriald::read(void *buffer, std::size_t count) +{ + auto *bss = reinterpret_cast<BaseSequentialStream *>(m_driver); + return streamRead(bss, static_cast<uint8_t *>(buffer), count); +} + +std::size_t USBSeriald::write(const void *buffer, std::size_t count) +{ + auto *bss = reinterpret_cast<BaseSequentialStream *>(m_driver); + return streamWrite(bss, static_cast<const uint8_t *>(buffer), count); +} + +void USBSeriald::initPins() +{ + palSetPadMode(GPIOA, 11, PAL_MODE_ALTERNATE(10)); + palSetPadMode(GPIOA, 12, PAL_MODE_ALTERNATE(10)); +} + |