diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-08-07 16:54:36 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-08-07 16:54:36 +0200 |
commit | 09e89c867c8dc14adee298176a0a4c72d8f32245 (patch) | |
tree | 8d125de0b4a1c9d608ddae6ff927fc3624663bd0 /hal/usart.h | |
parent | 2fc77d271db27ecb140191c2dfafdba835962ffb (diff) |
Split out reusable parts into the laks project.
Diffstat (limited to 'hal/usart.h')
-rw-r--r-- | hal/usart.h | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/hal/usart.h b/hal/usart.h deleted file mode 100644 index 24618fd..0000000 --- a/hal/usart.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef USART_H -#define USART_H - -#include "rcc.h" -#include "stm32.h" -#include "interrupt.h" -#include "thread.h" - -struct USART_reg_t { - volatile uint32_t SR; - volatile uint32_t DR; - volatile uint32_t BRR; - volatile uint32_t CR1; - volatile uint32_t CR2; - volatile uint32_t CR3; - volatile uint32_t GTPR; -}; - -class USART_t { - public: - USART_reg_t& reg; - const uint32_t clk; - - USART_t(uint32_t reg_addr, uint32_t bus_clk) : reg(*(USART_reg_t*)reg_addr), clk(bus_clk) {} - - inline void set_baudrate(uint32_t baudrate) { - reg.BRR = clk / baudrate; - } - - inline void enable() { - reg.CR1 = 0x202c; - } - - inline void send(uint8_t data) { - while(!(reg.SR & 0x80)) { - Thread::yield(); - } // Wait for TXE. - - reg.DR = data; - } - - inline uint8_t recv() { - return reg.DR; - } -}; - -#if defined(STM32F1) -static USART_t USART1(0x40013800, 72000000); -static USART_t USART2(0x40004400, 36000000); -static USART_t USART3(0x40004800, 36000000); -#elif defined(STM32F4) -static USART_t USART1(0x40011000, 84000000); -static USART_t USART2(0x40004400, 42000000); -static USART_t USART3(0x40004800, 42000000); -#endif - -inline void usart_enable() { - RCC.enable(RCC.USART1); - USART1.set_baudrate(115200); - USART1.enable(); - - //Interrupt::enable(Interrupt::USART1); -} - -inline void usart_send(uint8_t data) { - USART1.send(data); -} - -#endif |