2018-06-05 21:43:20 +02:00
|
|
|
#include "sx60.h"
|
2021-09-07 17:34:59 +02:00
|
|
|
#include "i2c_master.h"
|
2018-06-05 21:43:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool i2c_initialized = 0;
|
|
|
|
uint8_t mcp23018_status = 0x20;
|
|
|
|
|
|
|
|
uint8_t init_mcp23018(void) {
|
|
|
|
mcp23018_status = 0x20;
|
|
|
|
|
|
|
|
/* I2C subsystem */
|
|
|
|
|
|
|
|
if (i2c_initialized == 0) {
|
|
|
|
i2c_init(); // on pins D(1,0)
|
|
|
|
i2c_initialized = true;
|
|
|
|
_delay_ms(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* B Pins are Row, A pins are Columns
|
|
|
|
Set them to output */
|
2021-09-07 17:34:59 +02:00
|
|
|
static uint8_t direction[2] = {
|
|
|
|
0b11111111,
|
|
|
|
0b00000000,
|
|
|
|
};
|
|
|
|
static uint8_t pullup[2] = {
|
|
|
|
0b11111111,
|
|
|
|
0b00000000,
|
|
|
|
};
|
|
|
|
|
2024-01-16 03:26:40 +01:00
|
|
|
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, direction, 2, I2C_TIMEOUT);
|
2021-09-07 17:34:59 +02:00
|
|
|
if (mcp23018_status) return mcp23018_status;
|
|
|
|
|
2024-01-16 03:26:40 +01:00
|
|
|
mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, pullup, 2, I2C_TIMEOUT);
|
2018-06-05 21:43:20 +02:00
|
|
|
return mcp23018_status;
|
|
|
|
}
|