libmcp23s17  0.3.0
A simple static C library for the MCP23S17 port expander.
 All Files Functions
mcp23s17.h
Go to the documentation of this file.
1 
23 #ifndef _MCP23S17_H
24 #define _MCP23S17_H
25 
26 #include <stdint.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 
33 #define WRITE_CMD 0
34 #define READ_CMD 1
35 
36 // Register addresses
37 #define IODIRA 0x00 // I/O direction A
38 #define IODIRB 0x01 // I/O direction B
39 #define IPOLA 0x02 // I/O polarity A
40 #define IPOLB 0x03 // I/O polarity B
41 #define GPINTENA 0x04 // interupt enable A
42 #define GPINTENB 0x05 // interupt enable B
43 #define DEFVALA 0x06 // register default value A (interupts)
44 #define DEFVALB 0x07 // register default value B (interupts)
45 #define INTCONA 0x08 // interupt control A
46 #define INTCONB 0x09 // interupt control B
47 #define IOCON 0x0A // I/O config (also 0x0B)
48 #define GPPUA 0x0C // port A pullups
49 #define GPPUB 0x0D // port B pullups
50 #define INTFA 0x0E // interupt flag A (where the interupt came from)
51 #define INTFB 0x0F // interupt flag B
52 #define INTCAPA 0x10 // interupt capture A (value at interupt is saved here)
53 #define INTCAPB 0x11 // interupt capture B
54 #define GPIOA 0x12 // port A
55 #define GPIOB 0x13 // port B
56 #define OLATA 0x14 // output latch A
57 #define OLATB 0x15 // output latch B
58 
59 // I/O config
60 #define BANK_OFF 0x00 // addressing mode
61 #define BANK_ON 0x80
62 #define INT_MIRROR_ON 0x40 // interupt mirror (INTa|INTb)
63 #define INT_MIRROR_OFF 0x00
64 #define SEQOP_OFF 0x20 // incrementing address pointer
65 #define SEQOP_ON 0x00
66 #define DISSLW_ON 0x10 // slew rate
67 #define DISSLW_OFF 0x00
68 #define HAEN_ON 0x08 // hardware addressing
69 #define HAEN_OFF 0x00
70 #define ODR_ON 0x04 // open drain for interupts
71 #define ODR_OFF 0x00
72 #define INTPOL_HIGH 0x02 // interupt polarity
73 #define INTPOL_LOW 0x00
74 
75 #define GPIO_INTERRUPT_PIN 25
76 
84 int mcp23s17_open(int bus, int chip_select);
85 
94 uint8_t mcp23s17_read_reg(uint8_t reg, uint8_t hw_addr, int fd);
95 
105 void mcp23s17_write_reg(uint8_t data, uint8_t reg, uint8_t hw_addr, int fd);
106 
116 uint8_t mcp23s17_read_bit(uint8_t bit_num,
117  uint8_t reg,
118  uint8_t hw_addr,
119  int fd);
120 
131 void mcp23s17_write_bit(uint8_t data,
132  uint8_t bit_num,
133  uint8_t reg,
134  uint8_t hw_addr,
135  int fd);
136 
137 
144 int mcp23s17_enable_interrupts();
145 
146 
153 int mcp23s17_disable_interrupts();
154 
155 
173 int mcp23s17_wait_for_interrupt(int timeout);
174 
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif