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