Trivial changes from review of last PR.
This commit is contained in:
parent
e79e2e2d97
commit
e07f12954c
@ -93,10 +93,10 @@ struct lis3dh_sample_s
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void lis3dh_read_register(FAR struct lis3dh_dev_s *dev,
|
static void lis3dh_read_register(FAR struct lis3dh_dev_s *dev,
|
||||||
uint8_t const reg_addr, uint8_t *reg_data);
|
uint8_t const reg_addr, uint8_t *reg_data);
|
||||||
static void lis3dh_write_register(FAR struct lis3dh_dev_s *dev,
|
static void lis3dh_write_register(FAR struct lis3dh_dev_s *dev,
|
||||||
uint8_t const reg_addr,
|
uint8_t const reg_addr,
|
||||||
uint8_t const reg_data);
|
uint8_t const reg_data);
|
||||||
static void lis3dh_reset(FAR struct lis3dh_dev_s *dev);
|
static void lis3dh_reset(FAR struct lis3dh_dev_s *dev);
|
||||||
static int lis3dh_ident(FAR struct lis3dh_dev_s *dev);
|
static int lis3dh_ident(FAR struct lis3dh_dev_s *dev);
|
||||||
static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev);
|
static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev);
|
||||||
@ -108,9 +108,9 @@ static int lis3dh_fifo_enable(FAR struct lis3dh_dev_s *dev);
|
|||||||
static int lis3dh_open(FAR struct file *filep);
|
static int lis3dh_open(FAR struct file *filep);
|
||||||
static int lis3dh_close(FAR struct file *filep);
|
static int lis3dh_close(FAR struct file *filep);
|
||||||
static ssize_t lis3dh_read(FAR struct file *, FAR char *buffer,
|
static ssize_t lis3dh_read(FAR struct file *, FAR char *buffer,
|
||||||
size_t buflen);
|
size_t buflen);
|
||||||
static ssize_t lis3dh_write(FAR struct file *filep, FAR const char *buffer,
|
static ssize_t lis3dh_write(FAR struct file *filep, FAR const char *buffer,
|
||||||
size_t buflen);
|
size_t buflen);
|
||||||
static int lis3dh_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
static int lis3dh_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -133,10 +133,6 @@ static const struct file_operations g_lis3dh_fops =
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -188,15 +184,15 @@ static void lis3dh_read_register(FAR struct lis3dh_dev_s *dev,
|
|||||||
* Write a single register to the LIS3DH sensor.
|
* Write a single register to the LIS3DH sensor.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* dev - Pointer to device driver instance
|
* dev - Pointer to device driver instance
|
||||||
* reg_addr - LIS3DH register address
|
* reg_addr - LIS3DH register address
|
||||||
* reg_data - Value to write into the specified register address
|
* reg_data - Value to write into the specified register address
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void lis3dh_write_register(FAR struct lis3dh_dev_s *dev,
|
static void lis3dh_write_register(FAR struct lis3dh_dev_s *dev,
|
||||||
uint8_t const reg_addr,
|
uint8_t const reg_addr,
|
||||||
uint8_t const reg_data)
|
uint8_t const reg_data)
|
||||||
{
|
{
|
||||||
uint8_t buffer[2];
|
uint8_t buffer[2];
|
||||||
|
|
||||||
@ -258,14 +254,14 @@ static int lis3dh_ident(FAR struct lis3dh_dev_s *dev)
|
|||||||
uint8_t reg;
|
uint8_t reg;
|
||||||
lis3dh_read_register(dev, LIS3DH_WHO_AM_I, ®);
|
lis3dh_read_register(dev, LIS3DH_WHO_AM_I, ®);
|
||||||
|
|
||||||
if(reg == LIS3DH_DEVICE_ID)
|
if (reg == LIS3DH_DEVICE_ID)
|
||||||
{
|
{
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: lis3dh_queue_lock
|
* Name: lis3dh_queue_lock
|
||||||
*
|
*
|
||||||
@ -320,7 +316,7 @@ static int lis3dh_queue_push(FAR struct lis3dh_dev_s *dev,
|
|||||||
struct lis3dh_sensor_data_s *data)
|
struct lis3dh_sensor_data_s *data)
|
||||||
{
|
{
|
||||||
lis3dh_queue_lock(dev);
|
lis3dh_queue_lock(dev);
|
||||||
if(dev->queue_count >= LIS3DH_QUEUE_MAX)
|
if (dev->queue_count >= LIS3DH_QUEUE_MAX)
|
||||||
{
|
{
|
||||||
lis3dh_queue_unlock(dev);
|
lis3dh_queue_unlock(dev);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -354,7 +350,7 @@ static int lis3dh_queue_pop(FAR struct lis3dh_dev_s *dev,
|
|||||||
struct lis3dh_sensor_data_s *data)
|
struct lis3dh_sensor_data_s *data)
|
||||||
{
|
{
|
||||||
lis3dh_queue_lock(dev);
|
lis3dh_queue_lock(dev);
|
||||||
if(dev->queue_count == 0)
|
if (dev->queue_count == 0)
|
||||||
{
|
{
|
||||||
lis3dh_queue_unlock(dev);
|
lis3dh_queue_unlock(dev);
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
@ -406,7 +402,7 @@ static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev)
|
|||||||
|
|
||||||
count = fifosrc & 0x1f;
|
count = fifosrc & 0x1f;
|
||||||
|
|
||||||
if(fifosrc & LIS3DH_FIFO_SRC_REG_OVRN_FIFO)
|
if (fifosrc & LIS3DH_FIFO_SRC_REG_OVRN_FIFO)
|
||||||
{
|
{
|
||||||
snerr("FIFO overrun\n");
|
snerr("FIFO overrun\n");
|
||||||
}
|
}
|
||||||
@ -422,7 +418,7 @@ static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev)
|
|||||||
|
|
||||||
SPI_LOCK(dev->spi, false);
|
SPI_LOCK(dev->spi, false);
|
||||||
|
|
||||||
for(i=0;i<count;i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
struct lis3dh_sensor_data_s data;
|
struct lis3dh_sensor_data_s data;
|
||||||
uint16_t x_raw;
|
uint16_t x_raw;
|
||||||
@ -446,7 +442,7 @@ static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev)
|
|||||||
* shift it to the right depending on the selected power mode
|
* shift it to the right depending on the selected power mode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch(dev->power_mode)
|
switch (dev->power_mode)
|
||||||
{
|
{
|
||||||
case LIS3DH_POWER_LOW: /* 8 bit measurements */
|
case LIS3DH_POWER_LOW: /* 8 bit measurements */
|
||||||
x_acc = (int16_t)x_raw >> 8;
|
x_acc = (int16_t)x_raw >> 8;
|
||||||
@ -456,8 +452,8 @@ static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev)
|
|||||||
data.x_acc = (float)x_acc * 0.016;
|
data.x_acc = (float)x_acc * 0.016;
|
||||||
data.y_acc = (float)y_acc * 0.016;
|
data.y_acc = (float)y_acc * 0.016;
|
||||||
data.z_acc = (float)z_acc * 0.016;
|
data.z_acc = (float)z_acc * 0.016;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIS3DH_POWER_NORMAL: /* 10 bit measurements */
|
case LIS3DH_POWER_NORMAL: /* 10 bit measurements */
|
||||||
x_acc = (int16_t)x_raw >> 6;
|
x_acc = (int16_t)x_raw >> 6;
|
||||||
y_acc = (int16_t)y_raw >> 6;
|
y_acc = (int16_t)y_raw >> 6;
|
||||||
@ -466,8 +462,8 @@ static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev)
|
|||||||
data.x_acc = (float)x_acc * 0.004;
|
data.x_acc = (float)x_acc * 0.004;
|
||||||
data.y_acc = (float)y_acc * 0.004;
|
data.y_acc = (float)y_acc * 0.004;
|
||||||
data.z_acc = (float)z_acc * 0.004;
|
data.z_acc = (float)z_acc * 0.004;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIS3DH_POWER_HIGH: /* 12 bit measurements */
|
case LIS3DH_POWER_HIGH: /* 12 bit measurements */
|
||||||
x_acc = (int16_t)x_raw >> 4;
|
x_acc = (int16_t)x_raw >> 4;
|
||||||
y_acc = (int16_t)y_raw >> 4;
|
y_acc = (int16_t)y_raw >> 4;
|
||||||
@ -476,8 +472,8 @@ static int lis3dh_read_fifo(FAR struct lis3dh_dev_s *dev)
|
|||||||
data.x_acc = (float)x_acc * 0.001;
|
data.x_acc = (float)x_acc * 0.001;
|
||||||
data.y_acc = (float)y_acc * 0.001;
|
data.y_acc = (float)y_acc * 0.001;
|
||||||
data.z_acc = (float)z_acc * 0.001;
|
data.z_acc = (float)z_acc * 0.001;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
snerr("Unknown power mode\n");
|
snerr("Unknown power mode\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -576,7 +572,7 @@ static int lis3dh_set_power_mode(FAR struct lis3dh_dev_s *dev,
|
|||||||
uint8_t ctrl1;
|
uint8_t ctrl1;
|
||||||
uint8_t ctrl4;
|
uint8_t ctrl4;
|
||||||
|
|
||||||
switch(power_mode)
|
switch (power_mode)
|
||||||
{
|
{
|
||||||
case LIS3DH_POWER_LOW:
|
case LIS3DH_POWER_LOW:
|
||||||
lis3dh_read_register(dev, LIS3DH_CTRL_REG1, &ctrl1);
|
lis3dh_read_register(dev, LIS3DH_CTRL_REG1, &ctrl1);
|
||||||
@ -588,6 +584,7 @@ static int lis3dh_set_power_mode(FAR struct lis3dh_dev_s *dev,
|
|||||||
lis3dh_write_register(dev, LIS3DH_CTRL_REG1, ctrl1);
|
lis3dh_write_register(dev, LIS3DH_CTRL_REG1, ctrl1);
|
||||||
lis3dh_write_register(dev, LIS3DH_CTRL_REG4, ctrl4);
|
lis3dh_write_register(dev, LIS3DH_CTRL_REG4, ctrl4);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIS3DH_POWER_NORMAL:
|
case LIS3DH_POWER_NORMAL:
|
||||||
lis3dh_read_register(dev, LIS3DH_CTRL_REG1, &ctrl1);
|
lis3dh_read_register(dev, LIS3DH_CTRL_REG1, &ctrl1);
|
||||||
lis3dh_read_register(dev, LIS3DH_CTRL_REG4, &ctrl4);
|
lis3dh_read_register(dev, LIS3DH_CTRL_REG4, &ctrl4);
|
||||||
@ -598,6 +595,7 @@ static int lis3dh_set_power_mode(FAR struct lis3dh_dev_s *dev,
|
|||||||
lis3dh_write_register(dev, LIS3DH_CTRL_REG1, ctrl1);
|
lis3dh_write_register(dev, LIS3DH_CTRL_REG1, ctrl1);
|
||||||
lis3dh_write_register(dev, LIS3DH_CTRL_REG4, ctrl4);
|
lis3dh_write_register(dev, LIS3DH_CTRL_REG4, ctrl4);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LIS3DH_POWER_HIGH:
|
case LIS3DH_POWER_HIGH:
|
||||||
lis3dh_read_register(dev, LIS3DH_CTRL_REG1, &ctrl1);
|
lis3dh_read_register(dev, LIS3DH_CTRL_REG1, &ctrl1);
|
||||||
lis3dh_read_register(dev, LIS3DH_CTRL_REG4, &ctrl4);
|
lis3dh_read_register(dev, LIS3DH_CTRL_REG4, &ctrl4);
|
||||||
@ -608,6 +606,7 @@ static int lis3dh_set_power_mode(FAR struct lis3dh_dev_s *dev,
|
|||||||
lis3dh_write_register(dev, LIS3DH_CTRL_REG1, ctrl1);
|
lis3dh_write_register(dev, LIS3DH_CTRL_REG1, ctrl1);
|
||||||
lis3dh_write_register(dev, LIS3DH_CTRL_REG4, ctrl4);
|
lis3dh_write_register(dev, LIS3DH_CTRL_REG4, ctrl4);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
break;
|
break;
|
||||||
@ -677,7 +676,7 @@ static int lis3dh_irq_enable(FAR struct lis3dh_dev_s *dev, bool enable)
|
|||||||
|
|
||||||
reg = 0;
|
reg = 0;
|
||||||
|
|
||||||
if(enable == true)
|
if (enable == true)
|
||||||
{
|
{
|
||||||
reg = LIS3DH_CTRL_REG3_I1_WTM;
|
reg = LIS3DH_CTRL_REG3_I1_WTM;
|
||||||
}
|
}
|
||||||
@ -705,7 +704,7 @@ static int lis3dh_fifo_enable(FAR struct lis3dh_dev_s *dev)
|
|||||||
{
|
{
|
||||||
uint8_t reg;
|
uint8_t reg;
|
||||||
lis3dh_write_register(dev, LIS3DH_FIFO_CTRL_REG,
|
lis3dh_write_register(dev, LIS3DH_FIFO_CTRL_REG,
|
||||||
LIS3DH_FIFO_CTRL_REG_MODE_STREAM | 28);
|
LIS3DH_FIFO_CTRL_REG_MODE_STREAM | 28);
|
||||||
|
|
||||||
lis3dh_read_register(dev, LIS3DH_CTRL_REG5, ®);
|
lis3dh_read_register(dev, LIS3DH_CTRL_REG5, ®);
|
||||||
reg |= LIS3DH_CTRL_REG5_FIFO_EN;
|
reg |= LIS3DH_CTRL_REG5_FIFO_EN;
|
||||||
@ -765,7 +764,7 @@ static int lis3dh_enable(FAR struct lis3dh_dev_s *priv)
|
|||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* -ENODEV - Device was not identified on the SPI bus.
|
* -ENODEV - Device was not identified on the SPI bus.
|
||||||
* OK - Sensor device was opened successfully.
|
* OK - Sensor device was opened successfully.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@ -779,7 +778,7 @@ static int lis3dh_open(FAR struct file *filep)
|
|||||||
/* Perform a reset */
|
/* Perform a reset */
|
||||||
|
|
||||||
lis3dh_reset(priv);
|
lis3dh_reset(priv);
|
||||||
if(lis3dh_ident(priv) < 0)
|
if (lis3dh_ident(priv) < 0)
|
||||||
{
|
{
|
||||||
snerr("ERROR: Failed to identify LIS3DH on SPI bus\n");
|
snerr("ERROR: Failed to identify LIS3DH on SPI bus\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -795,7 +794,7 @@ static int lis3dh_open(FAR struct file *filep)
|
|||||||
|
|
||||||
/* Enable measurements on the sensor */
|
/* Enable measurements on the sensor */
|
||||||
|
|
||||||
if(lis3dh_enable(priv) < 0)
|
if (lis3dh_enable(priv) < 0)
|
||||||
{
|
{
|
||||||
snerr("ERROR: Failed to enable LIS3DH\n");
|
snerr("ERROR: Failed to enable LIS3DH\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -891,6 +890,7 @@ static ssize_t lis3dh_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
|
|
||||||
data++;
|
data++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return count * sizeof(struct lis3dh_sensor_data_s);
|
return count * sizeof(struct lis3dh_sensor_data_s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,7 +901,7 @@ static ssize_t lis3dh_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
* Character device write call. Not supported.
|
* Character device write call. Not supported.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* filep - Pointer to struct file
|
* filep - Pointer to struct file
|
||||||
* buffer - Pointer to user buffer
|
* buffer - Pointer to user buffer
|
||||||
* buflen - Size of user buffer in bytes
|
* buflen - Size of user buffer in bytes
|
||||||
*
|
*
|
||||||
@ -924,12 +924,12 @@ static ssize_t lis3dh_write(FAR struct file *filep, FAR const char *buffer,
|
|||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* filep - Pointer to struct file
|
* filep - Pointer to struct file
|
||||||
* cmd - SNIOC_*
|
* cmd - SNIOC_*
|
||||||
* arg - ioctl specific argument
|
* arg - ioctl specific argument
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* OK - The command was executed successfully.
|
* OK - The command was executed successfully.
|
||||||
* -ENOTTY - The request command is not applicible to the driver.
|
* -ENOTTY - The request command is not applicable to the driver.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ extern "C"
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int lis3dh_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
|
int lis3dh_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
|
||||||
FAR struct lis3dh_config_s *);
|
FAR struct lis3dh_config_s *);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
Reference in New Issue
Block a user