0,0 → 1,39 |
#include "defines.h" |
#include "MCP23009.h" |
#include "I2C2.h" |
|
static BTN_STATUS *status_ptr; |
|
void MCP23009_Init(BTN_STATUS *status) { |
status_ptr = status; |
|
uint8_t buffer[8]; |
|
buffer[0] = 0x00; // Starting register address |
buffer[1] = 0xFF; // IODIR, Set all pins as inputs |
buffer[2] = 0xFF; // IPOL, Reported values are inverted |
buffer[3] = 0xFF; // GPINTEN, Enable interrupt-on-change |
buffer[4] = 0x00; // DEFVAL, IOC default values |
buffer[5] = 0x00; // INTCON, IOC compare to previous value |
buffer[6] = 0x00; // IOCON, Incrementing address, active-low interrupt cleared on GPIO read |
buffer[7] = 0xFF; // GPPU, Enable pull-ups on all pins |
|
I2C2_Master_Send(MCP23009_ADDR, 8, buffer); |
uint8_t result; |
do { |
result = I2C2_Get_Status(); |
} while (!result); |
} |
|
void MCP23009_Query(void) { |
uint8_t buffer[2]; |
|
I2C2_Master_Restart(MCP23009_ADDR, MCP23009_GPIOA, 1); |
uint8_t result; |
do { |
result = I2C2_Get_Status(); |
} while (!result); |
I2C2_Read_Buffer(buffer); |
|
status_ptr->w = buffer[0]; |
} |