Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new driver for the lis2de12 accelerometer #20162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions drivers/include/lis2de12.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Copyright (C) 2023 LIG
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup drivers_lis2de12 lis2de12
* @ingroup drivers_sensors
* @brief driver for the lis2de12 accelerometer
*
* @{
*
* @file
*
* @author Léo <[email protected]>
*/

#ifndef LIS2DE12_H
#define LIS2DE12_H

/* Add header includes here */
#include "periph/i2c.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Declare the API of the driver */

/**
* @brief Available scale values
*/
typedef enum {
LIS2DE12_SCALE_2G = 0x0, /**< +- 2g */
LIS2DE12_SCALE_4G = 0x1, /**< +- 4g */
LIS2DE12_SCALE_8G = 0x2, /**< +- 8g */
LIS2DE12_SCALE_16G = 0x3, /**< +- 16g */
} lis2de12_scale_t;

/**
* @brief Available sampling rates
*
*/
typedef enum {
LIS2DE12_RATE_1HZ = 0x1, /**< sample with 1Hz @ all resolutions */
LIS2DE12_RATE_10HZ = 0x2, /**< sample with 10Hz @ all resolutions */
LIS2DE12_RATE_25HZ = 0x3, /**< sample with 25Hz @ all resolutions */
LIS2DE12_RATE_50HZ = 0x4, /**< sample with 50Hz @ all resolutions */
LIS2DE12_RATE_100HZ = 0x5, /**< sample with 100Hz @ all resolutions */
LIS2DE12_RATE_200HZ = 0x6, /**< sample with 200Hz @ all resolutions */
LIS2DE12_RATE_400HZ = 0x7, /**< sample with 400Hz @ all resolutions */
LIS2DE12_RATE_1620HZ = 0x8, /**< sample with 1620HZ @ 8-bit */
LIS2DE12_RATE_VERYHIGH = 0x9, /**< sample with 1344Hz @ High resolution or \
5376Hz @ 8-bit */
} lis2de12_rate_t;

/**
* @brief Device initialization parameters
*/
typedef struct {
/* add initialization params here */
i2c_t i2c; /**< I2C bus the device is connected to */
uint8_t addr; /**< device address on the I2C bus */
} lis2de12_params_t;

/**
* @brief LIS2DE12 FIFO data struct
*/
typedef union {
struct {
int16_t x; /**< X data in mili-g */
int16_t y; /**< Y data in mili-g */
int16_t z; /**< Z data in mili-g */
} axis; /**< named axis access */
int16_t data[3]; /**< x, y, z data in mili-g */
} lis2de12_fifo_data_t;

/**
* @brief LIS2DE12 FIFO modes
*/
typedef enum {
LIS2DE12_FIFO_MODE_BYPASS = 0, /**< default mode, FIFO is bypassed */
LIS2DE12_FIFO_MODE_FIFOMODE, /**< normal FIFO mode, stops if FIFO is full */
LIS2DE12_FIFO_MODE_STREAM, /**< Stream mode, oldest values get overwritten */
LIS2DE12_FIFO_MODE_STREAMtoFIFO, /**< Stream mode and on interrupt jumps to FIFO mode */
} lis2de12_fifo_mode_t;

/**
* @brief LIS2DE12 FIFO config values
*/
typedef struct {
lis2de12_fifo_mode_t FIFO_mode; /**< set FIFO mode */
uint8_t FIFO_watermark:5; /**< set the FIFO watermark level */
bool FIFO_set_INT2; /**< sets the FIFO interrupt to INT2, otherwise INT1 */
} lis2de12_fifo_t;


Check warning on line 100 in drivers/include/lis2de12.h

View workflow job for this annotation

GitHub Actions / static-tests

too many consecutive empty lines
/**
* @brief Device descriptor for the driver
*/
typedef struct {
/** Device initialization parameters */
lis2de12_scale_t scale; /**< sampling sensitivity used */
lis2de12_rate_t rate; /**< sampling rate used */

const lis2de12_params_t *params;

Check failure on line 109 in drivers/include/lis2de12.h

View workflow job for this annotation

GitHub Actions / static-tests

Member params (variable) of struct lis2de12_t is not documented.
} lis2de12_t;

/**
* @brief Status and error return codes
*/
enum {
LIS2DE12_OK = 0, /**< everything was fine */
LIS2DE12_NOBUS = -1, /**< bus interface error */
LIS2DE12_NODEV = -2, /**< unable to talk to device */
LIS2DE12_NOINT = -3, /**< wrong interrupt line (has to be LIS2DE12_INT1
or LIS2DE12_INT2) */
LIS2DE12_NODATA= -4, /**< no data available */
};

/**
* @brief Initialize the given device
*
* @param[inout] dev Device descriptor of the driver
* @param[in] params Initialization parameters
*
* @return 0 on success
*/
int lis2de12_init(lis2de12_t *dev, const lis2de12_params_t *params);

/**
* @brief Read acceleration data from the given device
*
* @param[in] dev device descriptor
* @param[out] data acceleration data in mili-g
*
* @return LIS2DE12_OK on success
* @return LIS2DE12_NOBUS on bus error
*/
int lis2de12_read(const lis2de12_t *dev, lis2de12_fifo_data_t *data);


Check warning on line 145 in drivers/include/lis2de12.h

View workflow job for this annotation

GitHub Actions / static-tests

too many consecutive empty lines
int lis2de12_clear_data(const lis2de12_t *dev);

Check failure on line 146 in drivers/include/lis2de12.h

View workflow job for this annotation

GitHub Actions / static-tests

Member lis2de12_clear_data(const lis2de12_t *dev) (function) of group drivers_lis2de12 is not documented.

int lis2de12_set_datarate(const lis2de12_t *dev, lis2de12_rate_t rate);

Check failure on line 148 in drivers/include/lis2de12.h

View workflow job for this annotation

GitHub Actions / static-tests

Member lis2de12_set_datarate(const lis2de12_t *dev, lis2de12_rate_t rate) (function) of group drivers_lis2de12 is not documented.
uint16_t lis2de12_get_datarate(const lis2de12_t *dev);

Check failure on line 149 in drivers/include/lis2de12.h

View workflow job for this annotation

GitHub Actions / static-tests

Member lis2de12_get_datarate(const lis2de12_t *dev) (function) of group drivers_lis2de12 is not documented.

int lis2de12_set_scale(lis2de12_t *dev, lis2de12_scale_t scale);

Check failure on line 151 in drivers/include/lis2de12.h

View workflow job for this annotation

GitHub Actions / static-tests

Member lis2de12_set_scale(lis2de12_t *dev, lis2de12_scale_t scale) (function) of group drivers_lis2de12 is not documented.
lis2de12_scale_t lis2de12_get_scale(lis2de12_t *dev);

Check failure on line 152 in drivers/include/lis2de12.h

View workflow job for this annotation

GitHub Actions / static-tests

Member lis2de12_get_scale(lis2de12_t *dev) (function) of group drivers_lis2de12 is not documented.

int lis2de12_set_fifo(const lis2de12_t *dev, const lis2de12_fifo_t *config);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are never doing anything with the fifo, you only read the first element with lis2de12_read()


/**
* @brief Read temperature data from the given device
*
* @note The temperature sensor is not calibrated.
* Temperature values are only relative to a device specific
* reference.
*
* @param[in] dev device descriptor
* @param[out] temp temperature data in centi-°C
*
* @return LIS2DE12_OK on success
* @return LIS2DE12_NOBUS on bus error
*/
int lis2de12_read_temperature(const lis2de12_t *dev, int16_t *temp);

#ifdef __cplusplus
}
#endif

#endif /* LIS2DE12_H */
/** @} */
11 changes: 11 additions & 0 deletions drivers/lis2de12/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2023 LIG
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.

config MODULE_LIS2DE12
bool "lis2de12"
depends on TEST_KCONFIG
depends on HAS_PERIPH_I2C
select MODULE_PERIPH_I2C
1 change: 1 addition & 0 deletions drivers/lis2de12/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(RIOTBASE)/Makefile.base
1 change: 1 addition & 0 deletions drivers/lis2de12/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FEATURES_REQUIRED += periph_i2c
2 changes: 2 additions & 0 deletions drivers/lis2de12/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
USEMODULE_INCLUDES_lis2de12 := $(LAST_MAKEFILEDIR)/include
USEMODULE_INCLUDES += $(USEMODULE_INCLUDES_lis2de12)
38 changes: 38 additions & 0 deletions drivers/lis2de12/include/lis2de12_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2023 LIG
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_lis2de12
* @{
*
* @file
* @brief Internal addresses, registers and constants
*
* @author Léo <[email protected]>
*/

#ifndef LIS2DE12_CONSTANTS_H
#define LIS2DE12_CONSTANTS_H

#ifdef __cplusplus
extern "C" {
#endif

/* define here the addresses, register and constants of the driver */
#define LIS2DE12_I2C_ADDRESS (0x19)
#define LIS2DE12_I2C_DEV I2C_DEV(0)


Check warning on line 30 in drivers/lis2de12/include/lis2de12_constants.h

View workflow job for this annotation

GitHub Actions / static-tests

too many consecutive empty lines


#ifdef __cplusplus
}
#endif

#endif /* LIS2DE12_CONSTANTS_H */
/** @} */
70 changes: 70 additions & 0 deletions drivers/lis2de12/include/lis2de12_params.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2023 LIG
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup drivers_lis2de12
*
* @{
* @file
* @brief Default configuration
*
* @author Léo <[email protected]>
*/

#ifndef LIS2DE12_PARAMS_H
#define LIS2DE12_PARAMS_H

#include "board.h"
#include "lis2de12.h"
#include "lis2de12_constants.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name Set default configuration parameters
* @{
*/
#ifndef LIS2DE12_PARAM_I2C
#define LIS2DE12_PARAM_I2C LIS2DE12_I2C_DEV
#endif

#ifndef LIS2DE12_PARAM_ADDR
#define LIS2DE12_PARAM_ADDR LIS2DE12_I2C_ADDRESS
#endif

#ifndef LIS2DE12_PARAMS
#define LIS2DE12_PARAMS { \
.i2c = LIS2DE12_PARAM_I2C, \
.addr = LIS2DE12_PARAM_ADDR \
}
#endif

#ifndef LIS2DE12_PARAM_SCALE
#define LIS2DE12_PARAM_SCALE LIS2DE12_SCALE_2G
#endif
#ifndef LIS2DE12_PARAM_RATE
#define LIS2DE12_PARAM_RATE LIS2DE12_RATE_100HZ
#endif
/**@}*/

/**
* @brief Configuration struct
*/
static const lis2de12_params_t lis2de12_params[] =
{
LIS2DE12_PARAMS
};

#ifdef __cplusplus
}
#endif

#endif /* LIS2DE12_PARAMS_H */
/** @} */
Loading
Loading