speichern
This commit is contained in:
parent
86da74bed0
commit
8e785e4b70
15 changed files with 443 additions and 282 deletions
|
@ -5,15 +5,20 @@
|
|||
#include <util/delay.h>
|
||||
#include <stdint.h>
|
||||
|
||||
constexpr uint32_t BAUDRATE = 115200; // 38400
|
||||
constexpr uint8_t CRC7_POLY = 0x91;
|
||||
constexpr uint8_t MAX_BLOCK_SIZE = 16;
|
||||
enum BlockSequence
|
||||
{
|
||||
IDLE = 0,
|
||||
LEN = 1,
|
||||
DATA = 2,
|
||||
CRC = 3,
|
||||
END = 4,
|
||||
};
|
||||
|
||||
class USART
|
||||
{
|
||||
public:
|
||||
void init(void);
|
||||
void flush(void);
|
||||
void clearInputBuffer(void);
|
||||
|
||||
void writeByte(uint8_t);
|
||||
void writeInt(uint16_t);
|
||||
|
@ -23,10 +28,24 @@ public:
|
|||
uint8_t readByte(void);
|
||||
uint16_t readInt(void);
|
||||
uint32_t readLong(void);
|
||||
|
||||
void nextByte(uint8_t byte);
|
||||
void readBlock(uint8_t*, uint8_t);
|
||||
|
||||
constexpr static uint8_t MSG_OK = 0xFF;
|
||||
constexpr static uint8_t MSG_FAIL = 0xFE;
|
||||
|
||||
uint8_t block_pos = 0;
|
||||
|
||||
// constants
|
||||
constexpr static uint32_t BAUDRATE = 115200; // 38400
|
||||
constexpr static uint8_t CRC7_POLY = 0x91;
|
||||
constexpr static uint8_t MAX_BLOCK_SIZE = 64;
|
||||
constexpr static uint8_t BLOCK_END = 0x80;
|
||||
private:
|
||||
uint8_t block_buffer[MAX_BLOCK_SIZE + 3]; // don't store BLOCK_END byte
|
||||
uint8_t crc;
|
||||
BlockSequence seq = BlockSequence::IDLE;
|
||||
};
|
||||
|
||||
#endif // USART_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue