This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
stk500.h
116 lines (100 loc) · 2.85 KB
/
stk500.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef _STK500_H_
#define _STK500_H_
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include "boards.h"
#include "debug.h"
// Command definitions
#define CMND_STK_GET_SYNC 0x30
#define CMND_STK_GET_SIGN_ON 0x31
#define CMND_STK_SET_PARAMETER 0x40 // NOT SUPPORTED
#define CMND_STK_GET_PARAMETER 0x41
#define CMND_STK_SET_DEVICE 0x42
#define CMND_STK_SET_DEVICE_EXT 0x45
#define CMND_STK_ENTER_PROGMODE 0x50
#define CMND_STK_LEAVE_PROGMODE 0x51
#define CMND_STK_CHIP_ERASE 0x52 // NOT SUPPORTED
#define CMND_STK_CHECK_AUTOINC 0x53 // NOT SUPPORTED
#define CMND_STK_LOAD_ADDRESS 0x55
#define CMND_STK_UNIVERSAL 0x56
#define CMND_STK_UNIVERSAL_MULTI 0x57 // NOT SUPPORTED
#define CMND_STK_PROG_FLASH 0x60 // IGNORED
#define CMND_STK_PROG_DATA 0x61 // IGNORED
#define CMND_STK_PROG_FUSE 0x62 // NOT SUPPORTED
#define CMND_STK_PROG_LOCK 0x63 // NOT SUPPORTED
#define CMND_STK_PROG_PAGE 0x64
#define CMND_STK_PROG_FUSE_EXT 0x65 // NOT SUPPORTED
#define CMND_STK_READ_FLASH 0x70 // NOT SUPPORTED
#define CMND_STK_READ_DATA 0x71 // NOT SUPPORTED
#define CMND_STK_READ_FUSE 0x72 // NOT SUPPORTED
#define CMND_STK_READ_LOCK 0x73 // NOT SUPPORTED
#define CMND_STK_READ_PAGE 0x74
#define CMND_STK_READ_SIGN 0x75 // NOT SUPPORTED
#define CMND_STK_READ_OSCCAL 0x76 // NOT SUPPORTED
#define CMND_STK_READ_FUSE_EXT 0x77 // NOT SUPPORTED
#define CMND_STK_READ_OSCCAL_EXT 0x78 // NOT SUPPORTED
// STK Definitions
#define STK_OK 0x10
#define STK_FAILED 0x11
#define STK_UNKNOWN 0x12
#define STK_INSYNC 0x14
#define STK_NOSYNC 0x15
#define CRC_EOP 0x20
// Software version
#define HWVER 2
#define SWMAJ 1
#define SWMIN 18
#define BUFFER_SIZE 256
typedef struct param
{
uint8_t devicecode;
uint8_t revision;
uint8_t progtype;
uint8_t parmode;
uint8_t polling;
uint8_t selftimed;
uint8_t lockbytes;
uint8_t fusebytes;
uint8_t flashpoll;
uint16_t eeprompoll;
uint16_t pagesize;
uint16_t eepromsize;
uint32_t flashsize;
uint8_t eeprom_page_size;
} parameter;
class STK500
{
public:
STK500(){};
STK500(SoftwareSerial *serial);
bool serial_busy = false;
bool programming = false;
bool reset_locked = false;
uint8_t error = 0;
void avrisp();
protected:
SoftwareSerial *sserial;
parameter param;
uint8_t flash_page = 0;
bool rst_active_high = true;
uint8_t buff[BUFFER_SIZE];
uint16_t addr = 0;
uint8_t getch();
void breply(char b);
void fill(int n);
uint16_t current_page();
virtual void start_programming();
virtual void end_programming();
virtual void program_page();
virtual void read_page();
virtual void read_signature();
virtual void universal();
private:
void empty_reply();
void get_version(uint8_t c);
void set_parameters();
void set_ext_parameters();
};
#endif