diff options
author | Dmitriy Lisin <d.lisin@thirdpin.ru> | 2018-06-21 18:27:34 +0300 |
---|---|---|
committer | Dmitriy Lisin <d.lisin@thirdpin.ru> | 2018-06-21 18:27:34 +0300 |
commit | 79b94465f667544edf97ad85f529ecfc710fdbec (patch) | |
tree | 6a88e51586410e55a7bada2ed5da02e99384472f | |
parent | d5ada6fa5b2ababee1eaa1c2bcbb8f798de81689 (diff) |
IMPR: [uart] Better initialization
-rw-r--r-- | cm3cpp_usart.cpp | 14 | ||||
-rw-r--r-- | cm3cpp_usart.h | 2 |
2 files changed, 13 insertions, 3 deletions
diff --git a/cm3cpp_usart.cpp b/cm3cpp_usart.cpp index 80f14c2..01732f0 100644 --- a/cm3cpp_usart.cpp +++ b/cm3cpp_usart.cpp @@ -36,7 +36,9 @@ Usart::Usart(LowLevelConfig config, Settings settings) void Usart::init(LowLevelConfig config, Settings settings)
{
- if (config.rx.port)
+ _mode = settings.mode;
+
+ if (_mode == Mode::RX or _mode == Mode::RX_TX)
{
_rx.init(config.rx);
_rx.mode_setup(Gpio::Mode::ALTERNATE_FUNCTION, Gpio::PullMode::NO_PULL);
@@ -47,7 +49,7 @@ void Usart::init(LowLevelConfig config, Settings settings) _rx.set_af(Gpio::AltFuncNumber::AF8);
}
- if (config.tx.port)
+ if (_mode == Mode::TX or _mode == Mode::RX_TX)
{
_tx.init(config.tx);
_tx.mode_setup(Gpio::Mode::ALTERNATE_FUNCTION, Gpio::PullMode::NO_PULL);
@@ -97,11 +99,17 @@ void Usart::deinit() {
usart_disable(_usart);
nvic_disable_irq(_usart_nvic);
- _tx.mode_setup(Gpio::Mode::INPUT, Gpio::PullMode::NO_PULL);
+
+ if (_mode == Mode::RX or _mode == Mode::RX_TX)
+ _rx.mode_setup(Gpio::Mode::INPUT, Gpio::PullMode::NO_PULL);
+
+ if (_mode == Mode::TX or _mode == Mode::RX_TX)
+ _tx.mode_setup(Gpio::Mode::INPUT, Gpio::PullMode::NO_PULL);
}
void Usart::set_settings(Settings settings)
{
+ _mode = settings.mode;
usart_set_baudrate(_usart, settings.baud_rate);
usart_set_databits(_usart, settings.word_length);
usart_set_stopbits(_usart, settings.stop_bits);
diff --git a/cm3cpp_usart.h b/cm3cpp_usart.h index 6c59cf7..c61b846 100644 --- a/cm3cpp_usart.h +++ b/cm3cpp_usart.h @@ -194,6 +194,8 @@ protected: Gpio _tx;
uint32_t _usart;
uint32_t _usart_nvic;
+
+ Mode _mode;
};
} // namespace usart
|