jacobrosenthal closed pull request #1338: Drv2605 odds and ends
URL: https://github.com/apache/mynewt-core/pull/1338
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/drivers/drv2605/src/drv2605.c b/hw/drivers/drv2605/src/drv2605.c
index d3efc13da1..631eb2f1ba 100644
--- a/hw/drivers/drv2605/src/drv2605.c
+++ b/hw/drivers/drv2605/src/drv2605.c
@@ -26,6 +26,7 @@
 #include "hal/hal_gpio.h"
 #include "drv2605/drv2605.h"
 #include "drv2605_priv.h"
+#include <syscfg/syscfg.h>
 
 #if MYNEWT_VAL(DRV2605_LOG)
 #include "modlog/modlog.h"
@@ -78,6 +79,11 @@ drv2605_write8(struct sensor_itf *itf, uint8_t reg, uint8_t 
value)
         .buffer = payload
     };
 
+    rc = sensor_itf_lock(itf, MYNEWT_VAL(DRV2605_ITF_LOCK_TMO));
+    if (rc) {
+        return rc;
+    }
+
     rc = hal_i2c_master_write(itf->si_num, &data_struct, OS_TICKS_PER_SEC, 1);
     if (rc) {
         DRV2605_LOG(ERROR,
@@ -86,8 +92,11 @@ drv2605_write8(struct sensor_itf *itf, uint8_t reg, uint8_t 
value)
 #if MYNEWT_VAL(DRV2605_STATS)
         STATS_INC(g_drv2605stats, errors);
 #endif
+        goto err;
     }
 
+err:
+    sensor_itf_unlock(itf);
     return rc;
 }
 
@@ -120,6 +129,11 @@ drv2605_writelen(struct sensor_itf *itf, uint8_t reg, 
uint8_t *buffer,
 
     memcpy(&payload[1], buffer, len);
 
+    rc = sensor_itf_lock(itf, MYNEWT_VAL(DRV2605_ITF_LOCK_TMO));
+    if (rc) {
+        return rc;
+    }
+
     /* Register write */
     rc = hal_i2c_master_write(itf->si_num, &data_struct, OS_TICKS_PER_SEC / 
10, 1);
     if (rc) {
@@ -131,8 +145,8 @@ drv2605_writelen(struct sensor_itf *itf, uint8_t reg, 
uint8_t *buffer,
         goto err;
     }
 
-    return 0;
 err:
+    sensor_itf_unlock(itf);
     return rc;
 }
 
@@ -159,6 +173,12 @@ drv2605_read8(struct sensor_itf *itf, uint8_t reg, uint8_t 
*value)
 
     /* Register write */
     payload = reg;
+
+    rc = sensor_itf_lock(itf, MYNEWT_VAL(DRV2605_ITF_LOCK_TMO));
+    if (rc) {
+        return rc;
+    }
+
     rc = hal_i2c_master_write(itf->si_num, &data_struct, OS_TICKS_PER_SEC / 
10, 0);
     if (rc) {
         DRV2605_LOG(ERROR,
@@ -180,9 +200,11 @@ drv2605_read8(struct sensor_itf *itf, uint8_t reg, uint8_t 
*value)
 #if MYNEWT_VAL(DRV2605_STATS)
         STATS_INC(g_drv2605stats, errors);
 #endif
+        goto err;
     }
 
 err:
+    sensor_itf_unlock(itf);
     return rc;
 }
 
@@ -214,6 +236,11 @@ drv2605_readlen(struct sensor_itf *itf, uint8_t reg, 
uint8_t *buffer,
     /* Clear the supplied buffer */
     memset(buffer, 0, len);
 
+    rc = sensor_itf_lock(itf, MYNEWT_VAL(DRV2605_ITF_LOCK_TMO));
+    if (rc) {
+        return rc;
+    }
+
     /* Register write */
     rc = hal_i2c_master_write(itf->si_num, &data_struct, OS_TICKS_PER_SEC / 
10, 0);
     if (rc) {
@@ -241,8 +268,8 @@ drv2605_readlen(struct sensor_itf *itf, uint8_t reg, 
uint8_t *buffer,
     /* Copy the I2C results into the supplied buffer */
     memcpy(buffer, payload, len);
 
-    return 0;
 err:
+    sensor_itf_unlock(itf);
     return rc;
 }
 
diff --git a/hw/drivers/drv2605/src/drv2605_shell.c 
b/hw/drivers/drv2605/src/drv2605_shell.c
index cd8f45019d..d8f1a6cd21 100644
--- a/hw/drivers/drv2605/src/drv2605_shell.c
+++ b/hw/drivers/drv2605/src/drv2605_shell.c
@@ -17,9 +17,11 @@
  * under the License.
  */
 
+#include "os/mynewt.h"
+
+#if MYNEWT_VAL(DRV2605_CLI)
 #include <string.h>
 #include <errno.h>
-#include "os/mynewt.h"
 #include "console/console.h"
 #include "shell/shell.h"
 #include "drv2605_priv.h"
@@ -27,8 +29,6 @@
 #include "sensor/sensor.h"
 #include "parse/parse.h"
 
-#if MYNEWT_VAL(DRV2605_CLI)
-
 static int drv2605_shell_cmd(int argc, char **argv);
 
 static struct shell_cmd drv2605_shell_cmd_struct = {
@@ -470,7 +470,7 @@ drv2605_shell_cmd(int argc, char **argv)
         return drv2605_shell_cmd_power_mode(argc, argv, drv2605);
     }
 
-    if (argc > 1 && strcmp(argv[1], "load") == 0) {
+    if (argc > 1 && strcmp(argv[1], "load_rom") == 0) {
         return drv2605_shell_cmd_load_rom(argc, argv, drv2605);
     }
 
diff --git a/hw/drivers/drv2605/syscfg.yml b/hw/drivers/drv2605/syscfg.yml
index 70a14bee0a..78acfa6486 100644
--- a/hw/drivers/drv2605/syscfg.yml
+++ b/hw/drivers/drv2605/syscfg.yml
@@ -39,6 +39,9 @@ syscfg.defs:
     DRV2605_SHELL_ITF_ADDR:
         description: 'DRV2605 I2C Address'
         value: 0x5A
+    DRV2605_ITF_LOCK_TMO:
+        description: 'DRV2605 interface lock timeout in milliseconds'
+        value: 1000
 
     DRV2605_EN_PIN:
         description: 'EN pin'


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to