mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
I2C: Eliminate the I2C_WRITE and I2C_READ macros
This commit is contained in:
@@ -1614,10 +1614,9 @@ o Other drivers (drivers/)
|
|||||||
in a multi-tasking I2C environment:
|
in a multi-tasking I2C environment:
|
||||||
- I2C_SETFREQUENCY: Frequency setting can be overwritten by other
|
- I2C_SETFREQUENCY: Frequency setting can be overwritten by other
|
||||||
I2C usage.
|
I2C usage.
|
||||||
- I2C_SETADDRESS used with I2C_READ and I2C_WRITE:
|
- I2C_SETADDRESS: The I2C address can and will be changed by other
|
||||||
Similarly, address can and will be changed by other I2C usage.
|
I2C usage. NOTE also that I2C_SETADDRESS also sets the address width
|
||||||
NOTE also that I2C_SETADDRESS also sets the address width (either
|
(either 7 or 10 bits).
|
||||||
7 or 10 bits).
|
|
||||||
- I2C_TRANSFER: This is the only interface that is properly self
|
- I2C_TRANSFER: This is the only interface that is properly self
|
||||||
contained and protected from most mult-tasking issues. But even
|
contained and protected from most mult-tasking issues. But even
|
||||||
this interface can suffer if there are differing frequency settings.
|
this interface can suffer if there are differing frequency settings.
|
||||||
@@ -1626,8 +1625,7 @@ o Other drivers (drivers/)
|
|||||||
are two ways to fix theses problems: (1) Add a locking method such
|
are two ways to fix theses problems: (1) Add a locking method such
|
||||||
as is provided with the SPI interface, or (2) make each interface
|
as is provided with the SPI interface, or (2) make each interface
|
||||||
self-contained and atomic: Remove the I2C_FREQUENCY and I2C_ADDRESS
|
self-contained and atomic: Remove the I2C_FREQUENCY and I2C_ADDRESS
|
||||||
methods; Add frequency to all interfaces and add the address to
|
methods; Add frequency to the I2C_TRANSFER message structure.
|
||||||
I2C_READ and I2C_WRITE.
|
|
||||||
|
|
||||||
o Linux/Cywgin simulation (arch/sim)
|
o Linux/Cywgin simulation (arch/sim)
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|||||||
+1
-1
Submodule configs updated: ee7d12e263...7286dea76c
@@ -332,8 +332,15 @@ uint16_t wm8904_readreg(FAR struct wm8904_dev_s *priv, uint8_t regaddr)
|
|||||||
static void wm8904_writereg(FAR struct wm8904_dev_s *priv, uint8_t regaddr,
|
static void wm8904_writereg(FAR struct wm8904_dev_s *priv, uint8_t regaddr,
|
||||||
uint16_t regval)
|
uint16_t regval)
|
||||||
{
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
int retries;
|
int retries;
|
||||||
|
|
||||||
|
/* Setup up the I2C configuration */
|
||||||
|
|
||||||
|
config.frequency = priv->lower->frequency;
|
||||||
|
config.address = priv->lower->address;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
/* Try up to three times to read the register */
|
/* Try up to three times to read the register */
|
||||||
|
|
||||||
for (retries = 1; retries <= 3; retries++)
|
for (retries = 1; retries <= 3; retries++)
|
||||||
@@ -351,13 +358,13 @@ static void wm8904_writereg(FAR struct wm8904_dev_s *priv, uint8_t regaddr,
|
|||||||
* completed.
|
* completed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = I2C_WRITE(priv->i2c, data, 3);
|
ret = i2c_write(priv->i2c, &config, data, 3);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_I2C_RESET
|
#ifdef CONFIG_I2C_RESET
|
||||||
/* Perhaps the I2C bus is locked up? Try to shake the bus free */
|
/* Perhaps the I2C bus is locked up? Try to shake the bus free */
|
||||||
|
|
||||||
auddbg("WARNING: I2C_TRANSFER failed: %d ... Resetting\n", ret);
|
auddbg("WARNING: i2c_write failed: %d ... Resetting\n", ret);
|
||||||
|
|
||||||
ret = up_i2creset(priv->i2c);
|
ret = up_i2creset(priv->i2c);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
|||||||
@@ -128,10 +128,10 @@ static const struct ioexpander_ops_s g_pca9555_ops =
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: pca9555_writeread
|
* Name: pca9555_write
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Write to then read from the I2C device.
|
* Write to the I2C device.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|||||||
+10
-11
@@ -103,6 +103,8 @@ static int pca9635pw_i2c_write_byte(FAR struct pca9635pw_dev_s *priv,
|
|||||||
uint8_t const reg_addr,
|
uint8_t const reg_addr,
|
||||||
uint8_t const reg_val)
|
uint8_t const reg_val)
|
||||||
{
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
dbg("pca9635pw_i2c_write_byte\n");
|
dbg("pca9635pw_i2c_write_byte\n");
|
||||||
|
|
||||||
/* assemble the 2 byte message comprised of reg_addr and reg_val */
|
/* assemble the 2 byte message comprised of reg_addr and reg_val */
|
||||||
@@ -113,25 +115,22 @@ static int pca9635pw_i2c_write_byte(FAR struct pca9635pw_dev_s *priv,
|
|||||||
buffer[0] = reg_addr;
|
buffer[0] = reg_addr;
|
||||||
buffer[1] = reg_val;
|
buffer[1] = reg_val;
|
||||||
|
|
||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Setup up the I2C configuration */
|
||||||
|
|
||||||
uint8_t const NUMBER_OF_I2C_ADDRESS_BITS = 7;
|
config.frequency = I2C_BUS_FREQ_HZ;
|
||||||
|
config.address = priv->i2c_addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
dbg("i2c addr: 0x%02X reg addr: 0x%02X value: 0x%02X\n", priv->i2c_addr,
|
dbg("i2c addr: 0x%02X reg addr: 0x%02X value: 0x%02X\n", priv->i2c_addr,
|
||||||
buffer[0], buffer[1]);
|
buffer[0], buffer[1]);
|
||||||
|
|
||||||
int ret = I2C_SETADDRESS(priv->i2c, priv->i2c_addr,
|
|
||||||
NUMBER_OF_I2C_ADDRESS_BITS);
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
dbg("I2C_SETADDRESS returned error code %d\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = I2C_WRITE(priv->i2c, buffer, BUFFER_SIZE);
|
ret = i2c_write(priv->i2c, &config, buffer, BUFFER_SIZE);
|
||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
{
|
{
|
||||||
dbg("I2C_WRITE returned error code %d\n", ret);
|
dbg("i2c_write returned error code %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+56
-8
@@ -4,9 +4,9 @@
|
|||||||
*
|
*
|
||||||
* Copyright (C) 2011 Li Zhuoyi. All rights reserved.
|
* Copyright (C) 2011 Li Zhuoyi. All rights reserved.
|
||||||
* Author: Li Zhuoyi <lzyy.cn@gmail.com>
|
* Author: Li Zhuoyi <lzyy.cn@gmail.com>
|
||||||
* History: 0.1 2011-08-20 initial version
|
|
||||||
*
|
*
|
||||||
* 2011-11-1 Added support for larger MTD block sizes: Hal Glenn <hglenn@2g-eng.com>
|
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Derived from drivers/mtd/m25px.c
|
* Derived from drivers/mtd/m25px.c
|
||||||
*
|
*
|
||||||
@@ -192,6 +192,54 @@ static struct at24c_dev_s g_at24c;
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: at24c_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int at24c_i2c_write(FAR struct at24c_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_AT24XX_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->dev, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: at24c_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int at24c_i2c_read(FAR struct at24c_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_AT24XX_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->dev, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: at24c_eraseall
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
static int at24c_eraseall(FAR struct at24c_dev_s *priv)
|
static int at24c_eraseall(FAR struct at24c_dev_s *priv)
|
||||||
{
|
{
|
||||||
int startblock = 0;
|
int startblock = 0;
|
||||||
@@ -212,12 +260,12 @@ static int at24c_eraseall(FAR struct at24c_dev_s *priv)
|
|||||||
I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7);
|
I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0)
|
while (at24c_i2c_write(priv, buf, AT24XX_ADDRSIZE) < 0)
|
||||||
{
|
{
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
I2C_WRITE(priv->dev, buf, AT24XX_PAGESIZE + AT24XX_ADDRSIZE);
|
at24c_i2c_write(priv, buf, AT24XX_PAGESIZE + AT24XX_ADDRSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
@@ -273,7 +321,7 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset,
|
|||||||
I2C_SETADDRESS(priv->dev, address | ((offset >> 8) & 0x07), 7);
|
I2C_SETADDRESS(priv->dev, address | ((offset >> 8) & 0x07), 7);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0)
|
while (at24c_i2c_write(priv, buf, AT24XX_ADDRSIZE) < 0)
|
||||||
{
|
{
|
||||||
fvdbg("wait\n");
|
fvdbg("wait\n");
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
@@ -281,7 +329,7 @@ static ssize_t at24c_read_internal(FAR struct at24c_dev_s *priv, off_t offset,
|
|||||||
|
|
||||||
/* Then transfer the following bytes */
|
/* Then transfer the following bytes */
|
||||||
|
|
||||||
I2C_READ(priv->dev, buffer, nbytes);
|
at24c_i2c_read(priv, buffer, nbytes);
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,7 +436,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t
|
|||||||
I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7);
|
I2C_SETADDRESS(priv->dev, priv->addr | ((offset >> 8) & 0x07), 7);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (I2C_WRITE(priv->dev, buf, AT24XX_ADDRSIZE) < 0)
|
while (at24c_i2c_write(priv, buf, AT24XX_ADDRSIZE) < 0)
|
||||||
{
|
{
|
||||||
fvdbg("wait\n");
|
fvdbg("wait\n");
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
@@ -396,7 +444,7 @@ static ssize_t at24c_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t
|
|||||||
|
|
||||||
memcpy(&buf[AT24XX_ADDRSIZE], buffer, priv->pagesize);
|
memcpy(&buf[AT24XX_ADDRSIZE], buffer, priv->pagesize);
|
||||||
|
|
||||||
I2C_WRITE(priv->dev, buf, priv->pagesize + AT24XX_ADDRSIZE);
|
at24c_i2c_write(priv, buf, priv->pagesize + AT24XX_ADDRSIZE);
|
||||||
startblock++;
|
startblock++;
|
||||||
buffer += priv->pagesize;
|
buffer += priv->pagesize;
|
||||||
}
|
}
|
||||||
|
|||||||
+52
-5
@@ -5,6 +5,9 @@
|
|||||||
* Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved.
|
* Copyright (C) 2015 Alan Carvalho de Assis. All rights reserved.
|
||||||
* Author: Alan Carvalho de Assis <acassis@gmail.com>
|
* Author: Alan Carvalho de Assis <acassis@gmail.com>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@@ -144,6 +147,50 @@ static const struct battery_charger_operations_s g_bq2425xops =
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: bq2425x_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int bq2425x_i2c_write(FAR struct bq2425x_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = priv->frequency;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: bq2425x_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int bq2425x_i2c_read(FAR struct bq2425x_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = priv->frequency;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: bq2425x_getreg8
|
* Name: bq2425x_getreg8
|
||||||
*
|
*
|
||||||
@@ -167,19 +214,19 @@ static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr,
|
|||||||
|
|
||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, 1);
|
ret = bq2425x_i2c_write(priv, ®addr, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
batdbg("I2C_WRITE failed: %d\n", ret);
|
batdbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 8-bits from the register */
|
/* Restart and read 8-bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, &val, 1);
|
ret = bq2425x_i2c_read(priv, &val, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
batdbg("I2C_READ failed: %d\n", ret);
|
batdbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +264,7 @@ static int bq2425x_putreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr,
|
|||||||
|
|
||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
return I2C_WRITE(priv->i2c, buffer, 2);
|
return bq2425x_i2c_write(priv, buffer, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* drivers/power/max1704x.c
|
* drivers/power/max1704x.c
|
||||||
* Lower half driver for MAX1704x battery fuel gauge
|
* Lower half driver for MAX1704x battery fuel gauge
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -229,6 +229,50 @@ static const struct battery_gauge_operations_s g_max1704xops =
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: max1704x_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int max1704x_i2c_write(FAR struct max1704x_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = priv->frequency;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: max1704x_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int max1704x_i2c_read(FAR struct max1704x_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = priv->frequency;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: max1704x_getreg16
|
* Name: max1704x_getreg16
|
||||||
*
|
*
|
||||||
@@ -252,19 +296,19 @@ static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
|
|||||||
|
|
||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, 1);
|
ret = max1704x_i2c_write(priv, ®addr, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
batdbg("I2C_WRITE failed: %d\n", ret);
|
batdbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 16-bits from the register */
|
/* Restart and read 16-bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, buffer, 2);
|
ret = max1704x_i2c_read(priv, buffer, 2);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
batdbg("I2C_READ failed: %d\n", ret);
|
batdbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,7 +346,7 @@ static int max1704x_putreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
|
|||||||
|
|
||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
return I2C_WRITE(priv->i2c, buffer, 3);
|
return max1704x_i2c_write(priv, buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ config SN_LSM9DS1
|
|||||||
---help---
|
---help---
|
||||||
Enable driver support for the STMicro LSM9DS1.
|
Enable driver support for the STMicro LSM9DS1.
|
||||||
|
|
||||||
|
config LSM9DS1_I2C_FREQUENCY
|
||||||
|
bool "LSM9DS1 I2C frequency"
|
||||||
|
default 400000
|
||||||
|
range 1 400000
|
||||||
|
depends on SN_LSM9DS1
|
||||||
|
|
||||||
config MB7040
|
config MB7040
|
||||||
bool "MaxBotix MB7040 Sonar support"
|
bool "MaxBotix MB7040 Sonar support"
|
||||||
default n
|
default n
|
||||||
@@ -38,6 +44,12 @@ config MB7040
|
|||||||
---help---
|
---help---
|
||||||
Enable driver support for the MaxBotix MB7040 sonar.
|
Enable driver support for the MaxBotix MB7040 sonar.
|
||||||
|
|
||||||
|
config MB7040_I2C_FREQUENCY
|
||||||
|
bool "MB7040 I2C frequency"
|
||||||
|
default 400000
|
||||||
|
range 1 400000
|
||||||
|
depends on MB7040
|
||||||
|
|
||||||
config MCP9844
|
config MCP9844
|
||||||
bool "MCP9844 Temperature Sensor"
|
bool "MCP9844 Temperature Sensor"
|
||||||
default n
|
default n
|
||||||
@@ -45,6 +57,12 @@ config MCP9844
|
|||||||
---help---
|
---help---
|
||||||
Enable driver support for the MCP9844 I2C Temperature sensor.
|
Enable driver support for the MCP9844 I2C Temperature sensor.
|
||||||
|
|
||||||
|
config MCP9844_I2C_FREQUENCY
|
||||||
|
bool "MCP9844 I2C frequency"
|
||||||
|
default 400000
|
||||||
|
range 1 400000
|
||||||
|
depends on MCP9844
|
||||||
|
|
||||||
config MS58XX
|
config MS58XX
|
||||||
bool "MEAS MS58XX Altimeter support"
|
bool "MEAS MS58XX Altimeter support"
|
||||||
default n
|
default n
|
||||||
@@ -52,6 +70,12 @@ config MS58XX
|
|||||||
---help---
|
---help---
|
||||||
Enable driver support for MEAS MS58XX altimeters.
|
Enable driver support for MEAS MS58XX altimeters.
|
||||||
|
|
||||||
|
config MS58XX_I2C_FREQUENCY
|
||||||
|
bool "MS58XX I2C frequency"
|
||||||
|
default 400000
|
||||||
|
range 1 400000
|
||||||
|
depends on MS58XX
|
||||||
|
|
||||||
config MS58XX_VDD
|
config MS58XX_VDD
|
||||||
int "MEAS MS58XX VDD"
|
int "MEAS MS58XX VDD"
|
||||||
default 30
|
default 30
|
||||||
@@ -134,6 +158,12 @@ config LM75
|
|||||||
This should also work with compatible temperature sensors such as
|
This should also work with compatible temperature sensors such as
|
||||||
the TI TMP100/101.
|
the TI TMP100/101.
|
||||||
|
|
||||||
|
config LM75_I2C_FREQUENCY
|
||||||
|
bool "LM75 I2C frequency"
|
||||||
|
default 100000
|
||||||
|
range 1 100000
|
||||||
|
depends on I2C_LM75
|
||||||
|
|
||||||
config LM92
|
config LM92
|
||||||
bool "TI LM92 Temperature Sensor support"
|
bool "TI LM92 Temperature Sensor support"
|
||||||
default n
|
default n
|
||||||
@@ -141,6 +171,12 @@ config LM92
|
|||||||
---help---
|
---help---
|
||||||
Enable driver support for the TI LM92 Temperature Sensor.
|
Enable driver support for the TI LM92 Temperature Sensor.
|
||||||
|
|
||||||
|
config LM92_I2C_FREQUENCY
|
||||||
|
bool "LM92 I2C frequency"
|
||||||
|
default 400000
|
||||||
|
range 1 400000
|
||||||
|
depends on LM92
|
||||||
|
|
||||||
config QENCODER
|
config QENCODER
|
||||||
bool "Qencoder"
|
bool "Qencoder"
|
||||||
default n
|
default n
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
* Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
* Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
||||||
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@@ -111,6 +114,50 @@ static const struct qe_ops_s g_qeops =
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: as5048b_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int as5048b_i2c_write(FAR struct as5048b_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = priv->frequency;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: as5048b_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int as5048b_i2c_read(FAR struct as5048b_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = priv->frequency;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: as5048b_readu8
|
* Name: as5048b_readu8
|
||||||
*
|
*
|
||||||
@@ -127,19 +174,19 @@ static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr));
|
ret = as5048b_i2c_write(priv, ®addr, sizeof(regaddr));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 8 bits from the register */
|
/* Restart and read 8 bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, regval, sizeof(*regval));
|
ret = as5048b_i2c_read(priv, regval, sizeof(*regval));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,10 +256,10 @@ static int as5048b_writeu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, buffer, sizeof(buffer));
|
ret = as5048b_i2c_write(priv, buffer, sizeof(buffer));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
+57
-11
@@ -3,10 +3,12 @@
|
|||||||
* drivers/sensors/bmp180.c
|
* drivers/sensors/bmp180.c
|
||||||
* Character driver for the Freescale BMP1801 Barometer Sensor
|
* Character driver for the Freescale BMP1801 Barometer Sensor
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
|
||||||
* Copyright (C) 2015 Alan Carvalho de Assis
|
* Copyright (C) 2015 Alan Carvalho de Assis
|
||||||
* Author: Alan Carvalho de Assis <acassis@gmail.com>
|
* Author: Alan Carvalho de Assis <acassis@gmail.com>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@@ -171,6 +173,50 @@ static const struct file_operations g_bmp180fops =
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: bmp180_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int bmp180_i2c_write(FAR struct bmp180_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = priv->freq;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: bmp180_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int bmp180_i2c_read(FAR struct bmp180_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = priv->freq;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: bmp180_getreg8
|
* Name: bmp180_getreg8
|
||||||
*
|
*
|
||||||
@@ -186,19 +232,19 @@ static uint8_t bmp180_getreg8(FAR struct bmp180_dev_s *priv, uint8_t regaddr)
|
|||||||
|
|
||||||
/* Restart the register */
|
/* Restart the register */
|
||||||
|
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, 1);
|
ret = bmp180_i2c_write(priv, ®addr, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart the register */
|
/* Restart the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, ®val, 1);
|
ret = bmp180_i2c_read(priv, ®val, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,19 +267,19 @@ static uint16_t bmp180_getreg16(FAR struct bmp180_dev_s *priv, uint8_t regaddr)
|
|||||||
|
|
||||||
/* Register to read */
|
/* Register to read */
|
||||||
|
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, 1);
|
ret = bmp180_i2c_write(priv, ®addr, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read register */
|
/* Read register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, (uint8_t *)®val, 2);
|
ret = bmp180_i2c_read(priv, (uint8_t *)®val, 2);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,10 +312,10 @@ static void bmp180_putreg8(FAR struct bmp180_dev_s *priv, uint8_t regaddr,
|
|||||||
|
|
||||||
/* Restart the register */
|
/* Restart the register */
|
||||||
|
|
||||||
ret = I2C_WRITE(priv->i2c, (uint8_t *) &data, 2);
|
ret = bmp180_i2c_write(priv, (uint8_t *) &data, 2);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+70
-17
@@ -2,7 +2,7 @@
|
|||||||
* drivers/sensors/lm75.c
|
* drivers/sensors/lm75.c
|
||||||
* Character driver for the STMicro LM-75 Temperature Sensor
|
* Character driver for the STMicro LM-75 Temperature Sensor
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2011, 2013, 2016 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -56,6 +56,10 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_LM75_I2C_FREQUENCY
|
||||||
|
# define CONFIG_LM75_I2C_FREQUENCY 100000
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Centigrade to Fahrenheit conversion: F = 9*C/5 + 32 */
|
/* Centigrade to Fahrenheit conversion: F = 9*C/5 + 32 */
|
||||||
|
|
||||||
#define B16_9DIV5 (9 * 65536 / 5)
|
#define B16_9DIV5 (9 * 65536 / 5)
|
||||||
@@ -77,13 +81,17 @@ struct lm75_dev_s
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/* I2C Helpers */
|
/* I2C Helpers */
|
||||||
|
|
||||||
static int lm75_readb16(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
static int lm75_i2c_write(FAR struct lm75_dev_s *priv,
|
||||||
FAR b16_t *regvalue);
|
FAR const uint8_t *buffer, int buflen);
|
||||||
static int lm75_writeb16(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
static int lm75_i2c_read(FAR struct lm75_dev_s *priv,
|
||||||
b16_t regval);
|
FAR uint8_t *buffer, int buflen);
|
||||||
static int lm75_readtemp(FAR struct lm75_dev_s *priv, FAR b16_t *temp);
|
static int lm75_readb16(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
||||||
static int lm75_readconf(FAR struct lm75_dev_s *priv, FAR uint8_t *conf);
|
FAR b16_t *regvalue);
|
||||||
static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf);
|
static int lm75_writeb16(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
||||||
|
b16_t regval);
|
||||||
|
static int lm75_readtemp(FAR struct lm75_dev_s *priv, FAR b16_t *temp);
|
||||||
|
static int lm75_readconf(FAR struct lm75_dev_s *priv, FAR uint8_t *conf);
|
||||||
|
static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf);
|
||||||
|
|
||||||
/* Character driver methods */
|
/* Character driver methods */
|
||||||
|
|
||||||
@@ -115,6 +123,51 @@ static const struct file_operations g_lm75fops =
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: lm75_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int lm75_i2c_write(FAR struct lm75_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_LM75_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: lm75_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int lm75_i2c_read(FAR struct lm75_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_LM75_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: lm75_readb16
|
* Name: lm75_readb16
|
||||||
*
|
*
|
||||||
@@ -132,19 +185,19 @@ static int lm75_readb16(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, 1);
|
ret = lm75_i2c_write(priv, ®addr, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 16-bits from the register (discarding 7) */
|
/* Restart and read 16-bits from the register (discarding 7) */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, buffer, 2);
|
ret = lm75_i2c_read(priv, buffer, 2);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +238,7 @@ static int lm75_writeb16(FAR struct lm75_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
return I2C_WRITE(priv->i2c, buffer, 3);
|
return lm75_i2c_write(priv, buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -244,16 +297,16 @@ static int lm75_readconf(FAR struct lm75_dev_s *priv, FAR uint8_t *conf)
|
|||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
|
|
||||||
buffer = LM75_CONF_REG;
|
buffer = LM75_CONF_REG;
|
||||||
ret = I2C_WRITE(priv->i2c, &buffer, 1);
|
ret = lm75_i2c_write(priv, &buffer, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 8-bits from the register */
|
/* Restart and read 8-bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, conf, 1);
|
ret = lm75_i2c_read(priv, conf, 1);
|
||||||
sndbg("conf: %02x ret: %d\n", *conf, ret);
|
sndbg("conf: %02x ret: %d\n", *conf, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -280,7 +333,7 @@ static int lm75_writeconf(FAR struct lm75_dev_s *priv, uint8_t conf)
|
|||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
return I2C_WRITE(priv->i2c, buffer, 2);
|
return lm75_i2c_write(priv, buffer, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
+73
-20
@@ -58,6 +58,10 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_LM92_I2C_FREQUENCY
|
||||||
|
# define CONFIG_LM92_I2C_FREQUENCY 400000
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Centigrade to Fahrenheit conversion: F = 9*C/5 + 32 */
|
/* Centigrade to Fahrenheit conversion: F = 9*C/5 + 32 */
|
||||||
|
|
||||||
#define B16_9DIV5 (9 * 65536 / 5)
|
#define B16_9DIV5 (9 * 65536 / 5)
|
||||||
@@ -79,13 +83,17 @@ struct lm92_dev_s
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/* I2C Helpers */
|
/* I2C Helpers */
|
||||||
|
|
||||||
static int lm92_readb16(FAR struct lm92_dev_s *priv, uint8_t regaddr,
|
static int lm92_i2c_write(FAR struct lm92_dev_s *priv,
|
||||||
FAR b16_t *regvalue);
|
FAR const uint8_t *buffer, int buflen);
|
||||||
static int lm92_writeb16(FAR struct lm92_dev_s *priv, uint8_t regaddr,
|
static int lm92_i2c_read(FAR struct lm92_dev_s *priv,
|
||||||
b16_t regval);
|
FAR uint8_t *buffer, int buflen);
|
||||||
static int lm92_readtemp(FAR struct lm92_dev_s *priv, FAR b16_t *temp);
|
static int lm92_readb16(FAR struct lm92_dev_s *priv, uint8_t regaddr,
|
||||||
static int lm92_readconf(FAR struct lm92_dev_s *priv, FAR uint8_t *conf);
|
FAR b16_t *regvalue);
|
||||||
static int lm92_writeconf(FAR struct lm92_dev_s *priv, uint8_t conf);
|
static int lm92_writeb16(FAR struct lm92_dev_s *priv, uint8_t regaddr,
|
||||||
|
b16_t regval);
|
||||||
|
static int lm92_readtemp(FAR struct lm92_dev_s *priv, FAR b16_t *temp);
|
||||||
|
static int lm92_readconf(FAR struct lm92_dev_s *priv, FAR uint8_t *conf);
|
||||||
|
static int lm92_writeconf(FAR struct lm92_dev_s *priv, uint8_t conf);
|
||||||
|
|
||||||
/* Character driver methods */
|
/* Character driver methods */
|
||||||
|
|
||||||
@@ -117,6 +125,51 @@ static const struct file_operations g_lm92fops =
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: lm92_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int lm92_i2c_write(FAR struct lm92_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_LM92_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: lm92_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int lm92_i2c_read(FAR struct lm92_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_LM92_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: lm92_readb16
|
* Name: lm92_readb16
|
||||||
*
|
*
|
||||||
@@ -135,19 +188,19 @@ static int lm92_readb16(FAR struct lm92_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, 1);
|
ret = lm92_i2c_write(priv, ®addr, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 16 bits from the register (discarding 3) */
|
/* Restart and read 16 bits from the register (discarding 3) */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, buffer, 2);
|
ret = lm92_i2c_read(priv, buffer, 2);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +241,7 @@ static int lm92_writeb16(FAR struct lm92_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
return I2C_WRITE(priv->i2c, buffer, 3);
|
return lm92_i2c_write(priv, buffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -247,16 +300,16 @@ static int lm92_readconf(FAR struct lm92_dev_s *priv, FAR uint8_t *conf)
|
|||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
|
|
||||||
buffer = LM92_CONF_REG;
|
buffer = LM92_CONF_REG;
|
||||||
ret = I2C_WRITE(priv->i2c, &buffer, 1);
|
ret = lm92_i2c_write(priv, &buffer, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 8 bits from the register */
|
/* Restart and read 8 bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, conf, 1);
|
ret = lm92_i2c_read(priv, conf, 1);
|
||||||
sndbg("conf: %02x ret: %d\n", *conf, ret);
|
sndbg("conf: %02x ret: %d\n", *conf, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -283,7 +336,7 @@ static int lm92_writeconf(FAR struct lm92_dev_s *priv, uint8_t conf)
|
|||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
return I2C_WRITE(priv->i2c, buffer, 2);
|
return lm92_i2c_write(priv, buffer, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -305,19 +358,19 @@ static int lm92_readid(FAR struct lm92_dev_s *priv, FAR uint16_t *id)
|
|||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
|
|
||||||
regaddr = LM92_ID_REG;
|
regaddr = LM92_ID_REG;
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, 1);
|
ret = lm92_i2c_write(priv, ®addr, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 16 bits from the register */
|
/* Restart and read 16 bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, buffer, 2);
|
ret = lm92_i2c_read(priv, buffer, 2);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
* Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved.
|
* Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved.
|
||||||
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@@ -53,6 +56,11 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_LSM9DS1_I2C_FREQUENCY
|
||||||
|
# define CONFIG_LSM9DS1_I2C_FREQUENCY 400000
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Register Addresses *******************************************************/
|
/* Register Addresses *******************************************************/
|
||||||
/* Accelerometer and gyroscope registers */
|
/* Accelerometer and gyroscope registers */
|
||||||
|
|
||||||
@@ -514,6 +522,10 @@ struct lsm9ds1_dev_s
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/* I2C Helpers */
|
/* I2C Helpers */
|
||||||
|
|
||||||
|
static int lsm9ds1_i2c_write(FAR struct lsm9ds1_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen);
|
||||||
|
static int lsm9ds1_i2c_read(FAR struct lsm9ds1_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen);
|
||||||
static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr,
|
static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr,
|
||||||
FAR uint8_t *regval);
|
FAR uint8_t *regval);
|
||||||
static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr,
|
static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr,
|
||||||
@@ -622,6 +634,50 @@ static const struct lsm9ds1_ops_s g_lsm9ds1mag_ops =
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: lsm9ds1_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int lsm9ds1_i2c_write(FAR struct lsm9ds1_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_LSM9DS1_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: lsm9ds1_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int lsm9ds1_i2c_read(FAR struct lsm9ds1_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_LSM9DS1_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: lsm9ds1_readreg8
|
* Name: lsm9ds1_readreg8
|
||||||
*
|
*
|
||||||
@@ -643,19 +699,19 @@ static int lsm9ds1_readreg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr));
|
ret = lsm9ds1_i2c_write(priv, ®addr, sizeof(regaddr));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 8 bits from the register */
|
/* Restart and read 8 bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, regval, sizeof(*regval));
|
ret = lsm9ds1_i2c_read(priv, regval, sizeof(*regval));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -689,10 +745,10 @@ static int lsm9ds1_writereg8(FAR struct lsm9ds1_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, buffer, sizeof(buffer));
|
ret = lsm9ds1_i2c_write(priv, buffer, sizeof(buffer));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
* Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
* Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
||||||
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@@ -51,6 +54,14 @@
|
|||||||
|
|
||||||
#if defined(CONFIG_I2C) && defined(CONFIG_MB7040)
|
#if defined(CONFIG_I2C) && defined(CONFIG_MB7040)
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_MB7040_I2C_FREQUENCY
|
||||||
|
# define CONFIG_MB7040_I2C_FREQUENCY 400000
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -66,6 +77,10 @@ struct mb7040_dev_s
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
/* I2C Helpers */
|
/* I2C Helpers */
|
||||||
|
|
||||||
|
static int mb7040_i2c_write(FAR struct mb7040_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen);
|
||||||
|
static int mb7040_i2c_read(FAR struct mb7040_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen);
|
||||||
static int mb7040_measurerange(FAR struct mb7040_dev_s *priv);
|
static int mb7040_measurerange(FAR struct mb7040_dev_s *priv);
|
||||||
static int mb7040_readrange(FAR struct mb7040_dev_s *priv,
|
static int mb7040_readrange(FAR struct mb7040_dev_s *priv,
|
||||||
FAR uint16_t *range);
|
FAR uint16_t *range);
|
||||||
@@ -106,6 +121,50 @@ static const struct file_operations g_fops =
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mb7040_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int mb7040_i2c_write(FAR struct mb7040_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_MB7040_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mb7040_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int mb7040_i2c_read(FAR struct mb7040_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_MB7040_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: mb7040_measurerange
|
* Name: mb7040_measurerange
|
||||||
*
|
*
|
||||||
@@ -125,10 +184,10 @@ static int mb7040_measurerange(FAR struct mb7040_dev_s *priv)
|
|||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr));
|
ret = mb7040_i2c_write(priv, ®addr, sizeof(regaddr));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -151,10 +210,10 @@ static int mb7040_readrange(FAR struct mb7040_dev_s *priv,
|
|||||||
/* Read two bytes */
|
/* Read two bytes */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_READ(priv->i2c, buffer, sizeof(buffer));
|
ret = mb7040_i2c_read(priv, buffer, sizeof(buffer));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,10 +251,10 @@ static int mb7040_changeaddr(FAR struct mb7040_dev_s *priv, uint8_t addr)
|
|||||||
/* Write the register address followed by the data (no RESTART) */
|
/* Write the register address followed by the data (no RESTART) */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, buffer, sizeof(buffer));
|
ret = mb7040_i2c_write(priv, buffer, sizeof(buffer));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
* Copyright (C) 2015 DS-Automotion GmbH. All rights reserved.
|
* Copyright (C) 2015 DS-Automotion GmbH. All rights reserved.
|
||||||
* Author: Alexander Entinger <a.entinger@ds-automotion.com>
|
* Author: Alexander Entinger <a.entinger@ds-automotion.com>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@@ -51,7 +54,15 @@
|
|||||||
#if defined(CONFIG_I2C) && defined(CONFIG_MCP9844)
|
#if defined(CONFIG_I2C) && defined(CONFIG_MCP9844)
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private
|
* Pre-process Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_MCP9844_I2C_FREQUENCY
|
||||||
|
# define CONFIG_MCP9844_I2C_FREQUENCY 400000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
struct mcp9844_dev_s
|
struct mcp9844_dev_s
|
||||||
@@ -66,6 +77,10 @@ struct mcp9844_dev_s
|
|||||||
|
|
||||||
/* I2C helper functions */
|
/* I2C helper functions */
|
||||||
|
|
||||||
|
static int mcp9844_i2c_write(FAR struct mcp9844_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen);
|
||||||
|
static int mcp9844_i2c_read(FAR struct mcp9844_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen);
|
||||||
static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv,
|
static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv,
|
||||||
uint8_t const regaddr, FAR uint16_t *value);
|
uint8_t const regaddr, FAR uint16_t *value);
|
||||||
static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv,
|
static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv,
|
||||||
@@ -103,6 +118,50 @@ static const struct file_operations g_mcp9844_fops =
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mcp9844_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int mcp9844_i2c_write(FAR struct mcp9844_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_MCP9844_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mcp9844_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int mcp9844_i2c_read(FAR struct mcp9844_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_MCP9844_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: mcp9844_read_u16
|
* Name: mcp9844_read_u16
|
||||||
*
|
*
|
||||||
@@ -120,10 +179,10 @@ static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv,
|
|||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
|
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, 1);
|
ret = mcp9844_i2c_write(priv, ®addr, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg ("I2C_WRITE failed: %d\n", ret);
|
sndbg ("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,10 +190,10 @@ static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv,
|
|||||||
|
|
||||||
uint8_t const BUFFER_SIZE = 2;
|
uint8_t const BUFFER_SIZE = 2;
|
||||||
uint8_t buffer[BUFFER_SIZE];
|
uint8_t buffer[BUFFER_SIZE];
|
||||||
ret = I2C_READ(priv->i2c, buffer, BUFFER_SIZE);
|
ret = mcp9844_i2c_read(priv, buffer, BUFFER_SIZE);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg ("I2C_READ failed: %d\n", ret);
|
sndbg ("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +232,7 @@ static int mcp9844_write_u16(FAR struct mcp9844_dev_s *priv,
|
|||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
|
|
||||||
return I2C_WRITE(priv->i2c, buffer, BUFFER_SIZE);
|
return mcp9844_i2c_write(priv, buffer, BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
+68
-12
@@ -6,6 +6,9 @@
|
|||||||
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||||
* Updated by: Karim Keddam <karim.keddam@polymtl.ca>
|
* Updated by: Karim Keddam <karim.keddam@polymtl.ca>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@@ -56,6 +59,11 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_MS58XX_I2C_FREQUENCY
|
||||||
|
# define CONFIG_MS58XX_I2C_FREQUENCY 400000
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Register Definitions *****************************************************/
|
/* Register Definitions *****************************************************/
|
||||||
/* Register Addresses */
|
/* Register Addresses */
|
||||||
|
|
||||||
@@ -135,6 +143,10 @@ static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex);
|
|||||||
|
|
||||||
/* I2C Helpers */
|
/* I2C Helpers */
|
||||||
|
|
||||||
|
static int ms58xx_i2c_write(FAR struct ms58xx_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen);
|
||||||
|
static int ms58xx_i2c_read(FAR struct ms58xx_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen);
|
||||||
static int ms58xx_readu16(FAR struct ms58xx_dev_s *priv, uint8_t regaddr,
|
static int ms58xx_readu16(FAR struct ms58xx_dev_s *priv, uint8_t regaddr,
|
||||||
FAR uint16_t *regval);
|
FAR uint16_t *regval);
|
||||||
static int ms58xx_readadc(FAR struct ms58xx_dev_s *priv, FAR uint32_t *adc);
|
static int ms58xx_readadc(FAR struct ms58xx_dev_s *priv, FAR uint32_t *adc);
|
||||||
@@ -228,6 +240,50 @@ static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex)
|
|||||||
return (n_rem ^ 0x00);
|
return (n_rem ^ 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: ms58xx_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int ms58xx_i2c_write(FAR struct ms58xx_dev_s *priv,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_MS58XX_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: ms58xx_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int ms58xx_i2c_read(FAR struct ms58xx_dev_s *priv,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_MS58XX_I2C_FREQUENCY;
|
||||||
|
config.address = priv->addr;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(priv->i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ms58xx_readu16
|
* Name: ms58xx_readu16
|
||||||
*
|
*
|
||||||
@@ -247,19 +303,19 @@ static int ms58xx_readu16(FAR struct ms58xx_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr));
|
ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 16 bits from the register */
|
/* Restart and read 16 bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, buffer, sizeof(buffer));
|
ret = ms58xx_i2c_read(priv, buffer, sizeof(buffer));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,19 +344,19 @@ static int ms58xx_readadc(FAR struct ms58xx_dev_s *priv, FAR uint32_t *adc)
|
|||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr));
|
ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 24 bits from the register */
|
/* Restart and read 24 bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(priv->i2c, buffer, sizeof(buffer));
|
ret = ms58xx_i2c_read(priv, buffer, sizeof(buffer));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_READ failed: %d\n", ret);
|
sndbg("i2c_read failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,10 +552,10 @@ static int ms58xx_reset(FAR struct ms58xx_dev_s *priv)
|
|||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr));
|
ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,10 +589,10 @@ static int ms58xx_convert(FAR struct ms58xx_dev_s *priv, uint8_t regaddr,
|
|||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
|
||||||
ret = I2C_WRITE(priv->i2c, ®addr, sizeof(regaddr));
|
ret = ms58xx_i2c_write(priv, ®addr, sizeof(regaddr));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
sndbg("I2C_WRITE failed: %d\n", ret);
|
sndbg("i2c_write failed: %d\n", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for the conversion to end */
|
/* Wait for the conversion to end */
|
||||||
|
|||||||
@@ -547,9 +547,8 @@ int up_rtc_settime(FAR const struct timespec *tp)
|
|||||||
|
|
||||||
I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY);
|
I2C_SETFREQUENCY(g_ds3231.i2c, CONFIG_DS3231_I2C_FREQUENCY);
|
||||||
|
|
||||||
/* Perform the transfer (This could be done with I2C_READ). This transfer
|
/* Perform the transfer. This transfer will be repeated if the seconds
|
||||||
* will be repeated if the seconds count rolls over to a smaller value
|
* count rolls over to a smaller value while writing.
|
||||||
* while writing.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -511,9 +511,8 @@ int up_rtc_settime(FAR const struct timespec *tp)
|
|||||||
|
|
||||||
I2C_SETFREQUENCY(g_pcf85263.i2c, CONFIG_PCF85263_I2C_FREQUENCY);
|
I2C_SETFREQUENCY(g_pcf85263.i2c, CONFIG_PCF85263_I2C_FREQUENCY);
|
||||||
|
|
||||||
/* Perform the transfer (This could be done with I2C_READ). This transfer
|
/* Perform the transfer. This transfer will be repeated if the seconds
|
||||||
* will be repeated if the seconds count rolls over to a smaller value
|
* count rolls over to a smaller value while writing.
|
||||||
* while writing.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
do
|
do
|
||||||
|
|||||||
+51
-6
@@ -670,6 +670,51 @@ static const struct ovr2640_reg_s g_ov2640_jpeg_uxga_resolution[] =
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: ov2640_i2c_write
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Write to the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int ov2640_i2c_write(FAR struct i2c_master_s *i2c,
|
||||||
|
FAR const uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_OV2640_FREQUENCY;
|
||||||
|
config.address = CONFIG_OV2640_I2CADDR;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_write(i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: ov2640_i2c_read
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Read from the I2C device.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int ov2640_i2c_read(FAR struct i2c_master_s *i2c,
|
||||||
|
FAR uint8_t *buffer, int buflen)
|
||||||
|
{
|
||||||
|
struct i2c_config_s config;
|
||||||
|
|
||||||
|
/* Set up the configuration and perform the write-read operation */
|
||||||
|
|
||||||
|
config.frequency = CONFIG_OV2640_FREQUENCY;
|
||||||
|
config.address = CONFIG_OV2640_I2CADDR;
|
||||||
|
config.addrlen = 7;
|
||||||
|
|
||||||
|
return i2c_read(i2c, &config, buffer, buflen);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ov2640_putreg
|
* Function: ov2640_putreg
|
||||||
*
|
*
|
||||||
@@ -704,10 +749,10 @@ static int ov2640_putreg(FAR struct i2c_master_s *i2c, uint8_t regaddr,
|
|||||||
|
|
||||||
/* And do it */
|
/* And do it */
|
||||||
|
|
||||||
ret = I2C_WRITE(i2c, buffer, 2);
|
ret = ov2640_i2c_write(i2c, buffer, 2);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
gdbg("ERROR: I2C_WRITE failed: %d\n", ret);
|
gdbg("ERROR: i2c_write failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,19 +783,19 @@ static uint8_t ov2640_getreg(FAR struct i2c_master_s *i2c, uint8_t regaddr)
|
|||||||
|
|
||||||
/* Write the register address */
|
/* Write the register address */
|
||||||
|
|
||||||
ret = I2C_WRITE(i2c, ®addr, 1);
|
ret = ov2640_i2c_write(i2c, ®addr, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
gdbg("ERROR: I2C_WRITE failed: %d\n", ret);
|
gdbg("ERROR: i2c_write failed: %d\n", ret);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restart and read 8-bits from the register */
|
/* Restart and read 8-bits from the register */
|
||||||
|
|
||||||
ret = I2C_READ(i2c, ®val, 1);
|
ret = ov2640_i2c_read(i2c, ®val, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
gdbg("ERROR: I2C_READ failed: %d\n", ret);
|
gdbg("ERROR: i2c_read failed: %d\n", ret);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_OV2640_REGDEBUG
|
#ifdef CONFIG_OV2640_REGDEBUG
|
||||||
|
|||||||
@@ -117,48 +117,6 @@
|
|||||||
|
|
||||||
#define I2C_SETADDRESS(d,a,n) ((d)->ops->setaddress(d,a,n))
|
#define I2C_SETADDRESS(d,a,n) ((d)->ops->setaddress(d,a,n))
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: I2C_WRITE
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Send a block of data on I2C using the previously selected I2C
|
|
||||||
* frequency and slave address. Each write operational will be an 'atomic'
|
|
||||||
* operation in the sense that any other I2C actions will be serialized
|
|
||||||
* and pend until this write completes. Required.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* dev - Device-specific state data
|
|
||||||
* buffer - A pointer to the read-only buffer of data to be written to device
|
|
||||||
* buflen - The number of bytes to send from the buffer
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* 0: success, <0: A negated errno
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define I2C_WRITE(d,b,l) ((d)->ops->write(d,b,l))
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: I2C_READ
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* Receive a block of data from I2C using the previously selected I2C
|
|
||||||
* frequency and slave address. Each read operational will be an 'atomic'
|
|
||||||
* operation in the sense that any other I2C actions will be serialized
|
|
||||||
* and pend until this read completes. Required.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* dev - Device-specific state data
|
|
||||||
* buffer - A pointer to a buffer of data to receive the data from the device
|
|
||||||
* buflen - The requested number of bytes to be read
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* 0: success, <0: A negated errno
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#define I2C_READ(d,b,l) ((d)->ops->read(d,b,l))
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: I2C_TRANSFER
|
* Name: I2C_TRANSFER
|
||||||
*
|
*
|
||||||
@@ -166,12 +124,15 @@
|
|||||||
* Perform a sequence of I2C transfers, each transfer is started with a
|
* Perform a sequence of I2C transfers, each transfer is started with a
|
||||||
* START and the final transfer is completed with a STOP. Each sequence
|
* START and the final transfer is completed with a STOP. Each sequence
|
||||||
* will be an 'atomic' operation in the sense that any other I2C actions
|
* will be an 'atomic' operation in the sense that any other I2C actions
|
||||||
* will be serialized and pend until this read completes. Optional.
|
* will be serialized and pend until this sequence of transfers completes.
|
||||||
|
* Required.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* dev - Device-specific state data
|
* dev
|
||||||
* msgs - A pointer to a set of message descriptors
|
|
||||||
* msgcount - The number of transfers to perform
|
- Device-specific state data
|
||||||
|
* msgs - A pointer to a set of message descriptors
|
||||||
|
* count - The number of transfers to perform
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* The number of transfers completed
|
* The number of transfers completed
|
||||||
@@ -191,13 +152,13 @@ struct i2c_msg_s;
|
|||||||
struct i2c_ops_s
|
struct i2c_ops_s
|
||||||
{
|
{
|
||||||
uint32_t (*setfrequency)(FAR struct i2c_master_s *dev, uint32_t frequency);
|
uint32_t (*setfrequency)(FAR struct i2c_master_s *dev, uint32_t frequency);
|
||||||
int (*setaddress)(FAR struct i2c_master_s *dev, int addr, int nbits);
|
int (*setaddress)(FAR struct i2c_master_s *dev, int addr, int nbits);
|
||||||
int (*write)(FAR struct i2c_master_s *dev, FAR const uint8_t *buffer,
|
int (*write)(FAR struct i2c_master_s *dev, FAR const uint8_t *buffer,
|
||||||
int buflen);
|
int buflen);
|
||||||
int (*read)(FAR struct i2c_master_s *dev, FAR uint8_t *buffer,
|
int (*read)(FAR struct i2c_master_s *dev, FAR uint8_t *buffer,
|
||||||
int buflen);
|
int buflen);
|
||||||
int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs,
|
int (*transfer)(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs,
|
||||||
int count);
|
int count);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This structure contains the full state of I2C as needed for a specific
|
/* This structure contains the full state of I2C as needed for a specific
|
||||||
|
|||||||
Reference in New Issue
Block a user