summaryrefslogtreecommitdiff
path: root/keyboards/hotdox
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/hotdox')
-rw-r--r--keyboards/hotdox/left.c34
-rw-r--r--keyboards/hotdox/left.h7
2 files changed, 12 insertions, 29 deletions
diff --git a/keyboards/hotdox/left.c b/keyboards/hotdox/left.c
index 970d36f1b5..f963ecdae7 100644
--- a/keyboards/hotdox/left.c
+++ b/keyboards/hotdox/left.c
@@ -5,8 +5,8 @@
bool i2c_initialized = false;
void left_config(void);
-uint8_t left_write(uint8_t reg, uint8_t data);
-uint8_t left_read(uint8_t reg, uint8_t *data);
+i2c_status_t left_write(uint8_t reg, uint8_t data);
+i2c_status_t left_read(uint8_t reg, uint8_t *data);
uint8_t init_mcp23017(void)
{
@@ -35,12 +35,11 @@ void left_init(void)
void left_scan(void)
{
- uint8_t ret = i2c_start(I2C_ADDR_WRITE, HOTDOX_I2C_TIMEOUT);
+
+ i2c_status_t ret = i2c_ping_address(I2C_ADDR, HOTDOX_I2C_TIMEOUT);
- if (ret == 0)
+ if (ret == I2C_STATUS_SUCCESS)
{
- i2c_stop();
-
if (!i2c_initialized)
{
i2c_initialized = true;
@@ -91,40 +90,29 @@ void left_config(void)
left_write(MCP23017_B0_GPIOB, 0xC0);
}
-uint8_t left_write(uint8_t reg, uint8_t data)
+i2c_status_t left_write(uint8_t reg, uint8_t data)
{
if (!i2c_initialized)
{
return 0;
}
- uint8_t ret;
+ i2c_status_t ret;
- ret = i2c_start(I2C_ADDR_WRITE, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
- ret = i2c_write(reg, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
- ret = i2c_write(data, HOTDOX_I2C_TIMEOUT);
+ ret = i2c_writeReg(I2C_ADDR, reg, &data, sizeof(data), HOTDOX_I2C_TIMEOUT);
-out:
- i2c_stop();
return ret;
}
-uint8_t left_read(uint8_t reg, uint8_t *data)
+i2c_status_t left_read(uint8_t reg, uint8_t *data)
{
if (!i2c_initialized)
{
return 0;
}
- uint8_t ret = 0;
-
- ret = i2c_start(I2C_ADDR_WRITE, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
- ret = i2c_write(reg, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
- ret = i2c_start(I2C_ADDR_READ, HOTDOX_I2C_TIMEOUT); if (ret) goto out;
-
- *data = i2c_read_nack(HOTDOX_I2C_TIMEOUT);
+ i2c_status_t ret = 0;
+ ret = i2c_readReg(I2C_ADDR, reg, data, 1, HOTDOX_I2C_TIMEOUT);
-out:
- i2c_stop();
return ret;
}
diff --git a/keyboards/hotdox/left.h b/keyboards/hotdox/left.h
index 3d8b5a6ead..32faadba21 100644
--- a/keyboards/hotdox/left.h
+++ b/keyboards/hotdox/left.h
@@ -10,10 +10,7 @@
#define MCP23017_A1 0
#define MCP23017_A2 0
-#define I2C_ADDR (0x20)
-#define I2C_ADDR_WRITE ((I2C_ADDR << 1) | I2C_WRITE)
-#define I2C_ADDR_READ ((I2C_ADDR << 1) | I2C_READ)
-
+#define I2C_ADDR ((0x20) << 1)
#define MCP23017_B0_IODIRA 0x00
#define MCP23017_B0_IODIRB 0x01
@@ -40,8 +37,6 @@
#define HOTDOX_I2C_TIMEOUT 100
-typedef int16_t i2c_status_t;
-
void left_init(void);
void left_scan(void);