-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmax7318.h
184 lines (162 loc) · 6.94 KB
/
max7318.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
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
/*
___ _ _ _ __ ___ ___ | |_ ___ _ _
/ __|| | | || '_ ` _ \ / _ \ | __|/ _ \ | | | |
\__ \| |_| || | | | | || (_) || |_| (_) || |_| |
|___/ \__,_||_| |_| |_| \___/ \__|\___/ \__, |
|___/
gpio_expander - An attemp to create a fast and universal library for drive many GPIO chips
model: company: pins: protocol: Special Features:
---------------------------------------------------------------------------------------------------------------------
MAX7318 MAXIM 16 I2C INT/Hot Insert Protection/64 addresses
---------------------------------------------------------------------------------------------------------------------
Version history:
0.5b1: first release, just coded and never tested
0.5b2: fixed 2wire version, added portPullup, tested output mode (ok)
0.5b3: added some drivers
0.5b4: ability to include library inside other libraries.
0.5b7: Changed functionalities of some function.
0.6b1: Changed gpioRegisterRead to gpioRegisterReadByte. Added gpioRegisterReadWord (for some GPIO)
0.8b3: Added 2 more commands and 2 gpio chip.
---------------------------------------------------------------------------------------------------------------------
Copyright (c) 2013-2014, s.u.m.o.t.o.y [sumotoy(at)gmail.com]
---------------------------------------------------------------------------------------------------------------------
gpio_expander Library 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 version 3 of the License, or
(at your option) any later version.
gpio_expander Library 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Version:0.8b3: Added 2 more commands and 2 gpio chip.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
/* ------------------------------ MAX7318 WIRING ------------------------------------
0x20...0xDE
__ __
int [| U |] +++++
A1 [| |] sda
A2 [| |] scl
IO-0 [| |] A0
IO-1 [| |] IO-15
IO-2 [| |] IO-14
IO-3 [| |] IO-13
IO-4 [| |] IO-12
IO-5 [| |] IO-11
IO-6 [| |] IO-10
IO-7 [| |] IO-9
GND [|_____|] IO-8
Basic Addressing: 0 0 1 0 0 A2 A1 A0
Advanced Addressing:
_______________________________________________
AD2 AD1 AD0 A6 A5 A4 A3 A2 A1 A0 ADDRESS (hex)
GND SCL GND 0 0 1 0 0 0 0 0x20
GND SCL V+ 0 0 1 0 0 0 1 0x22
GND SDA GND 0 0 1 0 0 1 0 0x24
GND SDA V+ 0 0 1 0 0 1 1 0x26
V+ SCL GND 0 0 1 0 1 0 0 0x28
V+ SCL V+ 0 0 1 0 1 0 1 0x2A
V+ SDA GND 0 0 1 0 1 1 0 0x2C
V+ SDA V+ 0 0 1 0 1 1 1 0x2E
GND SCL SCL 0 0 1 1 0 0 0 0x30
GND SCL SDA 0 0 1 1 0 0 1 0x32
GND SDA SCL 0 0 1 1 0 1 0 0x34
GND SDA SDA 0 0 1 1 0 1 1 0x36
V+ SCL SCL 0 0 1 1 1 0 0 0x38
V+ SCL SDA 0 0 1 1 1 0 1 0x3A
V+ SDA SCL 0 0 1 1 1 1 0 0x3C
V+ SDA SDA 0 0 1 1 1 1 1 0x3E
GND GND GND 0 1 0 0 0 0 0 0x40
GND GND V+ 0 1 0 0 0 0 1 0x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 0 0 1 1 0 0xCC
SDA V+ V+ 1 1 0 0 1 1 1 0xCE
SCL GND SCL 1 1 0 1 0 0 0 0xD0
SCL GND SDA 1 1 0 1 0 0 1 0xD2
SCL V+ SCL 1 1 0 1 0 1 0 0xD4
SCL V+ SDA 1 1 0 1 0 1 1 0xD6
SDA GND SCL 1 1 0 1 1 0 0 0xD8
SDA GND SDA 1 1 0 1 1 0 1 0xDA
SDA V+ SCL 1 1 0 1 1 1 0 0xDC
SDA V+ SDA 1 1 0 1 1 1 1 0xDE
*/
#ifndef _MAX7318_H_
#define _MAX7318_H_
#include <inttypes.h>
#include "gpio_expander.h"
class max7318 : public gpio_expander
{
public:
max7318(const uint8_t adrs);
max7318();
void postSetup(const uint8_t adrs);//used with other libraries only
virtual void begin(bool protocolInitOverride=false); //protocolInitOverride=true will not init the SPI
void gpioPinMode(uint16_t mode); //OUTPUT=all out,INPUT=all in,0xxxx=you choose
void gpioPinMode(uint8_t pin, bool mode); //set a unique pin as IN(1) or OUT (0)
void gpioPort(uint16_t value); //HIGH=all Hi, LOW=all Low,0xxxx=you choose witch low or hi
void gpioPort(byte lowByte, byte highByte); //same as abowe but uses 2 separate bytes
uint16_t readGpioPort(); //read the state of the pins (all)
uint16_t readGpioPortFast();
void gpioDigitalWrite(uint8_t pin, bool value); //write data to one pin
void gpioDigitalWriteFast(uint8_t pin, bool value);
int gpioDigitalRead(uint8_t pin); //read data from one pin
uint8_t gpioRegisterReadByte(byte reg); //read a byte from chip register
int gpioDigitalReadFast(uint8_t pin);
void gpioRegisterWriteByte(byte reg,byte data); //write a byte in a chip register
void gpioRegisterWriteWord(byte reg,word data); //write a word in a chip register
void portPullup(uint16_t data); // HIGH=all pullup, LOW=all pulldown,0xxxx=you choose witch
void gpioPortUpdate();
// direct access commands
uint16_t readAddress(byte addr);
//------------------------- REGISTERS
byte IODIR;//GPCONF
byte GPPU;//GPO
byte GPIO;//GPI
byte IPOL;//GPPOL
private:
uint8_t _adrs;
uint16_t _gpioDirection;
uint16_t _gpioState;
bool _error;
void writeByte(byte addr, byte data);
void writeWord(byte addr, uint16_t data);
};
#endif