1 /* Copyright 2018 Mike Roberts
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #define EXPANDER_ADDR 0x27
20 #define I2C_TIMEOUT 200 // milliseconds
21 #define EXPANDER_PAUSE 0 // microseconds
23 enum EXPANDER_REGISTERS {
24 EXPANDER_REG_IODIRA = 0x00,
25 EXPANDER_REG_IODIRB = 0x01,
26 EXPANDER_REG_IPOLA = 0x02,
27 EXPANDER_REG_IPOLB = 0x03,
28 EXPANDER_REG_GPINTENA = 0x04,
29 EXPANDER_REG_GPINTENB = 0x05,
30 EXPANDER_REG_DEFVALA = 0x06,
31 EXPANDER_REG_DEFVALB = 0x07,
32 EXPANDER_REG_INTCONA = 0x08,
33 EXPANDER_REG_INTCONB = 0x09,
34 EXPANDER_REG_IOCONA = 0x0A,
35 EXPANDER_REG_IOCONB = 0x0B,
36 EXPANDER_REG_GPPUA = 0x0C,
37 EXPANDER_REG_GPPUB = 0x0D,
38 EXPANDER_REG_INTFA = 0x0E,
39 EXPANDER_REG_INTFB = 0x0F,
40 EXPANDER_REG_INTCAPA = 0x10,
41 EXPANDER_REG_INTCAPB = 0x11,
42 EXPANDER_REG_GPIOA = 0x12,
43 EXPANDER_REG_GPIOB = 0x13,
44 EXPANDER_REG_OLATA = 0x14,
45 EXPANDER_REG_OLATB = 0x15
66 void expander_init(void);
67 void expander_select(uint8_t pin);
68 void expander_unselect(uint8_t pin);
69 void expander_unselect_all(void);