diff --git a/.gitignore b/.gitignore index 8d2b1ff..cd9493a 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,7 @@ *.list *.eeprom *.pre + +# QtCreator user-specific +*.pro.user + diff --git a/avr-c-bp.pro b/avr-c-bp.pro new file mode 100644 index 0000000..750f61b --- /dev/null +++ b/avr-c-bp.pro @@ -0,0 +1,44 @@ +TEMPLATE = app +CONFIG += console +CONFIG -= app_bundle +CONFIG -= qt + +INCLUDEPATH += \ + lib \ + /usr/avr/include + +DEFINES += __AVR_ATmega328P__ F_CPU=16000000UL + +DISTFILES += \ + style.astylerc \ + Makefile + +HEADERS += \ + lib/calc.h \ + lib/iopins.h \ + lib/usart.h + +SOURCES += \ + lib/iopins.c \ + main.c + +# === Flags for the Clang code model=== +# +#-Weverything +#-Wno-c++98-compat +#-Wno-c++98-compat-pedantic +#-Wno-unused-macros +#-Wno-newline-eof +#-Wno-exit-time-destructors +#-Wno-global-constructors +#-Wno-gnu-zero-variadic-macro-arguments +#-Wno-documentation +#-Wno-missing-prototypes +#-std=gnu99 +#-Wno-gnu +#-Wno-format-nonliteral +#-Wno-conversion +#-Wno-pointer-sign +#-Wno-unknown-attributes +#-Wno-main-return-type +#-Wno-missing-noreturn diff --git a/lib/usart.c b/lib/usart.c index 189c66b..ace6eaa 100644 --- a/lib/usart.c +++ b/lib/usart.c @@ -24,6 +24,26 @@ void usart_init(uint16_t ubrr) } +/** Send byte over USART */ +void usart_tx(uint8_t data) +{ + // Wait for transmit buffer + while (!usart_tx_ready()); + // send it + UDR0 = data; +} + + +/** Receive one byte over USART */ +uint8_t usart_rx(void) +{ + // Wait for data to be received + while (!usart_rx_ready()); + // Get and return received data from buffer + return UDR0; +} + + /** Send string over USART */ void usart_puts(const char* str) { diff --git a/lib/usart.h b/lib/usart.h index 760a4eb..6807588 100644 --- a/lib/usart.h +++ b/lib/usart.h @@ -14,6 +14,8 @@ #include #include +#include "calc.h" + /* USART BAUD RATE REGISTER values at 16 MHz */ enum { @@ -40,55 +42,36 @@ void usart_init(uint16_t ubrr); #define usart_tx_ready() (0 != (UCSR0A & (1 << UDRE0))) - - // ---- Enable UART interrupts ------------ /** Enable or disable RX ISR */ -inline void usart_rx_isr_enable(bool yes) -{ - set_bit(UCSR0B, RXCIE0, yes); -} +#define usart_rx_isr_enable(yes) set_bit(UCSR0B, RXCIE0, (yes)) + /** Enable or disable TX ISR (1 byte is sent) */ -inline void usart_tx_isr_enable(bool yes) -{ - set_bit(UCSR0B, TXCIE0, yes); -} +#define usart_tx_isr_enable(yes) set_bit(UCSR0B, TXCIE0, (yes)) + /** Enable or disable DRE ISR (all is sent) */ -inline void usart_dre_isr_enable(bool yes) -{ - set_bit(UCSR0B, UDRIE0, yes); -} +#define usart_dre_isr_enable(yes) set_bit(UCSR0B, UDRIE0, (yes)) // ---- Basic IO -------------------------- /** Send byte over USART */ -inline void usart_tx(uint8_t data) -{ - // Wait for transmit buffer - while (!usart_tx_ready()); - // send it - UDR0 = data; -} +void usart_tx(uint8_t data); /** Receive one byte over USART */ -inline uint8_t usart_rx(void) -{ - // Wait for data to be received - while (!usart_rx_ready()); - // Get and return received data from buffer - return UDR0; -} +uint8_t usart_rx(void); + /** Send byte over UART */ #define usart_putc(data) usart_tx((data)) + /** Clear receive buffer */ -void usart_clear_rx(); +void usart_clear_rx(void); // ---- Strings --------------------------- @@ -96,5 +79,6 @@ void usart_clear_rx(); /** Send string over UART */ void usart_puts(const char* str); + /** Send progmem string over UART */ void usart_puts_P(const char* str);