AVR_ATMEGA_USART/avr_usart.h

71 lines
1.5 KiB
C

/*
* Author: Jake Goodwin
* Date: 2023
* Description: AT-09 Bluetooth module library for AVR micro crontrollers.
* Filename: avr_at-09.h
*/
#define __AVR_ATmega328P__
#include <inttypes.h>
#include <stdint.h>
//#############################
//PIN DEFINES AND CONSTS
//#############################
/*
* AVR D0 --> AT-09 TX
* AVR D1 --> AT-09 RX
* AVR D2 --> AT-09 State
*/
#define FOSC 1000000UL
#define BLE_BAUD 4800
#define BT_UBRR ((FOSC)/(BLE_BAUD*16UL)-1)
#define TX_PIN PIND1
#define TX_DDR DDD1
#define RX_PIN PIND0
#define RX_DDR DDD0
#define AT_PORT PORTD
//LED PIN for indicator and debug.
#define LED_PIN PINC0
#define LED_DDR DDC0
//#############################
//MACROS
//#############################
#define USE_U2X 0
#define CARRIAGE_RETURN 1
#define LINE_FEED 1
//#############################
//FUNCTION PROTOTYPES
//#############################
static void led_blink(void);
void init_usart0(void);
void tx_usart0(unsigned char data);
unsigned char rx_usart0(void);
void serial0_write(unsigned char* buffer, uint8_t write_length);
void serial0_read(unsigned char* buffer, uint8_t buf_length);
void serial0_read_with_err_checking(unsigned char* buffer, uint8_t buf_length);
void serial0_set_baud(uint8_t baud);
void seiral0_enable_timeouts(uint8_t ms);
void serial0_flush_rxbuf(void);
void serial0_enable_line_feeds(void);
void serial0_enable_carriage_returns(void);
void serial0_enable_parity_bit(uint8_t pos);
void serial0_set_stop_bits(uint8_t number);