summaryrefslogtreecommitdiff
path: root/include/motion_sense.h
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-06-25 12:44:16 -0600
committerCommit Bot <commit-bot@chromium.org>2019-07-19 21:11:02 +0000
commitd1a18f82ed831d4e640336ff5571f5fa64bc7b36 (patch)
treec46aeb6136de1c27c66e3d5f662e9620161bef7b /include/motion_sense.h
parent1f14229fa7e499dfcee07d17add187598ff0a46c (diff)
downloadchrome-ec-d1a18f82ed831d4e640336ff5571f5fa64bc7b36.tar.gz
Use 7bit I2C/SPI slave addresses in EC
Opt for 7bit slave addresses in EC code. If 8bit is expected by a driver, make it local and show this in the naming. Use __7b, __7bf and __8b as name extensions for i2c/spi addresses used in the EC codebase. __7b indicates a 7bit address by itself. __7bf indicates a 7bit address with optional flags attached. __8b indicates a 8bit address by itself. Allow space for 10bit addresses, even though this is not currently being used by any of our attached devices. These extensions are for verification purposes only and will be removed in the last pass of this ticket. I want to make sure the variable names reflect the type to help eliminate future 7/8/7-flags confusion. BUG=chromium:971296 BRANCH=none TEST=make buildall -j Change-Id: I2fc3d1b52ce76184492b2aaff3060f486ca45f45 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1699893 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'include/motion_sense.h')
-rw-r--r--include/motion_sense.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 34da3f9ea5..0e9f79e422 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -12,6 +12,7 @@
#include "common.h"
#include "ec_commands.h"
#include "gpio.h"
+#include "i2c.h"
#include "math_util.h"
#include "queue.h"
#include "timer.h"
@@ -81,6 +82,24 @@ enum sensor_config {
#endif
/*
+ * I2C/SPI Slave Address encoding for motion sensors
+ * - The generic defines, I2C_ADDR_MASK and I2C_IS_BIG_ENDIAN_MASK
+ * are defined in i2c.h.
+ * - Motion sensors support some sensors on the SPI bus, so this
+ * overloads the I2C Address to use a single bit to indicate
+ * it is a SPI address instead of an I2C. Since SPI does not
+ * use slave addressing, it is up to the driver to use this
+ * field as it sees fit
+ */
+#define SLAVE_MK_I2C_ADDR__7bf(x__7b) (x__7b)
+#define SLAVE_MK_SPI_ADDR__7bf(x__7b) ((x__7b) | I2C_FLAG_ADDR_IS_SPI)
+
+#define SLAVE_GET_I2C_ADDR__7b(x__7bf) (I2C_GET_ADDR__7b(x__7bf))
+#define SLAVE_GET_SPI_ADDR__7b(x__7bf) ((x__7bf) & I2C_ADDR_MASK)
+
+#define SLAVE_IS_SPI(x__7bf) ((x__7bf) & I2C_FLAG_ADDR_IS_SPI)
+
+/*
* Define the frequency to use in max_frequency based on the maximal frequency
* the sensor support and what the EC can provide.
* Return a frequency the sensor supports.
@@ -131,7 +150,7 @@ struct motion_sensor_t {
/* i2c port */
uint8_t port;
/* i2c address or SPI slave logic GPIO. */
- uint8_t addr;
+ uint16_t i2c_spi_addr__7bf;
/*
* Various flags, see MOTIONSENSE_FLAG_*