b15f/firmware/usart.h

33 lines
690 B
C
Raw Normal View History

2019-03-26 10:35:41 +00:00
#ifndef USART_H
#define USART_H
#include <avr/io.h>
2019-03-27 09:33:26 +00:00
#include <util/delay.h>
2019-03-26 10:35:41 +00:00
#include <stdint.h>
2019-03-29 12:35:18 +00:00
constexpr uint32_t BAUDRATE = 115200; // 38400
2019-03-28 14:22:17 +00:00
constexpr uint8_t CRC7_POLY = 0x91;
2019-04-01 06:37:00 +00:00
constexpr uint8_t MAX_BLOCK_SIZE = 16;
2019-03-26 10:35:41 +00:00
class USART
{
public:
void init(void);
2019-03-29 12:35:18 +00:00
void flush(void);
2019-03-26 14:02:58 +00:00
2019-03-26 10:35:41 +00:00
void writeByte(uint8_t);
2019-03-26 14:02:58 +00:00
void writeInt(uint16_t);
void writeLong(uint32_t);
2019-03-27 14:48:36 +00:00
void writeStr(const char*, uint8_t);
2019-03-28 14:22:17 +00:00
uint8_t writeBlock(uint8_t*, uint8_t);
2019-03-26 10:35:41 +00:00
uint8_t readByte(void);
2019-03-26 14:02:58 +00:00
uint16_t readInt(void);
uint32_t readLong(void);
2019-03-29 12:35:18 +00:00
void readBlock(uint8_t*, uint8_t);
2019-03-26 10:35:41 +00:00
constexpr static uint8_t MSG_OK = 0xFF;
constexpr static uint8_t MSG_FAIL = 0xFE;
};
#endif // USART_H