i2c: rename read/write register functions (#22905)

This commit is contained in:
Ryan 2024-01-16 13:26:40 +11:00 committed by GitHub
parent e1f59a6efc
commit a522b1f156
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 184 additions and 170 deletions

View File

@ -197,11 +197,11 @@ Receive multiple bytes from the selected I2C device.
---
### `i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)` :id=api-i2c-writereg
### `i2c_status_t i2c_write_register(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)` :id=api-i2c-write-register
Writes to a register with an 8-bit address on the I2C device.
#### Arguments :id=api-i2c-writereg-arguments
#### Arguments :id=api-i2c-write-register-arguments
- `uint8_t devaddr`
The 7-bit I2C address of the device.
@ -214,17 +214,17 @@ Writes to a register with an 8-bit address on the I2C device.
- `uint16_t timeout`
The time in milliseconds to wait for a response from the target device.
#### Return Value :id=api-i2c-writereg-return
#### Return Value :id=api-i2c-write-register-return
`I2C_STATUS_TIMEOUT` if the timeout period elapses, `I2C_STATUS_ERROR` if some other error occurs, otherwise `I2C_STATUS_SUCCESS`.
---
### `i2c_status_t i2c_writeReg16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)` :id=api-i2c-writereg16
### `i2c_status_t i2c_write_register16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)` :id=api-i2c-write-register16
Writes to a register with a 16-bit address (big endian) on the I2C device.
#### Arguments :id=api-i2c-writereg16-arguments
#### Arguments :id=api-i2c-write-register16-arguments
- `uint8_t devaddr`
The 7-bit I2C address of the device.
@ -237,17 +237,17 @@ Writes to a register with a 16-bit address (big endian) on the I2C device.
- `uint16_t timeout`
The time in milliseconds to wait for a response from the target device.
#### Return Value :id=api-i2c-writereg16-return
#### Return Value :id=api-i2c-write-register16-return
`I2C_STATUS_TIMEOUT` if the timeout period elapses, `I2C_STATUS_ERROR` if some other error occurs, otherwise `I2C_STATUS_SUCCESS`.
---
### `i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)` :id=api-i2c-readreg
### `i2c_status_t i2c_read_register(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)` :id=api-i2c-read-register
Reads from a register with an 8-bit address on the I2C device.
#### Arguments :id=api-i2c-readreg-arguments
#### Arguments :id=api-i2c-read-register-arguments
- `uint8_t devaddr`
The 7-bit I2C address of the device.
@ -258,17 +258,17 @@ Reads from a register with an 8-bit address on the I2C device.
- `uint16_t timeout`
The time in milliseconds to wait for a response from the target device.
#### Return Value :id=api-i2c-readreg-return
#### Return Value :id=api-i2c-read-register-return
`I2C_STATUS_TIMEOUT` if the timeout period elapses, `I2C_STATUS_ERROR` if some other error occurs, otherwise `I2C_STATUS_SUCCESS`.
---
### `i2c_status_t i2c_readReg16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)`
### `i2c_status_t i2c_read_register16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)` :id=api-i2c-read-register16
Reads from a register with a 16-bit address (big endian) on the I2C device.
#### Arguments :id=api-i2c-readreg16-arguments
#### Arguments :id=api-i2c-read-register16-arguments
- `uint8_t devaddr`
The 7-bit I2C address of the device.
@ -279,7 +279,7 @@ Reads from a register with a 16-bit address (big endian) on the I2C device.
- `uint16_t timeout`
The time in milliseconds to wait for a response from the target device.
#### Return Value :id=api-i2c-readreg16-return
#### Return Value :id=api-i2c-read-register16-return
`I2C_STATUS_TIMEOUT` if the timeout period elapses, `I2C_STATUS_ERROR` if some other error occurs, otherwise `I2C_STATUS_SUCCESS`.

View File

@ -33,13 +33,13 @@ bool mcp23018_set_config(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf)
uint8_t cmdDirection = port ? CMD_IODIRB : CMD_IODIRA;
uint8_t cmdPullup = port ? CMD_GPPUB : CMD_GPPUA;
i2c_status_t ret = i2c_writeReg(addr, cmdDirection, &conf, sizeof(conf), TIMEOUT);
i2c_status_t ret = i2c_write_register(addr, cmdDirection, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_set_config::directionFAILED::%u\n", ret);
return false;
}
ret = i2c_writeReg(addr, cmdPullup, &conf, sizeof(conf), TIMEOUT);
ret = i2c_write_register(addr, cmdPullup, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_set_config::pullupFAILED::%u\n", ret);
return false;
@ -52,7 +52,7 @@ bool mcp23018_set_output(uint8_t slave_addr, mcp23018_port_t port, uint8_t conf)
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_GPIOB : CMD_GPIOA;
i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_set_output::FAILED::%u\n", ret);
return false;
@ -65,7 +65,7 @@ bool mcp23018_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t conf[2] = {confA, confB};
i2c_status_t ret = i2c_writeReg(addr, CMD_GPIOA, &conf[0], sizeof(conf), TIMEOUT);
i2c_status_t ret = i2c_write_register(addr, CMD_GPIOA, &conf[0], sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_set_output::FAILED::%u\n", ret);
return false;
@ -78,7 +78,7 @@ bool mcp23018_readPins(uint8_t slave_addr, mcp23018_port_t port, uint8_t* out) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_GPIOB : CMD_GPIOA;
i2c_status_t ret = i2c_readReg(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_readPins::FAILED::%u\n", ret);
return false;
@ -97,7 +97,7 @@ bool mcp23018_readPins_all(uint8_t slave_addr, uint16_t* out) {
data16 data = {.u16 = 0};
i2c_status_t ret = i2c_readReg(addr, CMD_GPIOA, &data.u8[0], sizeof(data), TIMEOUT);
i2c_status_t ret = i2c_read_register(addr, CMD_GPIOA, &data.u8[0], sizeof(data), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("mcp23018_readPins::FAILED::%u\n", ret);
return false;

View File

@ -66,7 +66,7 @@ bool pca9505_set_config(uint8_t slave_addr, pca9505_port_t port, uint8_t conf) {
break;
}
i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9505_set_config::FAILED\n");
return false;
@ -96,7 +96,7 @@ bool pca9505_set_polarity(uint8_t slave_addr, pca9505_port_t port, uint8_t conf)
break;
}
i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9505_set_polarity::FAILED\n");
return false;
@ -126,7 +126,7 @@ bool pca9505_set_output(uint8_t slave_addr, pca9505_port_t port, uint8_t conf) {
break;
}
i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9505_set_output::FAILED\n");
return false;
@ -156,7 +156,7 @@ bool pca9505_readPins(uint8_t slave_addr, pca9505_port_t port, uint8_t* out) {
break;
}
i2c_status_t ret = i2c_readReg(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9505_readPins::FAILED\n");
return false;

View File

@ -37,7 +37,7 @@ bool pca9555_set_config(uint8_t slave_addr, pca9555_port_t port, uint8_t conf) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_CONFIG_1 : CMD_CONFIG_0;
i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_set_config::FAILED\n");
return false;
@ -50,7 +50,7 @@ bool pca9555_set_output(uint8_t slave_addr, pca9555_port_t port, uint8_t conf) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_OUTPUT_1 : CMD_OUTPUT_0;
i2c_status_t ret = i2c_writeReg(addr, cmd, &conf, sizeof(conf), TIMEOUT);
i2c_status_t ret = i2c_write_register(addr, cmd, &conf, sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_set_output::FAILED\n");
return false;
@ -63,7 +63,7 @@ bool pca9555_set_output_all(uint8_t slave_addr, uint8_t confA, uint8_t confB) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t conf[2] = {confA, confB};
i2c_status_t ret = i2c_writeReg(addr, CMD_OUTPUT_0, &conf[0], sizeof(conf), TIMEOUT);
i2c_status_t ret = i2c_write_register(addr, CMD_OUTPUT_0, &conf[0], sizeof(conf), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
dprintf("pca9555_set_output::FAILED::%u\n", ret);
return false;
@ -76,7 +76,7 @@ bool pca9555_readPins(uint8_t slave_addr, pca9555_port_t port, uint8_t* out) {
uint8_t addr = SLAVE_TO_ADDR(slave_addr);
uint8_t cmd = port ? CMD_INPUT_1 : CMD_INPUT_0;
i2c_status_t ret = i2c_readReg(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
i2c_status_t ret = i2c_read_register(addr, cmd, out, sizeof(uint8_t), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_readPins::FAILED\n");
return false;
@ -95,7 +95,7 @@ bool pca9555_readPins_all(uint8_t slave_addr, uint16_t* out) {
data16 data = {.u16 = 0};
i2c_status_t ret = i2c_readReg(addr, CMD_INPUT_0, &data.u8[0], sizeof(data), TIMEOUT);
i2c_status_t ret = i2c_read_register(addr, CMD_INPUT_0, &data.u8[0], sizeof(data), TIMEOUT);
if (ret != I2C_STATUS_SUCCESS) {
print("pca9555_readPins_all::FAILED\n");
return false;

View File

@ -29,7 +29,7 @@ void drv2605l_write(uint8_t reg_addr, uint8_t data) {
}
uint8_t drv2605l_read(uint8_t reg_addr) {
i2c_readReg(DRV2605L_I2C_ADDRESS << 1, reg_addr, &drv2605l_read_buffer, 1, 100);
i2c_read_register(DRV2605L_I2C_ADDRESS << 1, reg_addr, &drv2605l_read_buffer, 1, 100);
return drv2605l_read_buffer;
}

View File

@ -253,7 +253,7 @@ __attribute__((weak)) bool oled_send_data(const uint8_t *data, uint16_t size) {
spi_stop();
return true;
#elif defined(OLED_TRANSPORT_I2C)
i2c_status_t status = i2c_writeReg((OLED_DISPLAY_ADDRESS << 1), I2C_DATA, data, size, OLED_I2C_TIMEOUT);
i2c_status_t status = i2c_write_register((OLED_DISPLAY_ADDRESS << 1), I2C_DATA, data, size, OLED_I2C_TIMEOUT);
return (status == I2C_STATUS_SUCCESS);
#endif
}

View File

@ -107,18 +107,18 @@ static struct {
i2c_status_t azoteq_iqs5xx_wake(void) {
uint8_t data = 0;
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PREVIOUS_CYCLE_TIME, (uint8_t *)&data, sizeof(data), 1);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PREVIOUS_CYCLE_TIME, (uint8_t *)&data, sizeof(data), 1);
i2c_stop();
wait_us(150);
return status;
}
i2c_status_t azoteq_iqs5xx_end_session(void) {
const uint8_t END_BYTE = 1; // any data
return i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_END_COMMS, &END_BYTE, 1, AZOTEQ_IQS5XX_TIMEOUT_MS);
return i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_END_COMMS, &END_BYTE, 1, AZOTEQ_IQS5XX_TIMEOUT_MS);
}
i2c_status_t azoteq_iqs5xx_get_base_data(azoteq_iqs5xx_base_data_t *base_data) {
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PREVIOUS_CYCLE_TIME, (uint8_t *)base_data, 10, AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PREVIOUS_CYCLE_TIME, (uint8_t *)base_data, 10, AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
azoteq_iqs5xx_end_session();
}
@ -131,7 +131,7 @@ i2c_status_t azoteq_iqs5xx_get_report_rate(azoteq_iqs5xx_report_rate_t *report_r
return I2C_STATUS_ERROR;
}
uint16_t selected_reg = AZOTEQ_IQS5XX_REG_REPORT_RATE_ACTIVE + (2 * mode);
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, selected_reg, (uint8_t *)report_rate, 2, AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, selected_reg, (uint8_t *)report_rate, 2, AZOTEQ_IQS5XX_TIMEOUT_MS);
if (end_session) {
azoteq_iqs5xx_end_session();
}
@ -147,7 +147,7 @@ i2c_status_t azoteq_iqs5xx_set_report_rate(uint16_t report_rate_ms, azoteq_iqs5x
azoteq_iqs5xx_report_rate_t report_rate = {0};
report_rate.h = (uint8_t)((report_rate_ms >> 8) & 0xFF);
report_rate.l = (uint8_t)(report_rate_ms & 0xFF);
i2c_status_t status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, selected_reg, (uint8_t *)&report_rate, 2, AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, selected_reg, (uint8_t *)&report_rate, 2, AZOTEQ_IQS5XX_TIMEOUT_MS);
if (end_session) {
azoteq_iqs5xx_end_session();
}
@ -156,10 +156,10 @@ i2c_status_t azoteq_iqs5xx_set_report_rate(uint16_t report_rate_ms, azoteq_iqs5x
i2c_status_t azoteq_iqs5xx_set_reati(bool enabled, bool end_session) {
azoteq_iqs5xx_system_config_0_t config = {0};
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
config.reati = enabled;
status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@ -169,7 +169,7 @@ i2c_status_t azoteq_iqs5xx_set_reati(bool enabled, bool end_session) {
i2c_status_t azoteq_iqs5xx_set_event_mode(bool enabled, bool end_session) {
azoteq_iqs5xx_system_config_1_t config = {0};
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
config.event_mode = enabled;
config.touch_event = true;
@ -179,7 +179,7 @@ i2c_status_t azoteq_iqs5xx_set_event_mode(bool enabled, bool end_session) {
config.reati_event = false;
config.alp_prox_event = false;
config.gesture_event = true;
status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONFIG_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_config_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@ -189,7 +189,7 @@ i2c_status_t azoteq_iqs5xx_set_event_mode(bool enabled, bool end_session) {
i2c_status_t azoteq_iqs5xx_set_gesture_config(bool end_session) {
azoteq_iqs5xx_gesture_config_t config = {0};
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SINGLE_FINGER_GESTURES, (uint8_t *)&config, sizeof(azoteq_iqs5xx_gesture_config_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SINGLE_FINGER_GESTURES, (uint8_t *)&config, sizeof(azoteq_iqs5xx_gesture_config_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
pd_dprintf("azo scroll: %d\n", config.multi_finger_gestures.scroll);
if (status == I2C_STATUS_SUCCESS) {
config.single_finger_gestures.single_tap = AZOTEQ_IQS5XX_TAP_ENABLE;
@ -211,7 +211,7 @@ i2c_status_t azoteq_iqs5xx_set_gesture_config(bool end_session) {
config.scroll_initial_distance = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(AZOTEQ_IQS5XX_SCROLL_INITIAL_DISTANCE);
config.zoom_initial_distance = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(AZOTEQ_IQS5XX_ZOOM_INITIAL_DISTANCE);
config.zoom_consecutive_distance = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(AZOTEQ_IQS5XX_ZOOM_CONSECUTIVE_DISTANCE);
status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SINGLE_FINGER_GESTURES, (uint8_t *)&config, sizeof(azoteq_iqs5xx_gesture_config_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SINGLE_FINGER_GESTURES, (uint8_t *)&config, sizeof(azoteq_iqs5xx_gesture_config_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@ -221,7 +221,7 @@ i2c_status_t azoteq_iqs5xx_set_gesture_config(bool end_session) {
i2c_status_t azoteq_iqs5xx_set_xy_config(bool flip_x, bool flip_y, bool switch_xy, bool palm_reject, bool end_session) {
azoteq_iqs5xx_xy_config_0_t config = {0};
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_XY_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_xy_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_XY_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_xy_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
if (flip_x) {
config.flip_x = !config.flip_x;
@ -233,7 +233,7 @@ i2c_status_t azoteq_iqs5xx_set_xy_config(bool flip_x, bool flip_y, bool switch_x
config.switch_xy_axis = !config.switch_xy_axis;
}
config.palm_reject = palm_reject;
status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_XY_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_xy_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_XY_CONFIG_0, (uint8_t *)&config, sizeof(azoteq_iqs5xx_xy_config_0_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@ -243,11 +243,11 @@ i2c_status_t azoteq_iqs5xx_set_xy_config(bool flip_x, bool flip_y, bool switch_x
i2c_status_t azoteq_iqs5xx_reset_suspend(bool reset, bool suspend, bool end_session) {
azoteq_iqs5xx_system_control_1_t config = {0};
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONTROL_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_control_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONTROL_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_control_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
config.reset = reset;
config.suspend = suspend;
status = i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONTROL_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_control_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
status = i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_SYSTEM_CONTROL_1, (uint8_t *)&config, sizeof(azoteq_iqs5xx_system_control_1_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
if (end_session) {
azoteq_iqs5xx_end_session();
@ -260,14 +260,14 @@ void azoteq_iqs5xx_set_cpi(uint16_t cpi) {
azoteq_iqs5xx_resolution_t resolution = {0};
resolution.x_resolution = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(MIN(azoteq_iqs5xx_device_resolution_t.resolution_x, AZOTEQ_IQS5XX_INCH_TO_RESOLUTION_X(cpi)));
resolution.y_resolution = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(MIN(azoteq_iqs5xx_device_resolution_t.resolution_y, AZOTEQ_IQS5XX_INCH_TO_RESOLUTION_Y(cpi)));
i2c_writeReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_X_RESOLUTION, (uint8_t *)&resolution, sizeof(azoteq_iqs5xx_resolution_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_write_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_X_RESOLUTION, (uint8_t *)&resolution, sizeof(azoteq_iqs5xx_resolution_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
}
}
uint16_t azoteq_iqs5xx_get_cpi(void) {
if (azoteq_iqs5xx_product_number != AZOTEQ_IQS5XX_UNKNOWN) {
azoteq_iqs5xx_resolution_t resolution = {0};
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_X_RESOLUTION, (uint8_t *)&resolution, sizeof(azoteq_iqs5xx_resolution_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_X_RESOLUTION, (uint8_t *)&resolution, sizeof(azoteq_iqs5xx_resolution_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
return AZOTEQ_IQS5XX_RESOLUTION_X_TO_INCH(AZOTEQ_IQS5XX_SWAP_H_L_BYTES(resolution.x_resolution));
}
@ -276,7 +276,7 @@ uint16_t azoteq_iqs5xx_get_cpi(void) {
}
uint16_t azoteq_iqs5xx_get_product(void) {
i2c_status_t status = i2c_readReg16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PRODUCT_NUMBER, (uint8_t *)&azoteq_iqs5xx_product_number, sizeof(uint16_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
i2c_status_t status = i2c_read_register16(AZOTEQ_IQS5XX_ADDRESS, AZOTEQ_IQS5XX_REG_PRODUCT_NUMBER, (uint8_t *)&azoteq_iqs5xx_product_number, sizeof(uint16_t), AZOTEQ_IQS5XX_TIMEOUT_MS);
if (status == I2C_STATUS_SUCCESS) {
azoteq_iqs5xx_product_number = AZOTEQ_IQS5XX_SWAP_H_L_BYTES(azoteq_iqs5xx_product_number);
}

View File

@ -14,9 +14,9 @@ extern bool touchpad_init;
void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) {
uint8_t cmdByte = READ_MASK | address; // Form the READ command byte
if (touchpad_init) {
i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT);
if (i2c_readReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
pd_dprintf("error cirque_pinnacle i2c_readReg\n");
i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT);
if (i2c_read_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
pd_dprintf("error cirque_pinnacle i2c_read_register\n");
touchpad_init = false;
}
i2c_stop();
@ -28,8 +28,8 @@ void RAP_Write(uint8_t address, uint8_t data) {
uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
if (touchpad_init) {
if (i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
pd_dprintf("error cirque_pinnacle i2c_writeReg\n");
if (i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
pd_dprintf("error cirque_pinnacle i2c_write_register\n");
touchpad_init = false;
}
i2c_stop();

View File

@ -56,13 +56,13 @@ void pimoroni_trackball_set_cpi(uint16_t cpi) {
void pimoroni_trackball_set_rgbw(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
uint8_t data[4] = {r, g, b, w};
__attribute__((unused)) i2c_status_t status = i2c_writeReg(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LED_RED, data, sizeof(data), PIMORONI_TRACKBALL_TIMEOUT);
__attribute__((unused)) i2c_status_t status = i2c_write_register(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LED_RED, data, sizeof(data), PIMORONI_TRACKBALL_TIMEOUT);
pd_dprintf("Trackball RGBW i2c_status_t: %d\n", status);
}
i2c_status_t read_pimoroni_trackball(pimoroni_data_t* data) {
i2c_status_t status = i2c_readReg(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LEFT, (uint8_t*)data, sizeof(*data), PIMORONI_TRACKBALL_TIMEOUT);
i2c_status_t status = i2c_read_register(PIMORONI_TRACKBALL_ADDRESS << 1, PIMORONI_TRACKBALL_REG_LEFT, (uint8_t*)data, sizeof(*data), PIMORONI_TRACKBALL_TIMEOUT);
#ifdef POINTING_DEVICE_DEBUG
static uint16_t d_timer;

View File

@ -70,7 +70,7 @@ uint8_t init_tca9555(void) {
// This means: we will write on pins 0 to 2 on port 1. read rest
0b11111000,
};
tca9555_status = i2c_writeReg(I2C_ADDR, IODIRA, conf, 2, I2C_TIMEOUT);
tca9555_status = i2c_write_register(I2C_ADDR, IODIRA, conf, 2, I2C_TIMEOUT);
return tca9555_status;
}
@ -189,7 +189,7 @@ static matrix_row_t read_cols(uint8_t row) {
} else {
uint8_t data = 0;
uint8_t ports[2] = {0};
tca9555_status = i2c_readReg(I2C_ADDR, IREGP0, ports, 2, I2C_TIMEOUT);
tca9555_status = i2c_read_register(I2C_ADDR, IREGP0, ports, 2, I2C_TIMEOUT);
if (tca9555_status) { // if there was an error
// do nothing
return 0;
@ -252,7 +252,7 @@ static void select_row(uint8_t row) {
}
uint8_t ports[2] = {port0, port1};
tca9555_status = i2c_writeReg(I2C_ADDR, OREGP0, ports, 2, I2C_TIMEOUT);
tca9555_status = i2c_write_register(I2C_ADDR, OREGP0, ports, 2, I2C_TIMEOUT);
// Select the desired row by writing a byte for the entire GPIOB bus where only the bit representing the row we want to select is a zero (write instruction) and every other bit is a one.
// Note that the row - MATRIX_ROWS_PER_SIDE reflects the fact that being on the right hand, the columns are numbered from MATRIX_ROWS_PER_SIDE to MATRIX_ROWS, but the pins we want to write to are indexed from zero up on the GPIOB bus.
}

View File

@ -120,7 +120,7 @@ bool pointing_device_task(void) {
static uint16_t debounce_timer;
uint8_t state[5] = {};
if (timer_elapsed(i2c_timeout_timer) > I2C_WAITCHECK) {
if (i2c_readReg(TRACKBALL_WRITE, 0x04, state, 5, I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
if (i2c_read_register(TRACKBALL_WRITE, 0x04, state, 5, I2C_TIMEOUT) == I2C_STATUS_SUCCESS) {
if (!state[4] && !debounce) {
if (scrolling) {
#ifdef PIMORONI_TRACKBALL_INVERT_X

View File

@ -70,7 +70,7 @@ uint8_t init_tca9555(void) {
// This means: we will write on pins 0 to 3 on port 1. read rest
0b11110000,
};
tca9555_status = i2c_writeReg(I2C_ADDR, IODIRA, conf, 2, I2C_TIMEOUT);
tca9555_status = i2c_write_register(I2C_ADDR, IODIRA, conf, 2, I2C_TIMEOUT);
return tca9555_status;
}
@ -189,7 +189,7 @@ static matrix_row_t read_cols(uint8_t row) {
} else {
uint8_t data = 0;
uint8_t port0 = 0;
tca9555_status = i2c_readReg(I2C_ADDR, IREGP0, &port0, 1, I2C_TIMEOUT);
tca9555_status = i2c_read_register(I2C_ADDR, IREGP0, &port0, 1, I2C_TIMEOUT);
if (tca9555_status) { // if there was an error
// do nothing
return 0;
@ -250,7 +250,7 @@ static void select_row(uint8_t row) {
default: break;
}
tca9555_status = i2c_writeReg(I2C_ADDR, OREGP1, &port1, 1, I2C_TIMEOUT);
tca9555_status = i2c_write_register(I2C_ADDR, OREGP1, &port1, 1, I2C_TIMEOUT);
// Select the desired row by writing a byte for the entire GPIOB bus where only the bit representing the row we want to select is a zero (write instruction) and every other bit is a one.
// Note that the row - MATRIX_ROWS_PER_SIDE reflects the fact that being on the right hand, the columns are numbered from MATRIX_ROWS_PER_SIDE to MATRIX_ROWS, but the pins we want to write to are indexed from zero up on the GPIOB bus.
}

View File

@ -78,9 +78,9 @@ static void init_pins(void) {
unselect_rows();
// Set I/O
uint8_t send_data = 0xFF;
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data, 1, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data, 1, 20);
// Set Pull-up
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x06, &send_data, 1, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x06, &send_data, 1, 20);
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
if (col_pins[x] != NO_PIN) {
@ -111,7 +111,7 @@ static bool matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t curre
matrix_output_select_delay();
uint8_t port_expander_buffer;
i2c_readReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &port_expander_buffer, 1, 20);
i2c_read_register((PORT_EXPANDER_ADDRESS << 1), 0x09, &port_expander_buffer, 1, 20);
// For each col...
// matrix_row_t row_shifter = MATRIX_ROW_SHIFTER;

View File

@ -42,9 +42,9 @@ static void init_pins(void) {
unselect_rows();
// Set I/O
uint8_t send_data[2] = { 0xFF, 0x03};
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data[0], 2, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data[0], 2, 20);
// Set Pull-up
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x0C, &send_data[0], 2, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x0C, &send_data[0], 2, 20);
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
if ( x < 8 ) {
@ -75,7 +75,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
matrix_io_delay();
uint8_t port_expander_col_buffer[2];
i2c_readReg((PORT_EXPANDER_ADDRESS << 1), 0x12, &port_expander_col_buffer[0], 2, 20);
i2c_read_register((PORT_EXPANDER_ADDRESS << 1), 0x12, &port_expander_col_buffer[0], 2, 20);
// For each col...
for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {

View File

@ -59,16 +59,16 @@ uint8_t init_mcp23017(void) {
uint8_t data[2];
data[0] = 0x0;
data[1] = 0b00111111;
mcp23017_status = i2c_writeReg(I2C_ADDR, I2C_IODIRA, data, 2, 50000);
mcp23017_status = i2c_write_register(I2C_ADDR, I2C_IODIRA, data, 2, 50000);
if (mcp23017_status) goto out;
data[0] = 0xFFU;
mcp23017_status = i2c_writeReg(I2C_ADDR, I2C_GPIOA, data, 1, 5000);
mcp23017_status = i2c_write_register(I2C_ADDR, I2C_GPIOA, data, 1, 5000);
if (mcp23017_status) goto out;
mcp23017_status = i2c_writeReg(I2C_ADDR, I2C_GPPUB, data+1, 1, 2);
mcp23017_status = i2c_write_register(I2C_ADDR, I2C_GPPUB, data+1, 1, 2);
if (mcp23017_status) goto out;
out:
return mcp23017_status;
// i2c_readReg(I2C_ADDR, );
// i2c_read_register(I2C_ADDR, );
}

View File

@ -134,7 +134,7 @@ static matrix_row_t read_cols(uint8_t row) {
uint8_t data = 0xFF;
if (!mcp23017_status) {
uint8_t regAddr = I2C_GPIOB;
mcp23017_status = i2c_readReg(I2C_ADDR, regAddr, &data, 1, 10);
mcp23017_status = i2c_read_register(I2C_ADDR, regAddr, &data, 1, 10);
}
if (mcp23017_status) {
return 0;
@ -174,7 +174,7 @@ static void select_row(uint8_t row) {
if (row < MATRIX_ROWS_PER_SIDE) {
if (!mcp23017_status) {
uint8_t data = (0xFF & ~(1 << row));
mcp23017_status = i2c_writeReg(I2C_ADDR, I2C_GPIOA, &data, 1, 10);
mcp23017_status = i2c_write_register(I2C_ADDR, I2C_GPIOA, &data, 1, 10);
}
} else {
GPIOB->BRR = 0x1 << (row+1);

View File

@ -35,18 +35,18 @@ void ad5258_init(void) {
uint8_t ad5258_read_rdac(void) {
// read RDAC register
uint8_t ret = 0;
i2c_readReg(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &ret, 1, 100);
i2c_read_register(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &ret, 1, 100);
return ret;
}
uint8_t ad5258_read_eeprom(void) {
uint8_t ret = 0;
i2c_readReg(AD5258_I2C_ADDRESS, AD5258_INST_EEPROM, &ret, 1, 100);
i2c_read_register(AD5258_I2C_ADDRESS, AD5258_INST_EEPROM, &ret, 1, 100);
return ret;
}
void ad5258_write_rdac(uint8_t rdac) {
// write RDAC register:
uint8_t data = rdac & 0x3F;
i2c_writeReg(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &data, 1, 100);
i2c_write_register(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &data, 1, 100);
}

View File

@ -35,18 +35,18 @@ void ad5258_init(void) {
uint8_t ad5258_read_rdac(void) {
// read RDAC register
uint8_t ret = 0;
i2c_readReg(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &ret, 1, 100);
i2c_read_register(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &ret, 1, 100);
return ret;
}
uint8_t ad5258_read_eeprom(void) {
uint8_t ret = 0;
i2c_readReg(AD5258_I2C_ADDRESS, AD5258_INST_EEPROM, &ret, 1, 100);
i2c_read_register(AD5258_I2C_ADDRESS, AD5258_INST_EEPROM, &ret, 1, 100);
return ret;
}
void ad5258_write_rdac(uint8_t rdac) {
// write RDAC register:
uint8_t data = rdac & 0x3F;
i2c_writeReg(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &data, 1, 100);
i2c_write_register(AD5258_I2C_ADDRESS, AD5258_INST_RDAC, &data, 1, 100);
}

View File

@ -45,10 +45,10 @@ void matrix_init_custom(void) {
uint8_t pullup[2] = {0, expander_input_mask};
for (uint8_t i = 0; i < 2; ++i) {
expander_status = i2c_writeReg(i2c_addr[i], IODIRA, direction, 2, I2C_TIMEOUT);
expander_status = i2c_write_register(i2c_addr[i], IODIRA, direction, 2, I2C_TIMEOUT);
if (expander_status) return;
expander_status = i2c_writeReg(i2c_addr[i], GPPUA, pullup, 2, I2C_TIMEOUT);
expander_status = i2c_write_register(i2c_addr[i], GPPUA, pullup, 2, I2C_TIMEOUT);
}
}
@ -79,7 +79,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
// On both expanders: select col and read rows
for (size_t i = 0; i < 2; ++i) {
if (!expander_status) {
expander_status = i2c_writeReg(i2c_addr[i], EXPANDER_COL_REGISTER, &port, 1, I2C_TIMEOUT);
expander_status = i2c_write_register(i2c_addr[i], EXPANDER_COL_REGISTER, &port, 1, I2C_TIMEOUT);
}
wait_us(30);
@ -87,7 +87,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
return false;
}
expander_status = i2c_readReg(i2c_addr[i], EXPANDER_ROW_REGISTER, &column_state[i], 1, I2C_TIMEOUT);
expander_status = i2c_read_register(i2c_addr[i], EXPANDER_ROW_REGISTER, &column_state[i], 1, I2C_TIMEOUT);
column_state[i] = (~column_state[i]) & ((1 << MATRIX_ROWS_PER_SIDE) - 1);
}

View File

@ -8,12 +8,12 @@ void ds1307_set_time(uint8_t h, uint8_t m, uint8_t s) {
((h % 10) | ((h / 10) << 4)) & 0x3F,
0, 0, 0, 0, 0
}; // 24-hour mode
i2c_writeReg(DS1307_ADDR, 0, data, 8, 100);
i2c_write_register(DS1307_ADDR, 0, data, 8, 100);
}
void ds1307_get_time(uint8_t *h, uint8_t *m, uint8_t *s) {
uint8_t data[3];
i2c_readReg(DS1307_ADDR, 0, data, 3, 100);
i2c_read_register(DS1307_ADDR, 0, data, 3, 100);
i2c_stop();
*s = (data[0] & 0b1111) + ((data[0] & 0b1110000) >> 4) * 10;
*m = (data[1] & 0b1111) + ((data[1] & 0b1110000) >> 4) * 10;

View File

@ -216,10 +216,10 @@ void init_expander(void) {
#endif
expander_status = i2c_writeReg(I2C_ADDR, IODIRA, direction, 2, I2C_TIMEOUT);
expander_status = i2c_write_register(I2C_ADDR, IODIRA, direction, 2, I2C_TIMEOUT);
if (expander_status) return;
expander_status = i2c_writeReg(I2C_ADDR, GPPUA, pullup, 2, I2C_TIMEOUT);
expander_status = i2c_write_register(I2C_ADDR, GPPUA, pullup, 2, I2C_TIMEOUT);
}
uint8_t matrix_scan(void)
@ -333,7 +333,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
// Read columns from expander, unless it's in an error state
if (! expander_status) {
uint8_t state = 0;
expander_status = i2c_readReg(I2C_ADDR, EXPANDER_COL_REGISTER, &state, 1, I2C_TIMEOUT);
expander_status = i2c_read_register(I2C_ADDR, EXPANDER_COL_REGISTER, &state, 1, I2C_TIMEOUT);
if (! expander_status) {
current_matrix[current_row] |= (~state) & expander_input_pin_mask;
}
@ -359,7 +359,7 @@ static void select_row(uint8_t row) {
// set active row low : 0
// set other rows hi-Z : 1
uint8_t port = 0xFF & ~(1<<row);
expander_status = i2c_writeReg(I2C_ADDR, EXPANDER_ROW_REGISTER, &port, 1, I2C_TIMEOUT);
expander_status = i2c_write_register(I2C_ADDR, EXPANDER_ROW_REGISTER, &port, 1, I2C_TIMEOUT);
}
// select on teensy
@ -415,7 +415,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
return false;
}
expander_status = i2c_readReg(I2C_ADDR, EXPANDER_ROW_REGISTER, &column_state, 1, I2C_TIMEOUT);
expander_status = i2c_read_register(I2C_ADDR, EXPANDER_ROW_REGISTER, &column_state, 1, I2C_TIMEOUT);
column_state = ~column_state;
} else {
@ -460,7 +460,7 @@ static void select_col(uint8_t col)
// set active col low : 0
// set other cols hi-Z : 1
uint8_t port = 0xFF & ~(1<<col);
expander_status = i2c_writeReg(I2C_ADDR, EXPANDER_COL_REGISTER, &port, 1, I2C_TIMEOUT);
expander_status = i2c_write_register(I2C_ADDR, EXPANDER_COL_REGISTER, &port, 1, I2C_TIMEOUT);
}
} else {
// select on teensy

View File

@ -14,7 +14,7 @@ i2c_status_t i2c_start_bodge(uint8_t address, uint16_t timeout) {
// except on ChibiOS where the only way is do do "something"
uint8_t data = 0;
return i2c_readReg(address, 0, &data, sizeof(data), TIMEOUT);
return i2c_read_register(address, 0, &data, sizeof(data), TIMEOUT);
}
# define i2c_start i2c_start_bodge

View File

@ -69,8 +69,8 @@ static void board_set_slave_led(board_info_t* board, uint8_t led_index, bool sta
board->led_status[led_index] = status;
uint8_t iodir = board_merge_led_config(board, 0xff);
uint8_t data = board_merge_led_status(board, 0x00);
i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRB, (const uint8_t*)&iodir, sizeof(iodir), BOARD_I2C_TIMEOUT);
i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_OLATB, (const uint8_t*)&data, sizeof(data), BOARD_I2C_TIMEOUT);
i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRB, (const uint8_t*)&iodir, sizeof(iodir), BOARD_I2C_TIMEOUT);
i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_OLATB, (const uint8_t*)&data, sizeof(data), BOARD_I2C_TIMEOUT);
}
static uint8_t board_merge_led_config(board_info_t* board, uint8_t iodir) {
@ -86,30 +86,30 @@ static bool board_slave_config(board_info_t* board) {
i2c_status_t res = 0;
// Set to input
res = i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRA, (const uint8_t*)&set, sizeof(set), BOARD_I2C_TIMEOUT);
res = i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRA, (const uint8_t*)&set, sizeof(set), BOARD_I2C_TIMEOUT);
if (res < 0) return false;
// RESTRICTION: LEDs only on PORT B.
set = board_merge_led_config(board, set);
res = i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRB, (const uint8_t*)&set, sizeof(set), BOARD_I2C_TIMEOUT);
res = i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRB, (const uint8_t*)&set, sizeof(set), BOARD_I2C_TIMEOUT);
if (res < 0) return false;
set = 0xff;
// Pull up for input - enable
res = i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPPUA, (const uint8_t*)&set, sizeof(set), BOARD_I2C_TIMEOUT);
res = i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPPUA, (const uint8_t*)&set, sizeof(set), BOARD_I2C_TIMEOUT);
if (res < 0) return false;
res = i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPPUB, (const uint8_t*)&set, sizeof(set), BOARD_I2C_TIMEOUT);
res = i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPPUB, (const uint8_t*)&set, sizeof(set), BOARD_I2C_TIMEOUT);
if (res < 0) return false;
// Disable interrupt
res = i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPINTENA, (const uint8_t*)&clear, sizeof(clear), BOARD_I2C_TIMEOUT);
res = i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPINTENA, (const uint8_t*)&clear, sizeof(clear), BOARD_I2C_TIMEOUT);
if (res < 0) return false;
res = i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPINTENB, (const uint8_t*)&clear, sizeof(clear), BOARD_I2C_TIMEOUT);
res = i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPINTENB, (const uint8_t*)&clear, sizeof(clear), BOARD_I2C_TIMEOUT);
if (res < 0) return false;
// Polarity - same logic
res = i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_IPOLA, (const uint8_t*)&clear, sizeof(clear), BOARD_I2C_TIMEOUT);
res = i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_IPOLA, (const uint8_t*)&clear, sizeof(clear), BOARD_I2C_TIMEOUT);
if (res < 0) return false;
res = i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_IPOLB, (const uint8_t*)&clear, sizeof(clear), BOARD_I2C_TIMEOUT);
res = i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_IPOLB, (const uint8_t*)&clear, sizeof(clear), BOARD_I2C_TIMEOUT);
if (res < 0) return false;
return true;
@ -203,7 +203,7 @@ static uint8_t board_read_slave_cols(board_info_t* board) {
return 0xff;
}
uint8_t data = 0xff;
i2c_status_t res = i2c_readReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPIOA, &data, sizeof(data), BOARD_I2C_TIMEOUT);
i2c_status_t res = i2c_read_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_GPIOA, &data, sizeof(data), BOARD_I2C_TIMEOUT);
return (res < 0) ? 0xff : data;
}
@ -214,8 +214,8 @@ static void board_select_slave_row(board_info_t* board, uint8_t board_row) {
uint8_t pin = board->row_pins[board_row];
uint8_t iodir = board_merge_led_config(board, PIN2MASK(pin));
uint8_t status = board_merge_led_status(board, PIN2MASK(pin));
i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRB, (const uint8_t*)&iodir, sizeof(iodir), BOARD_I2C_TIMEOUT);
i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_OLATB, (const uint8_t*)&status, sizeof(status), BOARD_I2C_TIMEOUT);
i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRB, (const uint8_t*)&iodir, sizeof(iodir), BOARD_I2C_TIMEOUT);
i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_OLATB, (const uint8_t*)&status, sizeof(status), BOARD_I2C_TIMEOUT);
}
static void board_unselect_slave_rows(board_info_t* board) {
@ -224,8 +224,8 @@ static void board_unselect_slave_rows(board_info_t* board) {
}
uint8_t iodir = board_merge_led_config(board, 0xff);
uint8_t data = board_merge_led_status(board, 0x00);
i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRB, (const uint8_t*)&iodir, sizeof(iodir), BOARD_I2C_TIMEOUT);
i2c_writeReg(EXPANDER_ADDR(board->i2c_address), EXPANDER_OLATB, (const uint8_t*)&data, sizeof(data), BOARD_I2C_TIMEOUT);
i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_IODIRB, (const uint8_t*)&iodir, sizeof(iodir), BOARD_I2C_TIMEOUT);
i2c_write_register(EXPANDER_ADDR(board->i2c_address), EXPANDER_OLATB, (const uint8_t*)&data, sizeof(data), BOARD_I2C_TIMEOUT);
}
static void board_unselect_slave_row(board_info_t* board, uint8_t board_row) { board_unselect_slave_rows(board); }

View File

@ -51,15 +51,15 @@ void aw9523b_init(uint8_t addr)
i2c_init();
// reset chip
uint8_t data = 0;
i2c_writeReg(addr, AW9523B_RESET, &data, 1, TIMEOUT);
i2c_write_register(addr, AW9523B_RESET, &data, 1, TIMEOUT);
wait_ms(1);
// set max led current
data = 0x03; // 37mA/4
i2c_writeReg(addr, AW9523B_CTL, &data, 1, TIMEOUT);
i2c_write_register(addr, AW9523B_CTL, &data, 1, TIMEOUT);
// set port to led mode
data = 0;
i2c_writeReg(addr, AW9523B_P0_LED, &data, 1, TIMEOUT);
i2c_writeReg(addr, AW9523B_P1_LED, &data, 1, TIMEOUT);
i2c_write_register(addr, AW9523B_P0_LED, &data, 1, TIMEOUT);
i2c_write_register(addr, AW9523B_P1_LED, &data, 1, TIMEOUT);
// clear pwm buff
for (uint8_t i = 0; i < 16; i++) {
aw9523b_pwm_buf[i] = 0;
@ -91,9 +91,9 @@ void aw9523b_update_pwm_buffers(uint8_t addr)
if (aw9523b_pwm_dirty) {
for (uint8_t i = 0; i < AW9523B_RGB_NUM; i++){
aw9523b_led led = g_aw9523b_leds[i];
i2c_writeReg(addr, led.r, &aw9523b_pwm_buf[PWM2BUF(led.r)], 1, TIMEOUT);
i2c_writeReg(addr, led.g, &aw9523b_pwm_buf[PWM2BUF(led.g)], 1, TIMEOUT);
i2c_writeReg(addr, led.b, &aw9523b_pwm_buf[PWM2BUF(led.b)], 1, TIMEOUT);
i2c_write_register(addr, led.r, &aw9523b_pwm_buf[PWM2BUF(led.r)], 1, TIMEOUT);
i2c_write_register(addr, led.g, &aw9523b_pwm_buf[PWM2BUF(led.g)], 1, TIMEOUT);
i2c_write_register(addr, led.b, &aw9523b_pwm_buf[PWM2BUF(led.b)], 1, TIMEOUT);
}
aw9523b_pwm_dirty = false;
}

View File

@ -47,13 +47,13 @@ void tca6424_init(void)
static void write_port(uint8_t p, uint8_t d)
{
i2c_writeReg(TCA6424_ADDR, p, &d, 1, TIMEOUT);
i2c_write_register(TCA6424_ADDR, p, &d, 1, TIMEOUT);
}
static uint8_t read_port(uint8_t port)
{
uint8_t data = 0;
i2c_readReg(TCA6424_ADDR, port, &data, 1, TIMEOUT);
i2c_read_register(TCA6424_ADDR, port, &data, 1, TIMEOUT);
return data;
}

View File

@ -45,13 +45,13 @@ void tca6424_init(void)
static void write_port(uint8_t p, uint8_t d)
{
i2c_writeReg(TCA6424_ADDR, p, &d, 1, TIMEOUT);
i2c_write_register(TCA6424_ADDR, p, &d, 1, TIMEOUT);
}
static uint8_t read_port(uint8_t port)
{
uint8_t data = 0;
i2c_readReg(TCA6424_ADDR, port, &data, 1, TIMEOUT);
i2c_read_register(TCA6424_ADDR, port, &data, 1, TIMEOUT);
return data;
}

View File

@ -102,9 +102,9 @@ static int32_t t_fine;
static void readTrim(void) {
uint8_t data[32];
i2c_readReg(BME280_ADDRESS, BME280_REG_CALIB00, &data[0], 24, I2C_BME280_TIMEOUT);
i2c_readReg(BME280_ADDRESS, BME280_REG_CALIB25, &data[25], 1, I2C_BME280_TIMEOUT);
i2c_readReg(BME280_ADDRESS, BME280_REG_CALIB26, &data[25], 7, I2C_BME280_TIMEOUT);
i2c_read_register(BME280_ADDRESS, BME280_REG_CALIB00, &data[0], 24, I2C_BME280_TIMEOUT);
i2c_read_register(BME280_ADDRESS, BME280_REG_CALIB25, &data[25], 1, I2C_BME280_TIMEOUT);
i2c_read_register(BME280_ADDRESS, BME280_REG_CALIB26, &data[25], 7, I2C_BME280_TIMEOUT);
dig_T1 = (data[1] << 8) | data[0];
dig_T2 = (data[3] << 8) | data[2];
@ -131,7 +131,7 @@ static void readTrim(void) {
static void readData(void) {
uint8_t data[8];
i2c_readReg(BME280_ADDRESS, 0xF7, &data[0], 8, I2C_BME280_TIMEOUT);
i2c_read_register(BME280_ADDRESS, 0xF7, &data[0], 8, I2C_BME280_TIMEOUT);
pres_raw = data[0];
pres_raw = (pres_raw<<8) | data[1];
@ -210,9 +210,9 @@ void bme280_init(void) {
config_reg = BME280_CONFIG_VAL;
i2c_init();
i2c_writeReg(BME280_ADDRESS, BME280_REG_CTRL_HUM, &ctrl_hum_reg, 1, I2C_BME280_TIMEOUT);
i2c_writeReg(BME280_ADDRESS, BME280_REG_CTRL_MEAS, &ctrl_meas_reg, 1, I2C_BME280_TIMEOUT);
i2c_writeReg(BME280_ADDRESS, BME280_REG_CONFIG, &config_reg, 1, I2C_BME280_TIMEOUT);
i2c_write_register(BME280_ADDRESS, BME280_REG_CTRL_HUM, &ctrl_hum_reg, 1, I2C_BME280_TIMEOUT);
i2c_write_register(BME280_ADDRESS, BME280_REG_CTRL_MEAS, &ctrl_meas_reg, 1, I2C_BME280_TIMEOUT);
i2c_write_register(BME280_ADDRESS, BME280_REG_CONFIG, &config_reg, 1, I2C_BME280_TIMEOUT);
readTrim();
return;

View File

@ -125,7 +125,7 @@ bool touch_slave_init = false;
slave_touch_status_t touch_slave_state = { 0, 0 };
static bool write_register8(uint8_t address, uint8_t data) {
i2c_status_t status = i2c_writeReg((I2C_ADDRESS << 1), address, &data, sizeof(data), I2C_TIMEOUT);
i2c_status_t status = i2c_write_register((I2C_ADDRESS << 1), address, &data, sizeof(data), I2C_TIMEOUT);
if (status != I2C_STATUS_SUCCESS) {
xprintf("write_register8 %d failed %d\n", address, status);
}
@ -133,7 +133,7 @@ static bool write_register8(uint8_t address, uint8_t data) {
}
static bool read_register(uint8_t address, uint8_t* data, uint16_t length) {
i2c_status_t status = i2c_readReg((I2C_ADDRESS << 1), address, data, length, I2C_TIMEOUT);
i2c_status_t status = i2c_read_register((I2C_ADDRESS << 1), address, data, length, I2C_TIMEOUT);
if (status != I2C_STATUS_SUCCESS) {
xprintf("read_register %d failed %d\n", address, status);
return false;

View File

@ -214,7 +214,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
return 0;
} else {
uint8_t data = 0;
mcp23018_status = i2c_readReg(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
mcp23018_status = i2c_read_register(I2C_ADDR, GPIOA, &data, 1, I2C_TIMEOUT);
if (!mcp23018_status) {
current_matrix[current_row] |= (~((uint16_t)data) << 8);
}
@ -245,7 +245,7 @@ static void select_row(uint8_t row)
set active row output : 1
set other rows hi-Z : 1 */
uint8_t port = 0xFF & ~(1<<abs(row-4));
mcp23018_status = i2c_writeReg(I2C_ADDR, GPIOB, &port, 1, I2C_TIMEOUT);
mcp23018_status = i2c_write_register(I2C_ADDR, GPIOB, &port, 1, I2C_TIMEOUT);
}
uint8_t pin = row_pins[row];

View File

@ -27,9 +27,9 @@ uint8_t init_mcp23018(void) {
0b00000000,
};
mcp23018_status = i2c_writeReg(I2C_ADDR, IODIRA, direction, 2, I2C_TIMEOUT);
mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, direction, 2, I2C_TIMEOUT);
if (mcp23018_status) return mcp23018_status;
mcp23018_status = i2c_writeReg(I2C_ADDR, GPPUA, pullup, 2, I2C_TIMEOUT);
mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, pullup, 2, I2C_TIMEOUT);
return mcp23018_status;
}

View File

@ -354,7 +354,7 @@ i2c_status_t ptn5110_init(struct PTN5110* self) {
// Read PTN5110 CC_STATUS.
// Returns zero on success or a negative number on error.
i2c_status_t ptn5110_get_cc_status(struct PTN5110* self, uint8_t* cc) { return i2c_readReg(self->addr << 1, 0x1D, cc, 1, I2C_TIMEOUT); }
i2c_status_t ptn5110_get_cc_status(struct PTN5110* self, uint8_t* cc) { return i2c_read_register(self->addr << 1, 0x1D, cc, 1, I2C_TIMEOUT); }
// Set PTN5110 SSMUX orientation.
// Returns zero on success or a negative number on error.
@ -362,7 +362,7 @@ i2c_status_t ptn5110_set_ssmux(struct PTN5110* self, bool orientation) { return
// Write PTN5110 COMMAND.
// Returns zero on success or negative number on error.
i2c_status_t ptn5110_command(struct PTN5110* self, uint8_t command) { return i2c_writeReg(self->addr << 1, 0x23, &command, 1, I2C_TIMEOUT); }
i2c_status_t ptn5110_command(struct PTN5110* self, uint8_t command) { return i2c_write_register(self->addr << 1, 0x23, &command, 1, I2C_TIMEOUT); }
// Set orientation of PTN5110 operating as a sink, call this once.
// Returns zero on success or a negative number on error.

View File

@ -48,7 +48,7 @@ i2c_status_t mcp23018_writeReg(uint8_t regaddr, const uint8_t* data, uint16_t le
return mcp23018_status;
}
mcp23018_status = i2c_writeReg((MCP23018_ADDR << 1), regaddr, data, length, MCP23018_TIMEOUT);
mcp23018_status = i2c_write_register((MCP23018_ADDR << 1), regaddr, data, length, MCP23018_TIMEOUT);
return mcp23018_status;
}
@ -57,6 +57,6 @@ i2c_status_t mcp23018_readReg(uint8_t regaddr, uint8_t* data, uint16_t length) {
return mcp23018_status;
}
mcp23018_status = i2c_readReg((MCP23018_ADDR << 1), regaddr, data, length, MCP23018_TIMEOUT);
mcp23018_status = i2c_read_register((MCP23018_ADDR << 1), regaddr, data, length, MCP23018_TIMEOUT);
return mcp23018_status;
}

View File

@ -38,7 +38,7 @@ volatile uint8_t LEDs[6][6] = {{0}};//Stores current LED values
//Read data from the cap touch IC
uint8_t readDataFromTS(uint8_t reg) {
uint8_t rx[1] = { 0 };
if (i2c_readReg(0x1C << 1, reg, rx, 1, 100) == 0) {
if (i2c_read_register(0x1C << 1, reg, rx, 1, 100) == 0) {
return rx[0];
}
return 0;

View File

@ -42,9 +42,9 @@ static void init_pins(void) {
unselect_rows();
// Set I/O
uint8_t send_data[2] = { 0xFF, 0x03};
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data[0], 2, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data[0], 2, 20);
// Set Pull-up
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x0C, &send_data[0], 2, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x0C, &send_data[0], 2, 20);
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
if ( x < 8 ) {
@ -75,7 +75,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
matrix_io_delay();
uint8_t port_expander_col_buffer[2];
i2c_readReg((PORT_EXPANDER_ADDRESS << 1), 0x12, &port_expander_col_buffer[0], 2, 20);
i2c_read_register((PORT_EXPANDER_ADDRESS << 1), 0x12, &port_expander_col_buffer[0], 2, 20);
// For each col...
for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {

View File

@ -22,7 +22,7 @@ void matrix_init_kb(void) {
// Due to the way the port expander is setup both LEDs are already outputs. This is set n matrix.copy
//Turn the red LED on as power indicator.
send_data = 0x10;
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &send_data, 1, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x09, &send_data, 1, 20);
matrix_init_user();
}
@ -31,7 +31,7 @@ bool led_update_kb(led_t led_state) {
bool res = led_update_user(led_state);
if(res) {
send_data = led_state.caps_lock ? 0x18 : 0x10;
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &send_data, 1, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x09, &send_data, 1, 20);
}
return res;
}

View File

@ -42,9 +42,9 @@ static void init_pins(void) {
unselect_rows();
// Set I/O
uint8_t send_data = 0x07;
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data, 1, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data, 1, 20);
// Set Pull-up
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x06, &send_data, 1, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x06, &send_data, 1, 20);
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
if ( (x > 0) && (x < 12) ) {
@ -80,15 +80,15 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
// Select the col pin to read (active low)
switch (col_index) {
case 0 :
i2c_readReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &pin_state, 1, 20);
i2c_read_register((PORT_EXPANDER_ADDRESS << 1), 0x09, &pin_state, 1, 20);
pin_state = pin_state & 0x01;
break;
case 12 :
i2c_readReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &pin_state, 1, 20);
i2c_read_register((PORT_EXPANDER_ADDRESS << 1), 0x09, &pin_state, 1, 20);
pin_state = pin_state & (1 << 2);
break;
case 13 :
i2c_readReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &pin_state, 1, 20);
i2c_read_register((PORT_EXPANDER_ADDRESS << 1), 0x09, &pin_state, 1, 20);
pin_state = pin_state & (1 << 1);
break;
default :

View File

@ -42,9 +42,9 @@ static void init_pins(void) {
unselect_rows();
// Set I/O
uint8_t send_data = 0x1F;
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data, 1, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x00, &send_data, 1, 20);
// Set Pull-up
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x06, &send_data, 1, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x06, &send_data, 1, 20);
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
if ( x < 10 ) {
@ -75,7 +75,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
matrix_io_delay();
uint8_t port_expander_col_buffer;
i2c_readReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &port_expander_col_buffer, 1, 20);
i2c_read_register((PORT_EXPANDER_ADDRESS << 1), 0x09, &port_expander_col_buffer, 1, 20);
// For each col...
for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {

View File

@ -26,7 +26,7 @@ void led_update_ports(led_t led_state) {
} else {
send_data &= ~(1 << 5);
}
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x0A, &send_data, 1, 20);
i2c_write_register((PORT_EXPANDER_ADDRESS << 1), 0x0A, &send_data, 1, 20);
}
__attribute__((weak)) layer_state_t layer_state_set_user(layer_state_t state) {

View File

@ -144,7 +144,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
// read col
mcp23018_tx[0] = 0x13; // GPIOB
if (MSG_OK != i2c_readReg(MCP23018_DEFAULT_ADDRESS << 1, mcp23018_tx[0], &mcp23018_rx[0], 1, MOONLANDER_I2C_TIMEOUT)) {
if (MSG_OK != i2c_read_register(MCP23018_DEFAULT_ADDRESS << 1, mcp23018_tx[0], &mcp23018_rx[0], 1, MOONLANDER_I2C_TIMEOUT)) {
dprintf("error vert\n");
mcp23018_initd = false;
}

View File

@ -189,7 +189,7 @@ i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16
return (status < 0) ? status : I2C_STATUS_SUCCESS;
}
i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t i2c_write_register(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t status = i2c_start(devaddr | 0x00, timeout);
if (status >= 0) {
status = i2c_write(regaddr, timeout);
@ -204,7 +204,7 @@ i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data,
return status;
}
i2c_status_t i2c_writeReg16(uint8_t devaddr, uint16_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t i2c_write_register16(uint8_t devaddr, uint16_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t status = i2c_start(devaddr | 0x00, timeout);
if (status >= 0) {
status = i2c_write(regaddr >> 8, timeout);
@ -223,7 +223,7 @@ i2c_status_t i2c_writeReg16(uint8_t devaddr, uint16_t regaddr, const uint8_t* da
return status;
}
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t i2c_read_register(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t status = i2c_start(devaddr, timeout);
if (status < 0) {
goto error;
@ -256,7 +256,7 @@ error:
return (status < 0) ? status : I2C_STATUS_SUCCESS;
}
i2c_status_t i2c_readReg16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t i2c_read_register16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t status = i2c_start(devaddr, timeout);
if (status < 0) {
goto error;

View File

@ -21,6 +21,13 @@
#include <stdint.h>
// ### DEPRECATED - DO NOT USE ###
#define i2c_writeReg(devaddr, regaddr, data, length, timeout) i2c_write_register(devaddr, regaddr, data, length, timeout)
#define i2c_writeReg16(devaddr, regaddr, data, length, timeout) i2c_write_register16(devaddr, regaddr, data, length, timeout)
#define i2c_readReg(devaddr, regaddr, data, length, timeout) i2c_read_register(devaddr, regaddr, data, length, timeout)
#define i2c_readReg16(devaddr, regaddr, data, length, timeout) i2c_read_register16(devaddr, regaddr, data, length, timeout)
// ###############################
#define I2C_READ 0x01
#define I2C_WRITE 0x00
@ -40,8 +47,8 @@ int16_t i2c_read_ack(uint16_t timeout);
int16_t i2c_read_nack(uint16_t timeout);
i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_writeReg16(uint8_t devaddr, uint16_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_readReg16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_write_register(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_write_register16(uint8_t devaddr, uint16_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_read_register(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_read_register16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
void i2c_stop(void);

View File

@ -170,7 +170,7 @@ i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16
return i2c_epilogue(status);
}
i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t i2c_write_register(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_address = devaddr;
i2cStart(&I2C_DRIVER, &i2cconfig);
@ -184,7 +184,7 @@ i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data,
return i2c_epilogue(status);
}
i2c_status_t i2c_writeReg16(uint8_t devaddr, uint16_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t i2c_write_register16(uint8_t devaddr, uint16_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_address = devaddr;
i2cStart(&I2C_DRIVER, &i2cconfig);
@ -199,14 +199,14 @@ i2c_status_t i2c_writeReg16(uint8_t devaddr, uint16_t regaddr, const uint8_t* da
return i2c_epilogue(status);
}
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t i2c_read_register(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_address = devaddr;
i2cStart(&I2C_DRIVER, &i2cconfig);
msg_t status = i2cMasterTransmitTimeout(&I2C_DRIVER, (i2c_address >> 1), &regaddr, 1, data, length, TIME_MS2I(timeout));
return i2c_epilogue(status);
}
i2c_status_t i2c_readReg16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_status_t i2c_read_register16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout) {
i2c_address = devaddr;
i2cStart(&I2C_DRIVER, &i2cconfig);
uint8_t register_packet[2] = {regaddr >> 8, regaddr & 0xFF};

View File

@ -26,6 +26,13 @@
#include <stdint.h>
// ### DEPRECATED - DO NOT USE ###
#define i2c_writeReg(devaddr, regaddr, data, length, timeout) i2c_write_register(devaddr, regaddr, data, length, timeout)
#define i2c_writeReg16(devaddr, regaddr, data, length, timeout) i2c_write_register16(devaddr, regaddr, data, length, timeout)
#define i2c_readReg(devaddr, regaddr, data, length, timeout) i2c_read_register(devaddr, regaddr, data, length, timeout)
#define i2c_readReg16(devaddr, regaddr, data, length, timeout) i2c_read_register16(devaddr, regaddr, data, length, timeout)
// ###############################
typedef int16_t i2c_status_t;
#define I2C_STATUS_SUCCESS (0)
@ -36,8 +43,8 @@ void i2c_init(void);
i2c_status_t i2c_start(uint8_t address);
i2c_status_t i2c_transmit(uint8_t address, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_writeReg16(uint8_t devaddr, uint16_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_readReg16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_write_register(uint8_t devaddr, uint8_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_write_register16(uint8_t devaddr, uint16_t regaddr, const uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_read_register(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
i2c_status_t i2c_read_register16(uint8_t devaddr, uint16_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
void i2c_stop(void);

View File

@ -56,7 +56,7 @@ i2c_status_t transport_trigger_callback(int8_t id) {
// Kick off the "callback executor", now that data has been written to the slave
split_shmem->transaction_id = id;
split_transaction_desc_t *trans = &split_transaction_table[I2C_EXECUTE_CALLBACK];
return i2c_writeReg(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size, SLAVE_I2C_TIMEOUT);
return i2c_write_register(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size, SLAVE_I2C_TIMEOUT);
}
bool transport_execute_transaction(int8_t id, const void *initiator2target_buf, uint16_t initiator2target_length, void *target2initiator_buf, uint16_t target2initiator_length) {
@ -65,7 +65,7 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf,
if (initiator2target_length > 0) {
size_t len = trans->initiator2target_buffer_size < initiator2target_length ? trans->initiator2target_buffer_size : initiator2target_length;
memcpy(split_trans_initiator2target_buffer(trans), initiator2target_buf, len);
if ((status = i2c_writeReg(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
if ((status = i2c_write_register(SLAVE_I2C_ADDRESS, trans->initiator2target_offset, split_trans_initiator2target_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
return false;
}
}
@ -77,7 +77,7 @@ bool transport_execute_transaction(int8_t id, const void *initiator2target_buf,
if (target2initiator_length > 0) {
size_t len = trans->target2initiator_buffer_size < target2initiator_length ? trans->target2initiator_buffer_size : target2initiator_length;
if ((status = i2c_readReg(SLAVE_I2C_ADDRESS, trans->target2initiator_offset, split_trans_target2initiator_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
if ((status = i2c_read_register(SLAVE_I2C_ADDRESS, trans->target2initiator_offset, split_trans_target2initiator_buffer(trans), len, SLAVE_I2C_TIMEOUT)) < 0) {
return false;
}
memcpy(target2initiator_buf, split_trans_target2initiator_buffer(trans), len);