Skip to content

Commit 6a24b36

Browse files
[nrf fromlist] drivers: i2c: i2c_nrfx_twim: Align shim to new error handling
Aligned nrfx_twim shim to new errno error handling in NRFX. Upstream PR #: 98569 Signed-off-by: Adam Kondraciuk <[email protected]>
1 parent 2aa339c commit 6a24b36

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

drivers/i2c/i2c_nrfx_twim.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct i2c_nrfx_twim_data {
3232
nrfx_twim_t twim;
3333
struct k_sem transfer_sync;
3434
struct k_sem completion_sync;
35-
volatile nrfx_err_t res;
35+
volatile int res;
3636
};
3737

3838
int i2c_nrfx_twim_exclusive_access_acquire(const struct device *dev, k_timeout_t timeout)
@@ -163,7 +163,7 @@ static int i2c_nrfx_twim_transfer(const struct device *dev,
163163
break;
164164
}
165165

166-
if (dev_data->res != NRFX_SUCCESS) {
166+
if (dev_data->res < 0) {
167167
ret = -EIO;
168168
break;
169169
}
@@ -199,16 +199,16 @@ static void event_handler(nrfx_twim_event_t const *p_event, void *p_context)
199199

200200
switch (p_event->type) {
201201
case NRFX_TWIM_EVT_DONE:
202-
dev_data->res = NRFX_SUCCESS;
202+
dev_data->res = 0;
203203
break;
204204
case NRFX_TWIM_EVT_ADDRESS_NACK:
205-
dev_data->res = NRFX_ERROR_DRV_TWI_ERR_ANACK;
205+
dev_data->res = -EFAULT;
206206
break;
207207
case NRFX_TWIM_EVT_DATA_NACK:
208-
dev_data->res = NRFX_ERROR_DRV_TWI_ERR_DNACK;
208+
dev_data->res = -EAGAIN;
209209
break;
210210
default:
211-
dev_data->res = NRFX_ERROR_INTERNAL;
211+
dev_data->res = -EIO;
212212
break;
213213
}
214214

drivers/i2c/i2c_nrfx_twim_common.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int i2c_nrfx_twim_recover_bus(const struct device *dev)
2020
enum pm_device_state state;
2121
uint32_t scl_pin;
2222
uint32_t sda_pin;
23-
nrfx_err_t err;
23+
int err;
2424

2525
scl_pin = nrf_twim_scl_pin_get(config->twim->p_twim);
2626
sda_pin = nrf_twim_sda_pin_get(config->twim->p_twim);
@@ -39,7 +39,7 @@ int i2c_nrfx_twim_recover_bus(const struct device *dev)
3939
nrfx_twim_enable(config->twim);
4040
}
4141

42-
return (err == NRFX_SUCCESS ? 0 : -EBUSY);
42+
return err;
4343
}
4444

4545
int i2c_nrfx_twim_configure(const struct device *dev, uint32_t i2c_config)
@@ -80,8 +80,6 @@ int i2c_nrfx_twim_msg_transfer(const struct device *dev, uint8_t flags, uint8_t
8080
.p_primary_buf = buf,
8181
.primary_length = buf_len,
8282
};
83-
nrfx_err_t res;
84-
int ret = 0;
8583

8684
if (buf_len > config->max_transfer_size) {
8785
LOG_ERR("Trying to transfer more than the maximum size "
@@ -90,16 +88,8 @@ int i2c_nrfx_twim_msg_transfer(const struct device *dev, uint8_t flags, uint8_t
9088
return -ENOSPC;
9189
}
9290

93-
res = nrfx_twim_xfer(config->twim, &cur_xfer,
94-
(flags & I2C_MSG_STOP) ? 0 : NRFX_TWIM_FLAG_TX_NO_STOP);
95-
if (res != NRFX_SUCCESS) {
96-
if (res == NRFX_ERROR_BUSY) {
97-
ret = -EBUSY;
98-
} else {
99-
ret = -EIO;
100-
}
101-
}
102-
return ret;
91+
return nrfx_twim_xfer(config->twim, &cur_xfer,
92+
(flags & I2C_MSG_STOP) ? 0 : NRFX_TWIM_FLAG_TX_NO_STOP);
10393
}
10494

10595
void twim_nrfx_pm_resume(const struct device *dev)
@@ -142,8 +132,8 @@ int i2c_nrfx_twim_common_init(const struct device *dev)
142132

143133
(void)pinctrl_apply_state(config->pcfg, PINCTRL_STATE_SLEEP);
144134

145-
if (nrfx_twim_init(config->twim, &config->twim_config, config->event_handler,
146-
(void *)dev) != NRFX_SUCCESS) {
135+
if (nrfx_twim_init(config->twim, &config->twim_config, config->event_handler, (void *)dev) <
136+
0) {
147137
LOG_ERR("Failed to initialize device: %s", dev->name);
148138
return -EIO;
149139
}

0 commit comments

Comments
 (0)