Fixed some semantic bugs & added .pro file for QtCreator

pull/1/head
Ondřej Hruška 9 years ago
parent aafedd03a6
commit d8d02fffca
  1. 4
      .gitignore
  2. 44
      avr-c-bp.pro
  3. 20
      lib/usart.c
  4. 42
      lib/usart.h

4
.gitignore vendored

@ -39,3 +39,7 @@
*.list *.list
*.eeprom *.eeprom
*.pre *.pre
# QtCreator user-specific
*.pro.user

@ -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

@ -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 */ /** Send string over USART */
void usart_puts(const char* str) void usart_puts(const char* str)
{ {

@ -14,6 +14,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "calc.h"
/* USART BAUD RATE REGISTER values at 16 MHz */ /* USART BAUD RATE REGISTER values at 16 MHz */
enum { enum {
@ -40,55 +42,36 @@ void usart_init(uint16_t ubrr);
#define usart_tx_ready() (0 != (UCSR0A & (1 << UDRE0))) #define usart_tx_ready() (0 != (UCSR0A & (1 << UDRE0)))
// ---- Enable UART interrupts ------------ // ---- Enable UART interrupts ------------
/** Enable or disable RX ISR */ /** Enable or disable RX ISR */
inline void usart_rx_isr_enable(bool yes) #define usart_rx_isr_enable(yes) set_bit(UCSR0B, RXCIE0, (yes))
{
set_bit(UCSR0B, RXCIE0, yes);
}
/** Enable or disable TX ISR (1 byte is sent) */ /** Enable or disable TX ISR (1 byte is sent) */
inline void usart_tx_isr_enable(bool yes) #define usart_tx_isr_enable(yes) set_bit(UCSR0B, TXCIE0, (yes))
{
set_bit(UCSR0B, TXCIE0, yes);
}
/** Enable or disable DRE ISR (all is sent) */ /** Enable or disable DRE ISR (all is sent) */
inline void usart_dre_isr_enable(bool yes) #define usart_dre_isr_enable(yes) set_bit(UCSR0B, UDRIE0, (yes))
{
set_bit(UCSR0B, UDRIE0, yes);
}
// ---- Basic IO -------------------------- // ---- Basic IO --------------------------
/** Send byte over USART */ /** Send byte over USART */
inline void usart_tx(uint8_t data) void usart_tx(uint8_t data);
{
// Wait for transmit buffer
while (!usart_tx_ready());
// send it
UDR0 = data;
}
/** Receive one byte over USART */ /** Receive one byte over USART */
inline uint8_t usart_rx(void) 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 byte over UART */ /** Send byte over UART */
#define usart_putc(data) usart_tx((data)) #define usart_putc(data) usart_tx((data))
/** Clear receive buffer */ /** Clear receive buffer */
void usart_clear_rx(); void usart_clear_rx(void);
// ---- Strings --------------------------- // ---- Strings ---------------------------
@ -96,5 +79,6 @@ void usart_clear_rx();
/** Send string over UART */ /** Send string over UART */
void usart_puts(const char* str); void usart_puts(const char* str);
/** Send progmem string over UART */ /** Send progmem string over UART */
void usart_puts_P(const char* str); void usart_puts_P(const char* str);

Loading…
Cancel
Save