drivers/sensors: Run all sensor drivers through tools/nxstyle, correcting as many complaints as possible.

This commit is contained in:
Gregory Nutt
2019-12-06 19:07:34 -06:00
parent db6fe28fa6
commit d1584d60a2
53 changed files with 619 additions and 468 deletions
+1
View File
@@ -347,6 +347,7 @@ static int adt7320_open(FAR struct file *filep)
set_errno(ENODEV); set_errno(ENODEV);
return -ENODEV; return -ENODEV;
} }
return OK; return OK;
} }
+7 -4
View File
@@ -264,11 +264,14 @@ static void adxl345_worker(FAR void *arg)
/* Read accelerometer data to sample */ /* Read accelerometer data to sample */
priv->sample.data_x = adxl345_getreg8(priv, ADXL345_DATAX1); priv->sample.data_x = adxl345_getreg8(priv, ADXL345_DATAX1);
priv->sample.data_x = (priv->sample.data_x << 8) | adxl345_getreg8(priv, ADXL345_DATAX0); priv->sample.data_x = (priv->sample.data_x << 8) |
adxl345_getreg8(priv, ADXL345_DATAX0);
priv->sample.data_y = adxl345_getreg8(priv, ADXL345_DATAY1); priv->sample.data_y = adxl345_getreg8(priv, ADXL345_DATAY1);
priv->sample.data_y = (priv->sample.data_y << 8) | adxl345_getreg8(priv, ADXL345_DATAY0); priv->sample.data_y = (priv->sample.data_y << 8) |
adxl345_getreg8(priv, ADXL345_DATAY0);
priv->sample.data_z = adxl345_getreg8(priv, ADXL345_DATAZ1); priv->sample.data_z = adxl345_getreg8(priv, ADXL345_DATAZ1);
priv->sample.data_z = (priv->sample.data_z << 8) | adxl345_getreg8(priv, ADXL345_DATAZ0); priv->sample.data_z = (priv->sample.data_z << 8) |
adxl345_getreg8(priv, ADXL345_DATAZ0);
} }
/* Re-enable the ADXL345 GPIO interrupt */ /* Re-enable the ADXL345 GPIO interrupt */
@@ -360,7 +363,7 @@ static void adxl345_reset(FAR struct adxl345_dev_s *priv)
/* Wait a bit to make the GOD of TIME happy */ /* Wait a bit to make the GOD of TIME happy */
nxsig_usleep(20*1000); nxsig_usleep(20 * 1000);
} }
/**************************************************************************** /****************************************************************************
+4
View File
@@ -53,6 +53,10 @@
#if defined(CONFIG_SENSORS_ADXL345) #if defined(CONFIG_SENSORS_ADXL345)
/****************************************************************************
* Public Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: adxl345_getreg8 * Name: adxl345_getreg8
* *
+8 -8
View File
@@ -266,7 +266,7 @@ static uint8_t adxl372_read_register(FAR struct adxl372_dev_s *dev,
* Name: adxl372_read_registerblk * Name: adxl372_read_registerblk
******************************************************************************/ ******************************************************************************/
static void adxl372_read_registerblk(FAR struct adxl372_dev_s *dev, static void adxl372_read_registerblk(FAR struct adxl372_dev_s *dev,
uint8_t reg_addr, uint8_t reg_addr,
FAR uint8_t *reg_data, FAR uint8_t *reg_data,
uint8_t xfercnt) uint8_t xfercnt)
@@ -288,7 +288,7 @@ static uint8_t adxl372_read_register(FAR struct adxl372_dev_s *dev,
/* Write idle bytes while receiving the requested data */ /* Write idle bytes while receiving the requested data */
while ( 0 != xfercnt-- ) while (0 != xfercnt--)
{ {
*reg_data++ = (uint8_t)SPI_SEND(dev->spi, 0xff); *reg_data++ = (uint8_t)SPI_SEND(dev->spi, 0xff);
} }
@@ -341,7 +341,7 @@ static void adxl372_write_register(FAR struct adxl372_dev_s *dev,
* Name: adxl372_write_registerblk * Name: adxl372_write_registerblk
****************************************************************************/ ****************************************************************************/
static void adxl372_write_registerblk(FAR struct adxl372_dev_s *dev, static void adxl372_write_registerblk(FAR struct adxl372_dev_s *dev,
uint8_t reg_addr, uint8_t reg_addr,
FAR uint8_t *reg_data, FAR uint8_t *reg_data,
uint8_t xfercnt) uint8_t xfercnt)
@@ -363,7 +363,7 @@ static void adxl372_write_register(FAR struct adxl372_dev_s *dev,
/* Transmit the content which should be written in the register block */ /* Transmit the content which should be written in the register block */
while ( 0 != xfercnt-- ) while (0 != xfercnt--)
{ {
SPI_SEND(dev->spi, *reg_data++); SPI_SEND(dev->spi, *reg_data++);
} }
@@ -408,7 +408,7 @@ static void adxl372_reset(FAR struct adxl372_dev_s *dev)
up_mdelay(5); up_mdelay(5);
wdcnt = 10; wdcnt = 10;
while (wdcnt>0 && (0 != adxl372_read_register(dev, ADXL372_RESET))) while (wdcnt > 0 && (0 != adxl372_read_register(dev, ADXL372_RESET)))
{ {
up_mdelay(1); up_mdelay(1);
} }
@@ -587,7 +587,7 @@ static ssize_t adxl372_dvr_read(FAR void *instance_handle, FAR char *buffer,
if (priv->seek_address == ADXL372_XDATA_H && buflen >= 6) if (priv->seek_address == ADXL372_XDATA_H && buflen >= 6)
{ {
p1 = p2 = buffer; p1 = p2 = buffer;
for (i=0; i<3; i++) for (i = 0; i < 3; i++)
{ {
un.d8[1] = *p1++; un.d8[1] = *p1++;
un.d8[0] = *p1++; un.d8[0] = *p1++;
@@ -742,13 +742,13 @@ static void adxl372_dvr_exchange(FAR void *instance_handle,
/* Unlock the SPI bus */ /* Unlock the SPI bus */
SPI_LOCK(spi, false); SPI_LOCK(spi, false);
} }
/**************************************************************************** /****************************************************************************
* Name: adxl372_open * Name: adxl372_open
****************************************************************************/ ****************************************************************************/
static int adxl372_open(FAR struct file *filep) static int adxl372_open(FAR struct file *filep)
{ {
FAR struct inode *inode = filep->f_inode; FAR struct inode *inode = filep->f_inode;
FAR struct adxl372_dev_s *priv = inode->i_private; FAR struct adxl372_dev_s *priv = inode->i_private;
+16 -10
View File
@@ -271,6 +271,7 @@ static int ak09912_putreg8(FAR struct ak09912_dev_s *priv,
{ {
snerr("I2C_TRANSFER failed: %d\n", ret); snerr("I2C_TRANSFER failed: %d\n", ret);
} }
return ret; return ret;
} }
@@ -283,7 +284,8 @@ static int ak09912_putreg8(FAR struct ak09912_dev_s *priv,
****************************************************************************/ ****************************************************************************/
static int32_t ak09912_getreg(FAR struct ak09912_dev_s *priv, static int32_t ak09912_getreg(FAR struct ak09912_dev_s *priv,
uint8_t regaddr, uint8_t* buffer, uint32_t cnt) uint8_t regaddr, FAR uint8_t *buffer,
uint32_t cnt)
{ {
struct i2c_msg_s msg[2]; struct i2c_msg_s msg[2];
int ret; int ret;
@@ -333,7 +335,7 @@ void ak09912_delay_msek(uint16_t msek)
* *
****************************************************************************/ ****************************************************************************/
static int ak09912_set_power_mode(FAR struct ak09912_dev_s* priv, static int ak09912_set_power_mode(FAR struct ak09912_dev_s *priv,
uint32_t mode) uint32_t mode)
{ {
int ret = 0; int ret = 0;
@@ -350,8 +352,8 @@ static int ak09912_set_power_mode(FAR struct ak09912_dev_s* priv,
* *
****************************************************************************/ ****************************************************************************/
static int ak09912_read_sensitivity_data(FAR struct ak09912_dev_s* priv, static int ak09912_read_sensitivity_data(FAR struct ak09912_dev_s *priv,
FAR struct sensi_data_s* asa_data) FAR struct sensi_data_s *asa_data)
{ {
int ret = 0; int ret = 0;
uint8_t buffer[3]; uint8_t buffer[3];
@@ -363,6 +365,7 @@ static int ak09912_read_sensitivity_data(FAR struct ak09912_dev_s* priv,
asa_data->y = buffer[1]; asa_data->y = buffer[1];
asa_data->z = buffer[2]; asa_data->z = buffer[2];
} }
return ret; return ret;
} }
@@ -374,7 +377,7 @@ static int ak09912_read_sensitivity_data(FAR struct ak09912_dev_s* priv,
* *
****************************************************************************/ ****************************************************************************/
static int ak09912_set_noice_suppr_flt(FAR struct ak09912_dev_s* priv, static int ak09912_set_noice_suppr_flt(FAR struct ak09912_dev_s *priv,
uint32_t nsf) uint32_t nsf)
{ {
int ret = 0; int ret = 0;
@@ -411,8 +414,8 @@ static void ak09912_wd_timeout(int argc, uint32_t arg, ...)
* *
****************************************************************************/ ****************************************************************************/
static int ak09912_read_mag_uncomp_data(FAR struct ak09912_dev_s* priv, static int ak09912_read_mag_uncomp_data(FAR struct ak09912_dev_s *priv,
FAR struct mag_data_s* mag_data) FAR struct mag_data_s *mag_data)
{ {
int ret = 0; int ret = 0;
uint8_t state = 0; uint8_t state = 0;
@@ -425,6 +428,7 @@ static int ak09912_read_mag_uncomp_data(FAR struct ak09912_dev_s* priv,
{ {
sem_wait(&priv->wait); sem_wait(&priv->wait);
} }
wd_cancel(priv->wd); wd_cancel(priv->wd);
ret = ak09912_getreg(priv, AK09912_HXL, buffer, sizeof(buffer)); ret = ak09912_getreg(priv, AK09912_HXL, buffer, sizeof(buffer));
@@ -443,8 +447,8 @@ static int ak09912_read_mag_uncomp_data(FAR struct ak09912_dev_s* priv,
* *
****************************************************************************/ ****************************************************************************/
static int ak09912_read_mag_data(FAR struct ak09912_dev_s* priv, static int ak09912_read_mag_data(FAR struct ak09912_dev_s *priv,
FAR struct mag_data_s* mag_data) FAR struct mag_data_s *mag_data)
{ {
int ret = 0; int ret = 0;
@@ -536,6 +540,7 @@ static int ak09912_open(FAR struct file *filep)
snerr("Failed to set power mode to %d.\n", priv->mode); snerr("Failed to set power mode to %d.\n", priv->mode);
return ret; return ret;
} }
return OK; return OK;
} }
@@ -559,6 +564,7 @@ static int ak09912_close(FAR struct file *filep)
snerr("Failed to set power mode to %d.\n", AKM_POWER_DOWN_MODE); snerr("Failed to set power mode to %d.\n", AKM_POWER_DOWN_MODE);
return ret; return ret;
} }
return OK; return OK;
} }
@@ -572,7 +578,7 @@ static ssize_t ak09912_read(FAR struct file *filep, FAR char *buffer,
FAR struct inode *inode = filep->f_inode; FAR struct inode *inode = filep->f_inode;
FAR struct ak09912_dev_s *priv = inode->i_private; FAR struct ak09912_dev_s *priv = inode->i_private;
int32_t ret = 0; int32_t ret = 0;
struct mag_data_s* mag_data = (struct mag_data_s*)buffer; FAR struct mag_data_s *mag_data = (FAR struct mag_data_s *)buffer;
if (! buffer) if (! buffer)
{ {
+2 -2
View File
@@ -1051,8 +1051,8 @@ static int apds9960_readgesture(FAR struct apds9960_dev_s *priv)
for (i = 0; i < fifo_level; i++) for (i = 0; i < fifo_level; i++)
{ {
sninfo("U: %03d | D: %03d | L: %03d | R: %03d\n", sninfo("U: %03d | D: %03d | L: %03d | R: %03d\n",
fifo_data[i], fifo_data[i+1], fifo_data[i], fifo_data[i + 1],
fifo_data[i+2], fifo_data[i+3]); fifo_data[i + 2], fifo_data[i + 3]);
} }
sninfo("\n"); sninfo("\n");
+3 -1
View File
@@ -69,6 +69,7 @@ struct as5048b_dev_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* I2C Helpers */ /* I2C Helpers */
static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr, static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr,
@@ -168,7 +169,8 @@ static int as5048b_readu8(FAR struct as5048b_dev_s *priv, uint8_t regaddr,
static int as5048b_readu16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi, static int as5048b_readu16(FAR struct as5048b_dev_s *priv, uint8_t regaddrhi,
uint8_t regaddrlo, FAR uint16_t *regval) uint8_t regaddrlo, FAR uint16_t *regval)
{ {
uint8_t hi, lo; uint8_t hi;
uint8_t lo;
int ret; int ret;
/* Read the high 8 bits of the 13-bit value */ /* Read the high 8 bits of the 13-bit value */
+1
View File
@@ -268,6 +268,7 @@ static void write_register(FAR struct as726x_dev_s *priv, uint8_t addr,
{ {
0 0
}; };
int ret; int ret;
config.frequency = CONFIG_AS726X_I2C_FREQUENCY; config.frequency = CONFIG_AS726X_I2C_FREQUENCY;
+5 -5
View File
@@ -149,7 +149,7 @@ static int bh1750fvi_read16(FAR struct bh1750fvi_dev_s *priv,
/* Copy the content of the buffer to the location of the uint16_t pointer */ /* Copy the content of the buffer to the location of the uint16_t pointer */
*regval = (uint16_t)((buffer[0]<<8) | (buffer[1])); *regval = (uint16_t)((buffer[0] << 8) | (buffer[1]));
sninfo("value: %08x ret: %d\n", *regval, ret); sninfo("value: %08x ret: %d\n", *regval, ret);
return OK; return OK;
@@ -246,8 +246,8 @@ static ssize_t bh1750fvi_read(FAR struct file *filep, FAR char *buffer,
return ret; return ret;
} }
buffer[0] = lux & 0xFF; buffer[0] = lux & 0xff;
buffer[1] = (lux & 0xFF00) >> 8; buffer[1] = (lux & 0xff00) >> 8;
add_sensor_randomness(lux); add_sensor_randomness(lux);
@@ -357,7 +357,7 @@ static int bh1750fvi_ioctl(FAR struct file *filep, int cmd,
uint8_t reg; uint8_t reg;
DEBUGASSERT(ptr != NULL); DEBUGASSERT(ptr != NULL);
reg = BH1750FVI_MEASURE_TIMEH | ((*ptr & 0xE0) >> 5); reg = BH1750FVI_MEASURE_TIMEH | ((*ptr & 0xe0) >> 5);
ret = bh1750fvi_write8(priv, reg); ret = bh1750fvi_write8(priv, reg);
if (ret < 0) if (ret < 0)
@@ -365,7 +365,7 @@ static int bh1750fvi_ioctl(FAR struct file *filep, int cmd,
snerr("ERROR: Cannot Change Measure Time at MEASURE_TIMEH!\n"); snerr("ERROR: Cannot Change Measure Time at MEASURE_TIMEH!\n");
} }
reg = BH1750FVI_MEASURE_TIMEL | (*ptr & 0x1F); reg = BH1750FVI_MEASURE_TIMEL | (*ptr & 0x1f);
ret = bh1750fvi_write8(priv, reg); ret = bh1750fvi_write8(priv, reg);
if (ret < 0) if (ret < 0)
+6 -3
View File
@@ -205,7 +205,7 @@ static void bmg160_write_register(FAR struct bmg160_dev_s *dev,
static void bmg160_reset(FAR struct bmg160_dev_s *dev) static void bmg160_reset(FAR struct bmg160_dev_s *dev)
{ {
bmg160_write_register(dev, BMG160_BGW_SOFTRESET_REG, 0xB6); bmg160_write_register(dev, BMG160_BGW_SOFTRESET_REG, 0xb6);
up_mdelay(100); up_mdelay(100);
} }
@@ -220,7 +220,9 @@ static void bmg160_read_measurement_data(FAR struct bmg160_dev_s *dev)
/* Read Gyroscope */ /* Read Gyroscope */
uint16_t x_gyr = 0, y_gyr = 0, z_gyr = 0; uint16_t x_gyr = 0;
uint16_t y_gyr = 0;
uint16_t z_gyr = 0;
bmg160_read_gyroscope_data(dev, &x_gyr, &y_gyr, &z_gyr); bmg160_read_gyroscope_data(dev, &x_gyr, &y_gyr, &z_gyr);
@@ -588,7 +590,8 @@ int bmg160_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
/* Since we support multiple BMG160 devices, we will need to add this new /* Since we support multiple BMG160 devices, we will need to add this new
* instance to a list of device instances so that it can be found by the * instance to a list of device instances so that it can be found by the
* interrupt handler based on the received IRQ number. */ * interrupt handler based on the received IRQ number.
*/
priv->flink = g_bmg160_list; priv->flink = g_bmg160_list;
g_bmg160_list = priv; g_bmg160_list = priv;
+3
View File
@@ -286,6 +286,7 @@ static const struct file_operations g_bmi160fops =
* Description: * Description:
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_SENSORS_BMI160_SPI #ifdef CONFIG_SENSORS_BMI160_SPI
static inline void bmi160_configspi(FAR struct spi_dev_s *spi) static inline void bmi160_configspi(FAR struct spi_dev_s *spi)
{ {
@@ -647,6 +648,7 @@ static void bmi160_enable_stepcounter(FAR struct bmi160_dev_s *priv,
{ {
val &= ~STEP_CNT_EN; val &= ~STEP_CNT_EN;
} }
bmi160_putreg8(priv, BMI160_STEP_CONFIG_1, val); bmi160_putreg8(priv, BMI160_STEP_CONFIG_1, val);
sninfo("Step counter %sabled.\n", val & STEP_CNT_EN ? "en" : "dis"); sninfo("Step counter %sabled.\n", val & STEP_CNT_EN ? "en" : "dis");
@@ -755,6 +757,7 @@ int bmi160_register(FAR const char *devpath, FAR struct spi_dev_s *dev)
snerr("Failed to allocate instance\n"); snerr("Failed to allocate instance\n");
return -ENOMEM; return -ENOMEM;
} }
#ifdef CONFIG_SENSORS_BMI160_I2C #ifdef CONFIG_SENSORS_BMI160_I2C
priv->i2c = dev; priv->i2c = dev;
priv->addr = BMI160_I2C_ADDR; priv->addr = BMI160_I2C_ADDR;
+4 -4
View File
@@ -1,4 +1,3 @@
/**************************************************************************** /****************************************************************************
* drivers/sensors/bmp180.c * drivers/sensors/bmp180.c
* Character driver for the Freescale BMP1801 Barometer Sensor * Character driver for the Freescale BMP1801 Barometer Sensor
@@ -227,7 +226,8 @@ static uint8_t bmp180_getreg8(FAR struct bmp180_dev_s *priv, uint8_t regaddr)
static uint16_t bmp180_getreg16(FAR struct bmp180_dev_s *priv, uint8_t regaddr) static uint16_t bmp180_getreg16(FAR struct bmp180_dev_s *priv, uint8_t regaddr)
{ {
struct i2c_config_s config; struct i2c_config_s config;
uint16_t msb, lsb; uint16_t msb;
uint16_t lsb;
uint16_t regval = 0; uint16_t regval = 0;
int ret; int ret;
@@ -257,8 +257,8 @@ static uint16_t bmp180_getreg16(FAR struct bmp180_dev_s *priv, uint8_t regaddr)
/* MSB and LSB are inverted */ /* MSB and LSB are inverted */
msb = (regval & 0xFF); msb = (regval & 0xff);
lsb = (regval & 0xFF00) >> 8; lsb = (regval & 0xff00) >> 8;
regval = (msb << 8) | lsb; regval = (msb << 8) | lsb;
+4 -4
View File
@@ -388,8 +388,8 @@ static int bmp280_initialize(FAR struct bmp280_dev_s *priv)
priv->calib.t2 = (int16_t) buf[3] << 8 | buf[2]; priv->calib.t2 = (int16_t) buf[3] << 8 | buf[2];
priv->calib.t3 = (int16_t) buf[5] << 8 | buf[4]; priv->calib.t3 = (int16_t) buf[5] << 8 | buf[4];
priv->calib.p1 = (uint16_t)buf[ 7] << 8 | buf[ 6]; priv->calib.p1 = (uint16_t)buf[7] << 8 | buf[6];
priv->calib.p2 = (int16_t) buf[ 9] << 8 | buf[ 8]; priv->calib.p2 = (int16_t) buf[9] << 8 | buf[8];
priv->calib.p3 = (int16_t) buf[11] << 8 | buf[10]; priv->calib.p3 = (int16_t) buf[11] << 8 | buf[10];
priv->calib.p4 = (int16_t) buf[13] << 8 | buf[12]; priv->calib.p4 = (int16_t) buf[13] << 8 | buf[12];
priv->calib.p5 = (int16_t) buf[15] << 8 | buf[14]; priv->calib.p5 = (int16_t) buf[15] << 8 | buf[14];
@@ -486,10 +486,10 @@ static uint32_t bmp280_compensate_press(FAR struct bmp280_dev_s *priv,
(void) bmp280_compensate_temp(priv, temp); (void) bmp280_compensate_temp(priv, temp);
var1 = (priv->tempfine >> 1) - 64000; var1 = (priv->tempfine >> 1) - 64000;
var2 = (((var1 >> 2) * (var1 >> 2)) >> 11 ) * ((int32_t)c->p6); var2 = (((var1 >> 2) * (var1 >> 2)) >> 11) * ((int32_t)c->p6);
var2 = var2 + ((var1 * ((int32_t)c->p5)) << 1); var2 = var2 + ((var1 * ((int32_t)c->p5)) << 1);
var2 = (var2 >> 2) + (((int32_t)c->p4) << 16); var2 = (var2 >> 2) + (((int32_t)c->p4) << 16);
var1 = (((c->p3 * (((var1 >> 2) * (var1 >> 2)) >> 13 )) >> 3) + var1 = (((c->p3 * (((var1 >> 2) * (var1 >> 2)) >> 13)) >> 3) +
((((int32_t)c->p2) * var1) >> 1)) >> 18; ((((int32_t)c->p2) * var1) >> 1)) >> 18;
var1 = (((32768 + var1) * ((int32_t)c->p1)) >> 15); var1 = (((32768 + var1) * ((int32_t)c->p1)) >> 15);
+13 -10
View File
@@ -252,10 +252,11 @@ static int dht_read_raw_data(FAR struct dhtxx_dev_s *priv)
int64_t start_time; int64_t start_time;
int64_t end_time; int64_t end_time;
int64_t current_time; int64_t current_time;
uint8_t j, i; uint8_t i;
uint8_t j;
j = 0U; j = 0u;
for (i = 0U; i < DHTXX_RESPONSE_BITS; i++) for (i = 0u; i < DHTXX_RESPONSE_BITS; i++)
{ {
/* Start of transmission begins with a ~50uS low. */ /* Start of transmission begins with a ~50uS low. */
@@ -313,7 +314,7 @@ static bool dht_verify_checksum(FAR struct dhtxx_dev_s *priv)
uint8_t sum; uint8_t sum;
sum = (priv->raw_data[0] + priv->raw_data[1] + sum = (priv->raw_data[0] + priv->raw_data[1] +
priv->raw_data[2] + priv->raw_data[3]) & 0xFFU; priv->raw_data[2] + priv->raw_data[3]) & 0xffu;
return (sum == priv->raw_data[4]); return (sum == priv->raw_data[4]);
} }
@@ -377,8 +378,8 @@ static int dht_parse_data(FAR struct dhtxx_dev_s *priv,
case DHTXX_DHT12: case DHTXX_DHT12:
data->hum = priv->raw_data[0] + priv->raw_data[1] * 0.1F; data->hum = priv->raw_data[0] + priv->raw_data[1] * 0.1F;
data->temp = priv->raw_data[2] + (priv->raw_data[3] & 0x7FU) * 0.1F; data->temp = priv->raw_data[2] + (priv->raw_data[3] & 0x7fu) * 0.1F;
if (priv->raw_data[3] & 0x80U) if (priv->raw_data[3] & 0x80u)
{ {
data->temp *= -1; data->temp *= -1;
} }
@@ -395,11 +396,11 @@ static int dht_parse_data(FAR struct dhtxx_dev_s *priv,
case DHTXX_DHT22: case DHTXX_DHT22:
case DHTXX_DHT33: case DHTXX_DHT33:
case DHTXX_DHT44: case DHTXX_DHT44:
data->hum = (priv->raw_data[0] << 8U | priv->raw_data[1]) * 0.1F; data->hum = (priv->raw_data[0] << 8u | priv->raw_data[1]) * 0.1F;
data->temp = (((priv->raw_data[2] & 0x7FU) << 8U) | data->temp = (((priv->raw_data[2] & 0x7fu) << 8u) |
priv->raw_data[3]) * 0.1F; priv->raw_data[3]) * 0.1F;
if (priv->raw_data[2] & 0x80U) if (priv->raw_data[2] & 0x80u)
{ {
data->temp *= -1; data->temp *= -1;
} }
@@ -488,7 +489,7 @@ static ssize_t dhtxx_read(FAR struct file *filep, FAR char *buffer,
return -ENOSYS; return -ENOSYS;
} }
memset(priv->raw_data, 0U, sizeof(priv->raw_data)); memset(priv->raw_data, 0u, sizeof(priv->raw_data));
do do
{ {
@@ -530,6 +531,7 @@ static ssize_t dhtxx_read(FAR struct file *filep, FAR char *buffer,
} }
out: out:
/* Done reading, set the sensor back to low mode. */ /* Done reading, set the sensor back to low mode. */
dht_standby_mode(priv); dht_standby_mode(priv);
@@ -608,6 +610,7 @@ int dhtxx_register(FAR const char *devpath, FAR struct dhtxx_config_s *config)
snerr("ERROR: Failed to allocate instance\n"); snerr("ERROR: Failed to allocate instance\n");
return -ENOMEM; return -ENOMEM;
} }
priv->config = config; priv->config = config;
/* Register the character driver */ /* Register the character driver */
+2 -3
View File
@@ -91,8 +91,8 @@ struct hcsr04_dev_s
}; };
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static const struct file_operations g_hcsr04ops = static const struct file_operations g_hcsr04ops =
{ {
@@ -292,7 +292,6 @@ static int hcsr04_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break; break;
case SNIOC_READ_RAW_DATA: case SNIOC_READ_RAW_DATA:
//ret = hcsr04_read_raw_data(priv, (FAR hcsr04_raw_data_t *) arg);
break; break;
#ifdef CONFIG_HCSR04_DEBUG #ifdef CONFIG_HCSR04_DEBUG
+30 -14
View File
@@ -119,8 +119,8 @@
#define HTS221_I2C_RETRIES 10 #define HTS221_I2C_RETRIES 10
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
*****************************************************************************/ *****************************************************************************/
static int hts221_open(FAR struct file *filep); static int hts221_open(FAR struct file *filep);
static int hts221_close(FAR struct file *filep); static int hts221_close(FAR struct file *filep);
@@ -133,8 +133,8 @@ static int hts221_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup); bool setup);
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
struct hts221_dev_s struct hts221_dev_s
{ {
@@ -158,8 +158,8 @@ struct hts221_dev_s
}; };
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
static const struct file_operations g_humidityops = static const struct file_operations g_humidityops =
{ {
@@ -176,8 +176,8 @@ static const struct file_operations g_humidityops =
}; };
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
static int hts221_do_transfer(FAR struct hts221_dev_s *priv, static int hts221_do_transfer(FAR struct hts221_dev_s *priv,
FAR struct i2c_msg_s *msgv, FAR struct i2c_msg_s *msgv,
@@ -196,6 +196,7 @@ static int hts221_do_transfer(FAR struct hts221_dev_s *priv,
else else
{ {
/* Some error. Try to reset I2C bus and keep trying. */ /* Some error. Try to reset I2C bus and keep trying. */
#ifdef CONFIG_I2C_RESET #ifdef CONFIG_I2C_RESET
if (retries == HTS221_I2C_RETRIES - 1) if (retries == HTS221_I2C_RETRIES - 1)
{ {
@@ -283,7 +284,11 @@ static int hts221_cfgr_resolution(FAR struct hts221_dev_s *priv,
uint8_t value; uint8_t value;
const uint8_t addr = HTS221_AV_CONF; const uint8_t addr = HTS221_AV_CONF;
uint8_t regval = 0; uint8_t regval = 0;
uint8_t cmd[2] = { 0 }; uint8_t cmd[2] =
{
0
};
const uint8_t mask = 0x3f; const uint8_t mask = 0x3f;
ret = hts221_read_reg(priv, &addr, &regval); ret = hts221_read_reg(priv, &addr, &regval);
@@ -315,7 +320,10 @@ static int hts221_config_ctrl_reg3(FAR struct hts221_dev_s *priv,
uint8_t regval = 0; uint8_t regval = 0;
uint8_t addr = HTS221_CTRL_REG3; uint8_t addr = HTS221_CTRL_REG3;
const uint8_t mask = 0xc4; const uint8_t mask = 0xc4;
uint8_t data_to_write[2] = { 0 }; uint8_t data_to_write[2] =
{
0
};
ret = hts221_read_reg(priv, &addr, &regval); ret = hts221_read_reg(priv, &addr, &regval);
hts221_dbg("CTRL_REG%d: 0x%02X\n", 3, regval); hts221_dbg("CTRL_REG%d: 0x%02X\n", 3, regval);
@@ -353,7 +361,11 @@ static int hts221_config_ctrl_reg2(FAR struct hts221_dev_s *priv,
uint8_t regval = 0; uint8_t regval = 0;
uint8_t addr = HTS221_CTRL_REG2; uint8_t addr = HTS221_CTRL_REG2;
const uint8_t mask = 0x80; const uint8_t mask = 0x80;
uint8_t data_to_write[2] = { 0 }; uint8_t data_to_write[2] =
{
0
};
int retries = 5; int retries = 5;
if (!settings->is_boot) if (!settings->is_boot)
@@ -424,7 +436,10 @@ static int hts221_config_ctrl_reg1(FAR struct hts221_dev_s *priv,
uint8_t regval = 0; uint8_t regval = 0;
uint8_t addr = HTS221_CTRL_REG1; uint8_t addr = HTS221_CTRL_REG1;
const uint8_t mask = 0x87; const uint8_t mask = 0x87;
uint8_t data_to_write[2] = { 0 }; uint8_t data_to_write[2] =
{
0
};
ret = hts221_read_reg(priv, &addr, &regval); ret = hts221_read_reg(priv, &addr, &regval);
hts221_dbg("CTRL_REG%d: 0x%02X\n", 1, regval); hts221_dbg("CTRL_REG%d: 0x%02X\n", 1, regval);
@@ -434,8 +449,8 @@ static int hts221_config_ctrl_reg1(FAR struct hts221_dev_s *priv,
} }
regval &= ~mask; regval &= ~mask;
regval |= (uint8_t) (settings->odr & 0xFF); regval |= (uint8_t)(settings->odr & 0xff);
regval |= (uint8_t) (settings->is_bdu ? HTS221_CTRL_REG1_BDU : 0); regval |= (uint8_t)(settings->is_bdu ? HTS221_CTRL_REG1_BDU : 0);
data_to_write[0] = addr; data_to_write[0] = addr;
data_to_write[1] = regval; data_to_write[1] = regval;
@@ -476,6 +491,7 @@ static int hts221_power_on_off(FAR struct hts221_dev_s *priv, bool on)
{ {
regval &= ~HTS221_CTRL_REG1_PD; regval &= ~HTS221_CTRL_REG1_PD;
} }
data_to_write[0] = addr; data_to_write[0] = addr;
data_to_write[1] = regval; data_to_write[1] = regval;
+3 -3
View File
@@ -145,7 +145,7 @@ static const struct file_operations g_ina219fops =
static int ina219_access(FAR struct ina219_dev_s *priv, static int ina219_access(FAR struct ina219_dev_s *priv,
uint8_t start_register_address, bool reading, uint8_t start_register_address, bool reading,
FAR uint8_t* register_value, uint8_t data_length) FAR uint8_t *register_value, uint8_t data_length)
{ {
struct i2c_msg_s msg[I2C_NOSTARTSTOP_MSGS]; struct i2c_msg_s msg[I2C_NOSTARTSTOP_MSGS];
int ret; int ret;
@@ -167,13 +167,13 @@ static int ina219_access(FAR struct ina219_dev_s *priv,
sninfo("start_register_address: " sninfo("start_register_address: "
"0x%02X data_length: %d register_value: 0x%02x (0x%04x) ret: %d\n", "0x%02X data_length: %d register_value: 0x%02x (0x%04x) ret: %d\n",
start_register_address, data_length, *register_value, start_register_address, data_length, *register_value,
*((uint16_t*)register_value), ret); *((FAR uint16_t *)register_value), ret);
return ret; return ret;
} }
static int ina219_read16(FAR struct ina219_dev_s *priv, uint8_t regaddr, static int ina219_read16(FAR struct ina219_dev_s *priv, uint8_t regaddr,
FAR uint16_t* regvalue) FAR uint16_t *regvalue)
{ {
uint8_t buf[2]; uint8_t buf[2];
+3 -3
View File
@@ -128,7 +128,7 @@ static const struct file_operations g_ina226fops =
static int ina226_access(FAR struct ina226_dev_s *priv, static int ina226_access(FAR struct ina226_dev_s *priv,
uint8_t start_register_address, bool reading, uint8_t start_register_address, bool reading,
FAR uint8_t* register_value, uint8_t data_length) FAR uint8_t *register_value, uint8_t data_length)
{ {
struct i2c_msg_s msg[I2C_NOSTARTSTOP_MSGS]; struct i2c_msg_s msg[I2C_NOSTARTSTOP_MSGS];
int ret; int ret;
@@ -150,13 +150,13 @@ static int ina226_access(FAR struct ina226_dev_s *priv,
sninfo("start_register_address: " sninfo("start_register_address: "
"0x%02X data_length: %d register_value: 0x%02x (0x%04x) ret: %d\n", "0x%02X data_length: %d register_value: 0x%02x (0x%04x) ret: %d\n",
start_register_address, data_length, *register_value, start_register_address, data_length, *register_value,
*((uint16_t*)register_value), ret); *((FAR uint16_t *)register_value), ret);
return ret; return ret;
} }
static int ina226_read16(FAR struct ina226_dev_s *priv, uint8_t regaddr, static int ina226_read16(FAR struct ina226_dev_s *priv, uint8_t regaddr,
FAR uint16_t* regvalue) FAR uint16_t *regvalue)
{ {
uint8_t buf[2]; uint8_t buf[2];
+4 -5
View File
@@ -155,7 +155,7 @@ static const struct file_operations g_ina3221fops =
static int ina3221_access(FAR struct ina3221_dev_s *priv, static int ina3221_access(FAR struct ina3221_dev_s *priv,
uint8_t start_register_address, bool reading, uint8_t start_register_address, bool reading,
FAR uint8_t* register_value, uint8_t data_length) FAR uint8_t *register_value, uint8_t data_length)
{ {
struct i2c_msg_s msg[I2C_NOSTARTSTOP_MSGS]; struct i2c_msg_s msg[I2C_NOSTARTSTOP_MSGS];
int ret; int ret;
@@ -177,13 +177,13 @@ static int ina3221_access(FAR struct ina3221_dev_s *priv,
sninfo("start_register_address: " sninfo("start_register_address: "
"0x%02X data_length: %d register_value: 0x%02x (0x%04x) ret: %d\n", "0x%02X data_length: %d register_value: 0x%02x (0x%04x) ret: %d\n",
start_register_address, data_length, *register_value, start_register_address, data_length, *register_value,
*((uint16_t*)register_value), ret); *((FAR uint16_t *)register_value), ret);
return ret; return ret;
} }
static int ina3221_read16(FAR struct ina3221_dev_s *priv, uint8_t regaddr, static int ina3221_read16(FAR struct ina3221_dev_s *priv, uint8_t regaddr,
FAR uint16_t* regvalue) FAR uint16_t *regvalue)
{ {
uint8_t buf[2]; uint8_t buf[2];
@@ -392,8 +392,7 @@ static int ina3221_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: ina3221_reCommits * Name: ina3221_register
gister
* *
* Description: * Description:
* Register the INA3221 character device as 'devpath' * Register the INA3221 character device as 'devpath'
+1
View File
@@ -145,6 +145,7 @@ static const struct file_operations g_isl29023fops =
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: isl29023_i2c_write * Name: isl29023_i2c_write
* *
+2
View File
@@ -88,6 +88,7 @@
#define PC1_ON (1 << 7) #define PC1_ON (1 << 7)
/* CTRL_REG1: set resolution, g-range, data ready enable */ /* CTRL_REG1: set resolution, g-range, data ready enable */
/* Output resolution: 8-bit valid or 12-bit valid */ /* Output resolution: 8-bit valid or 12-bit valid */
#define RES_8BIT 0 #define RES_8BIT 0
@@ -104,6 +105,7 @@
#define KXTJ9_G_8G (1 << 4) #define KXTJ9_G_8G (1 << 4)
/* Interrupt control register 1 bits */ /* Interrupt control register 1 bits */
/* Set these during probe if using irq mode */ /* Set these during probe if using irq mode */
#define KXTJ9_IEL (1 << 3) #define KXTJ9_IEL (1 << 3)
+5 -4
View File
@@ -308,8 +308,8 @@ static void l3gd20_read_gyroscope_data(FAR struct l3gd20_dev_s *dev,
* Name: l3gd20_read_temperature * Name: l3gd20_read_temperature
****************************************************************************/ ****************************************************************************/
static void l3gd20_read_temperature(FAR struct l3gd20_dev_s* dev, static void l3gd20_read_temperature(FAR struct l3gd20_dev_s *dev,
uint8_t* temperature) FAR uint8_t *temperature)
{ {
/* Lock the SPI bus so that only one device can access it at the same time */ /* Lock the SPI bus so that only one device can access it at the same time */
@@ -342,7 +342,7 @@ static void l3gd20_read_temperature(FAR struct l3gd20_dev_s* dev,
* Name: l3gd20_interrupt_handler * Name: l3gd20_interrupt_handler
****************************************************************************/ ****************************************************************************/
static int l3gd20_interrupt_handler(int irq, FAR void* context) static int l3gd20_interrupt_handler(int irq, FAR void *context)
{ {
/* This function should be called upon a rising edge on the L3GD20 new data /* This function should be called upon a rising edge on the L3GD20 new data
* interrupt pin since it signals that new data has been measured. * interrupt pin since it signals that new data has been measured.
@@ -644,7 +644,8 @@ int l3gd20_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
/* Since we support multiple L3GD20 devices, we will need to add this new /* Since we support multiple L3GD20 devices, we will need to add this new
* instance to a list of device instances so that it can be found by the * instance to a list of device instances so that it can be found by the
* interrupt handler based on the received IRQ number. */ * interrupt handler based on the received IRQ number.
*/
priv->flink = g_l3gd20_list; priv->flink = g_l3gd20_list;
g_l3gd20_list = priv; g_l3gd20_list = priv;
+46 -17
View File
@@ -108,7 +108,7 @@ struct lis2dh_dev_s
int scale; /* Full scale in milliG */ int scale; /* Full scale in milliG */
sem_t devsem; /* Manages exclusive access to this structure */ sem_t devsem; /* Manages exclusive access to this structure */
bool fifo_used; /* LIS2DH configured to use FIFO */ bool fifo_used; /* LIS2DH configured to use FIFO */
bool fifo_stopped;/* FIFO got full and has stopped. */ bool fifo_stopped; /* FIFO got full and has stopped. */
#ifdef LIS2DH_COUNT_INTS #ifdef LIS2DH_COUNT_INTS
volatile int16_t int_pending; /* Interrupt received but data not read, yet */ volatile int16_t int_pending; /* Interrupt received but data not read, yet */
#else #else
@@ -221,7 +221,9 @@ static int lis2dh_open(FAR struct file *filep)
if (regval == ST_LIS2DH_WHOAMI_VALUE) if (regval == ST_LIS2DH_WHOAMI_VALUE)
{ {
priv->config->irq_enable(priv->config, true); priv->config->irq_enable(priv->config, true);
/* Normal exit point */ /* Normal exit point */
ret = lis2dh_clear_interrupts(priv, LIS2DH_INT1 | LIS2DH_INT2); ret = lis2dh_clear_interrupts(priv, LIS2DH_INT1 | LIS2DH_INT2);
return ret; return ret;
} }
@@ -313,7 +315,8 @@ static ssize_t lis2dh_read(FAR struct file *filep, FAR char *buffer,
FAR struct inode *inode = filep->f_inode; FAR struct inode *inode = filep->f_inode;
FAR struct lis2dh_dev_s *priv = inode->i_private; FAR struct lis2dh_dev_s *priv = inode->i_private;
FAR struct lis2dh_result *ptr; FAR struct lis2dh_result *ptr;
int readcount = (buflen - sizeof(struct lis2dh_res_header)) / sizeof(struct lis2dh_vector_s); int readcount = (buflen - sizeof(struct lis2dh_res_header)) /
sizeof(struct lis2dh_vector_s);
uint8_t buf; uint8_t buf;
uint8_t int1_src = 0; uint8_t int1_src = 0;
uint8_t int2_src = 0; uint8_t int2_src = 0;
@@ -321,7 +324,8 @@ static ssize_t lis2dh_read(FAR struct file *filep, FAR char *buffer,
int ret; int ret;
if (buflen < sizeof(struct lis2dh_result) || if (buflen < sizeof(struct lis2dh_result) ||
(buflen - sizeof(struct lis2dh_res_header)) % sizeof(struct lis2dh_vector_s) != 0) (buflen - sizeof(struct lis2dh_res_header)) %
sizeof(struct lis2dh_vector_s) != 0)
{ {
lis2dh_dbg("lis2dh: Illegal amount of bytes to read: %d\n", buflen); lis2dh_dbg("lis2dh: Illegal amount of bytes to read: %d\n", buflen);
return -EINVAL; return -EINVAL;
@@ -474,6 +478,7 @@ static ssize_t lis2dh_read(FAR struct file *filep, FAR char *buffer,
lis2dh_dbg("lis2dh: Failed to read INT1_SRC_REG\n"); lis2dh_dbg("lis2dh: Failed to read INT1_SRC_REG\n");
ret = -EIO; ret = -EIO;
} }
if (buf & ST_LIS2DH_INT_SR_ACTIVE) if (buf & ST_LIS2DH_INT_SR_ACTIVE)
{ {
/* Interrupt has happened */ /* Interrupt has happened */
@@ -496,6 +501,7 @@ static ssize_t lis2dh_read(FAR struct file *filep, FAR char *buffer,
lis2dh_dbg("lis2dh: Failed to read INT2_SRC_REG\n"); lis2dh_dbg("lis2dh: Failed to read INT2_SRC_REG\n");
ret = -EIO; ret = -EIO;
} }
if (buf & ST_LIS2DH_INT_SR_ACTIVE) if (buf & ST_LIS2DH_INT_SR_ACTIVE)
{ {
/* Interrupt has happened */ /* Interrupt has happened */
@@ -507,6 +513,7 @@ static ssize_t lis2dh_read(FAR struct file *filep, FAR char *buffer,
{ {
ptr->header.int2_occurred = false; ptr->header.int2_occurred = false;
} }
ptr->header.int1_source = int1_src; ptr->header.int1_source = int1_src;
ptr->header.int2_source = int2_src; ptr->header.int2_source = int2_src;
@@ -814,7 +821,8 @@ static int lis2dh_int_handler(int irq, FAR void *context, FAR void *arg)
static int lis2dh_clear_registers(FAR struct lis2dh_dev_s *priv) static int lis2dh_clear_registers(FAR struct lis2dh_dev_s *priv)
{ {
uint8_t i, buf = 0; uint8_t buf = 0;
uint8_t i;
DEBUGASSERT(priv); DEBUGASSERT(priv);
@@ -864,6 +872,7 @@ static int lis2dh_write_register(FAR struct lis2dh_dev_s *priv, uint8_t reg,
value, reg); value, reg);
return ERROR; return ERROR;
} }
return OK; return OK;
} }
@@ -1085,10 +1094,11 @@ static int lis2dh_handle_selftest(FAR struct lis2dh_dev_s *priv)
} }
/* 400Hz ODR all axes enabled /* 400Hz ODR all axes enabled
FIFO overrun & DATA READY on INT1 * FIFO overrun & DATA READY on INT1
FIFO enabled and INT1 & INT2 latched * FIFO enabled and INT1 & INT2 latched
FIFO mode, INT1 , THS 0 * FIFO mode, INT1 , THS 0
OR combination, all events enabled */ * OR combination, all events enabled
*/
if ((lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG1, 0x77) != OK) || if ((lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG1, 0x77) != OK) ||
(lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG3, 0x12) != OK) || (lis2dh_write_register(priv, ST_LIS2DH_CTRL_REG3, 0x12) != OK) ||
@@ -1219,6 +1229,7 @@ static bool lis2dh_data_available(FAR struct lis2dh_dev_s *dev)
{ {
return ((retval & ST_LIS2DH_SR_ZYXDA) != 0); return ((retval & ST_LIS2DH_SR_ZYXDA) != 0);
} }
return false; return false;
} }
@@ -1398,6 +1409,7 @@ static unsigned int lis2dh_get_fifo_readings(FAR struct lis2dh_dev_s *priv,
uint8_t raw[6]; uint8_t raw[6];
struct lis2dh_vector_s sample; struct lis2dh_vector_s sample;
} *buf = (void *)&res->measurements[res->header.meas_count]; } *buf = (void *)&res->measurements[res->header.meas_count];
bool xy_axis_fixup = priv->setup->xy_axis_fixup; bool xy_axis_fixup = priv->setup->xy_axis_fixup;
size_t buflen = readcount * 6; size_t buflen = readcount * 6;
int16_t x; int16_t x;
@@ -1491,7 +1503,10 @@ static inline int16_t lis2dh_raw_to_mg(uint8_t raw_hibyte, uint8_t raw_lobyte,
static int lis2dh_read_temp(FAR struct lis2dh_dev_s *dev, FAR int16_t *temper) static int lis2dh_read_temp(FAR struct lis2dh_dev_s *dev, FAR int16_t *temper)
{ {
int ret; int ret;
uint8_t buf[2] = { 0 }; uint8_t buf[2] =
{
0
};
ret = lis2dh_access(dev, ST_LIS2DH_OUT_TEMP_L_REG, buf, 2); ret = lis2dh_access(dev, ST_LIS2DH_OUT_TEMP_L_REG, buf, 2);
if (ret < 0) if (ret < 0)
@@ -1564,6 +1579,7 @@ static int lis2dh_access(FAR struct lis2dh_dev_s *dev, uint8_t subaddr,
if (subaddr == ST_LIS2DH_OUT_X_L_REG) if (subaddr == ST_LIS2DH_OUT_X_L_REG)
{ {
/* FIFO bulk read, length maximum 6*32 = 192 bytes. */ /* FIFO bulk read, length maximum 6*32 = 192 bytes. */
if (length > 6 * 32) if (length > 6 * 32)
{ {
length = 6 * 32; length = 6 * 32;
@@ -1617,6 +1633,7 @@ static int lis2dh_access(FAR struct lis2dh_dev_s *dev, uint8_t subaddr,
else else
{ {
/* Some error. Try to reset I2C bus and keep trying. */ /* Some error. Try to reset I2C bus and keep trying. */
#ifdef CONFIG_I2C_RESET #ifdef CONFIG_I2C_RESET
int ret = I2C_RESET(dev->i2c); int ret = I2C_RESET(dev->i2c);
if (ret < 0) if (ret < 0)
@@ -1625,6 +1642,7 @@ static int lis2dh_access(FAR struct lis2dh_dev_s *dev, uint8_t subaddr,
return ret; return ret;
} }
#endif #endif
continue; continue;
} }
} }
@@ -1646,7 +1664,8 @@ static int lis2dh_access(FAR struct lis2dh_dev_s *dev, uint8_t subaddr,
static int lis2dh_reboot(FAR struct lis2dh_dev_s *dev) static int lis2dh_reboot(FAR struct lis2dh_dev_s *dev)
{ {
struct timespec start, curr; struct timespec start;
struct timespec curr;
int32_t diff_msec; int32_t diff_msec;
uint8_t value; uint8_t value;
@@ -1753,7 +1772,8 @@ static int lis2dh_setup(FAR struct lis2dh_dev_s * dev,
/* Clear old configuration. On first boot after power-loss, reboot bit does /* Clear old configuration. On first boot after power-loss, reboot bit does
* not get cleared, and lis2dh_reboot() times out. Anyway, chip accepts * not get cleared, and lis2dh_reboot() times out. Anyway, chip accepts
* new configuration and functions correctly. */ * new configuration and functions correctly.
*/
(void)lis2dh_reboot(dev); (void)lis2dh_reboot(dev);
@@ -1833,9 +1853,13 @@ static int lis2dh_setup(FAR struct lis2dh_dev_s * dev,
/* INT1_CFG */ /* INT1_CFG */
value = dev->setup->int1_interrupt_mode | dev->setup->int1_enable_6d | dev->setup->int1_int_z_high_enable | value = dev->setup->int1_interrupt_mode |
dev->setup->int1_int_z_low_enable | dev->setup->int1_int_y_high_enable | dev->setup->int1_enable_6d |
dev->setup->int1_int_y_low_enable | dev->setup->int1_int_x_high_enable | dev->setup->int1_int_z_high_enable |
dev->setup->int1_int_z_low_enable |
dev->setup->int1_int_y_high_enable |
dev->setup->int1_int_y_low_enable |
dev->setup->int1_int_x_high_enable |
dev->setup->int1_int_x_low_enable; dev->setup->int1_int_x_low_enable;
if (lis2dh_access(dev, ST_LIS2DH_INT1_CFG_REG, &value, -1) != 1) if (lis2dh_access(dev, ST_LIS2DH_INT1_CFG_REG, &value, -1) != 1)
{ {
@@ -1860,9 +1884,13 @@ static int lis2dh_setup(FAR struct lis2dh_dev_s * dev,
/* INT2_CFG */ /* INT2_CFG */
value = dev->setup->int2_interrupt_mode | dev->setup->int2_enable_6d | dev->setup->int2_int_z_high_enable | value = dev->setup->int2_interrupt_mode |
dev->setup->int2_int_z_low_enable | dev->setup->int2_int_y_high_enable | dev->setup->int2_enable_6d |
dev->setup->int2_int_y_low_enable | dev->setup->int2_int_x_high_enable | dev->setup->int2_int_z_high_enable |
dev->setup->int2_int_z_low_enable |
dev->setup->int2_int_y_high_enable |
dev->setup->int2_int_y_low_enable |
dev->setup->int2_int_x_high_enable |
dev->setup->int2_int_x_low_enable; dev->setup->int2_int_x_low_enable;
if (lis2dh_access(dev, ST_LIS2DH_INT2_CFG_REG, &value, -1) != 1) if (lis2dh_access(dev, ST_LIS2DH_INT2_CFG_REG, &value, -1) != 1)
{ {
@@ -2042,6 +2070,7 @@ int lis2dh_register(FAR const char *devpath, FAR struct i2c_master_s *i2c,
{ {
priv->config->irq_clear(config); priv->config->irq_clear(config);
} }
priv->config->irq_attach(config, lis2dh_int_handler, priv); priv->config->irq_attach(config, lis2dh_int_handler, priv);
priv->config->irq_enable(config, false); priv->config->irq_enable(config, false);
return OK; return OK;
+2 -2
View File
@@ -359,10 +359,10 @@ int lis331dl_getprecision(FAR struct lis331dl_dev_s * dev)
{ {
if (dev->cr1 & ST_LIS331DL_CR1_FS) if (dev->cr1 & ST_LIS331DL_CR1_FS)
{ {
return 9200/127; /* typ. 9.2g full scale */ return 9200 / 127; /* typ. 9.2g full scale */
} }
return 2300/127; /* typ. 2.3g full scale */ return 2300 / 127; /* typ. 2.3g full scale */
} }
/**************************************************************************** /****************************************************************************
+9 -10
View File
@@ -406,10 +406,10 @@ static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev)
} }
memset(dev->fifobuf, 0, LIS3DH_FIFOBUF_SIZE); memset(dev->fifobuf, 0, LIS3DH_FIFOBUF_SIZE);
dev->fifobuf[0] = LIS3DH_OUT_X_L | 0xC0; dev->fifobuf[0] = LIS3DH_OUT_X_L | 0xc0;
SPI_SELECT(dev->spi, dev->config->spi_devid, true); SPI_SELECT(dev->spi, dev->config->spi_devid, true);
SPI_EXCHANGE(dev->spi, dev->fifobuf, dev->fifobuf, 1 + count*6); SPI_EXCHANGE(dev->spi, dev->fifobuf, dev->fifobuf, 1 + count * 6);
SPI_SELECT(dev->spi, dev->config->spi_devid, false); SPI_SELECT(dev->spi, dev->config->spi_devid, false);
/* Unlock the SPI bus */ /* Unlock the SPI bus */
@@ -427,14 +427,14 @@ static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev)
int16_t y_acc; int16_t y_acc;
int16_t z_acc; int16_t z_acc;
x_raw = (uint16_t)dev->fifobuf[(i*6)+1] | x_raw = (uint16_t)dev->fifobuf[(i * 6) + 1] |
(uint16_t)dev->fifobuf[(i*6)+2] << 8; (uint16_t)dev->fifobuf[(i * 6) + 2] << 8;
y_raw = (uint16_t)dev->fifobuf[(i*6)+3] | y_raw = (uint16_t)dev->fifobuf[(i * 6) + 3] |
(uint16_t)dev->fifobuf[(i*6)+4] << 8; (uint16_t)dev->fifobuf[(i * 6) + 4] << 8;
z_raw = (uint16_t)dev->fifobuf[(i*6)+5] | z_raw = (uint16_t)dev->fifobuf[(i * 6) + 5] |
(uint16_t)dev->fifobuf[(i*6)+6] << 8; (uint16_t)dev->fifobuf[(i * 6) + 6] << 8;
/* The sensor left justifies the data in the register, so we must /* The sensor left justifies the data in the register, so we must
* shift it to the right depending on the selected power mode * shift it to the right depending on the selected power mode
@@ -875,9 +875,8 @@ static ssize_t lis3dh_read(FAR struct file *filep, FAR char *buffer,
data = (FAR struct lis3dh_sensor_data_s *)buffer; data = (FAR struct lis3dh_sensor_data_s *)buffer;
for (remain=count;remain > 0;remain--) for (remain = count; remain > 0; remain--)
{ {
/* Wait for data to be available in the queue */ /* Wait for data to be available in the queue */
nxsem_wait(&priv->readsem); nxsem_wait(&priv->readsem);
+2 -1
View File
@@ -375,7 +375,8 @@ static int lis3dsh_open(FAR struct file *filep)
/* Enable - Measurement of X-, Y-, and Z-axis - Block data update for /* Enable - Measurement of X-, Y-, and Z-axis - Block data update for
* accelerating data This should prevent race conditions when reading sensor * accelerating data This should prevent race conditions when reading sensor
* data - fastest output data rate (ODR = 1600 Hz) */ * data - fastest output data rate (ODR = 1600 Hz).
*/
lis3dsh_write_register(priv, lis3dsh_write_register(priv,
LIS3DSH_CTRL_REG_4, LIS3DSH_CTRL_REG_4,
+20 -9
View File
@@ -221,7 +221,9 @@ static void lis3mdl_read_measurement_data(FAR struct lis3mdl_dev_s *dev)
{ {
/* Magnetic data */ /* Magnetic data */
uint16_t x_mag = 0, y_mag = 0, z_mag = 0; uint16_t x_mag = 0;
uint16_t y_mag = 0;
uint16_t z_mag = 0;
lis3mdl_read_magnetic_data(dev, &x_mag, &y_mag, &z_mag); lis3mdl_read_magnetic_data(dev, &x_mag, &y_mag, &z_mag);
@@ -314,7 +316,8 @@ static void lis3mdl_read_temperature(FAR struct lis3mdl_dev_s *dev,
/* Transmit the register address from where we want to start reading 0x80 -> /* Transmit the register address from where we want to start reading 0x80 ->
* MSB is set -> Read Indication 0x40 -> MSB-1 (MS-Bit) is set -> auto * MSB is set -> Read Indication 0x40 -> MSB-1 (MS-Bit) is set -> auto
* increment of address when reading multiple bytes */ * increment of address when reading multiple bytes.
*/
SPI_SEND(dev->spi, (LIS3MDL_TEMP_OUT_L_REG | 0x80 | 0x40)); SPI_SEND(dev->spi, (LIS3MDL_TEMP_OUT_L_REG | 0x80 | 0x40));
@@ -339,7 +342,8 @@ static void lis3mdl_read_temperature(FAR struct lis3mdl_dev_s *dev,
static int lis3mdl_interrupt_handler(int irq, FAR void *context) static int lis3mdl_interrupt_handler(int irq, FAR void *context)
{ {
/* This function should be called upon a rising edge on the LIS3MDL DRDY pin /* This function should be called upon a rising edge on the LIS3MDL DRDY pin
* since it signals that new data has been measured. */ * since it signals that new data has been measured.
*/
FAR struct lis3mdl_dev_s *priv = 0; FAR struct lis3mdl_dev_s *priv = 0;
int ret; int ret;
@@ -352,7 +356,8 @@ static int lis3mdl_interrupt_handler(int irq, FAR void *context)
/* Task the worker with retrieving the latest sensor data. We should not do /* Task the worker with retrieving the latest sensor data. We should not do
* this in a interrupt since it might take too long. Also we cannot lock the * this in a interrupt since it might take too long. Also we cannot lock the
* SPI bus from within an interrupt. */ * SPI bus from within an interrupt.
*/
DEBUGASSERT(priv->work.worker == NULL); DEBUGASSERT(priv->work.worker == NULL);
ret = work_queue(HPWORK, &priv->work, lis3mdl_worker, priv, 0); ret = work_queue(HPWORK, &priv->work, lis3mdl_worker, priv, 0);
@@ -384,6 +389,7 @@ static void lis3mdl_worker(FAR void *arg)
/**************************************************************************** /****************************************************************************
* Name: lis3mdl_open * Name: lis3mdl_open
****************************************************************************/ ****************************************************************************/
static int lis3mdl_open(FAR struct file *filep) static int lis3mdl_open(FAR struct file *filep)
{ {
FAR struct inode *inode = filep->f_inode; FAR struct inode *inode = filep->f_inode;
@@ -398,7 +404,8 @@ static int lis3mdl_open(FAR struct file *filep)
lis3mdl_reset(priv); lis3mdl_reset(priv);
/* Enable * - the maximum full scale mode. * Full scale = +/- 1.6 mT (16 /* Enable * - the maximum full scale mode. * Full scale = +/- 1.6 mT (16
* Gauss) */ * Gauss).
*/
lis3mdl_write_register(priv, lis3mdl_write_register(priv,
LIS3MDL_CTRL_REG_2, LIS3MDL_CTRL_REG_2,
@@ -407,7 +414,8 @@ static int lis3mdl_open(FAR struct file *filep)
/* Enable - temperature sensor - ultra high performance mode (UMP) for X and /* Enable - temperature sensor - ultra high performance mode (UMP) for X and
* Y - fast output data rates This results in a output data rate of 155 Hz * Y - fast output data rates This results in a output data rate of 155 Hz
* for X and Y */ * for X and Y.
*/
lis3mdl_write_register(priv, lis3mdl_write_register(priv,
LIS3MDL_CTRL_REG_1, LIS3MDL_CTRL_REG_1,
@@ -416,7 +424,8 @@ static int lis3mdl_open(FAR struct file *filep)
| LIS3MDL_CTRL_REG_1_FAST_ODR_bm); | LIS3MDL_CTRL_REG_1_FAST_ODR_bm);
/* Enable * - ultra high performance mode (UMP) for Z * This should result to /* Enable * - ultra high performance mode (UMP) for Z * This should result to
* the same output data rate as for X and Y. */ * the same output data rate as for X and Y.
*/
lis3mdl_write_register(priv, lis3mdl_write_register(priv,
LIS3MDL_CTRL_REG_4, LIS3MDL_CTRL_REG_4,
@@ -424,7 +433,8 @@ static int lis3mdl_open(FAR struct file *filep)
LIS3MDL_CTRL_REG_4_OMZ_0_bm); LIS3MDL_CTRL_REG_4_OMZ_0_bm);
/* Enable * - block data update for magnetic sensor data * This should /* Enable * - block data update for magnetic sensor data * This should
* prevent race conditions when reading sensor data. */ * prevent race conditions when reading sensor data.
*/
lis3mdl_write_register(priv, LIS3MDL_CTRL_REG_5, LIS3MDL_CTRL_REG_5_BDU_bm); lis3mdl_write_register(priv, LIS3MDL_CTRL_REG_5, LIS3MDL_CTRL_REG_5_BDU_bm);
@@ -627,7 +637,8 @@ int lis3mdl_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
/* Since we support multiple LIS3MDL devices are supported, we will need to /* Since we support multiple LIS3MDL devices are supported, we will need to
* add this new instance to a list of device instances so that it can be * add this new instance to a list of device instances so that it can be
* found by the interrupt handler based on the received IRQ number. */ * found by the interrupt handler based on the received IRQ number.
*/
priv->flink = g_lis3mdl_list; priv->flink = g_lis3mdl_list;
g_lis3mdl_list = priv; g_lis3mdl_list = priv;
+3 -1
View File
@@ -80,6 +80,7 @@ struct lm75_dev_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* I2C Helpers */ /* I2C Helpers */
static int lm75_i2c_write(FAR struct lm75_dev_s *priv, static int lm75_i2c_write(FAR struct lm75_dev_s *priv,
@@ -102,7 +103,8 @@ static ssize_t lm75_read(FAR struct file *filep, FAR char *buffer,
size_t buflen); size_t buflen);
static ssize_t lm75_write(FAR struct file *filep, FAR const char *buffer, static ssize_t lm75_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen); size_t buflen);
static int lm75_ioctl(FAR struct file *filep,int cmd,unsigned long arg); static int lm75_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
+1
View File
@@ -82,6 +82,7 @@ struct lm92_dev_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* I2C Helpers */ /* I2C Helpers */
static int lm92_i2c_write(FAR struct lm92_dev_s *priv, static int lm92_i2c_write(FAR struct lm92_dev_s *priv,
+2
View File
@@ -253,6 +253,7 @@ static int lps25h_do_transfer(FAR struct lps25h_dev_s *dev,
else else
{ {
/* Some error. Try to reset I2C bus and keep trying. */ /* Some error. Try to reset I2C bus and keep trying. */
#ifdef CONFIG_I2C_RESET #ifdef CONFIG_I2C_RESET
if (retries == LPS25H_I2C_RETRIES - 1) if (retries == LPS25H_I2C_RETRIES - 1)
{ {
@@ -450,6 +451,7 @@ static ssize_t lps25h_read(FAR struct file *filep, FAR char *buffer,
} }
out: out:
nxsem_post(&dev->devsem); nxsem_post(&dev->devsem);
return length; return length;
} }
+10 -8
View File
@@ -422,7 +422,7 @@ static bool lsm303agr_isbitset(int8_t b, int8_t m)
static int lsm303agr_sensor_start(FAR struct lsm303agr_dev_s *priv) static int lsm303agr_sensor_start(FAR struct lsm303agr_dev_s *priv)
{ {
/* readreg8 is not necessary to modify. Clearbits can be 0x00 or 0xFF */ /* readreg8 is not necessary to modify. Clearbits can be 0x00 or 0xff */
uint8_t value; uint8_t value;
@@ -441,15 +441,15 @@ static int lsm303agr_sensor_start(FAR struct lsm303agr_dev_s *priv)
/* Accelerometer config registers Turn on the accelerometer: 833Hz, +- 16g */ /* Accelerometer config registers Turn on the accelerometer: 833Hz, +- 16g */
lsm303agr_writereg8(priv, LSM303AGR_CTRL_REG1_A, 0x77); lsm303agr_writereg8(priv, LSM303AGR_CTRL_REG1_A, 0x77);
lsm303agr_writereg8(priv, LSM303AGR_CTRL_REG4_A, 0xB0); lsm303agr_writereg8(priv, LSM303AGR_CTRL_REG4_A, 0xb0);
g_accelerofactor = 11.72; g_accelerofactor = 11.72;
/* Gyro config registers Turn on the gyro: FS=2000dps, ODR=833Hz Not using /* Gyro config registers Turn on the gyro: FS=2000dps, ODR=833Hz Not using
* modifyreg with empty value!!!! Then read value first!!! * modifyreg with empty value!!!! Then read value first!!!
* lsm303agr_modifyreg8(priv, lsm303agr_CTRL2_G, value, 0x7C); * lsm303agr_modifyreg8(priv, lsm303agr_CTRL2_G, value, 0x7c);
*/ */
lsm303agr_writereg8(priv, LSM303AGR_CFG_REG_A_M, 0x8C); lsm303agr_writereg8(priv, LSM303AGR_CFG_REG_A_M, 0x8c);
g_magnetofactor = 1.5; g_magnetofactor = 1.5;
return OK; return OK;
@@ -574,7 +574,7 @@ static int lsm303agr_selftest(FAR struct lsm303agr_dev_s *priv, uint32_t mode)
else else
{ {
registershift = 0x40; registershift = 0x40;
lsm303agr_writereg8(priv, LSM303AGR_CFG_REG_A_M, 0x8C); lsm303agr_writereg8(priv, LSM303AGR_CFG_REG_A_M, 0x8c);
lsm303agr_writereg8(priv, LSM303AGR_CFG_REG_B_M, 0x02); lsm303agr_writereg8(priv, LSM303AGR_CFG_REG_B_M, 0x02);
lsm303agr_writereg8(priv, LSM303AGR_CFG_REG_C_M, 0x10); lsm303agr_writereg8(priv, LSM303AGR_CFG_REG_C_M, 0x10);
g_magnetofactor = 1; g_magnetofactor = 1;
@@ -878,7 +878,6 @@ static int lsm303agr_selftest(FAR struct lsm303agr_dev_s *priv, uint32_t mode)
static int lsm303agr_sensor_read(FAR struct lsm303agr_dev_s *priv, static int lsm303agr_sensor_read(FAR struct lsm303agr_dev_s *priv,
FAR struct lsm303agr_sensor_data_s *sensor_data) FAR struct lsm303agr_sensor_data_s *sensor_data)
{ {
int16_t lo = 0; int16_t lo = 0;
int16_t lox = 0; int16_t lox = 0;
int16_t loxg = 0; int16_t loxg = 0;
@@ -1078,7 +1077,8 @@ static ssize_t lsm303agr_read(FAR struct file *filep,
} }
/* The value is negative, so find its absolute value by taking the /* The value is negative, so find its absolute value by taking the
* two's complement */ * two's complement.
*/
else if (data > 0x8000) else if (data > 0x8000)
{ {
@@ -1087,7 +1087,8 @@ static ssize_t lsm303agr_read(FAR struct file *filep,
} }
/* The value is negative and can't be represented as a positive /* The value is negative and can't be represented as a positive
* int16_t value */ * int16_t value.
*/
else else
{ {
@@ -1270,6 +1271,7 @@ static int lsm303agr_register(FAR const char *devpath,
* Zero (OK) on success; a negated errno value on failure. * Zero (OK) on success; a negated errno value on failure.
* *
****************************************************************************/ ****************************************************************************/
int lsm303agr_sensor_register(FAR const char *devpath, int lsm303agr_sensor_register(FAR const char *devpath,
FAR struct i2c_master_s *i2c, uint8_t addr) FAR struct i2c_master_s *i2c, uint8_t addr)
{ {
+15 -14
View File
@@ -317,7 +317,7 @@ static struct lsm330_reg_pair_s g_default_lsm330_gyrocr_values[] =
{ {
.addr = LSM330_GYRO_CTRL_REG1, .addr = LSM330_GYRO_CTRL_REG1,
.value = 0xFF .value = 0xff
}, },
/* CR2 EXTRen LVLen HPM[1:0] HPCF[3:0] */ /* CR2 EXTRen LVLen HPM[1:0] HPCF[3:0] */
@@ -401,12 +401,11 @@ static uint8_t lsm330_read_register(FAR struct lsm330_dev_s *dev,
* Name: lsm330_read_acl_registerblk * Name: lsm330_read_acl_registerblk
******************************************************************************/ ******************************************************************************/
static void lsm330_read_acl_registerblk(FAR struct lsm330_dev_s *dev, static void lsm330_read_acl_registerblk(FAR struct lsm330_dev_s *dev,
uint8_t reg_addr, uint8_t reg_addr,
FAR uint8_t *reg_data, FAR uint8_t *reg_data,
uint8_t xfercnt) uint8_t xfercnt)
{ {
/* Lock the SPI bus so that only one device can access it at the same time */ /* Lock the SPI bus so that only one device can access it at the same time */
SPI_LOCK(dev->spi, true); SPI_LOCK(dev->spi, true);
@@ -426,7 +425,7 @@ static uint8_t lsm330_read_register(FAR struct lsm330_dev_s *dev,
/* Write idle bytes while receiving the requested data */ /* Write idle bytes while receiving the requested data */
while ( 0 != xfercnt-- ) while (0 != xfercnt--)
{ {
*reg_data++ = (uint8_t)SPI_SEND(dev->spi, 0xff); *reg_data++ = (uint8_t)SPI_SEND(dev->spi, 0xff);
} }
@@ -444,7 +443,7 @@ static uint8_t lsm330_read_register(FAR struct lsm330_dev_s *dev,
* Name: lsm330_read_gyro_registerblk * Name: lsm330_read_gyro_registerblk
******************************************************************************/ ******************************************************************************/
static void lsm330_read_gyro_registerblk(FAR struct lsm330_dev_s *dev, static void lsm330_read_gyro_registerblk(FAR struct lsm330_dev_s *dev,
uint8_t reg_addr, uint8_t reg_addr,
FAR uint8_t *reg_data, FAR uint8_t *reg_data,
uint8_t xfercnt) uint8_t xfercnt)
@@ -464,11 +463,12 @@ static uint8_t lsm330_read_register(FAR struct lsm330_dev_s *dev,
/* Transmit the register address from where we want to start reading */ /* Transmit the register address from where we want to start reading */
SPI_SEND(dev->spi, reg_addr | LSM330_READ | (xfercnt>1 ? LSM330_GYRO_AUTO : 0)); SPI_SEND(dev->spi, reg_addr | LSM330_READ |
(xfercnt > 1 ? LSM330_GYRO_AUTO : 0));
/* Write idle bytes while receiving the requested data */ /* Write idle bytes while receiving the requested data */
while ( 0 != xfercnt-- ) while (0 != xfercnt--)
{ {
*reg_data++ = (uint8_t)SPI_SEND(dev->spi, 0xff); *reg_data++ = (uint8_t)SPI_SEND(dev->spi, 0xff);
} }
@@ -524,7 +524,7 @@ static void lsm330_write_register(FAR struct lsm330_dev_s *dev,
* Name: lsm330_write_acl_registerblk * Name: lsm330_write_acl_registerblk
****************************************************************************/ ****************************************************************************/
static void lsm330_write_acl_registerblk(FAR struct lsm330_dev_s *dev, static void lsm330_write_acl_registerblk(FAR struct lsm330_dev_s *dev,
uint8_t reg_addr, uint8_t reg_addr,
FAR uint8_t *reg_data, FAR uint8_t *reg_data,
uint8_t xfercnt) uint8_t xfercnt)
@@ -548,7 +548,7 @@ static void lsm330_write_register(FAR struct lsm330_dev_s *dev,
/* Transmit the content which should be written in the register block */ /* Transmit the content which should be written in the register block */
while ( 0 != xfercnt-- ) while (0 != xfercnt--)
{ {
SPI_SEND(dev->spi, *reg_data++); SPI_SEND(dev->spi, *reg_data++);
} }
@@ -566,7 +566,7 @@ static void lsm330_write_register(FAR struct lsm330_dev_s *dev,
* Name: lsm330_write_gyro_registerblk * Name: lsm330_write_gyro_registerblk
****************************************************************************/ ****************************************************************************/
static void lsm330_write_gyro_registerblk(FAR struct lsm330_dev_s *dev, static void lsm330_write_gyro_registerblk(FAR struct lsm330_dev_s *dev,
uint8_t reg_addr, uint8_t reg_addr,
FAR uint8_t *reg_data, FAR uint8_t *reg_data,
uint8_t xfercnt) uint8_t xfercnt)
@@ -586,11 +586,12 @@ static void lsm330_write_register(FAR struct lsm330_dev_s *dev,
/* Transmit the register address to where we want to start writing */ /* Transmit the register address to where we want to start writing */
SPI_SEND(dev->spi, reg_addr | LSM330_WRITE | (xfercnt>1 ? LSM330_GYRO_AUTO : 0)); SPI_SEND(dev->spi, reg_addr | LSM330_WRITE |
(xfercnt > 1 ? LSM330_GYRO_AUTO : 0));
/* Transmit the content which should be written in the register block */ /* Transmit the content which should be written in the register block */
while ( 0 != xfercnt-- ) while (0 != xfercnt--)
{ {
SPI_SEND(dev->spi, *reg_data++); SPI_SEND(dev->spi, *reg_data++);
} }
@@ -682,7 +683,7 @@ static int lsm330acl_dvr_open(FAR void *instance_handle, int32_t arg)
sninfo("LSM330_ACL_IDREG = 0x%02x\n", reg_content); sninfo("LSM330_ACL_IDREG = 0x%02x\n", reg_content);
if (reg_content!=LSM330_ACL_IDREG_VALUE) if (reg_content != LSM330_ACL_IDREG_VALUE)
{ {
/* Made info log level to permit open being used as a device probe. */ /* Made info log level to permit open being used as a device probe. */
@@ -776,7 +777,7 @@ static int lsm330gyro_dvr_open(FAR void *instance_handle, int32_t arg)
sninfo("LSM330_GYRO_IDREG = 0x%02x\n", reg_content); sninfo("LSM330_GYRO_IDREG = 0x%02x\n", reg_content);
if (reg_content!=LSM330_GYRO_IDREG_VALUE) if (reg_content != LSM330_GYRO_IDREG_VALUE)
{ {
/* Made warning log level to permit open being used as a device probe. */ /* Made warning log level to permit open being used as a device probe. */
+4 -6
View File
@@ -139,7 +139,7 @@ static const struct file_operations g_fops =
# endif # endif
}; };
static const struct lsm6dsl_ops_s g_LSM6DSLsensor_ops = static const struct lsm6dsl_ops_s g_lsm6dsl_sensor_ops =
{ {
lsm6dsl_sensor_config, lsm6dsl_sensor_config,
lsm6dsl_sensor_start, lsm6dsl_sensor_start,
@@ -439,7 +439,7 @@ static int lsm6dsl_sensor_start(FAR struct lsm6dsl_dev_s *priv)
* modifyreg with empty value!!!! Then read value first!!! * modifyreg with empty value!!!! Then read value first!!!
*/ */
lsm6dsl_writereg8(priv, LSM6DSL_CTRL2_G, 0x7C); lsm6dsl_writereg8(priv, LSM6DSL_CTRL2_G, 0x7c);
g_gyrofactor = 70; g_gyrofactor = 70;
lsm6dsl_writereg8(priv, LSM6DSL_CTRL6_C, 0x00); lsm6dsl_writereg8(priv, LSM6DSL_CTRL6_C, 0x00);
@@ -493,7 +493,6 @@ static int lsm6dsl_sensor_stop(FAR struct lsm6dsl_dev_s *priv)
static int lsm6dsl_selftest(FAR struct lsm6dsl_dev_s *priv, uint32_t mode) static int lsm6dsl_selftest(FAR struct lsm6dsl_dev_s *priv, uint32_t mode)
{ {
int samples = 5; int samples = 5;
int i; int i;
int i2; int i2;
@@ -589,7 +588,7 @@ static int lsm6dsl_selftest(FAR struct lsm6dsl_dev_s *priv, uint32_t mode)
/* Gyro; power down accelero CTRL1_XL FS=2000dps,208Hz 2000dps=65535 */ /* Gyro; power down accelero CTRL1_XL FS=2000dps,208Hz 2000dps=65535 */
lsm6dsl_writereg8(priv, LSM6DSL_CTRL1_XL, 0x00); lsm6dsl_writereg8(priv, LSM6DSL_CTRL1_XL, 0x00);
lsm6dsl_writereg8(priv, LSM6DSL_CTRL2_G, 0x5C); lsm6dsl_writereg8(priv, LSM6DSL_CTRL2_G, 0x5c);
lsm6dsl_writereg8(priv, LSM6DSL_CTRL3_C, 0x44); lsm6dsl_writereg8(priv, LSM6DSL_CTRL3_C, 0x44);
g_gyrofactor = (70 / 1000); /* 2000dps */ g_gyrofactor = (70 / 1000); /* 2000dps */
} }
@@ -898,7 +897,6 @@ static int lsm6dsl_selftest(FAR struct lsm6dsl_dev_s *priv, uint32_t mode)
static int lsm6dsl_sensor_read(FAR struct lsm6dsl_dev_s *priv, static int lsm6dsl_sensor_read(FAR struct lsm6dsl_dev_s *priv,
FAR struct lsm6dsl_sensor_data_s *sensor_data) FAR struct lsm6dsl_sensor_data_s *sensor_data)
{ {
int16_t lo = 0; int16_t lo = 0;
int16_t lox = 0; int16_t lox = 0;
int16_t loxg = 0; int16_t loxg = 0;
@@ -1337,7 +1335,7 @@ int lsm6dsl_sensor_register(FAR const char *devpath,
sninfo("Trying to register accel\n"); sninfo("Trying to register accel\n");
return lsm6dsl_register(devpath, i2c, addr, &g_LSM6DSLsensor_ops, return lsm6dsl_register(devpath, i2c, addr, &g_lsm6dsl_sensor_ops,
LSM6DSL_OUTX_L_XL_SHIFT, sensor_data); LSM6DSL_OUTX_L_XL_SHIFT, sensor_data);
} }
+3
View File
@@ -63,6 +63,7 @@
#endif #endif
/* Register Addresses *******************************************************/ /* Register Addresses *******************************************************/
/* Accelerometer and gyroscope registers */ /* Accelerometer and gyroscope registers */
#define LSM9DS1_ACT_THS 0x04 /* Inactivity threshold */ #define LSM9DS1_ACT_THS 0x04 /* Inactivity threshold */
@@ -143,6 +144,7 @@
#define LSM9DS1_INT_THS_H_M 0x33 /* Interrupt threshold high byte */ #define LSM9DS1_INT_THS_H_M 0x33 /* Interrupt threshold high byte */
/* Register Bit Definitions *************************************************/ /* Register Bit Definitions *************************************************/
/* Inactivity threshold register */ /* Inactivity threshold register */
#define LSM9DS1_ACT_THS_ACT_THS_SHIFT 0 /* Inactivity threshold */ #define LSM9DS1_ACT_THS_ACT_THS_SHIFT 0 /* Inactivity threshold */
@@ -521,6 +523,7 @@ struct lsm9ds1_dev_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* I2C Helpers */ /* I2C Helpers */
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,
+9 -6
View File
@@ -78,6 +78,7 @@ struct ltc4151_dev_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* I2C Helpers */ /* I2C Helpers */
static int ltc4151_read16(FAR struct ltc4151_dev_s *priv, uint8_t regaddr, static int ltc4151_read16(FAR struct ltc4151_dev_s *priv, uint8_t regaddr,
@@ -89,10 +90,12 @@ static int ltc4151_readpower(FAR struct ltc4151_dev_s *priv,
static int ltc4151_open(FAR struct file *filep); static int ltc4151_open(FAR struct file *filep);
static int ltc4151_close(FAR struct file *filep); static int ltc4151_close(FAR struct file *filep);
static ssize_t ltc4151_read(FAR struct file *filep, FAR char *buffer, size_t buflen); static ssize_t ltc4151_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static ssize_t ltc4151_write(FAR struct file *filep, FAR const char *buffer, static ssize_t ltc4151_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen); size_t buflen);
static int ltc4151_ioctl(FAR struct file *filep,int cmd,unsigned long arg); static int ltc4151_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@@ -118,7 +121,7 @@ static const struct file_operations g_ltc4151fops =
static int ltc4151_read_reg(FAR struct ltc4151_dev_s *priv, static int ltc4151_read_reg(FAR struct ltc4151_dev_s *priv,
uint8_t start_register_address, uint8_t start_register_address,
FAR uint8_t* register_value, uint8_t data_length) FAR uint8_t *register_value, uint8_t data_length)
{ {
struct i2c_msg_s msg[I2C_NOSTARTSTOP_MSGS]; struct i2c_msg_s msg[I2C_NOSTARTSTOP_MSGS];
int ret; int ret;
@@ -137,14 +140,14 @@ static int ltc4151_read_reg(FAR struct ltc4151_dev_s *priv,
sninfo("start_register_address: " sninfo("start_register_address: "
"0x%02X data_length: %d register_value: 0x%02x (0x%04x) ret: %d\n", "0x%02X data_length: %d register_value: 0x%02x (0x%04x) ret: %d\n",
start_register_address, data_length, *register_value, start_register_address, data_length, *register_value,
*((uint16_t*)register_value), ret); *((FAR uint16_t *)register_value), ret);
return ret; return ret;
} }
static int ltc4151_read16(FAR struct ltc4151_dev_s *priv, uint8_t regaddr, static int ltc4151_read16(FAR struct ltc4151_dev_s *priv, uint8_t regaddr,
FAR uint16_t* regvalue) FAR uint16_t *regvalue)
{ {
int ret = ltc4151_read_reg(priv, regaddr, (uint8_t*)regvalue, int ret = ltc4151_read_reg(priv, regaddr, (FAR uint8_t *)regvalue,
sizeof(*regvalue)); sizeof(*regvalue));
/* Bytes are 8bit_msb.4bit_0.4bit_lsb = 16bit */ /* Bytes are 8bit_msb.4bit_0.4bit_lsb = 16bit */
+6 -6
View File
@@ -70,8 +70,8 @@
#define MAX31855_SHORT_VCC (1 << 2) #define MAX31855_SHORT_VCC (1 << 2)
#define MAX31855_SHORT_GND (1 << 1) #define MAX31855_SHORT_GND (1 << 1)
#define MAX31855_OPEN_CIRCUIT (1 << 0) #define MAX31855_OPEN_CIRCUIT (1 << 0)
#define MAX31855_TEMP_COUPLE 0xFFFFC000 #define MAX31855_TEMP_COUPLE 0xffffc000
#define MAX31855_TEMP_JUNCTION 0xFFF0 #define MAX31855_TEMP_JUNCTION 0xfff0
struct max31855_dev_s struct max31855_dev_s
{ {
@@ -222,10 +222,10 @@ static ssize_t max31855_read(FAR struct file *filep, FAR char *buffer,
return -EINVAL; return -EINVAL;
} }
regval = (regmsb & 0xFF000000) >> 24; regval = (regmsb & 0xff000000) >> 24;
regval |= (regmsb & 0xFF0000) >> 8; regval |= (regmsb & 0xff0000) >> 8;
regval |= (regmsb & 0xFF00) << 8; regval |= (regmsb & 0xff00) << 8;
regval |= (regmsb & 0xFF) << 24; regval |= (regmsb & 0xff) << 24;
sninfo("Read from MAX31855 = 0x%08X\n", regval); sninfo("Read from MAX31855 = 0x%08X\n", regval);
+7 -2
View File
@@ -714,7 +714,8 @@ static int max44009_read_data(FAR struct max44009_dev_s *priv,
} }
/* Merge HBYTE and LBYTE to 16-bit integer: /* Merge HBYTE and LBYTE to 16-bit integer:
* --.--.--.--.E3.E2.E1.E0.M7.M6.M5.M4.M3.M2.M1.M0 */ * --.--.--.--.E3.E2.E1.E0.M7.M6.M5.M4.M3.M2.M1.M0
*/
data->raw_value = (hvalue << 4) | (lvalue & 0xf); data->raw_value = (hvalue << 4) | (lvalue & 0xf);
@@ -850,7 +851,8 @@ static int max44009_poll(FAR struct file *filep, FAR struct pollfd *fds,
} }
/* This is a request to set up the poll. Find an available slot for the /* This is a request to set up the poll. Find an available slot for the
* poll structure reference */ * poll structure reference.
*/
for (i = 0; i < CONFIG_MAX44009_NPOLLWAITERS; i++) for (i = 0; i < CONFIG_MAX44009_NPOLLWAITERS; i++)
{ {
@@ -872,6 +874,7 @@ static int max44009_poll(FAR struct file *filep, FAR struct pollfd *fds,
ret = -EBUSY; ret = -EBUSY;
goto out; goto out;
} }
if (priv->int_pending) if (priv->int_pending)
{ {
max44009_notify(priv); max44009_notify(priv);
@@ -889,7 +892,9 @@ static int max44009_poll(FAR struct file *filep, FAR struct pollfd *fds,
*slot = NULL; *slot = NULL;
fds->priv = NULL; fds->priv = NULL;
} }
out: out:
nxsem_post(&priv->dev_sem); nxsem_post(&priv->dev_sem);
return ret; return ret;
} }
+3 -3
View File
@@ -37,7 +37,7 @@
/* NOTE: Some Maxim MAX6675 chips have an issue it report value 25% lower /* NOTE: Some Maxim MAX6675 chips have an issue it report value 25% lower
* of real temperature, for more info read this thread: * of real temperature, for more info read this thread:
* http://www.eevblog.com/forum/projects/max6675-temperature-error/ * http://www.eevblog.com/forum/projects/max6675-temperature-error/
*/ */
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@@ -208,8 +208,8 @@ static ssize_t max6675_read(FAR struct file *filep, FAR char *buffer, size_t buf
SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE(0), false); SPI_SELECT(priv->spi, SPIDEV_TEMPERATURE(0), false);
max6675_unlock(priv->spi); max6675_unlock(priv->spi);
regval = (regmsb & 0xFF00) >> 8; regval = (regmsb & 0xff00) >> 8;
regval |= (regmsb & 0xFF) << 8; regval |= (regmsb & 0xff) << 8;
sninfo("Read from MAX6675 = 0x%04X\n", regval); sninfo("Read from MAX6675 = 0x%04X\n", regval);
+1
View File
@@ -76,6 +76,7 @@ struct mb7040_dev_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* I2C Helpers */ /* I2C Helpers */
static int mb7040_measurerange(FAR struct mb7040_dev_s *priv); static int mb7040_measurerange(FAR struct mb7040_dev_s *priv);
+7 -5
View File
@@ -154,7 +154,7 @@ static int mcp9844_read_u16(FAR struct mcp9844_dev_s *priv,
/* Copy the content of the buffer to the location of the uint16_t pointer */ /* Copy the content of the buffer to the location of the uint16_t pointer */
*value = (((uint16_t)(buffer[0]))<<8) + ((uint16_t)(buffer[1])); *value = (((uint16_t)(buffer[0])) << 8) + ((uint16_t)(buffer[1]));
sninfo("addr: %02x value: %08x ret: %d\n", regaddr, *value, ret); sninfo("addr: %02x value: %08x ret: %d\n", regaddr, *value, ret);
return OK; return OK;
@@ -284,11 +284,11 @@ static int mcp9844_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
* need to be masked out. * need to be masked out.
*/ */
raw_temperature &= 0x0FFF; /* 0x0FFF = 0b 0000 1111 1111 1111 */ raw_temperature &= 0x0fff; /* 0x0fff = 0b 0000 1111 1111 1111 */
/* The post comma temperature value is encoded in BIT3 to BIT0 */ /* The post comma temperature value is encoded in BIT3 to BIT0 */
temp_result->temp_post_comma = (uint8_t)(raw_temperature & 0x000F); temp_result->temp_post_comma = (uint8_t)(raw_temperature & 0x000f);
/* The pre comma temperature value is encoded in BIT11 to BIT4 */ /* The pre comma temperature value is encoded in BIT11 to BIT4 */
@@ -296,7 +296,8 @@ static int mcp9844_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
} }
else else
{ {
snerr("ERROR: ioctl::SNIOC_READTEMP - mcp9844_read_u16 failed - no temperature retrieved\n"); snerr("ERROR: ioctl::SNIOC_READTEMP - mcp9844_read_u16 failed"
" - no temperature retrieved\n");
} }
} }
break; break;
@@ -306,7 +307,8 @@ static int mcp9844_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
ret = mcp9844_write_u16(priv, MCP9844_RESO_REG, (uint16_t)(arg)); ret = mcp9844_write_u16(priv, MCP9844_RESO_REG, (uint16_t)(arg));
if (ret != OK) if (ret != OK)
{ {
snerr("ERROR: ioctl::SNIOC_SETRESOLUTION - mcp9844_write_u16 failed - no resolution set\n"); snerr("ERROR: ioctl::SNIOC_SETRESOLUTION - mcp9844_write_u16 failed"
" - no resolution set\n");
} }
} }
break; break;
+4 -3
View File
@@ -334,11 +334,11 @@ static void mlx90393_write_register(FAR struct mlx90393_dev_s *dev,
/* Send the data high byte of the register */ /* Send the data high byte of the register */
SPI_SEND(dev->spi, (uint8_t) ((reg_data & 0xFF00) >> 8)); SPI_SEND(dev->spi, (uint8_t) ((reg_data & 0xff00) >> 8));
/* Send the data low byte of the register */ /* Send the data low byte of the register */
SPI_SEND(dev->spi, (uint8_t) (reg_data & 0x00FF)); SPI_SEND(dev->spi, (uint8_t) (reg_data & 0x00ff));
/* Send the register address which needs to be left shifted by 2 */ /* Send the register address which needs to be left shifted by 2 */
@@ -616,7 +616,8 @@ int mlx90393_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
/* Since we support multiple MLX90393 devices are supported, we will need to /* Since we support multiple MLX90393 devices are supported, we will need to
* add this new instance to a list of device instances so that it can be * add this new instance to a list of device instances so that it can be
* found by the interrupt handler based on the received IRQ number. */ * found by the interrupt handler based on the received IRQ number.
*/
priv->flink = g_mlx90393_list; priv->flink = g_mlx90393_list;
g_mlx90393_list = priv; g_mlx90393_list = priv;
+41 -16
View File
@@ -79,7 +79,8 @@ struct mpl115a_dev_s
****************************************************************************/ ****************************************************************************/
static inline void mpl115a_configspi(FAR struct spi_dev_s *spi); static inline void mpl115a_configspi(FAR struct spi_dev_s *spi);
static uint8_t mpl115a_getreg8(FAR struct mpl115a_dev_s *priv, uint8_t regaddr); static uint8_t mpl115a_getreg8(FAR struct mpl115a_dev_s *priv,
uint8_t regaddr);
static void mpl115a_updatecaldata(FAR struct mpl115a_dev_s *priv); static void mpl115a_updatecaldata(FAR struct mpl115a_dev_s *priv);
static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv); static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv);
static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv); static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv);
@@ -90,7 +91,8 @@ static int mpl115a_open(FAR struct file *filep);
static int mpl115a_close(FAR struct file *filep); static int mpl115a_close(FAR struct file *filep);
static ssize_t mpl115a_read(FAR struct file *filep, FAR char *buffer, static ssize_t mpl115a_read(FAR struct file *filep, FAR char *buffer,
size_t buflen); size_t buflen);
static ssize_t mpl115a_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); static ssize_t mpl115a_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@@ -176,26 +178,38 @@ static void mpl115a_updatecaldata(FAR struct mpl115a_dev_s *priv)
{ {
/* Get a0 coefficient */ /* Get a0 coefficient */
priv->mpl115a_cal_a0 = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_A0_MSB << 1)) << 8; priv->mpl115a_cal_a0 =
priv->mpl115a_cal_a0 |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_A0_LSB << 1)); mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_A0_MSB << 1)) << 8;
priv->mpl115a_cal_a0 |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_A0_LSB << 1));
sninfo("a0 = %d\n", priv->mpl115a_cal_a0); sninfo("a0 = %d\n", priv->mpl115a_cal_a0);
/* Get b1 coefficient */ /* Get b1 coefficient */
priv->mpl115a_cal_b1 = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B1_MSB << 1)) << 8; priv->mpl115a_cal_b1 =
priv->mpl115a_cal_b1 |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B1_LSB << 1)); mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B1_MSB << 1)) << 8;
priv->mpl115a_cal_b1 |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B1_LSB << 1));
sninfo("b1 = %d\n", priv->mpl115a_cal_b1); sninfo("b1 = %d\n", priv->mpl115a_cal_b1);
/* Get b2 coefficient */ /* Get b2 coefficient */
priv->mpl115a_cal_b2 = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B2_MSB << 1)) << 8; priv->mpl115a_cal_b2 =
priv->mpl115a_cal_b2 |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B2_LSB << 1)); mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B2_MSB << 1)) << 8;
priv->mpl115a_cal_b2 |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_B2_LSB << 1));
sninfo("b2 = %d\n", priv->mpl115a_cal_b2); sninfo("b2 = %d\n", priv->mpl115a_cal_b2);
/* Get c12 coefficient */ /* Get c12 coefficient */
priv->mpl115a_cal_c12 = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_C12_MSB << 1)) << 8; priv->mpl115a_cal_c12 =
priv->mpl115a_cal_c12 |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_C12_LSB << 1)); mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_C12_MSB << 1)) << 8;
priv->mpl115a_cal_c12 |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_C12_LSB << 1));
sninfo("c12 = %d\n", priv->mpl115a_cal_c12); sninfo("c12 = %d\n", priv->mpl115a_cal_c12);
} }
@@ -218,14 +232,18 @@ static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv)
nxsig_usleep(5000); nxsig_usleep(5000);
priv->mpl115a_pressure = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_PADC_MSB << 1)) << 8; priv->mpl115a_pressure =
priv->mpl115a_pressure |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_PADC_LSB << 1)); mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_PADC_MSB << 1)) << 8;
priv->mpl115a_pressure |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_PADC_LSB << 1));
priv->mpl115a_pressure >>= 6; /* Padc is 10bit unsigned */ priv->mpl115a_pressure >>= 6; /* Padc is 10bit unsigned */
sninfo("Pressure = %d\n", priv->mpl115a_pressure); sninfo("Pressure = %d\n", priv->mpl115a_pressure);
priv->mpl115a_temperature = mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_TADC_MSB << 1)) << 8; priv->mpl115a_temperature =
priv->mpl115a_temperature |= mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_TADC_LSB << 1)); mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_TADC_MSB << 1)) << 8;
priv->mpl115a_temperature |=
mpl115a_getreg8(priv, MPL115A_BASE_CMD | (MPL115A_TADC_LSB << 1));
priv->mpl115a_temperature >>= 6; /* Tadc is 10bit unsigned */ priv->mpl115a_temperature >>= 6; /* Tadc is 10bit unsigned */
sninfo("Temperature = %d\n", priv->mpl115a_temperature); sninfo("Temperature = %d\n", priv->mpl115a_temperature);
@@ -247,8 +265,15 @@ static void mpl115a_read_press_temp(FAR struct mpl115a_dev_s *priv)
static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv) static int mpl115a_getpressure(FAR struct mpl115a_dev_s *priv)
{ {
int32_t c12x2, a1, a1x1, y1, a2x2, pcomp; int32_t c12x2;
uint16_t padc, tadc, pressure; int32_t a1;
int32_t a1x1;
int32_t y1;
int32_t a2x2;
int32_t pcomp;
uint16_t padc;
uint16_t tadc;
uint16_t pressure;
/* Check if coefficient data were read correctly */ /* Check if coefficient data were read correctly */
+7 -5
View File
@@ -66,6 +66,7 @@
#endif #endif
/* Register Definitions *****************************************************/ /* Register Definitions *****************************************************/
/* Register Addresses */ /* Register Addresses */
#define MS58XX_RESET_REG 0x1e /* Reset Register */ #define MS58XX_RESET_REG 0x1e /* Reset Register */
@@ -138,6 +139,7 @@ struct ms58xx_dev_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* CRC Calculation */ /* CRC Calculation */
static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcndx, uint16_t crcmask); static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcndx, uint16_t crcmask);
@@ -234,7 +236,7 @@ static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcndx, uint16_t crcmask)
} }
} }
n_rem = (0x000F & (n_rem >> 12)); n_rem = (0x000f & (n_rem >> 12));
src[crcndx] = crc_read; src[crcndx] = crc_read;
return (n_rem ^ 0x00); return (n_rem ^ 0x00);
} }
@@ -417,7 +419,7 @@ static int ms58xx_setosr_1(FAR struct ms58xx_dev_s *priv, uint16_t osr)
case 8192: case 8192:
priv->delay = 18080; priv->delay = 18080;
priv->osr = 0xA; priv->osr = 0xa;
break; break;
default: default:
@@ -492,7 +494,7 @@ static int ms58xx_setosr(FAR struct ms58xx_dev_s *priv, uint16_t osr)
{ {
case MS58XX_MODEL_MS5805_02: case MS58XX_MODEL_MS5805_02:
case MS58XX_MODEL_MS5837_30: case MS58XX_MODEL_MS5837_30:
ret = ms58xx_setosr_1(priv,osr); ret = ms58xx_setosr_1(priv, osr);
break; break;
case MS58XX_MODEL_MS5803_02: case MS58XX_MODEL_MS5803_02:
@@ -501,7 +503,7 @@ static int ms58xx_setosr(FAR struct ms58xx_dev_s *priv, uint16_t osr)
case MS58XX_MODEL_MS5803_14: case MS58XX_MODEL_MS5803_14:
case MS58XX_MODEL_MS5803_30: case MS58XX_MODEL_MS5803_30:
case MS58XX_MODEL_MS5806_02: case MS58XX_MODEL_MS5806_02:
ret = ms58xx_setosr_2(priv,osr); ret = ms58xx_setosr_2(priv, osr);
break; break;
default: default:
@@ -535,7 +537,7 @@ static int ms58xx_readprom(FAR struct ms58xx_dev_s *priv)
{ {
case MS58XX_MODEL_MS5805_02: case MS58XX_MODEL_MS5805_02:
case MS58XX_MODEL_MS5837_30: case MS58XX_MODEL_MS5837_30:
prom[MS58XX_PROM_LEN-1] = 0; prom[MS58XX_PROM_LEN - 1] = 0;
len--; len--;
crcindex = 0; crcindex = 0;
crcshift = 12; crcshift = 12;
+5 -2
View File
@@ -63,6 +63,7 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Debug ********************************************************************/ /* Debug ********************************************************************/
/**************************************************************************** /****************************************************************************
@@ -84,8 +85,10 @@ struct qe_upperhalf_s
static int qe_open(FAR struct file *filep); static int qe_open(FAR struct file *filep);
static int qe_close(FAR struct file *filep); static int qe_close(FAR struct file *filep);
static ssize_t qe_read(FAR struct file *filep, FAR char *buffer, size_t buflen); static ssize_t qe_read(FAR struct file *filep, FAR char *buffer,
static ssize_t qe_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); size_t buflen);
static ssize_t qe_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static int qe_ioctl(FAR struct file *filep, int cmd, unsigned long arg); static int qe_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
/**************************************************************************** /****************************************************************************
+6 -3
View File
@@ -84,7 +84,7 @@
#define SCD30_CMD_SET_FRC 0x5204 #define SCD30_CMD_SET_FRC 0x5204
#define SCD30_CMD_SET_TEMP_OFFSET 0x5403 #define SCD30_CMD_SET_TEMP_OFFSET 0x5403
#define SCD30_CMD_SET_ALT_COMPENSATION 0x5102 #define SCD30_CMD_SET_ALT_COMPENSATION 0x5102
#define SCD30_CMD_SOFT_RESET 0xD304 #define SCD30_CMD_SOFT_RESET 0xd304
#define SCD30_DEFAULT_MEASUREMENT_INTERVAL 2 /* seconds */ #define SCD30_DEFAULT_MEASUREMENT_INTERVAL 2 /* seconds */
#define SCD30_DEFAULT_PRESSURE_COMPENSATION 0 #define SCD30_DEFAULT_PRESSURE_COMPENSATION 0
@@ -131,6 +131,7 @@ struct scd30_word_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* IO Helpers */ /* IO Helpers */
#ifdef CONFIG_SCD30_I2C #ifdef CONFIG_SCD30_I2C
@@ -226,6 +227,7 @@ static int scd30_do_transfer(FAR struct i2c_master_s *i2c,
else else
{ {
/* Some error. Try to reset I2C bus and keep trying. */ /* Some error. Try to reset I2C bus and keep trying. */
#ifdef CONFIG_I2C_RESET #ifdef CONFIG_I2C_RESET
if (retries == SCD30_I2C_RETRIES - 1) if (retries == SCD30_I2C_RETRIES - 1)
{ {
@@ -330,7 +332,8 @@ static uint8_t scd30_crc_word(uint16_t word)
0x00, 0x31, 0x62, 0x53, 0xc4, 0xf5, 0xa6, 0x97, 0x00, 0x31, 0x62, 0x53, 0xc4, 0xf5, 0xa6, 0x97,
0xb9, 0x88, 0xdb, 0xea, 0x7d, 0x4c, 0x1f, 0x2e 0xb9, 0x88, 0xdb, 0xea, 0x7d, 0x4c, 0x1f, 0x2e
}; };
uint8_t crc = 0xFF;
uint8_t crc = 0xff;
crc ^= word >> 8; crc ^= word >> 8;
crc = (crc << 4) ^ crc_table[crc >> 4]; crc = (crc << 4) ^ crc_table[crc >> 4];
@@ -1079,7 +1082,7 @@ int scd30_register_i2c(FAR const char *devpath, FAR struct i2c_master_s *i2c,
DEBUGASSERT(i2c != NULL); DEBUGASSERT(i2c != NULL);
DEBUGASSERT(addr == CONFIG_SCD30_ADDR); DEBUGASSERT(addr == CONFIG_SCD30_ADDR);
DEBUGASSERT(scd30_crc_word(0xBEEF) == 0x92); DEBUGASSERT(scd30_crc_word(0xbeef) == 0x92);
/* Initialize the device structure */ /* Initialize the device structure */
+10 -5
View File
@@ -106,6 +106,7 @@ struct sgp30_cmd_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* IO Helpers */ /* IO Helpers */
static int sgp30_do_transfer(FAR struct i2c_master_s *i2c, static int sgp30_do_transfer(FAR struct i2c_master_s *i2c,
@@ -245,6 +246,7 @@ static int sgp30_do_transfer(FAR struct i2c_master_s *i2c,
else else
{ {
/* Some error. Try to reset I2C bus and keep trying. */ /* Some error. Try to reset I2C bus and keep trying. */
#ifdef CONFIG_I2C_RESET #ifdef CONFIG_I2C_RESET
if (retries == SGP30_I2C_RETRIES - 1) if (retries == SGP30_I2C_RETRIES - 1)
{ {
@@ -359,7 +361,8 @@ static uint8_t sgp30_crc_word(uint16_t word)
0x00, 0x31, 0x62, 0x53, 0xc4, 0xf5, 0xa6, 0x97, 0x00, 0x31, 0x62, 0x53, 0xc4, 0xf5, 0xa6, 0x97,
0xb9, 0x88, 0xdb, 0xea, 0x7d, 0x4c, 0x1f, 0x2e 0xb9, 0x88, 0xdb, 0xea, 0x7d, 0x4c, 0x1f, 0x2e
}; };
uint8_t crc = 0xFF;
uint8_t crc = 0xff;
crc ^= word >> 8; crc ^= word >> 8;
crc = (crc << 4) ^ crc_table[crc >> 4]; crc = (crc << 4) ^ crc_table[crc >> 4];
@@ -556,7 +559,8 @@ static int sgp30_open(FAR struct file *filep)
ret = sgp30_write_cmd(priv, SGP30_CMD_INIT_AIR_QUALITY, NULL, 0); ret = sgp30_write_cmd(priv, SGP30_CMD_INIT_AIR_QUALITY, NULL, 0);
if (ret < 0) if (ret < 0)
{ {
sgp30_dbg("sgp30_write_cmd(SGP30_CMD_INIT_AIR_QUALITY) failed, %d\n", ret); sgp30_dbg("sgp30_write_cmd(SGP30_CMD_INIT_AIR_QUALITY) failed, %d\n",
ret);
} }
} }
else else
@@ -636,7 +640,8 @@ static ssize_t sgp30_read(FAR struct file *filep, FAR char *buffer,
FAR struct inode *inode = filep->f_inode; FAR struct inode *inode = filep->f_inode;
FAR struct sgp30_dev_s *priv = inode->i_private; FAR struct sgp30_dev_s *priv = inode->i_private;
ssize_t length = 0; ssize_t length = 0;
struct timespec ts, ts_sleep; struct timespec ts;
struct timespec ts_sleep;
struct sgp30_conv_data_s data; struct sgp30_conv_data_s data;
int ret; int ret;
@@ -893,7 +898,7 @@ static int sgp30_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
sgp30_dbg("crc error\n"); sgp30_dbg("crc error\n");
ret = -EIO; ret = -EIO;
} }
else if (sgp30_data_word_to_uint16(buf) != 0xD400) else if (sgp30_data_word_to_uint16(buf) != 0xd400)
{ {
sgp30_dbg("self-test failed, 0x%04x\n", sgp30_dbg("self-test failed, 0x%04x\n",
sgp30_data_word_to_uint16(buf)); sgp30_data_word_to_uint16(buf));
@@ -989,7 +994,7 @@ int sgp30_register(FAR const char *devpath, FAR struct i2c_master_s *i2c,
DEBUGASSERT(i2c != NULL); DEBUGASSERT(i2c != NULL);
DEBUGASSERT(addr == CONFIG_SGP30_ADDR); DEBUGASSERT(addr == CONFIG_SGP30_ADDR);
DEBUGASSERT(sgp30_crc_word(0xBEEF) == 0x92); DEBUGASSERT(sgp30_crc_word(0xbeef) == 0x92);
/* Initialize the device structure */ /* Initialize the device structure */
+1
View File
@@ -99,6 +99,7 @@ struct sht21_dev_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* I2C Helpers */ /* I2C Helpers */
static int sht21_access(FAR struct sht21_dev_s *priv, static int sht21_access(FAR struct sht21_dev_s *priv,
+1
View File
@@ -306,6 +306,7 @@ static uint8_t sht3x_crc_word(uint16_t word)
0x00, 0x31, 0x62, 0x53, 0xc4, 0xf5, 0xa6, 0x97, 0x00, 0x31, 0x62, 0x53, 0xc4, 0xf5, 0xa6, 0x97,
0xb9, 0x88, 0xdb, 0xea, 0x7d, 0x4c, 0x1f, 0x2e 0xb9, 0x88, 0xdb, 0xea, 0x7d, 0x4c, 0x1f, 0x2e
}; };
uint8_t crc = 0xff; uint8_t crc = 0xff;
crc ^= word >> 8; crc ^= word >> 8;
+9 -5
View File
@@ -84,9 +84,9 @@
#define SPS30_CMD_READ_MEASUREMENT 0x0300 #define SPS30_CMD_READ_MEASUREMENT 0x0300
#define SPS30_CMD_SET_AUTO_CLEANING_INTERVAL 0x8004 #define SPS30_CMD_SET_AUTO_CLEANING_INTERVAL 0x8004
#define SPS30_CMD_START_FAN_CLEANING 0x5607 #define SPS30_CMD_START_FAN_CLEANING 0x5607
#define SPS30_CMD_READ_ARTICLE_CODE 0xD025 #define SPS30_CMD_READ_ARTICLE_CODE 0xd025
#define SPS30_CMD_READ_SERIAL_NUMBER 0xD033 #define SPS30_CMD_READ_SERIAL_NUMBER 0xd033
#define SPS30_CMD_SOFT_RESET 0xD304 #define SPS30_CMD_SOFT_RESET 0xd304
/**************************************************************************** /****************************************************************************
* Private * Private
@@ -123,6 +123,7 @@ struct sps30_word_s
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
/* IO Helpers */ /* IO Helpers */
#ifdef CONFIG_SPS30_I2C #ifdef CONFIG_SPS30_I2C
@@ -220,6 +221,7 @@ static int sps30_do_transfer(FAR struct i2c_master_s *i2c,
else else
{ {
/* Some error. Try to reset I2C bus and keep trying. */ /* Some error. Try to reset I2C bus and keep trying. */
#ifdef CONFIG_I2C_RESET #ifdef CONFIG_I2C_RESET
if (retries == SPS30_I2C_RETRIES - 1) if (retries == SPS30_I2C_RETRIES - 1)
{ {
@@ -344,7 +346,8 @@ static uint8_t sps30_crc_word(uint16_t word)
0x00, 0x31, 0x62, 0x53, 0xc4, 0xf5, 0xa6, 0x97, 0x00, 0x31, 0x62, 0x53, 0xc4, 0xf5, 0xa6, 0x97,
0xb9, 0x88, 0xdb, 0xea, 0x7d, 0x4c, 0x1f, 0x2e 0xb9, 0x88, 0xdb, 0xea, 0x7d, 0x4c, 0x1f, 0x2e
}; };
uint8_t crc = 0xFF;
uint8_t crc = 0xff;
crc ^= word >> 8; crc ^= word >> 8;
crc = (crc << 4) ^ crc_table[crc >> 4]; crc = (crc << 4) ^ crc_table[crc >> 4];
@@ -667,6 +670,7 @@ static int sps30_open(FAR struct file *filep)
uint32_t u32[8]; uint32_t u32[8];
char c[32]; char c[32];
} code, sn; } code, sn;
int ret; int ret;
/* Get exclusive access */ /* Get exclusive access */
@@ -1095,7 +1099,7 @@ int sps30_register_i2c(FAR const char *devpath, FAR struct i2c_master_s *i2c,
DEBUGASSERT(i2c != NULL); DEBUGASSERT(i2c != NULL);
DEBUGASSERT(addr == CONFIG_SPS30_ADDR); DEBUGASSERT(addr == CONFIG_SPS30_ADDR);
DEBUGASSERT(sps30_crc_word(0xBEEF) == 0x92); DEBUGASSERT(sps30_crc_word(0xbeef) == 0x92);
/* Initialize the device structure */ /* Initialize the device structure */
+12 -12
View File
@@ -202,7 +202,11 @@ static int t67xx_read16(FAR struct t67xx_dev_s *priv, uint16_t regaddr,
{ {
struct i2c_config_s config; struct i2c_config_s config;
uint8_t buf[5]; uint8_t buf[5];
uint8_t rxbuf[4] = { 0 }; uint8_t rxbuf[4] =
{
0
};
int ret; int ret;
DEBUGASSERT(priv != NULL); DEBUGASSERT(priv != NULL);
@@ -222,8 +226,6 @@ static int t67xx_read16(FAR struct t67xx_dev_s *priv, uint16_t regaddr,
buf[3] = 0; buf[3] = 0;
buf[4] = 1; buf[4] = 1;
//sninfo("->[%d %d %d %d %d]\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
/* Write the Modbus read request. */ /* Write the Modbus read request. */
ret = i2c_write(priv->i2c, &config, buf, sizeof(buf)); ret = i2c_write(priv->i2c, &config, buf, sizeof(buf));
@@ -244,8 +246,6 @@ static int t67xx_read16(FAR struct t67xx_dev_s *priv, uint16_t regaddr,
return ret; return ret;
} }
//sninfo("<-[%d %d %d %d]\n", rxbuf[0], rxbuf[1], rxbuf[2], rxbuf[3]);
if (rxbuf[0] != 4 || rxbuf[1] != 2) if (rxbuf[0] != 4 || rxbuf[1] != 2)
{ {
#ifdef CONFIG_DEBUG_SENSORS_ERROR #ifdef CONFIG_DEBUG_SENSORS_ERROR
@@ -272,7 +272,11 @@ static int t67xx_write16(FAR struct t67xx_dev_s *priv, uint16_t regaddr,
{ {
struct i2c_config_s config; struct i2c_config_s config;
uint8_t buf[5]; uint8_t buf[5];
uint8_t rxbuf[5] = { 0 }; uint8_t rxbuf[5] =
{
0
};
int ret; int ret;
DEBUGASSERT(priv != NULL); DEBUGASSERT(priv != NULL);
@@ -291,8 +295,6 @@ static int t67xx_write16(FAR struct t67xx_dev_s *priv, uint16_t regaddr,
buf[3] = (regvalue >> 8) & 0xff; buf[3] = (regvalue >> 8) & 0xff;
buf[4] = regvalue & 0xff; buf[4] = regvalue & 0xff;
//sninfo("->[%d %d %d %d %d]\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
/* Write the Modbus write request. */ /* Write the Modbus write request. */
ret = i2c_write(priv->i2c, &config, buf, sizeof(buf)); ret = i2c_write(priv->i2c, &config, buf, sizeof(buf));
@@ -320,8 +322,6 @@ static int t67xx_write16(FAR struct t67xx_dev_s *priv, uint16_t regaddr,
return ret; return ret;
} }
//sninfo("<-[%d %d %d %d %d]\n", rxbuf[0], rxbuf[1], rxbuf[2], rxbuf[3], rxbuf[4]);
if (memcmp(rxbuf, buf, sizeof(rxbuf)) != 0) if (memcmp(rxbuf, buf, sizeof(rxbuf)) != 0)
{ {
#ifdef CONFIG_DEBUG_SENSORS_ERROR #ifdef CONFIG_DEBUG_SENSORS_ERROR
@@ -426,7 +426,6 @@ static bool has_time_passed(struct timespec curr,
return (long)((start.tv_sec + secs_since_start) - curr.tv_sec) <= 0; return (long)((start.tv_sec + secs_since_start) - curr.tv_sec) <= 0;
} }
/**************************************************************************** /****************************************************************************
* Name: t67xx_read_gas_ppm * Name: t67xx_read_gas_ppm
* *
@@ -439,7 +438,8 @@ static int t67xx_read_gas_ppm(FAR struct t67xx_dev_s *priv,
FAR struct t67xx_value_s *buffer) FAR struct t67xx_value_s *buffer)
{ {
uint16_t ppm; uint16_t ppm;
bool warming_up, calibrating; bool warming_up;
bool calibrating;
struct timespec ts; struct timespec ts;
int ret; int ret;

Some files were not shown because too many files have changed in this diff Show More