Cosmetic changes from review of the last PR
This commit is contained in:
parent
147a99a9cc
commit
6e32d74b33
@ -386,7 +386,6 @@ int board_app_initialize(uintptr_t arg)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to initialize l3gd20 sensor: %d\n", ret);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
|
@ -1,7 +1,8 @@
|
||||
/****************************************************************************
|
||||
* configs/stm32f429i-disco/src/stm32_l3gd20.c
|
||||
*
|
||||
* Authors: Mateusz Szafoni <raiden00@railab.me>
|
||||
* Copyright (C) Gregory Nutt. All rights reserved.
|
||||
* Author: Mateusz Szafoni <raiden00@railab.me>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -30,7 +31,6 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
@ -68,11 +68,11 @@ static int l3gd20_attach(FAR struct l3gd20_config_s * cfg, xcpt_t irq);
|
||||
/* Only one L3GD20 device on board */
|
||||
|
||||
static struct l3gd20_config_s g_l3gd20_config =
|
||||
{
|
||||
.attach = l3gd20_attach,
|
||||
.irq = L3GD20_IRQ,
|
||||
.spi_devid = SPIDEV_ACCELEROMETER
|
||||
};
|
||||
{
|
||||
.attach = l3gd20_attach,
|
||||
.irq = L3GD20_IRQ,
|
||||
.spi_devid = SPIDEV_ACCELEROMETER
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
@ -137,7 +137,7 @@ int stm32_l3gd20initialize(FAR const char *devpath)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
errout:
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -114,10 +114,10 @@
|
||||
#define GPIO_CS_SST25 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
|
||||
GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN4)
|
||||
|
||||
/* L3GD20 MEMS*/
|
||||
/* L3GD20 MEMS */
|
||||
|
||||
#define GPIO_L3GD20_DREADY (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTA|GPIO_PIN2)
|
||||
#define L3GD20_IRQ (2 + STM32_IRQ_EXTI0)
|
||||
#define L3GD20_IRQ (2 + STM32_IRQ_EXTI0)
|
||||
|
||||
/* USB OTG HS
|
||||
*
|
||||
@ -235,7 +235,6 @@ void stm32_ledpminitialize(void);
|
||||
void stm32_pmbuttons(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32F429I_DISCO_ILI9341
|
||||
/****************************************************************************
|
||||
* Name: stm32_ili93414ws_initialize
|
||||
*
|
||||
@ -251,10 +250,10 @@ void stm32_pmbuttons(void);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32F429I_DISCO_ILI9341
|
||||
FAR struct ili9341_lcd_s *stm32_ili93414ws_initialize(void);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32_SPI5
|
||||
/****************************************************************************
|
||||
* Name: stm32_spi5initialize
|
||||
*
|
||||
@ -277,11 +276,11 @@ FAR struct ili9341_lcd_s *stm32_ili93414ws_initialize(void);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_STM32_SPI5
|
||||
FAR struct spi_dev_s *stm32_spi5initialize(void);
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(CONFIG_SPI) & defined(CONFIG_SENSORS_L3GD20)
|
||||
/****************************************************************************
|
||||
* Name: stm32_l3gd20initialize()
|
||||
*
|
||||
@ -296,6 +295,7 @@ FAR struct spi_dev_s *stm32_spi5initialize(void);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_SPI) & defined(CONFIG_SENSORS_L3GD20)
|
||||
int stm32_l3gd20initialize(FAR const char *devpath);
|
||||
#endif
|
||||
|
||||
|
@ -2,8 +2,10 @@
|
||||
* drivers/sensors/l3gd20.c
|
||||
* Character driver for the ST L3GD20 3-Axis gyroscope.
|
||||
*
|
||||
* Authors: Mateusz Szafoni <raiden00@railab.me>
|
||||
* based on drivers/sensors/lis3dsh.c
|
||||
* Copyright (C) Gregory Nutt. All rights reserved.
|
||||
* Author: Mateusz Szafoni <raiden00@railab.me>
|
||||
*
|
||||
* Based on drivers/sensors/lis3dsh.c
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -54,14 +56,14 @@
|
||||
|
||||
#if defined(CONFIG_SPI) && defined(CONFIG_SENSORS_L3GD20)
|
||||
|
||||
#if !defined(CONFIG_SCHED_HPWORK)
|
||||
# error Hi-priority work queue support is required (CONFIG_SCHED_HPWORK)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_SCHED_HPWORK)
|
||||
# error Hi-priority work queue support is required (CONFIG_SCHED_HPWORK)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@ -87,15 +89,15 @@ struct l3gd20_dev_s
|
||||
****************************************************************************/
|
||||
|
||||
static void l3gd20_read_register(FAR struct l3gd20_dev_s *dev,
|
||||
uint8_t const reg_addr, uint8_t * reg_data);
|
||||
uint8_t const reg_addr, uint8_t *reg_data);
|
||||
static void l3gd20_write_register(FAR struct l3gd20_dev_s *dev,
|
||||
uint8_t const reg_addr,
|
||||
uint8_t const reg_data);
|
||||
static void l3gd20_reset(FAR struct l3gd20_dev_s *dev);
|
||||
static void l3gd20_read_measurement_data(FAR struct l3gd20_dev_s *dev);
|
||||
static void l3gd20_read_gyroscope_data(FAR struct l3gd20_dev_s *dev,
|
||||
uint16_t * x_gyr, uint16_t * y_gyr,
|
||||
uint16_t * z_gyr);
|
||||
uint16_t *x_gyr, uint16_t *y_gyr,
|
||||
uint16_t *z_gyr);
|
||||
static void l3gd20_read_temperature(FAR struct l3gd20_dev_s *dev,
|
||||
uint8_t * temperature);
|
||||
static int l3gd20_interrupt_handler(int irq, FAR void *context);
|
||||
@ -103,7 +105,8 @@ static void l3gd20_worker(FAR void *arg);
|
||||
|
||||
static int l3gd20_open(FAR struct file *filep);
|
||||
static int l3gd20_close(FAR struct file *filep);
|
||||
static ssize_t l3gd20_read(FAR struct file *, FAR char *, size_t);
|
||||
static ssize_t l3gd20_read(FAR struct file *filep, FAR char *buffer,
|
||||
size_t buflen);
|
||||
static ssize_t l3gd20_write(FAR struct file *filep, FAR const char *buffer,
|
||||
size_t buflen);
|
||||
static int l3gd20_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
||||
@ -113,20 +116,20 @@ static int l3gd20_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
||||
****************************************************************************/
|
||||
|
||||
static const struct file_operations g_l3gd20_fops =
|
||||
{
|
||||
l3gd20_open,
|
||||
l3gd20_close,
|
||||
l3gd20_read,
|
||||
l3gd20_write,
|
||||
NULL,
|
||||
l3gd20_ioctl
|
||||
{
|
||||
l3gd20_open,
|
||||
l3gd20_close,
|
||||
l3gd20_read,
|
||||
l3gd20_write,
|
||||
NULL,
|
||||
l3gd20_ioctl
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
, NULL
|
||||
, NULL
|
||||
#endif
|
||||
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
||||
, NULL
|
||||
, NULL
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
/* Single linked list to store instances of drivers */
|
||||
|
||||
@ -141,7 +144,7 @@ static struct l3gd20_dev_s *g_l3gd20_list = NULL;
|
||||
****************************************************************************/
|
||||
|
||||
static void l3gd20_read_register(FAR struct l3gd20_dev_s *dev,
|
||||
uint8_t const reg_addr, uint8_t * reg_data)
|
||||
uint8_t const reg_addr, uint8_t *reg_data)
|
||||
{
|
||||
/* Lock the SPI bus so that only one device can access it at the same time */
|
||||
|
||||
@ -206,6 +209,7 @@ static void l3gd20_write_register(FAR struct l3gd20_dev_s *dev,
|
||||
/****************************************************************************
|
||||
* Name: l3gd20_reset
|
||||
****************************************************************************/
|
||||
|
||||
static void l3gd20_reset(FAR struct l3gd20_dev_s *dev)
|
||||
{
|
||||
/* Reboot memory content */
|
||||
@ -221,9 +225,11 @@ static void l3gd20_reset(FAR struct l3gd20_dev_s *dev)
|
||||
|
||||
static void l3gd20_read_measurement_data(FAR struct l3gd20_dev_s *dev)
|
||||
{
|
||||
int ret;
|
||||
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;
|
||||
uint8_t temperature = 0;
|
||||
int ret;
|
||||
|
||||
/* Read Gyroscope */
|
||||
|
||||
@ -253,7 +259,6 @@ static void l3gd20_read_measurement_data(FAR struct l3gd20_dev_s *dev)
|
||||
sem_post(&dev->datasem);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: l3gd20_read_gyroscope_data
|
||||
****************************************************************************/
|
||||
@ -296,10 +301,10 @@ static void l3gd20_read_gyroscope_data(FAR struct l3gd20_dev_s *dev,
|
||||
SPI_LOCK(dev->spi, false);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: l3gd20_read_temperature
|
||||
****************************************************************************/
|
||||
|
||||
static void l3gd20_read_temperature(FAR struct l3gd20_dev_s* dev,
|
||||
uint8_t* temperature)
|
||||
{
|
||||
@ -390,7 +395,6 @@ static int l3gd20_open(FAR struct file *filep)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct l3gd20_dev_s *priv = inode->i_private;
|
||||
|
||||
#ifdef CONFIG_DEBUG_SENSORS_INFO
|
||||
uint8_t reg_content;
|
||||
uint8_t reg_addr;
|
||||
@ -457,7 +461,6 @@ static int l3gd20_open(FAR struct file *filep)
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: l3gd20_close
|
||||
****************************************************************************/
|
||||
@ -472,7 +475,6 @@ static int l3gd20_close(FAR struct file *filep)
|
||||
/* Perform a reset */
|
||||
|
||||
l3gd20_reset(priv);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -498,7 +500,7 @@ static ssize_t l3gd20_read(FAR struct file *filep, FAR char *buffer,
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/* Aquire the semaphore before the data is copied */
|
||||
/* Acquire the semaphore before the data is copied */
|
||||
|
||||
ret = sem_wait(&priv->datasem);
|
||||
if (ret < 0)
|
||||
@ -525,7 +527,6 @@ static ssize_t l3gd20_read(FAR struct file *filep, FAR char *buffer,
|
||||
return sizeof(FAR struct l3gd20_sensor_data_s);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: l3gd20_write
|
||||
****************************************************************************/
|
||||
@ -600,13 +601,13 @@ int l3gd20_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
|
||||
goto errout;
|
||||
}
|
||||
|
||||
priv->spi = spi;
|
||||
priv->config = config;
|
||||
priv->work.worker = NULL;
|
||||
priv->spi = spi;
|
||||
priv->config = config;
|
||||
priv->work.worker = NULL;
|
||||
|
||||
priv->data.x_gyr = 0;
|
||||
priv->data.y_gyr = 0;
|
||||
priv->data.z_gyr = 0;
|
||||
priv->data.x_gyr = 0;
|
||||
priv->data.y_gyr = 0;
|
||||
priv->data.z_gyr = 0;
|
||||
priv->data.temperature = 0;
|
||||
|
||||
/* Initialize sensor data access semaphore */
|
||||
@ -642,10 +643,10 @@ int l3gd20_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
|
||||
* instance to a list of device instances so that it can be found by the
|
||||
* interrupt handler based on the received IRQ number. */
|
||||
|
||||
priv->flink = g_l3gd20_list;
|
||||
priv->flink = g_l3gd20_list;
|
||||
g_l3gd20_list = priv;
|
||||
|
||||
errout:
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
/****************************************************************************
|
||||
* drivers/sensors/l3gd20.c
|
||||
* include/nuttx/sensors/l3gd20.h
|
||||
*
|
||||
* Authors: Mateusz Szafoni <raiden00@railab.me>
|
||||
* Copyright (C) Gregory Nutt. All rights reserved.
|
||||
* Author: Mateusz Szafoni <raiden00@railab.me>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -85,23 +86,22 @@
|
||||
#define L3GD20_INT_GEN_THS_Z_L_REG 0x37 /* Gyroscope yaw (Z) interrupt threshold low byte */
|
||||
#define L3GD20_INT_GEN_DUR_REG 0x38 /* Gyroscope interrupt duration */
|
||||
|
||||
|
||||
/* Register Bit Definitions *************************************************/
|
||||
|
||||
/* Device identification register */
|
||||
|
||||
#define L3GD20_WHO_AM_I_VALUE 0xD4
|
||||
#define L3GD20_WHO_AM_I_VALUE 0xD4
|
||||
|
||||
/* Gyroscope control register 1 */
|
||||
|
||||
#define L3GD20_CTRL_REG_1_X_EN_bm (1 << 0)
|
||||
#define L3GD20_CTRL_REG_1_Y_EN_bm (1 << 1)
|
||||
#define L3GD20_CTRL_REG_1_Z_EN_bm (1 << 2)
|
||||
#define L3GD20_CTRL_REG_1_POWERDOWN_bm (1 << 3)
|
||||
#define L3GD20_CTRL_REG_1_BW_0_bm (1 << 4)
|
||||
#define L3GD20_CTRL_REG_1_BW_1_bm (1 << 5)
|
||||
#define L3GD20_CTRL_REG_1_DR_0_bm (1 << 6)
|
||||
#define L3GD20_CTRL_REG_1_DR_1_bm (1 << 7)
|
||||
#define L3GD20_CTRL_REG_1_X_EN_bm (1 << 0)
|
||||
#define L3GD20_CTRL_REG_1_Y_EN_bm (1 << 1)
|
||||
#define L3GD20_CTRL_REG_1_Z_EN_bm (1 << 2)
|
||||
#define L3GD20_CTRL_REG_1_POWERDOWN_bm (1 << 3)
|
||||
#define L3GD20_CTRL_REG_1_BW_0_bm (1 << 4)
|
||||
#define L3GD20_CTRL_REG_1_BW_1_bm (1 << 5)
|
||||
#define L3GD20_CTRL_REG_1_DR_0_bm (1 << 6)
|
||||
#define L3GD20_CTRL_REG_1_DR_1_bm (1 << 7)
|
||||
|
||||
/* Gyroscope control register 2 */
|
||||
|
||||
@ -177,14 +177,14 @@
|
||||
|
||||
/* FIFO status control register */
|
||||
|
||||
#define L3GD20_FIFO_SRC_FSS_0_bm (1 << 0)
|
||||
#define L3GD20_FIFO_SRC_FSS_1_bm (1 << 1)
|
||||
#define L3GD20_FIFO_SRC_FSS_2_bm (1 << 2)
|
||||
#define L3GD20_FIFO_SRC_FSS_3_bm (1 << 3)
|
||||
#define L3GD20_FIFO_SRC_FSS_4_bm (1 << 4)
|
||||
#define L3GD20_FIFO_SRC_EMPTY_bm (1 << 5)
|
||||
#define L3GD20_FIFO_SRC_OVRUN_bm (1 << 6)
|
||||
#define L3GD20_FIFO_SRC_WTM_bm (1 << 7)
|
||||
#define L3GD20_FIFO_SRC_FSS_0_bm (1 << 0)
|
||||
#define L3GD20_FIFO_SRC_FSS_1_bm (1 << 1)
|
||||
#define L3GD20_FIFO_SRC_FSS_2_bm (1 << 2)
|
||||
#define L3GD20_FIFO_SRC_FSS_3_bm (1 << 3)
|
||||
#define L3GD20_FIFO_SRC_FSS_4_bm (1 << 4)
|
||||
#define L3GD20_FIFO_SRC_EMPTY_bm (1 << 5)
|
||||
#define L3GD20_FIFO_SRC_OVRUN_bm (1 << 6)
|
||||
#define L3GD20_FIFO_SRC_WTM_bm (1 << 7)
|
||||
|
||||
/* Gyroscope interrupt configuration */
|
||||
|
||||
@ -200,14 +200,14 @@
|
||||
|
||||
/* Gyroscope interrupt source */
|
||||
|
||||
#define L3GD20_INT_GEN_SRC_X_L_bm (1 << 0)
|
||||
#define L3GD20_INT_GEN_SRC_X_H_bm (1 << 1)
|
||||
#define L3GD20_INT_GEN_SRC_Y_L_bm (1 << 2)
|
||||
#define L3GD20_INT_GEN_SRC_Y_H_bm (1 << 3)
|
||||
#define L3GD20_INT_GEN_SRC_Z_L_bm (1 << 4)
|
||||
#define L3GD20_INT_GEN_SRC_Z_H_bm (1 << 5)
|
||||
#define L3GD20_INT_GEN_SRC_I_A_bm (1 << 6)
|
||||
#define L3GD20_INT_GEN_SRC_RES7_ (1 << 7)
|
||||
#define L3GD20_INT_GEN_SRC_X_L_bm (1 << 0)
|
||||
#define L3GD20_INT_GEN_SRC_X_H_bm (1 << 1)
|
||||
#define L3GD20_INT_GEN_SRC_Y_L_bm (1 << 2)
|
||||
#define L3GD20_INT_GEN_SRC_Y_H_bm (1 << 3)
|
||||
#define L3GD20_INT_GEN_SRC_Z_L_bm (1 << 4)
|
||||
#define L3GD20_INT_GEN_SRC_Z_H_bm (1 << 5)
|
||||
#define L3GD20_INT_GEN_SRC_I_A_bm (1 << 6)
|
||||
#define L3GD20_INT_GEN_SRC_RES7_ (1 << 7)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
@ -253,7 +253,6 @@ struct l3gd20_sensor_data_s
|
||||
int8_t temperature; /* Measurement result for temperature sensor */
|
||||
};
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
@ -266,7 +265,6 @@ extern "C"
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: l3gd20_register
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user