-
Notifications
You must be signed in to change notification settings - Fork 2
/
onbrightFlasher.h
108 lines (84 loc) · 2.92 KB
/
onbrightFlasher.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
/*
OnbrightFlasher.h - description
Copyright (c) 2023 Jonathan Armstrong. All right reserved.
*/
// ensure this library description is only included once
#ifndef Onbright_flasher_h
#define Onbright_flasher_h
// for byte type
#include <Arduino.h>
// advice on switching between SoftWire and Wire libraries
// [https://arduino-craft-corner.de/index.php/2023/11/29/replacing-the-wire-library-sometimes/]
// notes
// setfuse 18 249
// reset function, input only, no deglitch
// chip ID for OBS38S03
#define RESET_CHIP 0x7c
#define HANDSHAKE01 0x7d
#define HANDSHAKE02 0x2d
// FIXME: need to rename because sometimes we send READ even when writing as per official programmer
#define DEVICE_ADDRESS 0x7e
#define DATA_ADDRESS 0x7f
// chip commands
#define ERASE_CHIP 0x03
#define WRITE_FLASH 0x05
#define READ_FLASH 0x06
#define WRITE_CONFIG_BYTE 0x08
#define READ_CONFIG_BYTE 0x09
//
// config bytes
#define CHIP_TYPE_BYTE 0x00
#define CONFIG_BYTE01 0x11
#define CONFIG_BYTE02 0x12
#define CONFIG_BYTE03 0x13
#define CONFIG_BYTE04 0x14
#define CONFIG_BYTE05 0x15
#define CONFIG_BYTE06 0x16
#define CONFIG_BYTE07 0x17
// Checksum is calculated as a SUM of all FLASH bytes? Same is for EEPROM?
#define FLASH_CHECKSUM01 0x2c
#define FLASH_CHECKSUM02 0x2d
#define FLASH_CHECKSUM03 0x2e
#define FLASH_CHECKSUM04 0x2f
// seems to be enough to achieve handshake
#define MAX_HANDSHAKE_RETRIES 10
// target flash memory addresses
#define BLOCK_SIZE 512
enum { block00 = 0x0000,
block01 = 0x0200,
block02 = 0x0400,
block03 = 0x0600,
block04 = 0x0800,
block05 = 0x0A00,
block06 = 0x0C00,
block07 = 0x0E00,
block08 = 0x1000,
block09 = 0x1200,
block10 = 0x1400,
block11 = 0x1600,
block12 = 0x1800,
block13 = 0x1A00,
block14 = 0x1C00,
block15 = 0x1E00
};
// library interface description
class OnbrightFlasher
{
// user-accessible "public" interface
public:
byte eraseChip(void);
bool onbrightHandshake(void);
byte readConfigByte(const unsigned char address, unsigned char &configByte);
byte writeConfigByte(const unsigned char address, const unsigned char configByte);
byte readConfigBlock(const unsigned char address, unsigned char (&configByte)[], const unsigned char length);
byte readFlashByte(const unsigned int address, unsigned char &flashByte);
byte writeFlashByte(const unsigned int address, const unsigned char flashByte);
byte readFlashBlock(const unsigned int flashAddress, unsigned char (&flashbyte)[], const unsigned int length);
byte writeFlashBlock(const unsigned int flashAddress, unsigned char* flashbyte, const unsigned int length);
byte readChipType(unsigned char& chipType);
void resetMCU(void);
// library-accessible "private" interface
private:
int dummyVariable;
};
#endif