bdk: i2c: homogenize return values

This commit is contained in:
CTCaer
2026-02-22 02:42:53 +02:00
parent 2b87c39a7a
commit cb81aaecdb
5 changed files with 28 additions and 33 deletions

View File

@@ -24,7 +24,6 @@
#include <soc/fuse.h>
#include <soc/gpio.h>
#include <soc/hw_init.h>
#include <soc/i2c.h>
#include <soc/pinmux.h>
#include <soc/pmc.h>
#include <soc/timer.h>

View File

@@ -44,12 +44,12 @@ static touch_panel_info_t _touch_panel_info = { 0 };
static int _touch_command(u8 cmd, u8 *buf, u8 size)
{
return !i2c_send_buf_small(I2C_3, FTS4_I2C_ADDR, cmd, buf, size);
return i2c_send_buf_small(I2C_3, FTS4_I2C_ADDR, cmd, buf, size);
}
static int _touch_read_reg(u8 *cmd, u32 csize, u8 *buf, u32 size)
{
return !i2c_xfer_packet(I2C_3, FTS4_I2C_ADDR, cmd, csize, buf, size);
return i2c_xfer_packet(I2C_3, FTS4_I2C_ADDR, cmd, csize, buf, size);
}
int touch_get_event_count()
@@ -75,7 +75,7 @@ static int _touch_wait_event(u8 event, u8 status, u32 timeout, u8 *buf)
int res = i2c_recv_buf_big(tmp, FTS4_EVENT_SIZE, I2C_3, FTS4_I2C_ADDR, FTS4_CMD_READ_ONE_EVENT);
// Check that event type and status match.
if (res && tmp[0] == event && tmp[1] == status)
if (!res && tmp[0] == event && tmp[1] == status)
{
if (buf)
memcpy(buf, &tmp[2], 6);
@@ -163,7 +163,7 @@ static int _touch_parse_input_event(touch_event_t *event)
int touch_poll(touch_event_t *event)
{
int res = !i2c_recv_buf_big(event->raw, FTS4_EVENT_SIZE, I2C_3, FTS4_I2C_ADDR, FTS4_CMD_LATEST_EVENT);
int res = i2c_recv_buf_big(event->raw, FTS4_EVENT_SIZE, I2C_3, FTS4_I2C_ADDR, FTS4_CMD_LATEST_EVENT);
if (!res)
res = _touch_parse_input_event(event);

View File

@@ -147,18 +147,14 @@ static int _max17050_write_verify_reg(u8 reg, u16 value)
{
int retries = 8;
int ret;
u16 read_value;
do
{
ret = i2c_send_buf_small(I2C_1, MAXIM17050_I2C_ADDR, reg, (u8 *)&value, 2);
read_value = max17050_get_reg(reg);
if (read_value != value)
{
ret = -1;
retries--;
}
} while (retries && read_value != value);
u16 read_value = max17050_get_reg(reg);
if (!ret && read_value == value)
break;
} while (--retries);
return ret;
}

View File

@@ -137,7 +137,7 @@ static void _max7762x_set_reg(u8 addr, u8 reg, u8 val)
u32 retries = 100;
while (retries)
{
if (i2c_send_byte(I2C_5, addr, reg, val))
if (!i2c_send_byte(I2C_5, addr, reg, val))
break;
usleep(50);

View File

@@ -102,7 +102,7 @@ static void _i2c_load_cfg_wait(vu32 *base)
static int _i2c_send_normal(u32 i2c_idx, u32 dev_addr, const u8 *buf, u32 size)
{
if (size > 8)
return 0;
return 1;
u32 tmp = 0;
@@ -138,19 +138,19 @@ static int _i2c_send_normal(u32 i2c_idx, u32 dev_addr, const u8 *buf, u32 size)
while (base[I2C_STATUS] & I2C_STATUS_BUSY)
{
if (get_tmr_ms() > timeout)
return 0;
return 1;
}
if (base[I2C_STATUS] & I2C_STATUS_NOACK)
return 0;
return 1;
return 1;
return 0;
}
static int _i2c_recv_normal(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr)
{
if (size > 8)
return 0;
return 1;
vu32 *base = (vu32 *)(I2C_BASE + (u32)_i2c_base_offsets[i2c_idx]);
@@ -170,11 +170,11 @@ static int _i2c_recv_normal(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr)
while (base[I2C_STATUS] & I2C_STATUS_BUSY)
{
if (get_tmr_ms() > timeout)
return 0;
return 1;
}
if (base[I2C_STATUS] & I2C_STATUS_NOACK)
return 0;
return 1;
u32 tmp = base[I2C_CMD_DATA1]; // Get LS value.
if (size > 4)
@@ -186,15 +186,15 @@ static int _i2c_recv_normal(u32 i2c_idx, u8 *buf, u32 size, u32 dev_addr)
else
memcpy(buf, &tmp, size);
return 1;
return 0;
}
static int _i2c_send_packet(u32 i2c_idx, const u8 *buf, u32 size, u32 dev_addr)
{
if (size > 32)
return 0;
return 1;
int res = 1;
int res = 0;
vu32 *base = (vu32 *)(I2C_BASE + (u32)_i2c_base_offsets[i2c_idx]);
@@ -235,14 +235,14 @@ static int _i2c_send_packet(u32 i2c_idx, const u8 *buf, u32 size, u32 dev_addr)
{
if (get_tmr_ms() > timeout)
{
res = 0;
res = 1;
break;
}
}
// Check if no reply.
if (base[I2C_STATUS] & I2C_STATUS_NOACK)
res = 0;
res = 1;
// Wait for STOP and disable packet mode.
usleep(20);
@@ -255,9 +255,9 @@ int i2c_xfer_packet(u32 i2c_idx, u32 dev_addr, const u8 *tx_buf, u32 tx_size, u8
{
// Max 32 bytes TX/RX fifo.
if (tx_size > 20 || rx_size > 32) // Header included.
return 0;
return 1;
int res = 1;
int res = 0;
vu32 *base = (vu32 *)(I2C_BASE + (u32)_i2c_base_offsets[i2c_idx]);
@@ -298,7 +298,7 @@ int i2c_xfer_packet(u32 i2c_idx, u32 dev_addr, const u8 *tx_buf, u32 tx_size, u8
{
if (get_tmr_ms() > timeout)
{
res = 0;
res = 1;
goto out;
}
}
@@ -323,7 +323,7 @@ int i2c_xfer_packet(u32 i2c_idx, u32 dev_addr, const u8 *tx_buf, u32 tx_size, u8
if (get_tmr_ms() > timeout)
{
res = 0;
res = 1;
break;
}
}
@@ -331,7 +331,7 @@ int i2c_xfer_packet(u32 i2c_idx, u32 dev_addr, const u8 *tx_buf, u32 tx_size, u8
out:
// Check if no reply.
if (base[I2C_STATUS] & I2C_STATUS_NOACK)
res = 0;
res = 1;
// Wait for STOP and disable packet mode.
usleep(20);
@@ -374,7 +374,7 @@ int i2c_recv_buf_big(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg)
int i2c_send_buf_small(u32 i2c_idx, u32 dev_addr, u32 reg, const u8 *buf, u32 size)
{
if (size > 7)
return 0;
return 1;
u8 tmp[8];
tmp[0] = reg;
@@ -386,7 +386,7 @@ int i2c_send_buf_small(u32 i2c_idx, u32 dev_addr, u32 reg, const u8 *buf, u32 si
int i2c_recv_buf_small(u8 *buf, u32 size, u32 i2c_idx, u32 dev_addr, u32 reg)
{
int res = _i2c_send_normal(i2c_idx, dev_addr, (u8 *)&reg, 1);
if (res)
if (!res)
res = _i2c_recv_normal(i2c_idx, buf, size, dev_addr);
return res;
}