1 #include "i2c_master.h"
6 #define SLAVE_TO_ADDR(n) (n<<1)
20 void pca9555_init(uint8_t slave_addr) {
21 static uint8_t s_init = 0;
28 // TODO: could check device connected
29 //i2c_start(SLAVE_TO_ADDR(slave) | I2C_WRITE);
33 void pca9555_set_config(uint8_t slave_addr, uint8_t port, uint8_t conf) {
34 uint8_t addr = SLAVE_TO_ADDR(slave_addr);
35 uint8_t cmd = port ? CMD_OUTPUT_1 : CMD_OUTPUT_0;
37 i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
38 if (ret != I2C_STATUS_SUCCESS) {
39 print("pca9555_set_config::FAILED\n");
43 void pca9555_set_output(uint8_t slave_addr, uint8_t port, uint8_t conf) {
44 uint8_t addr = SLAVE_TO_ADDR(slave_addr);
45 uint8_t cmd = port ? CMD_CONFIG_1 : CMD_CONFIG_0;
47 i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
48 if (ret != I2C_STATUS_SUCCESS) {
49 print("pca9555_set_output::FAILED\n");
53 uint8_t pca9555_readPins(uint8_t slave_addr, uint8_t port) {
54 uint8_t addr = SLAVE_TO_ADDR(slave_addr);
55 uint8_t cmd = port ? CMD_INPUT_1 : CMD_INPUT_0;
58 i2c_status_t ret = i2c_readReg(addr, cmd, &data, sizeof(data), TIMEOUT);
59 if (ret != I2C_STATUS_SUCCESS) {
60 print("pca9555_readPins::FAILED\n");