-
Notifications
You must be signed in to change notification settings - Fork 0
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
LSM6DSOX - Get Configuration #10
Changes from 2 commits
fc8edca
016c3cc
3cbe9ef
1ec5825
34c9ea8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MBED_OS_DIR=./lib/mbed-os | ||
TARGET=disco_f769ni | ||
TOOLCHAIN=GCC_ARM | ||
ROOT=. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
### Ignored directories to speed up compilation time | ||
|
||
test/** | ||
lib/mbed-os/components/** | ||
lib/mbed-os/features/cellular/** | ||
lib/mbed-os/features/cryptocell/** | ||
lib/mbed-os/features/deprecated_warnings/** | ||
|
||
lib/mbed-os/features/FEATURE_BLE/** | ||
lib/mbed-os/features/FEATURE_BOOTLOADER/** | ||
|
||
lib/mbed-os/features/lorawan/** | ||
lib/mbed-os/features/lwipstack/** | ||
|
||
lib/mbed-os/features/nanostack/** | ||
lib/mbed-os/features/netsocket/** | ||
lib/mbed-os/features/nfc/** | ||
lib/mbed-os/features/unsupported/** | ||
|
||
### Needed directories | ||
|
||
# lib/mbed-os/features/device_key/** | ||
# lib/mbed-os/features/frameworks/** | ||
# lib/mbed-os/features/mbedtls/** |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# LKExp - LSM6DSOX Examples | ||
|
||
## Goal | ||
|
||
Create an abstraction class of lsm6dsox driver for Leka applications. | ||
Construction relies on examples provided by ST. | ||
|
||
## Ressources | ||
[STMems\_Standard\_C\_drivers](https://github.com/STMicroelectronics/STMems_Standard_C_drivers) for: | ||
|
||
* [Driver](https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lsm6dsox_STdC/driver) -> commit `3fca83f875bbcbb6a428a7deb0ff01c0e5a2b033` (30 April 2020) | ||
* [Examples](https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lsm6dsox_STdC/example) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
****************************************************************************** | ||
* @file accelerometer.h | ||
* @author Yann Locatelli | ||
* @brief Implement accelerometer of LSM6DSOX for Leka. | ||
****************************************************************************** | ||
*/ | ||
|
||
/* Includes ------------------------------------------------------------------*/ | ||
|
||
#include "accelerometer.h" | ||
|
||
/* Class Implementation ------------------------------------------------------*/ | ||
|
||
/** Constructor | ||
* @param i2c object which handles the I2C peripheral | ||
* @param address the address of the component | ||
*/ | ||
Accelerometer::Accelerometer(I2C *i2c, uint8_t address) : _i2c(i2c), _address(address) | ||
{ | ||
assert (i2c); | ||
|
||
_reg_ctx.write_reg = LSM6DSOX_acc_io_write; | ||
_reg_ctx.read_reg = LSM6DSOX_acc_io_read; | ||
_reg_ctx.handle = (void *)this; | ||
} | ||
|
||
/** | ||
* @brief Initializing the component | ||
* @param init pointer to device specific initalization structure | ||
* @retval 0 in case of success, an error code otherwise | ||
*/ | ||
LSM6DSOXAccStatusTypeDef Accelerometer::init(void *init) | ||
{ | ||
///* Output data rate selection - power down. */ | ||
//if (lsm6dsox_xl_data_rate_set(&_reg_ctx, LSM6DSOX_XL_ODR_OFF) != LSM6DSOX_OK) | ||
//{ | ||
// return LSM6DSOX_ERROR; | ||
//} | ||
|
||
///* Full scale selection. */ | ||
//if (lsm6dsox_xl_full_scale_set(&_reg_ctx, LSM6DSOX_2g) != LSM6DSOX_OK) | ||
//{ | ||
// return LSM6DSOX_ERROR; | ||
//} | ||
|
||
return LSM6DSOX_Acc_OK; | ||
} | ||
|
||
/** | ||
* @brief Read component ID | ||
* @param id the WHO_AM_I value | ||
* @retval 0 in case of success, an error code otherwise | ||
*/ | ||
LSM6DSOXAccStatusTypeDef Accelerometer::read_id(uint8_t *id) | ||
{ | ||
if (lsm6dsox_device_id_get(&_reg_ctx, id) != LSM6DSOX_Acc_OK) | ||
{ | ||
return LSM6DSOX_Acc_ERROR; | ||
} | ||
|
||
return LSM6DSOX_Acc_OK; | ||
} | ||
|
||
int32_t LSM6DSOX_acc_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite) | ||
{ | ||
return ((Accelerometer *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); | ||
} | ||
|
||
int32_t LSM6DSOX_acc_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead) | ||
{ | ||
return ((Accelerometer *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); | ||
} | ||
Comment on lines
+243
to
+251
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mentionné dans un appel, il serait intéressant de rentrer cette fonction à l'intérieur de la classe afin de simplifier son utilisation. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
****************************************************************************** | ||
* @file accelerometer.cpp | ||
* @author Yann Locatelli | ||
* @brief Implement accelerometer of LSM6DSOX for Leka. | ||
****************************************************************************** | ||
*/ | ||
|
||
/* Prevent recursive inclusion -----------------------------------------------*/ | ||
|
||
#ifndef __ACCELEROMETER_H__ | ||
#define __ACCELEROMETER_H__ | ||
|
||
/* Includes ------------------------------------------------------------------*/ | ||
|
||
#include <assert.h> | ||
#include "mbed.h" | ||
#include "lsm6dsox_reg.h" | ||
|
||
/* Defines -------------------------------------------------------------------*/ | ||
|
||
/* Typedefs ------------------------------------------------------------------*/ | ||
|
||
typedef enum | ||
ladislas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
LSM6DSOX_Acc_OK = 0, | ||
LSM6DSOX_Acc_ERROR = -1 | ||
} LSM6DSOXAccStatusTypeDef; | ||
|
||
typedef enum | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. il faut préféré les C'est Bjarn lui même qui le dit ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ca a été ajouté dans le commit 34c9ea8 Même si ça allège le nom, les comparaison (avec There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tu peux donner un type à ton enum avec testes et dis moi si ça marche :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
Transmission_Acc_OK = 0, | ||
Transmission_Acc_ERROR = -1, | ||
Transmission_Acc_OVERFLOW = -2 | ||
} TransmissionAccStatusTypeDef; | ||
|
||
/* Class Declaration ---------------------------------------------------------*/ | ||
|
||
/** | ||
* Abstract class of an LSM6DSOX Inertial Measurement Unit (IMU) 6 axes | ||
* sensor. | ||
*/ | ||
|
||
class Accelerometer | ||
{ | ||
public: | ||
Accelerometer(I2C *i2c, uint8_t address=LSM6DSOX_I2C_ADD_L); | ||
LSM6DSOXAccStatusTypeDef init(void *init); | ||
LSM6DSOXAccStatusTypeDef read_id(uint8_t *id); | ||
|
||
/** | ||
* @brief Utility function to read data. | ||
* @param pBuffer: pointer to data to be read. | ||
* @param RegisterAddr: specifies internal address register to be read. | ||
* @param NumByteToRead: number of bytes to be read. | ||
* @retval 0 if ok, an error code otherwise. | ||
*/ | ||
uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) | ||
{ | ||
//if (!_i2c) return Transmission_ERROR; | ||
|
||
int ret; | ||
|
||
/* Send device address, with no STOP condition */ | ||
ret = _i2c->write(_address, (const char*)&RegisterAddr, 1, true); | ||
if(!ret) { | ||
/* Read data, with STOP condition */ | ||
ret = _i2c->read(_address, (char*)pBuffer, NumByteToRead, false); | ||
} | ||
|
||
if(ret) return Transmission_Acc_ERROR; | ||
return Transmission_Acc_OK; | ||
} | ||
|
||
/** | ||
* @brief Utility function to write data. | ||
* @param pBuffer: pointer to data to be written. | ||
* @param RegisterAddr: specifies internal address register to be written. | ||
* @param NumByteToWrite: number of bytes to write. | ||
* @retval 0 if ok, an error code otherwise. | ||
*/ | ||
uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) | ||
{ | ||
//if (!_i2c) return Transmission_ERROR; | ||
|
||
int ret; | ||
uint8_t tmp[TEMP_BUF_SIZE]; | ||
|
||
if(NumByteToWrite >= TEMP_BUF_SIZE) return Transmission_Acc_OVERFLOW; | ||
|
||
/* First, send device address. Then, send data and STOP condition */ | ||
tmp[0] = RegisterAddr; | ||
memcpy(tmp+1, pBuffer, NumByteToWrite); | ||
|
||
ret = _i2c->write(_address, (const char*)tmp, NumByteToWrite+1, false); | ||
|
||
if(ret) return Transmission_Acc_ERROR; | ||
return Transmission_Acc_OK; | ||
} | ||
|
||
private: | ||
I2C *_i2c; | ||
uint8_t _address; | ||
|
||
stmdev_ctx_t _reg_ctx; | ||
static const unsigned int TEMP_BUF_SIZE = 32; | ||
|
||
}; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
int32_t LSM6DSOX_acc_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); | ||
int32_t LSM6DSOX_acc_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // __ACCELEROMETER_H__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
il faudra bien vérifier qu'on compile après avec
NDEBUG
https://en.cppreference.com/w/cpp/error/assertvoir aussi si c'est conseillé en dehors des tests de mettre des assert dans le code. pas sûr que ce soit utile de crasher le robot si l'i2c ne marche plus. on voudrait plutôt continuer en faisant remonter le problème.