You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2022/02/14 08:11:51 UTC
[mynewt-core] 07/10: bus/i2c_nrf5340: Add probe to i2c_nrf5340 driver
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit c2e0d053cb3df6008aab29e1eadbb50dae7f2bf4
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jun 30 15:50:59 2021 +0200
bus/i2c_nrf5340: Add probe to i2c_nrf5340 driver
This adds probe function to i2c_nrf5340 driver.
Probing functionality uses write without data bytes.
---
hw/bus/drivers/i2c_nrf5340/src/i2c_nrf5340.c | 71 +++++++++++++++++++++++++---
1 file changed, 64 insertions(+), 7 deletions(-)
diff --git a/hw/bus/drivers/i2c_nrf5340/src/i2c_nrf5340.c b/hw/bus/drivers/i2c_nrf5340/src/i2c_nrf5340.c
index c183b59..b354310 100644
--- a/hw/bus/drivers/i2c_nrf5340/src/i2c_nrf5340.c
+++ b/hw/bus/drivers/i2c_nrf5340/src/i2c_nrf5340.c
@@ -389,13 +389,70 @@ bus_i2c_nrf5340_disable(struct bus_dev *bdev)
return 0;
}
-static const struct bus_dev_ops bus_i2c_nrf5340_ops = {
- .init_node = bus_i2c_nrf5340_init_node,
- .enable = bus_i2c_nrf5340_enable,
- .configure = bus_i2c_nrf5340_configure,
- .read = bus_i2c_nrf5340_read,
- .write = bus_i2c_nrf5340_write,
- .disable = bus_i2c_nrf5340_disable,
+static int
+bus_i2c_nrf5340_probe(struct bus_i2c_dev *dev, uint16_t address, os_time_t timeout)
+{
+ struct twim_dev_data *dd;
+ NRF_TWIM_Type *nrf_twim;
+ int rc;
+
+ BUS_DEBUG_VERIFY_DEV(dev);
+
+ rc = os_error_to_sys(os_mutex_pend(&dev->bdev.lock, timeout));
+ if (rc == 0) {
+ rc = bus_i2c_nrf5340_configure_controller(dev, address, 100);
+ assert(rc == 0);
+ nrf_twim = twims[dev->cfg.i2c_num].nrf_twim;
+ dd = &twim_devs_data[dev->cfg.i2c_num];
+
+ nrf_twim->TXD.MAXCNT = 0;
+ nrf_twim->TXD.LIST = 0;
+
+ nrf_twim->EVENTS_STOPPED = 0;
+ nrf_twim->EVENTS_ERROR = 0;
+
+ nrf_twim->SHORTS = 0;
+ nrf_twim->INTEN = TWIM_INTEN_ERROR_Msk;
+
+ nrf_twim->TASKS_STARTTX = 1;
+
+ /* Wait for enough time to have NACK detected */
+ os_cputime_delay_usecs(125);
+
+ /* If semaphore is signaled, there was an error. */
+ rc = os_sem_pend(&dd->sem, 0);
+ /* Stop condition is not automatically send */
+ nrf_twim->INTEN = TWIM_INTEN_STOPPED_Msk;
+ nrf_twim->TASKS_STOP = 1;
+
+ /*
+ * Previous os_sem_pend() returning OS_TIMEOUT means that
+ * device ACK'ed address.
+ */
+ if (rc == OS_TIMEOUT) {
+ rc = 0;
+ } else {
+ rc = SYS_ENOENT;
+ }
+ /* Wait for STOP condition */
+ (void)os_sem_pend(&dd->sem, OS_TICKS_PER_SEC);
+
+ (void)os_mutex_release(&dev->bdev.lock);
+ }
+
+ return rc;
+}
+
+static const struct i2c_dev_ops bus_i2c_nrf5340_ops = {
+ .bus_ops = {
+ .init_node = bus_i2c_nrf5340_init_node,
+ .enable = bus_i2c_nrf5340_enable,
+ .configure = bus_i2c_nrf5340_configure,
+ .read = bus_i2c_nrf5340_read,
+ .write = bus_i2c_nrf5340_write,
+ .disable = bus_i2c_nrf5340_disable,
+ },
+ .probe = bus_i2c_nrf5340_probe,
};
#include <hal/hal_gpio.h>