Skip to content

Commit 9ff08b2

Browse files
[nrf fromlist] drivers: i2c: nrfx_twi: align to errno codes in nrfx
NRFX drivers now return errno codes, aligned driver. Upstream PR #: 97997 Signed-off-by: Michał Stasiak <[email protected]>
1 parent ed177f5 commit 9ff08b2

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

drivers/i2c/i2c_nrfx_twi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct i2c_nrfx_twi_data {
2727
uint32_t dev_config;
2828
struct k_sem transfer_sync;
2929
struct k_sem completion_sync;
30-
volatile nrfx_err_t res;
30+
volatile int res;
3131
};
3232

3333
/* Enforce dev_config matches the same offset as the common structure,
@@ -109,16 +109,16 @@ static void event_handler(nrfx_twi_evt_t const *p_event, void *p_context)
109109

110110
switch (p_event->type) {
111111
case NRFX_TWI_EVT_DONE:
112-
dev_data->res = NRFX_SUCCESS;
112+
dev_data->res = 0;
113113
break;
114114
case NRFX_TWI_EVT_ADDRESS_NACK:
115-
dev_data->res = NRFX_ERROR_DRV_TWI_ERR_ANACK;
115+
dev_data->res = -EIO;
116116
break;
117117
case NRFX_TWI_EVT_DATA_NACK:
118-
dev_data->res = NRFX_ERROR_DRV_TWI_ERR_DNACK;
118+
dev_data->res = -EAGAIN;
119119
break;
120120
default:
121-
dev_data->res = NRFX_ERROR_INTERNAL;
121+
dev_data->res = -ECANCELED;
122122
break;
123123
}
124124

drivers/i2c/i2c_nrfx_twi_common.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ LOG_MODULE_DECLARE(i2c_nrfx_twi);
1616
int i2c_nrfx_twi_init(const struct device *dev)
1717
{
1818
const struct i2c_nrfx_twi_config *config = dev->config;
19-
nrfx_err_t result = nrfx_twi_init(&config->twi, &config->config,
20-
config->event_handler, (void *)dev);
21-
if (result != NRFX_SUCCESS) {
19+
int result = nrfx_twi_init(&config->twi, &config->config,
20+
config->event_handler, (void *)dev);
21+
if (result != 0) {
2222
LOG_ERR("Failed to initialize device: %s",
2323
dev->name);
24-
return -EBUSY;
24+
return result;
2525
}
2626

2727
return 0;
@@ -58,13 +58,11 @@ int i2c_nrfx_twi_recover_bus(const struct device *dev)
5858
const struct i2c_nrfx_twi_config *config = dev->config;
5959
uint32_t scl_pin;
6060
uint32_t sda_pin;
61-
nrfx_err_t err;
6261

6362
scl_pin = nrf_twi_scl_pin_get(config->twi.p_twi);
6463
sda_pin = nrf_twi_sda_pin_get(config->twi.p_twi);
6564

66-
err = nrfx_twi_bus_recover(scl_pin, sda_pin);
67-
return (err == NRFX_SUCCESS ? 0 : -EBUSY);
65+
return nrfx_twi_bus_recover(scl_pin, sda_pin);
6866
}
6967

7068
int i2c_nrfx_twi_msg_transfer(const struct device *dev, uint8_t flags,
@@ -74,7 +72,6 @@ int i2c_nrfx_twi_msg_transfer(const struct device *dev, uint8_t flags,
7472
const struct i2c_nrfx_twi_config *config = dev->config;
7573
int ret = 0;
7674
uint32_t xfer_flags = 0;
77-
nrfx_err_t res;
7875
nrfx_twi_xfer_desc_t cur_xfer = {
7976
.p_primary_buf = buf,
8077
.primary_length = buf_len,
@@ -110,17 +107,7 @@ int i2c_nrfx_twi_msg_transfer(const struct device *dev, uint8_t flags,
110107
}
111108

112109
if (!ret) {
113-
res = nrfx_twi_xfer(&config->twi, &cur_xfer, xfer_flags);
114-
switch (res) {
115-
case NRFX_SUCCESS:
116-
break;
117-
case NRFX_ERROR_BUSY:
118-
ret = -EBUSY;
119-
break;
120-
default:
121-
ret = -EIO;
122-
break;
123-
}
110+
ret = nrfx_twi_xfer(&config->twi, &cur_xfer, xfer_flags);
124111
}
125112

126113
return ret;

0 commit comments

Comments
 (0)