-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtmslclafioexpander.pas
More file actions
279 lines (230 loc) · 7.8 KB
/
Copy pathtmslclafioexpander.pas
File metadata and controls
279 lines (230 loc) · 7.8 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
{***************************************************************************}
{ TMS LCL HW components for Raspberry Pi }
{ for Lazarus }
{ }
{ written by TMS Software }
{ copyright © 2016 }
{ Email : info@tmssoftware.com }
{ Web : http://www.tmssoftware.com }
{ }
{ The source code is given as is. The author is not responsible }
{ for any possible damage done due to the use of this code. }
{ The component can be freely used in any application. The complete }
{ source code remains property of the author and may not be distributed, }
{ published, given or sold in any form as such. No parts of the source }
{ code can be included in any other component or application without }
{ written authorization of the author. }
{***************************************************************************}
// i2c IO expander
unit TMSLCLAFIOExpander;
{$mode delphi}
interface
uses
Classes, SysUtils, TMSLCLRaspiHW;
type
{ TTMSLCLAdaIOExpander }
{ TTMSLCLAdaI2CIOExpander }
TTMSLCLAdaI2CIOExpander = class(TTMSLCLRaspiI2C)
private
function GetIODirA: byte;
function GetIODirB: byte;
function GetIOIntConA: byte;
function GetIOIntConB: byte;
function GetIOIntDefA: byte;
function GetIOIntDefB: byte;
function GetIOIntEnA: byte;
function GetIOIntEnB: byte;
function GetIOIntFlagA: byte;
function GetIOIntFlagB: byte;
function GetIOPolarityA: byte;
function GetIOPolarityB: byte;
function GetIOPullupA: byte;
function GetIOPullupB: byte;
function GetIOValA: byte;
function GetIOValB: byte;
procedure SetIODirA(AValue: byte);
procedure SetIODirB(AValue: byte);
procedure SetIOIntConA(AValue: byte);
procedure SetIOIntConB(AValue: byte);
procedure SetIOIntDefA(AValue: byte);
procedure SetIOIntDefB(AValue: byte);
procedure SetIOIntEnA(AValue: byte);
procedure SetIOIntEnB(AValue: byte);
procedure SetIOPolarityA(AValue: byte);
procedure SetIOPolarityB(AValue: byte);
procedure SetIOPullupA(AValue: byte);
procedure SetIOPullupB(AValue: byte);
procedure SetIOValA(AValue: byte);
procedure SetIOValB(AValue: byte);
protected
public
constructor Create(AOwner: TComponent); override;
property IODirA: byte read GetIODirA write SetIODirA;
property IODirB: byte read GetIODirB write SetIODirB;
property IOPolarityA: byte read GetIOPolarityA write SetIOPolarityA;
property IOPolarityB: byte read GetIOPolarityB write SetIOPolarityB;
property IOValA: byte read GetIOValA write SetIOValA;
property IOValB: byte read GetIOValB write SetIOValB;
property IOPullupA: byte read GetIOPullupA write SetIOPullupA;
property IOPullupB: byte read GetIOPullupB write SetIOPullupB;
property IOIntEnA: byte read GetIOIntEnA write SetIOIntEnA;
property IOIntEnB: byte read GetIOIntEnB write SetIOIntEnB;
property IOIntConA: byte read GetIOIntConA write SetIOIntConA;
property IOIntDefA: byte read GetIOIntDefA write SetIOIntDefA;
property IOIntDefB: byte read GetIOIntDefB write SetIOIntDefB;
property IOIntConB: byte read GetIOIntConB write SetIOIntConB;
property IOIntFlagA: byte read GetIOIntFlagA;
property IOIntFlagB: byte read GetIOIntFlagB;
end;
implementation
const
MCP23017_ADDRESS = $20;
MCP23017_IODIRA = $00;
MCP23017_IODIRB = $01;
MCP23017_IPOLA = $02;
MCP23017_IPOLB = $03;
MCP23017_GPINTENA = $04;
MCP23017_GPINTENB = $05;
MCP23017_DEFVALA = $06;
MCP23017_DEFVALB = $07;
MCP23017_INTCONA = $08;
MCP23017_INTCONB = $09;
MCP23017_IOCONA = $0A;
MCP23017_IOCONB = $0B;
MCP23017_GPPUA = $0C;
MCP23017_GPPUB = $0D;
MCP23017_INTFA = $0E;
MCP23017_INTFB = $0F;
MCP23017_INTCAPA = $10;
MCP23017_INTCAPB = $11;
MCP23017_GPIOA = $12;
MCP23017_GPIOB = $13;
MCP23017_OLATA = $14;
MCP23017_OLATB = $15;
{ TTMSLCLAdaIOExpander }
constructor TTMSLCLAdaI2CIOExpander.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
I2CAddress := MCP23017_ADDRESS;
end;
procedure TTMSLCLAdaI2CIOExpander.SetIODirA(AValue: byte);
begin
SetByteRegister(MCP23017_IODIRA, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIODirB(AValue: byte);
begin
SetByteRegister(MCP23017_IODIRB, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOIntConA(AValue: byte);
begin
SetByteRegister(MCP23017_INTCONA, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOIntConB(AValue: byte);
begin
SetByteRegister(MCP23017_INTCONB, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOIntDefA(AValue: byte);
begin
SetByteRegister(MCP23017_DEFVALA, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOIntDefB(AValue: byte);
begin
SetByteRegister(MCP23017_DEFVALB, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOIntEnA(AValue: byte);
begin
SetByteRegister(MCP23017_GPINTENA, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOIntEnB(AValue: byte);
begin
SetByteRegister(MCP23017_GPINTENB, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOPolarityA(AValue: byte);
begin
SetByteRegister(MCP23017_IPOLA, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOPolarityB(AValue: byte);
begin
SetByteRegister(MCP23017_IPOLB, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOPullupA(AValue: byte);
begin
SetByteRegister(MCP23017_GPPUA, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOPullupB(AValue: byte);
begin
SetByteRegister(MCP23017_GPPUB, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOValA(AValue: byte);
begin
SetByteRegister(MCP23017_GPIOA, AValue);
end;
procedure TTMSLCLAdaI2CIOExpander.SetIOValB(AValue: byte);
begin
SetByteRegister(MCP23017_GPIOB, AValue);
end;
function TTMSLCLAdaI2CIOExpander.GetIODirA: byte;
begin
Result := GetByteRegister(MCP23017_IODIRA);
end;
function TTMSLCLAdaI2CIOExpander.GetIODirB: byte;
begin
Result := GetByteRegister(MCP23017_IODIRB);
end;
function TTMSLCLAdaI2CIOExpander.GetIOIntConA: byte;
begin
Result := GetByteRegister(MCP23017_INTCONA);
end;
function TTMSLCLAdaI2CIOExpander.GetIOIntConB: byte;
begin
Result := GetByteRegister(MCP23017_INTCONB);
end;
function TTMSLCLAdaI2CIOExpander.GetIOIntDefA: byte;
begin
Result := GetByteRegister(MCP23017_DEFVALA);
end;
function TTMSLCLAdaI2CIOExpander.GetIOIntDefB: byte;
begin
Result := GetByteRegister(MCP23017_DEFVALB);
end;
function TTMSLCLAdaI2CIOExpander.GetIOIntEnA: byte;
begin
Result := GetByteRegister(MCP23017_GPINTENA);
end;
function TTMSLCLAdaI2CIOExpander.GetIOIntEnB: byte;
begin
Result := GetByteRegister(MCP23017_GPINTENB);
end;
function TTMSLCLAdaI2CIOExpander.GetIOIntFlagA: byte;
begin
Result := GetByteRegister(MCP23017_INTFA);
end;
function TTMSLCLAdaI2CIOExpander.GetIOIntFlagB: byte;
begin
Result := GetByteRegister(MCP23017_INTFB);
end;
function TTMSLCLAdaI2CIOExpander.GetIOPolarityA: byte;
begin
Result := GetByteRegister(MCP23017_IPOLA);
end;
function TTMSLCLAdaI2CIOExpander.GetIOPolarityB: byte;
begin
Result := GetByteRegister(MCP23017_IPOLB);
end;
function TTMSLCLAdaI2CIOExpander.GetIOPullupA: byte;
begin
Result := GetByteRegister(MCP23017_GPPUA);
end;
function TTMSLCLAdaI2CIOExpander.GetIOPullupB: byte;
begin
Result := GetByteRegister(MCP23017_GPPUB);
end;
function TTMSLCLAdaI2CIOExpander.GetIOValA: byte;
begin
Result := GetByteRegister(MCP23017_GPIOA);
end;
function TTMSLCLAdaI2CIOExpander.GetIOValB: byte;
begin
Result := GetByteRegister(MCP23017_GPIOB);
end;
end.