drivers/adxl345: fixes & cleanup
Signed-off-by: dylad <dylan.laduranty@mesotic.com>
This commit is contained in:
parent
ccb5653f8a
commit
d114e2852c
@ -29,8 +29,8 @@
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
#define BUS (dev->i2c)
|
||||
#define ADDR (dev->addr)
|
||||
#define BUS (dev->params->i2c)
|
||||
#define ADDR (dev->params->addr)
|
||||
|
||||
int adxl345_init(adxl345_t *dev, const adxl345_params_t* params)
|
||||
{
|
||||
|
||||
@ -57,7 +57,9 @@ extern "C" {
|
||||
#define ADXL345_PARAM_SCALE_FACTOR (3.9)
|
||||
#endif
|
||||
#ifndef ADXL345_PARAMS
|
||||
#define ADXL345_PARAMS { .offset = ADXL345_PARAM_OFFSET, \
|
||||
#define ADXL345_PARAMS { .i2c = ADXL345_PARAM_I2C, \
|
||||
.addr = ADXL345_PARAM_ADDR, \
|
||||
.offset = ADXL345_PARAM_OFFSET, \
|
||||
.range = ADXL345_PARAM_RANGE, \
|
||||
.rate = ADXL345_PARAM_RATE, \
|
||||
.full_res = ADXL345_PARAM_FULL_RES }
|
||||
|
||||
@ -40,20 +40,20 @@ enum {
|
||||
* @brief List ADXL345 power mode
|
||||
*/
|
||||
enum {
|
||||
ADXL345_MEASURE_MODE,
|
||||
ADXL345_STANDBY_MODE,
|
||||
ADXL345_SLEEP_MODE,
|
||||
ADXL345_AUTOSLEEP_MODE,
|
||||
ADXL345_MEASURE_MODE, /**< Measure mode */
|
||||
ADXL345_STANDBY_MODE, /**< Standby mode */
|
||||
ADXL345_SLEEP_MODE, /**< Sleep mode */
|
||||
ADXL345_AUTOSLEEP_MODE, /**< Autosleep mode */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Define ADXL345 sensitivity
|
||||
*/
|
||||
enum {
|
||||
ADXL345_RANGE_2G = 1, /**< +/- 2 g Full Scale Rang */
|
||||
ADXL345_RANGE_4G = 2, /**< +/- 4 g Full Scale Rang */
|
||||
ADXL345_RANGE_8G = 4, /**< +/- 8 g Full Scale Rang */
|
||||
ADXL345_RANGE_16G = 8 /**< +/- 16 g Full Scale Rang */
|
||||
ADXL345_RANGE_2G = 1, /**< +/- 2 g Full Scale Range */
|
||||
ADXL345_RANGE_4G = 2, /**< +/- 4 g Full Scale Range */
|
||||
ADXL345_RANGE_8G = 4, /**< +/- 8 g Full Scale Range */
|
||||
ADXL345_RANGE_16G = 8 /**< +/- 16 g Full Scale Range */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -140,6 +140,8 @@ typedef struct {
|
||||
* @brief Configuration struct for the ADXL345 sensor
|
||||
*/
|
||||
typedef struct {
|
||||
i2c_t i2c; /**< I2C device which is used */
|
||||
uint8_t addr; /**< I2C address */
|
||||
gpio_t int1; /**< accelerometer int1 pin */
|
||||
gpio_t int2; /**< accelerometer int2 pin */
|
||||
uint8_t offset[3]; /**< offset axis */
|
||||
@ -152,8 +154,6 @@ typedef struct {
|
||||
* @brief Device descriptor for the ADXL345 sensor
|
||||
*/
|
||||
typedef struct {
|
||||
i2c_t i2c; /**< I2C device which is used */
|
||||
uint8_t addr; /**< I2C address */
|
||||
adxl345_params_t *params; /**< Device configuration */
|
||||
adxl345_interrupt_t interrupt; /**< Interrupts configuration */
|
||||
float scale_factor; /**< Scale factor for converting value to mg */
|
||||
|
||||
@ -31,14 +31,11 @@ int main(void)
|
||||
adxl345_t dev;
|
||||
adxl345_data_t data;
|
||||
|
||||
dev.i2c = ADXL345_PARAM_I2C;
|
||||
dev.addr = ADXL345_PARAM_ADDR;
|
||||
|
||||
puts("ADXL345 test application");
|
||||
printf("Initializing ADXL345 accelerometer at I2C_DEV(%i)... ",
|
||||
dev.i2c);
|
||||
adxl345_params[0].i2c);
|
||||
|
||||
if (adxl345_init(&dev, (adxl345_params_t*)adxl345_params) == ADXL345_OK) {
|
||||
if (adxl345_init(&dev, &adxl345_params[0]) == ADXL345_OK) {
|
||||
puts("[OK]\n");
|
||||
}
|
||||
else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user