aboutsummaryrefslogtreecommitdiff
path: root/usart/src/usart.c
diff options
context:
space:
mode:
Diffstat (limited to 'usart/src/usart.c')
-rw-r--r--usart/src/usart.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/usart/src/usart.c b/usart/src/usart.c
index 23dbd95..eddfbe7 100644
--- a/usart/src/usart.c
+++ b/usart/src/usart.c
@@ -40,16 +40,15 @@ void usart_set_parity(__IO usart_t* usart, usart_parity_t parity)
void usart_set_enabled(__IO usart_t* usart, usart_enable_t enabled)
{
uint32_t c_r1 = usart->c_r1;
- /* Clear relevant bits. */
- c_r1 &= ~USART_ENABLE_TX_RX;
- /* Set TX/RX enabled, but not actually USART enabled. */
- c_r1 |= (enabled & ~1);
-
- /* Set usart enabled bit separately. */
- c_r1 |= enabled & 1;
-
- usart->c_r1 = c_r1;
+ if (!enabled) {
+ usart->c1_bf.ue = 0;
+ } else {
+ /* Set the rx enabled. */
+ usart->c1_bf.re = !!(enabled & USART_ENABLE_RX);
+ usart->c1_bf.te = !!(enabled & USART_ENABLE_TX);
+ usart->c1_bf.ue = 1;
+ }
}
void usart_transmit_byte(__IO usart_t* usart, uint8_t byte)
@@ -62,3 +61,20 @@ void usart_transmit_byte(__IO usart_t* usart, uint8_t byte)
while (!(usart->is_r & BIT(7)))
;
}
+
+void usart_transmit_bytes(__IO usart_t* usart, const uint8_t* bytes, uint32_t n)
+{
+ while (n --) {
+ usart_transmit_byte(usart, *(bytes ++));
+ }
+}
+
+void usart_transmit_str(__IO usart_t* usart, const char* str)
+{
+ while (*str) {
+ if (*str == '\n') {
+ usart_transmit_byte(usart, '\r');
+ }
+ usart_transmit_byte(usart, *(str ++));
+ }
+}