Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/thirdpin/libopencm3_cpp_extensions.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'cm3cpp/rs485.hpp')
-rw-r--r--cm3cpp/rs485.hpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/cm3cpp/rs485.hpp b/cm3cpp/rs485.hpp
index ea9865e..7e14fff 100644
--- a/cm3cpp/rs485.hpp
+++ b/cm3cpp/rs485.hpp
@@ -27,6 +27,8 @@ RS485 implementation, public interface
#define RS_485_H
#include <stdint.h>
+#include <cassert>
+#include <limits>
#include <libopencm3/stm32/usart.h>
#ifdef STM32F2
@@ -77,7 +79,10 @@ class RS485
void usart_enable_tc_interrupt() { USART_CR1(_rs485) |= USART_CR1_TCIE; }
- void usart_disable_tc_interrupt() { USART_CR1(_rs485) &= ~USART_CR1_TCIE; }
+ void usart_disable_tc_interrupt()
+ {
+ USART_CR1(_rs485) &= ~static_cast<uint32_t>(USART_CR1_TCIE);
+ }
bool interrupt_source_RXNE()
{
@@ -106,7 +111,12 @@ class RS485
void receive_handler()
{
if (interrupt_source_RXNE()) {
- rb_in->push(usart_recv(_rs485));
+ using byte_t = uint8_t;
+
+ const uint16_t byte16 = usart_recv(_rs485);
+ assert(byte16 < std::numeric_limits<byte_t>::max());
+
+ rb_in->push(static_cast<byte_t>(byte16));
}
}