-
Notifications
You must be signed in to change notification settings - Fork 2
/
Stk500Client.h
62 lines (46 loc) · 1.51 KB
/
Stk500Client.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef ARDUINO_STK500CLIENT_H
#define ARDUINO_STK500CLIENT_H
#include <Arduino.h>
#include "UploaderUI.h"
typedef struct _SktResponse {
Stk status;
uint8_t *data;
uint16_t size;
} StkResponse;
class Stk500Client
{
public:
Stk500Client(const Stk500Client&) = delete;
void operator=(const Stk500Client&) = delete;
Stk500Client(UploaderUI &ui, HardwareSerial &line) :
_ui(ui), _line(line),
_response{Stk::FAILED, _readBuf, 0}
{};
void begin(unsigned long baudRate);
const StkResponse & getSignon();
Stk sync();
const StkResponse & getParameter(StkParam param);
Stk enterProgramming();
void resetAddress();
Stk loadAddress(uint32_t wordAddress);
StkResponse readFlash(uint16_t count, uint8_t *buf);
Stk writeFlash(uint16_t count, uint8_t *data);
Stk leaveProgramming();
void end();
const StkResponse & readSignature();
private:
UploaderUI &_ui;
HardwareSerial &_line;
static const uint8_t READ_BUF_SIZE = 16;
uint8_t _readBuf[READ_BUF_SIZE];
uint16_t _readLen = 0u;
uint8_t _extendedAddress;
StkResponse _response;
uint8_t getByte();
Stk readData(uint16_t size, uint8_t *buf = 0);
Stk toStk(uint8_t byte);
void send(StkCommand cmd, uint8_t argCount = 0, uint8_t *args = 0);
const StkResponse &execute(StkCommand command, uint8_t responseSize = 0);
const StkResponse & execute(StkCommand cmd, uint8_t responseSize, uint8_t argCount, uint8_t *args);
};
#endif //ARDUINO_STK500CLIENT_H