You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2018/12/05 14:34:31 UTC
[mynewt-core] branch master updated (f933321 -> 0350849)
This is an automated email from the ASF dual-hosted git repository.
andk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.
from f933321 hw/drivers: Fix spiflash initialization function
new 27efa6a hw/bus: Fix typo
new f583bb3 hw/bus: Fix lock timeout value usage
new cffe5e9 hw/bus: Enable bus driver statistics
new 5e8f467 hw/bus: Allow to override lock timeout per-node
new d37c47f hw/drivers/lis2dw12: Add proper I2C/SPI interface handling
new 4a246d1 hw/drivers/lis2dh12: Add proper I2C/SPI interface handling
new 3ff35b3 hw/drivers/lps33thw: Add proper I2C/SPI interface handling
new 0350849 hw/drivers/lps33hw: Add SPI support
The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
hw/bus/include/bus/bus.h | 2 +-
hw/bus/include/bus/bus_driver.h | 25 +++++++
hw/bus/src/bus.c | 84 ++++++++++++++++++++--
hw/bus/syscfg.yml | 12 ++++
.../sensors/lis2dh12/include/lis2dh12/lis2dh12.h | 3 +
hw/drivers/sensors/lis2dh12/src/lis2dh12.c | 26 ++++++-
hw/drivers/sensors/lis2dh12/src/lis2dh12_priv.h | 4 +-
.../sensors/lis2dw12/include/lis2dw12/lis2dw12.h | 3 +
hw/drivers/sensors/lis2dw12/src/lis2dw12.c | 12 ++++
.../sensors/lps33hw/include/lps33hw/lps33hw.h | 23 +++++-
hw/drivers/sensors/lps33hw/src/lps33hw.c | 29 ++++++++
.../sensors/lps33thw/include/lps33thw/lps33thw.h | 3 +
hw/drivers/sensors/lps33thw/src/lps33thw.c | 12 ++++
13 files changed, 228 insertions(+), 10 deletions(-)
[mynewt-core] 05/08: hw/drivers/lis2dw12: Add proper I2C/SPI
interface handling
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit d37c47f6b4b853856b5271de450a51fe5bf39a3c
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Dec 4 17:48:49 2018 +0100
hw/drivers/lis2dw12: Add proper I2C/SPI interface handling
---
hw/drivers/sensors/lis2dw12/include/lis2dw12/lis2dw12.h | 3 +++
hw/drivers/sensors/lis2dw12/src/lis2dw12.c | 12 ++++++++++++
2 files changed, 15 insertions(+)
diff --git a/hw/drivers/sensors/lis2dw12/include/lis2dw12/lis2dw12.h b/hw/drivers/sensors/lis2dw12/include/lis2dw12/lis2dw12.h
index 7148269..53afb51 100644
--- a/hw/drivers/sensors/lis2dw12/include/lis2dw12/lis2dw12.h
+++ b/hw/drivers/sensors/lis2dw12/include/lis2dw12/lis2dw12.h
@@ -285,6 +285,9 @@ struct lis2dw12 {
struct lis2dw12_cfg cfg;
struct lis2dw12_int intr;
struct lis2dw12_pdd pdd;
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+ bool node_is_spi;
+#endif
};
/**
diff --git a/hw/drivers/sensors/lis2dw12/src/lis2dw12.c b/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
index d8b2e38..f81af8a 100644
--- a/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
+++ b/hw/drivers/sensors/lis2dw12/src/lis2dw12.c
@@ -515,6 +515,12 @@ lis2dw12_readlen(struct sensor_itf *itf, uint8_t reg, uint8_t *buffer,
int rc;
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+ struct lis2dw12 *dev = (struct lis2dw12 *)itf->si_dev;
+
+ if (dev->node_is_spi) {
+ reg |= LIS2DW12_SPI_READ_CMD_BIT;
+ }
+
rc = bus_node_simple_write_read_transact(itf->si_dev, ®, 1, buffer, len);
#else
rc = sensor_itf_lock(itf, MYNEWT_VAL(LIS2DW12_ITF_LOCK_TMO));
@@ -3362,11 +3368,14 @@ lis2dw12_create_i2c_sensor_dev(struct bus_i2c_node *node, const char *name,
const struct bus_i2c_node_cfg *i2c_cfg,
struct sensor_itf *sensor_itf)
{
+ struct lis2dw12 *dev = (struct lis2dw12 *)node;
struct bus_node_callbacks cbs = {
.init = init_node_cb,
};
int rc;
+ dev->node_is_spi = false;
+
bus_node_set_callbacks((struct os_dev *)node, &cbs);
rc = bus_i2c_node_create(name, node, i2c_cfg, sensor_itf);
@@ -3379,11 +3388,14 @@ lis2dw12_create_spi_sensor_dev(struct bus_spi_node *node, const char *name,
const struct bus_spi_node_cfg *spi_cfg,
struct sensor_itf *sensor_itf)
{
+ struct lis2dw12 *dev = (struct lis2dw12 *)node;
struct bus_node_callbacks cbs = {
.init = init_node_cb,
};
int rc;
+ dev->node_is_spi = true;
+
bus_node_set_callbacks((struct os_dev *)node, &cbs);
rc = bus_spi_node_create(name, node, spi_cfg, sensor_itf);
[mynewt-core] 04/08: hw/bus: Allow to override lock timeout per-node
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 5e8f46782aede92251ecc89a2595bc6ac004e6e5
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Dec 3 16:48:49 2018 +0100
hw/bus: Allow to override lock timeout per-node
To save some space we may want to allow to disable per-node
configuration in future, but for now let's make it always enabled since
it only uses few extra bytes.
---
hw/bus/include/bus/bus_driver.h | 4 ++++
hw/bus/src/bus.c | 11 ++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/hw/bus/include/bus/bus_driver.h b/hw/bus/include/bus/bus_driver.h
index 934a6b8..5ad822f 100644
--- a/hw/bus/include/bus/bus_driver.h
+++ b/hw/bus/include/bus/bus_driver.h
@@ -86,6 +86,8 @@ struct bus_node_callbacks {
struct bus_node_cfg {
/** Bus device name where node is attached */
const char *bus_name;
+ /** Lock timeout [ms], 0 = default timeout */
+ uint16_t lock_timeout_ms;
};
/**
@@ -129,6 +131,8 @@ struct bus_node {
void *init_arg;
};
+ os_time_t lock_timeout;
+
#if MYNEWT_VAL(BUS_STATS_PER_NODE)
STATS_SECT_DECL(bus_stats_section) stats;
#endif
diff --git a/hw/bus/src/bus.c b/hw/bus/src/bus.c
index ab808ed..6f987fb 100644
--- a/hw/bus/src/bus.c
+++ b/hw/bus/src/bus.c
@@ -167,6 +167,13 @@ bus_node_init_func(struct os_dev *odev, void *arg)
init_arg = bnode->init_arg;
bnode->parent_bus = (struct bus_dev *)parent_odev;
+ if (node_cfg->lock_timeout_ms) {
+ bnode->lock_timeout = os_time_ms_to_ticks32(node_cfg->lock_timeout_ms);
+ } else {
+ /* Use default */
+ bnode->lock_timeout = 0;
+ }
+
odev->od_handlers.od_open = bus_node_open_func;
odev->od_handlers.od_close = bus_node_close_func;
@@ -362,7 +369,9 @@ bus_node_unlock(struct os_dev *node)
os_time_t
bus_node_get_lock_timeout(struct os_dev *node)
{
- return g_bus_node_lock_timeout;
+ struct bus_node *bnode = (struct bus_node *)node;
+
+ return bnode->lock_timeout ? bnode->lock_timeout : g_bus_node_lock_timeout;
}
void
[mynewt-core] 03/08: hw/bus: Enable bus driver statistics
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit cffe5e9f37379b25c9811f734d7aad1417f404da
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Dec 3 16:09:35 2018 +0100
hw/bus: Enable bus driver statistics
This adds option to enable statistics for bus driver. There are two
types of statistics which can be used:
- per-device statistics (default)
- per-node statistics (optional)
For now cumulative number of reads, writes and errors for those are
counted as well as number of lock timeouts.
Stats for bus device are registered with bus device name prefixed by
"bd_" while bus nodes are prefixed with "bn_".
---
hw/bus/include/bus/bus_driver.h | 21 +++++++++++++
hw/bus/src/bus.c | 67 +++++++++++++++++++++++++++++++++++++++++
hw/bus/syscfg.yml | 12 ++++++++
3 files changed, 100 insertions(+)
diff --git a/hw/bus/include/bus/bus_driver.h b/hw/bus/include/bus/bus_driver.h
index 04306e5..934a6b8 100644
--- a/hw/bus/include/bus/bus_driver.h
+++ b/hw/bus/include/bus/bus_driver.h
@@ -22,6 +22,9 @@
#include <stdint.h>
#include "os/mynewt.h"
+#if MYNEWT_VAL(BUS_STATS)
+#include "stats/stats.h"
+#endif
#ifdef __cplusplus
extern "C" {
@@ -30,6 +33,16 @@ extern "C" {
struct bus_dev;
struct bus_node;
+#if MYNEWT_VAL(BUS_STATS)
+STATS_SECT_START(bus_stats_section)
+ STATS_SECT_ENTRY(lock_timeouts)
+ STATS_SECT_ENTRY(read_ops)
+ STATS_SECT_ENTRY(read_errors)
+ STATS_SECT_ENTRY(write_ops)
+ STATS_SECT_ENTRY(write_errors)
+STATS_SECT_END
+#endif
+
/**
* Bus device operations
*
@@ -88,6 +101,10 @@ struct bus_dev {
struct os_mutex lock;
struct bus_node *configured_for;
+#if MYNEWT_VAL(BUS_STATS)
+ STATS_SECT_DECL(bus_stats_section) stats;
+#endif
+
#if MYNEWT_VAL(BUS_DEBUG_OS_DEV)
uint32_t devmagic;
#endif
@@ -112,6 +129,10 @@ struct bus_node {
void *init_arg;
};
+#if MYNEWT_VAL(BUS_STATS_PER_NODE)
+ STATS_SECT_DECL(bus_stats_section) stats;
+#endif
+
#if MYNEWT_VAL(BUS_DEBUG_OS_DEV)
uint32_t nodemagic;
#endif
diff --git a/hw/bus/src/bus.c b/hw/bus/src/bus.c
index 0bc7c0f..ab808ed 100644
--- a/hw/bus/src/bus.c
+++ b/hw/bus/src/bus.c
@@ -23,9 +23,39 @@
#include "bus/bus.h"
#include "bus/bus_debug.h"
#include "bus/bus_driver.h"
+#if MYNEWT_VAL(BUS_STATS)
+#include "stats/stats.h"
+#endif
static os_time_t g_bus_node_lock_timeout;
+#if MYNEWT_VAL(BUS_STATS)
+STATS_NAME_START(bus_stats_section)
+ STATS_NAME(bus_stats_section, lock_timeouts)
+ STATS_NAME(bus_stats_section, read_ops)
+ STATS_NAME(bus_stats_section, read_errors)
+ STATS_NAME(bus_stats_section, write_ops)
+ STATS_NAME(bus_stats_section, write_errors)
+STATS_NAME_END(bus_stats_section)
+
+#if MYNEWT_VAL(BUS_STATS_PER_NODE)
+#define BUS_STATS_INC(_bdev, _bnode, _var) \
+ do { \
+ STATS_INC((_bdev)->stats, _var); \
+ STATS_INC((_bnode)->stats, _var); \
+ } while (0)
+#else
+#define BUS_STATS_INC(_bdev, _bnode, _var) \
+ do { \
+ STATS_INC((_bdev)->stats, _var); \
+ } while (0)
+#endif
+#else
+#define BUS_STATS_INC(_bdev, _bnode, _var) \
+ do { \
+ } while (0)
+#endif
+
static int
bus_node_open_func(struct os_dev *odev, uint32_t wait, void *arg)
{
@@ -92,6 +122,9 @@ bus_dev_init_func(struct os_dev *odev, void *arg)
{
struct bus_dev *bdev = (struct bus_dev *)odev;
struct bus_dev_ops *ops = arg;
+#if MYNEWT_VAL(BUS_STATS)
+ char *stats_name;
+#endif
BUS_DEBUG_POISON_DEV(bdev);
@@ -100,6 +133,15 @@ bus_dev_init_func(struct os_dev *odev, void *arg)
os_mutex_init(&bdev->lock);
+#if MYNEWT_VAL(BUS_STATS)
+ asprintf(&stats_name, "bd_%s", odev->od_name);
+ /* XXX should we assert or return error on failure? */
+ stats_init_and_reg(STATS_HDR(bdev->stats),
+ STATS_SIZE_INIT_PARMS(bdev->stats, STATS_SIZE_32),
+ STATS_NAME_INIT_PARMS(bus_stats_section),
+ stats_name);
+#endif
+
return 0;
}
@@ -110,6 +152,9 @@ bus_node_init_func(struct os_dev *odev, void *arg)
struct bus_node_cfg *node_cfg = arg;
struct os_dev *parent_odev;
void *init_arg;
+#if MYNEWT_VAL(BUS_STATS_PER_NODE)
+ char *stats_name;
+#endif
parent_odev = os_dev_lookup(node_cfg->bus_name);
if (!parent_odev) {
@@ -125,6 +170,15 @@ bus_node_init_func(struct os_dev *odev, void *arg)
odev->od_handlers.od_open = bus_node_open_func;
odev->od_handlers.od_close = bus_node_close_func;
+#if MYNEWT_VAL(BUS_STATS_PER_NODE)
+ asprintf(&stats_name, "bn_%s", odev->od_name);
+ /* XXX should we assert or return error on failure? */
+ stats_init_and_reg(STATS_HDR(bnode->stats),
+ STATS_SIZE_INIT_PARMS(bnode->stats, STATS_SIZE_32),
+ STATS_NAME_INIT_PARMS(bus_stats_section),
+ stats_name);
+#endif
+
if (bnode->callbacks.init) {
bnode->callbacks.init(bnode, init_arg);
}
@@ -152,7 +206,11 @@ bus_node_read(struct os_dev *node, void *buf, uint16_t length,
return rc;
}
+ BUS_STATS_INC(bdev, bnode, read_ops);
rc = bdev->dops->read(bdev, bnode, buf, length, timeout, flags);
+ if (rc) {
+ BUS_STATS_INC(bdev, bnode, read_errors);
+ }
(void)bus_node_unlock(node);
@@ -179,7 +237,11 @@ bus_node_write(struct os_dev *node, const void *buf, uint16_t length,
return rc;
}
+ BUS_STATS_INC(bdev, bnode, write_ops);
rc = bdev->dops->write(bdev, bnode, buf, length, timeout, flags);
+ if (rc) {
+ BUS_STATS_INC(bdev, bnode, write_errors);
+ }
(void)bus_node_unlock(node);
@@ -213,13 +275,17 @@ bus_node_write_read_transact(struct os_dev *node, const void *wbuf,
* too many flags now (like we literally have only one flag) let's just pass
* no flags for now
*/
+ BUS_STATS_INC(bdev, bnode, write_ops);
rc = bdev->dops->write(bdev, bnode, wbuf, wlength, timeout, BUS_F_NOSTOP);
if (rc) {
+ BUS_STATS_INC(bdev, bnode, write_errors);
goto done;
}
+ BUS_STATS_INC(bdev, bnode, read_ops);
rc = bdev->dops->read(bdev, bnode, rbuf, rlength, timeout, flags);
if (rc) {
+ BUS_STATS_INC(bdev, bnode, read_errors);
goto done;
}
@@ -247,6 +313,7 @@ bus_node_lock(struct os_dev *node, os_time_t timeout)
err = os_mutex_pend(&bdev->lock, timeout);
if (err == OS_TIMEOUT) {
+ BUS_STATS_INC(bdev, bnode, lock_timeouts);
return SYS_ETIMEOUT;
}
diff --git a/hw/bus/syscfg.yml b/hw/bus/syscfg.yml
index b7e03f3..db25199 100644
--- a/hw/bus/syscfg.yml
+++ b/hw/bus/syscfg.yml
@@ -32,6 +32,18 @@ syscfg.defs:
transaction APIs (i.e. without timeout set explicitly)
value: 50
+ BUS_STATS:
+ description: >
+ Enable statistics for bus devices. By default only global per-device
+ statistics are enabled. Use BUS_STATS_PER_NODE to enable statistics
+ for each node also.
+ value: 0
+ BUS_STATS_PER_NODE:
+ description: >
+ Enable per-node statistics for each bus node.
+ value: 0
+ restrictions: BUS_STATS
+
BUS_DEBUG_OS_DEV:
description: >
Enable additional debugging for os_dev objects.
[mynewt-core] 08/08: hw/drivers/lps33hw: Add SPI support
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 0350849e9bdea186c5872204062cbd5a3c72d94f
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Dec 4 17:48:49 2018 +0100
hw/drivers/lps33hw: Add SPI support
---
.../sensors/lps33hw/include/lps33hw/lps33hw.h | 23 ++++++++++++++++-
hw/drivers/sensors/lps33hw/src/lps33hw.c | 29 ++++++++++++++++++++++
2 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h b/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h
index baa9a31..014da64 100644
--- a/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h
+++ b/hw/drivers/sensors/lps33hw/include/lps33hw/lps33hw.h
@@ -82,7 +82,10 @@ struct lps33hw_private_driver_data {
struct lps33hw {
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
- struct bus_i2c_node i2c_node;
+ union {
+ struct bus_i2c_node i2c_node;
+ struct bus_spi_node spi_node;
+ };
#else
struct os_dev dev;
#endif
@@ -90,6 +93,9 @@ struct lps33hw {
struct lps33hw_cfg cfg;
os_time_t last_read_time;
struct lps33hw_private_driver_data pdd;
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+ bool node_is_spi;
+#endif
};
/**
@@ -235,6 +241,21 @@ int
lps33hw_create_i2c_sensor_dev(struct bus_i2c_node *node, const char *name,
const struct bus_i2c_node_cfg *i2c_cfg,
struct sensor_itf *sensor_itf);
+
+/**
+ * Create SPI bus node for LPS33HW sensor
+ *
+ * @param node Bus node
+ * @param name Device name
+ * @param spi_cfg SPI node configuration
+ * @param sensor_itf Sensors interface
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+lps33hw_create_spi_sensor_dev(struct bus_spi_node *node, const char *name,
+ const struct bus_spi_node_cfg *spi_cfg,
+ struct sensor_itf *sensor_itf);
#endif
#ifdef __cplusplus
diff --git a/hw/drivers/sensors/lps33hw/src/lps33hw.c b/hw/drivers/sensors/lps33hw/src/lps33hw.c
index 7cc221b..d215b36 100644
--- a/hw/drivers/sensors/lps33hw/src/lps33hw.c
+++ b/hw/drivers/sensors/lps33hw/src/lps33hw.c
@@ -404,6 +404,12 @@ lps33hw_get_regs(struct sensor_itf *itf, uint8_t reg, uint8_t size,
int rc;
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+ struct lps33hw *dev = (struct lps33hw *)itf->si_dev;
+
+ if (dev->node_is_spi) {
+ reg |= LPS33HW_SPI_READ_CMD_BIT;
+ }
+
rc = bus_node_simple_write_read_transact(itf->si_dev, ®, 1, buffer, size);
#else
rc = sensor_itf_lock(itf, MYNEWT_VAL(LPS33HW_ITF_LOCK_TMO));
@@ -1121,15 +1127,38 @@ lps33hw_create_i2c_sensor_dev(struct bus_i2c_node *node, const char *name,
const struct bus_i2c_node_cfg *i2c_cfg,
struct sensor_itf *sensor_itf)
{
+ struct lps33hw *dev = (struct lps33hw *)node;
struct bus_node_callbacks cbs = {
.init = init_node_cb,
};
int rc;
+ dev->node_is_spi = false;
+
bus_node_set_callbacks((struct os_dev *)node, &cbs);
rc = bus_i2c_node_create(name, node, i2c_cfg, sensor_itf);
return rc;
}
+
+int
+lps33hw_create_spi_sensor_dev(struct bus_spi_node *node, const char *name,
+ const struct bus_spi_node_cfg *spi_cfg,
+ struct sensor_itf *sensor_itf)
+{
+ struct lps33hw *dev = (struct lps33hw *)node;
+ struct bus_node_callbacks cbs = {
+ .init = init_node_cb,
+ };
+ int rc;
+
+ dev->node_is_spi = true;
+
+ bus_node_set_callbacks((struct os_dev *)node, &cbs);
+
+ rc = bus_spi_node_create(name, node, spi_cfg, sensor_itf);
+
+ return rc;
+}
#endif
[mynewt-core] 06/08: hw/drivers/lis2dh12: Add proper I2C/SPI
interface handling
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 4a246d17bba2d5e89ebf9f7dc2749c71ff3ac70d
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Dec 4 17:48:55 2018 +0100
hw/drivers/lis2dh12: Add proper I2C/SPI interface handling
---
.../sensors/lis2dh12/include/lis2dh12/lis2dh12.h | 3 +++
hw/drivers/sensors/lis2dh12/src/lis2dh12.c | 26 ++++++++++++++++++++--
hw/drivers/sensors/lis2dh12/src/lis2dh12_priv.h | 4 ++--
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/hw/drivers/sensors/lis2dh12/include/lis2dh12/lis2dh12.h b/hw/drivers/sensors/lis2dh12/include/lis2dh12/lis2dh12.h
index b7b86ca..fe89b57 100644
--- a/hw/drivers/sensors/lis2dh12/include/lis2dh12/lis2dh12.h
+++ b/hw/drivers/sensors/lis2dh12/include/lis2dh12/lis2dh12.h
@@ -274,6 +274,9 @@ struct lis2dh12 {
struct lis2dh12_int intr;
os_time_t last_read_time;
struct lis2dh12_pdd pdd;
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+ bool node_is_spi;
+#endif
};
/**
diff --git a/hw/drivers/sensors/lis2dh12/src/lis2dh12.c b/hw/drivers/sensors/lis2dh12/src/lis2dh12.c
index 41bdce6..20042f8 100644
--- a/hw/drivers/sensors/lis2dh12/src/lis2dh12.c
+++ b/hw/drivers/sensors/lis2dh12/src/lis2dh12.c
@@ -236,7 +236,7 @@ lis2dh12_i2c_readlen(struct sensor_itf *itf, uint8_t addr, uint8_t *buffer,
int rc;
if (len > 1)
{
- addr |= 0x80;
+ addr |= LIS2DH12_I2C_ADDR_INC;
}
uint8_t payload[20] = { addr, 0, 0, 0, 0, 0, 0, 0,
@@ -310,7 +310,7 @@ lis2dh12_spi_readlen(struct sensor_itf *itf, uint8_t addr, uint8_t *payload,
* requested is more than 1
*/
if (len > 1) {
- addr |= LIS2DH12_SPI_ADR_INC;
+ addr |= LIS2DH12_SPI_ADDR_INC;
}
/* Select the device */
@@ -483,6 +483,13 @@ lis2dh12_writelen(struct sensor_itf *itf, uint8_t addr, uint8_t *payload,
*/
uint8_t payload[19];
} write_data;
+ struct lis2dh12 *dev = (struct lis2dh12 *)itf->si_dev;
+
+ if (dev->node_is_spi) {
+ addr |= LIS2DH12_SPI_ADDR_INC;
+ } else {
+ addr |= LIS2DH12_I2C_ADDR_INC;
+ }
if (len > sizeof(write_data.payload)) {
return -1;
@@ -526,6 +533,15 @@ lis2dh12_readlen(struct sensor_itf *itf, uint8_t addr, uint8_t *payload,
int rc;
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+ struct lis2dh12 *dev = (struct lis2dh12 *)itf->si_dev;
+
+ if (dev->node_is_spi) {
+ addr |= LIS2DH12_SPI_READ_CMD_BIT;
+ addr |= LIS2DH12_SPI_ADDR_INC;
+ } else {
+ addr |= LIS2DH12_I2C_ADDR_INC;
+ }
+
rc = bus_node_simple_write_read_transact(itf->si_dev, &addr, 1, payload, len);
#else
rc = sensor_itf_lock(itf, MYNEWT_VAL(LIS2DH12_ITF_LOCK_TMO));
@@ -3019,11 +3035,14 @@ lis2dh12_create_i2c_sensor_dev(struct bus_i2c_node *node, const char *name,
const struct bus_i2c_node_cfg *i2c_cfg,
struct sensor_itf *sensor_itf)
{
+ struct lis2dh12 *dev = (struct lis2dh12 *)node;
struct bus_node_callbacks cbs = {
.init = init_node_cb,
};
int rc;
+ dev->node_is_spi = false;
+
bus_node_set_callbacks((struct os_dev *)node, &cbs);
rc = bus_i2c_node_create(name, node, i2c_cfg, sensor_itf);
@@ -3036,11 +3055,14 @@ lis2dh12_create_spi_sensor_dev(struct bus_spi_node *node, const char *name,
const struct bus_spi_node_cfg *spi_cfg,
struct sensor_itf *sensor_itf)
{
+ struct lis2dh12 *dev = (struct lis2dh12 *)node;
struct bus_node_callbacks cbs = {
.init = init_node_cb,
};
int rc;
+ dev->node_is_spi = true;
+
bus_node_set_callbacks((struct os_dev *)node, &cbs);
rc = bus_spi_node_create(name, node, spi_cfg, sensor_itf);
diff --git a/hw/drivers/sensors/lis2dh12/src/lis2dh12_priv.h b/hw/drivers/sensors/lis2dh12/src/lis2dh12_priv.h
index 6848b15..035a2ce 100644
--- a/hw/drivers/sensors/lis2dh12/src/lis2dh12_priv.h
+++ b/hw/drivers/sensors/lis2dh12/src/lis2dh12_priv.h
@@ -171,8 +171,8 @@ extern "C" {
#define LIS2DH12_REG_ACT_DUR 0x3F
#define LIS2DH12_SPI_READ_CMD_BIT 0x80
-
-#define LIS2DH12_SPI_ADR_INC 0x40
+#define LIS2DH12_SPI_ADDR_INC 0x40
+#define LIS2DH12_I2C_ADDR_INC 0x80
int lis2dh12_writelen(struct sensor_itf *itf, uint8_t addr, uint8_t *payload, uint8_t len);
int lis2dh12_readlen(struct sensor_itf *itf, uint8_t addr, uint8_t *payload, uint8_t len);
[mynewt-core] 07/08: hw/drivers/lps33thw: Add proper I2C/SPI
interface handling
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 3ff35b3dc24d295b8ef62fc3f81f17c3e69680af
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Dec 4 17:48:49 2018 +0100
hw/drivers/lps33thw: Add proper I2C/SPI interface handling
---
hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h | 3 +++
hw/drivers/sensors/lps33thw/src/lps33thw.c | 12 ++++++++++++
2 files changed, 15 insertions(+)
diff --git a/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h b/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h
index 083d8ac..de17a31 100644
--- a/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h
+++ b/hw/drivers/sensors/lps33thw/include/lps33thw/lps33thw.h
@@ -94,6 +94,9 @@ struct lps33thw {
struct lps33thw_cfg cfg;
os_time_t last_read_time;
struct lps33thw_private_driver_data pdd;
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+ bool node_is_spi;
+#endif
};
/**
diff --git a/hw/drivers/sensors/lps33thw/src/lps33thw.c b/hw/drivers/sensors/lps33thw/src/lps33thw.c
index d4d94f0..eaab21a 100644
--- a/hw/drivers/sensors/lps33thw/src/lps33thw.c
+++ b/hw/drivers/sensors/lps33thw/src/lps33thw.c
@@ -411,6 +411,12 @@ lps33thw_get_regs(struct sensor_itf *itf, uint8_t reg, uint8_t size,
int rc;
#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+ struct lps33thw *dev = (struct lps33thw *)itf->si_dev;
+
+ if (dev->node_is_spi) {
+ reg |= LPS33THW_SPI_READ_CMD_BIT;
+ }
+
rc = bus_node_simple_write_read_transact(itf->si_dev, ®, 1, buffer, size);
#else
rc = sensor_itf_lock(itf, MYNEWT_VAL(LPS33THW_ITF_LOCK_TMO));
@@ -1128,11 +1134,14 @@ lps33thw_create_i2c_sensor_dev(struct bus_i2c_node *node, const char *name,
const struct bus_i2c_node_cfg *i2c_cfg,
struct sensor_itf *sensor_itf)
{
+ struct lps33thw *dev = (struct lps33thw *)node;
struct bus_node_callbacks cbs = {
.init = init_node_cb,
};
int rc;
+ dev->node_is_spi = false;
+
bus_node_set_callbacks((struct os_dev *)node, &cbs);
rc = bus_i2c_node_create(name, node, i2c_cfg, sensor_itf);
@@ -1145,11 +1154,14 @@ lps33thw_create_spi_sensor_dev(struct bus_spi_node *node, const char *name,
const struct bus_spi_node_cfg *spi_cfg,
struct sensor_itf *sensor_itf)
{
+ struct lps33thw *dev = (struct lps33thw *)node;
struct bus_node_callbacks cbs = {
.init = init_node_cb,
};
int rc;
+ dev->node_is_spi = true;
+
bus_node_set_callbacks((struct os_dev *)node, &cbs);
rc = bus_spi_node_create(name, node, spi_cfg, sensor_itf);
[mynewt-core] 02/08: hw/bus: Fix lock timeout value usage
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit f583bb3d668adca14b706bfe660f91a91b97015b
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Nov 30 11:30:58 2018 +0100
hw/bus: Fix lock timeout value usage
---
hw/bus/src/bus.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/bus/src/bus.c b/hw/bus/src/bus.c
index c555f17..0bc7c0f 100644
--- a/hw/bus/src/bus.c
+++ b/hw/bus/src/bus.c
@@ -147,7 +147,7 @@ bus_node_read(struct os_dev *node, void *buf, uint16_t length,
return SYS_ENOTSUP;
}
- rc = bus_node_lock(node, g_bus_node_lock_timeout);
+ rc = bus_node_lock(node, bus_node_get_lock_timeout(node));
if (rc) {
return rc;
}
@@ -174,7 +174,7 @@ bus_node_write(struct os_dev *node, const void *buf, uint16_t length,
return SYS_ENOTSUP;
}
- rc = bus_node_lock(node, g_bus_node_lock_timeout);
+ rc = bus_node_lock(node, bus_node_get_lock_timeout(node));
if (rc) {
return rc;
}
@@ -202,7 +202,7 @@ bus_node_write_read_transact(struct os_dev *node, const void *wbuf,
return SYS_ENOTSUP;
}
- rc = bus_node_lock(node, g_bus_node_lock_timeout);
+ rc = bus_node_lock(node, bus_node_get_lock_timeout(node));
if (rc) {
return rc;
}
[mynewt-core] 01/08: hw/bus: Fix typo
Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 27efa6adc65383b947a16cb2d1cb73aa53cdbd01
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Nov 30 11:29:55 2018 +0100
hw/bus: Fix typo
---
hw/bus/include/bus/bus.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/bus/include/bus/bus.h b/hw/bus/include/bus/bus.h
index 9158570..9e1ec03 100644
--- a/hw/bus/include/bus/bus.h
+++ b/hw/bus/include/bus/bus.h
@@ -221,7 +221,7 @@ bus_node_unlock(struct os_dev *node);
/**
* Get node configured lock timeout
*
- * Returns lock timeout as configured for node. If not timeout is configured for
+ * Returns lock timeout as configured for node. If no timeout is configured for
* give node or no node is specified, default timeout is returned.
*
* @param node Node to get timeout for