-
Notifications
You must be signed in to change notification settings - Fork 13
/
at89sbus.h
113 lines (97 loc) · 4.26 KB
/
at89sbus.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
//=========================================================================https://
// //
// PonyProg - Serial Device Programmer //
// //
// Copyright (C) 1997-2021 Claudio Lanconelli //
// //
// https://ponyprog.sourceforge.net //
// //
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
// as published by the Free Software Foundation; either version2 of //
// the License, or (at your option) any later version. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
// General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program (see LICENSE); if not, write to the //
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
// //
//=========================================================================https://
#ifndef _AT89SBUS_H
#define _AT89SBUS_H
#include "spi-bus.h"
class At89sBus : public SPIBus
{
public:
At89sBus(BusInterface *ptr = 0);
//virtual ~At89sBus();
long Read(int addr, uint8_t *data, long length, int page_size = 0);
long Write(int addr, uint8_t const *data, long length, int page_size = 0);
virtual int Reset();
virtual int Erase(int type = 0);
int ReadDeviceCode(int addr);
int WriteLockBits(uint32_t val, long model);
int WriteFuseBits(uint32_t val, long model);
int ReadLockBits(uint32_t &res, long model);
int ReadFuseBits(uint32_t &res, long model);
void SetDelay();
void SetPagePolling(bool prog, bool val)
{
if (prog)
{
enable_progpage_polling = val;
}
else
{
enable_datapage_polling = val;
}
}
bool GetPagePolling(bool prog) const
{
return prog ? enable_progpage_polling : enable_datapage_polling;
}
void SetCompatibilityMode(bool old)
{
oldmode = old;
}
protected:
//Programming commands
const uint8_t EnableProg0, EnableProg1;
const uint8_t ChipErase0, ChipErase1, OldChipErase1;
const uint8_t ReadProgByteMem, OldReadProgMem;
const uint8_t WriteProgByteMem, OldWriteProgMem;
const uint8_t ReadProgPageMem;
const uint8_t WriteProgPageMem;
const uint8_t ReadDataByteMem, OldReadDataMem;
const uint8_t WriteDataByteMem, OldWriteDataMem;
const uint8_t ReadDataPageMem;
const uint8_t WriteDataPageMem;
const uint8_t ReadUserFuses0, ReadUserFuses1;
const uint8_t WriteUserFuses0, WriteUserFuses1;
const uint8_t ReadLockBits0, ReadLockBits1;
const uint8_t WriteLockBits0, WriteLockBits1, OldWriteLockBits1;
const uint8_t ReadSignatureByte;
int ReadDataByte(long addr);
void WriteDataByte(long addr, int data);
int ReadProgByte(long addr);
void WriteProgByte(long addr, int data);
int WriteProgPage(long addr, uint8_t const *data, long page_size, long timeout = 5000);
int WriteDataPage(long addr, uint8_t const *data, long page_size, long timeout = 5000);
void ReadProgPage(long addr, uint8_t *data, long page_size, long timeout = 5000);
void ReadDataPage(long addr, uint8_t *data, long page_size, long timeout = 5000);
int WaitReadyAfterWrite(int type, long addr, int data, long timeout = 5000);
bool CheckBlankPage(uint8_t const *data, long length);
private:
bool enable_datapage_polling, enable_progpage_polling;
//Erase and programming delays
int twd_erase;
int twd_prog;
bool oldmode;
};
#endif