Hardware Reference
In-Depth Information
47 #define GPPU 6
48 #define INTF 7
49 #define INTCAP 8
50 #define GPIO 9
51 #define OLAT 10
52
53 #define MCP_REGISTER(r,g) (((r) <<1)|(g)) /
For I2C routines
/
54
55 static unsigned gpio_addr = 0x20; /
MCP23017 I2C Address
/
56 static const int gpio_inta = 17; /
GPIO pin for INTA connection
/
57 static int is_signaled = 0; /
Exit program if signaled
/
58
59 #include "sysgpio.c"
60
61 /
62
Signal handler to quit the program :
63
/
64 static void
65 sigint_handler(int signo) {
66 is_signaled = 1; /
Signal to exit program
/
67 }
68
69 /
70
Write to MCP23017 A or B register set:
71
/
72 static int
73 mcp23017_write(int reg,int AB,int value) {
74 unsigned reg_addr = MCP_REGISTER(reg,AB);
75 int rc;
76
77 rc = i2c_write8(gpio_addr,reg_addr,value);
78 return rc;
79 }
80
81 /
82
Write value to both MCP23017 register sets :
83
/
84 static void
85 mcp23017_write_both(int reg,int value) {
86 mcp23017_write(reg,GPIOA,value); /
Set A
/
87 mcp23017_write(reg,GPIOB,value); /
Set B
/
88 }
89
90 /
91
Read the MCP23017 input pins (excluding outputs,
92
16-bits) :
93
/
Search WWH ::




Custom Search