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

Feature/cpp migration #2

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
29ad2a6
✨ Add thundervolt modifications in lsm6ds3 lib
phMachad0 Apr 8, 2023
98847cb
🐛 comment unsed variable
VanderSant Jun 16, 2023
6572c6c
➕ Add lsm6dso driver registers
phMachad0 Jul 11, 2023
a6dc04a
♻️ Refactor existent files
phMachad0 Jul 11, 2023
86786a9
🏷️ Add setting type for lsm6ds
phMachad0 Jul 11, 2023
a09d8f0
📝 Update README
phMachad0 Jul 11, 2023
8354f9e
🔥 Remove rgb debug
phMachad0 Jul 12, 2023
7c1ff13
🚨 Fix compiler warning
phMachad0 Jul 16, 2023
cd1da09
💥 Add CMake
Aug 4, 2023
f3897e2
🐛 Fix path
Aug 4, 2023
989fc66
✨ Adds lsmds3tr-c sensor reg files
Bruno1406 Aug 14, 2023
5390bd9
🧱 Lays ground for fifo related code
Bruno1406 Aug 15, 2023
18b9ea1
🚚 Folder organization and OOP setup
Bruno1406 Aug 22, 2023
90173df
✨ Implementation of LSM6DS Class
Bruno1406 Aug 23, 2023
1c0bebd
🎨 Architecture changes in classes structure
Bruno1406 Aug 24, 2023
d8585ba
🚚 changes file name
Bruno1406 Aug 24, 2023
cbb8a1b
🔥
Bruno1406 Aug 24, 2023
4c47a2b
🐛 Fixes type problem in proxys init
Bruno1406 Aug 24, 2023
a701b13
🚧 Lays ground for c and cpp integration
Bruno1406 Aug 25, 2023
c11cf0b
🧱 Changes interface with reg files
Bruno1406 Aug 25, 2023
e1be706
🤡 Adds cube_mocks and updates cmake
Bruno1406 Aug 25, 2023
6a51881
🐛 Fixes interface with sensors reg lib
Bruno1406 Aug 25, 2023
c27823b
💚 Fixes cube mocks and cmake
Bruno1406 Aug 25, 2023
729b6fe
✨ lsm6ds3tr-c concretion implemented
Bruno1406 Aug 26, 2023
1178ba6
🚧 Adds implementations for compilation purposes
Bruno1406 Aug 26, 2023
29b0bb3
✨ Adds a C compatible interface
Bruno1406 Aug 26, 2023
6634163
🎨 Changes C interface function names
Bruno1406 Aug 26, 2023
3cf4d35
💚 Changes .cmake
Bruno1406 Aug 27, 2023
c7bb605
🚨 Fix compilation problems
Bruno1406 Aug 27, 2023
22e56bb
🐛 Fixes init to initialize I2C before using it
Bruno1406 Aug 29, 2023
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
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LSM6DS3
# LSM6DS

Biblioteca adaptada do [driver da ST](https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lsm6ds3_STdC) para utilizar o sensor de 6 eixos LSM6DS3 (Os arquivos `lsm6ds3_reg.h/.c` não foram modificados)
Biblioteca adaptada do driver da ST para utilizar tanto o sensor de 6 eixos [LSM6DS3](https://github.com/STMicroelectronics/lsm6ds3-pid) quanto o [LSM6DSO](https://github.com/STMicroelectronics/stm32-lsm6dso)

# Utilização
## Cube:
Expand All @@ -11,7 +11,10 @@ Biblioteca adaptada do [driver da ST](https://github.com/STMicroelectronics/STMe
* CPOL deve ter valor 1 (High) e CPHA deve ter valor 1 (2 Edge)
* É necessário escolher um pino e setar como GPIO_Output, esse pino será usado como Chip Select

## No arquivo lsm6ds3.c:
## No arquivo lsm6ds.c:

Neste arquivo, no momento em que a placa é ligada, já é identificado qual sensor está sendo utilizado.

* Descomentar a linha com o protocolo usado e comentar a outra
* Para I2C:
```c
Expand Down Expand Up @@ -61,35 +64,35 @@ Biblioteca adaptada do [driver da ST](https://github.com/STMicroelectronics/STMe
* Criar uma struct que contém os valores desejados de sensibilidades e de frequências de amostragem do acelerômetro e do giroscópio
```c
// Exemplo
lsm6ds3_settings_t lsm6ds3_settings = {
.lsm6ds3_xl_fs = LSM6DS3_16g,
.lsm6ds3_fs_g = LSM6DS3_2000dps,
.lsm6ds3_odr_xl = LSM6DS3_XL_ODR_6k66Hz,
.lsm6ds3_odr_g = LSM6DS3_GY_ODR_1k66Hz
lsm6ds_settings_t lsm6ds_settings = {
.lsm6ds_xl_fs = LSM6DS_16g,
.lsm6ds_fs_g = LSM6DS_2000dps,
.lsm6ds_odr_xl = LSM6DS_XL_ODR_6k66Hz,
.lsm6ds_odr_g = LSM6DS_GY_ODR_1k66Hz
};
```
* Para inicializar o sensor, use a função
```c
int8_t lsm6ds3_init(lsm6ds3_settings_t lsm6ds3_settings)
int8_t lsm6ds_init(lsm6ds_settings_t lsm6ds_settings)
```
* A função `lsm6ds3_init` retorna `1` caso haja erro na leitura do registrador `WHO_AM_I` do sensor
* A função `lsm6ds_init` retorna `1` caso haja erro na leitura do registrador `WHO_AM_I` do sensor

## Para obter as leituras do sensor:
* Primeiro é necessário atualizar os dados brutos:
* Se os pinos INT não estão sendo usados, use a função:
```c
void lsm6ds3_update_data()
void lsm6ds_update_data()
```
* Se os pinos INT estão sendo usados, use a função:
```c
void lsm6ds3_update_data_interrupt()
void lsm6ds_update_data_interrupt()
```
* Depois disso, para obter as leituras já convertidas, use as funções
```c
float* lsm6ds3_get_acc_data_mg()
float* lsm6ds3_get_gyro_data_mdps()
float* lsm6ds_get_acc_data_mg()
float* lsm6ds_get_gyro_data_mdps()
```

---------------------

Equipe ThundeRatz de Robótica
Equipe ThundeRatz de Robótica
27 changes: 27 additions & 0 deletions cmake/FindLSM6DS3.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
set(LSM6DS3_PATH ./lib/LSM6DS3)
set(CUBE_INC_PATH ${CMAKE_SOURCE_DIR}/cube/Inc)

file(GLOB_RECURSE SOURCES LIST_DIRECTORIES false "${LSM6DS3_PATH}/src/*")

list(APPEND LIB_SOURCES
${SOURCES}
)

list(APPEND LIB_INCLUDE_DIRECTORIES
${LSM6DS3_PATH}/inc
${LSM6DS3_PATH}/inc/types
${LSM6DS3_PATH}/inc/reg
${LSM6DS3_PATH}/inc/proxys
${LSM6DS3_PATH}/inc/interfaces
${LSM6DS3_PATH}/inc/platforms
)

if(NOT EXISTS ${CUBE_INC_PATH}/i2c.h)
list(APPEND LIB_INCLUDE_DIRECTORIES
${LSM6DS3_PATH}/inc/cube_mock/i2c_mock
)
elseif(NOT EXISTS ${CUBE_INC_PATH}/spi.h)
list(APPEND LIB_INCLUDE_DIRECTORIES
${LSM6DS3_PATH}/inc/cube_mock/spi_mock
)
endif()
17 changes: 17 additions & 0 deletions inc/cube_mock/i2c_mock/i2c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file i2c.h
*
* @brief This file is a mock file for when "i2c.h" is not defined
*
* @author Bruno Machado <[email protected]>
* @author Pedro Machado <[email protected]>
*
* @date 08/2023
*/


#ifndef __I2C_H__
#define __I2C_H__


#endif
17 changes: 17 additions & 0 deletions inc/cube_mock/spi_mock/spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file spi.h
*
* @brief This file is a mock file for when "spi.h" is not defined
*
* @author Bruno Machado <[email protected]>
* @author Pedro Machado <[email protected]>
*
* @date 08/2023
*/

#ifndef __SPI_H__
#define __SPI_H__



#endif
75 changes: 75 additions & 0 deletions inc/interfaces/lsm6ds_c_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @file lsm6ds_c_interface.h
*
* @brief This file is a declaration for a c compatible interface
*
* @author Bruno Machado <[email protected]>
* @author Pedro Machado <[email protected]>
*
* @date 08/2023
*/

#ifndef __LSM6DS_C_INTERFACE_H__
#define __LSM6DS_C_INTERFACE_H__

#include "lsm6ds_settings_type.h"
#include "lsm6ds_pinout.h"
#include "lsm6ds_common.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Initialize the sensor and set acc/gyro sensitivities and data rates
*
* @param lsm6ds_settings Struct of acc/gyro sensitivities and data rates settings
* @param I2C_pinout_config Struct of sensor pinout configurations in I2C mode
*
*/
int8_t lsm6ds_init_I2C(lsm6ds_settings_t lsm6ds_settings, lsm6ds_I2C_pinout_t I2C_pinout_config);

/**
* @brief Initialize the sensor and set acc/gyro sensitivities and data rates
*
* @param lsm6ds_settings Struct of acc/gyro sensitivities and data rates settings
* @param SPI_pinout_config Struct of sensor pinout configurations in SPI mode
*
*/
int8_t lsm6ds_init_SPI(lsm6ds_settings_t lsm6ds_settings, lsm6ds_SPI_pinout_t SPI_pinout_config);

/**
* @brief Update sensor data if available (Use this function if not using interrupt pins)
*/
void lsm6ds_update_data();

/**
* @brief Update sensor data (Use this function when using interrupt pins)
*/
void lsm6ds_update_data_ready_interrupt();

/**
* @brief Update sensor data (Use this function if using fifo continuous mode with interrupt pins)
*/
void lsm6ds_update_data_fifo_full_interrupt();

/**
* @brief Resets fifo data
*/
void lsm6ds_reset_fifo();

/**
* @brief Get accelerometer data array in mg
*/
float* lsm6ds_get_acc_data_mg();

/**
* @brief Get gyroscope data array in mdps
*/
float* lsm6ds_get_gyro_data_mdps();

#ifdef __cplusplus
}
#endif

#endif // __LSM6DS_C_INTERFACE_H__
83 changes: 83 additions & 0 deletions inc/interfaces/lsm6ds_interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @file lsm6ds_interface.hpp
*
* @brief This file is a declaration of the LSM6DS_Interface class
*
* @author Bruno Machado <[email protected]>
* @author Pedro Machado <[email protected]>
*
* @date 08/2023
*/

#ifndef __LSM6DS_INTERFACE_HPP__
#define __LSM6DS_INTERFACE_HPP__

#include "lsm6ds_proxy.hpp"

class LSM6DS_Interface {
public:
/**
* @brief Construct a new LSM6DS_Interface object
*
*/
LSM6DS_Interface() = default;

/**
* @brief Destroy the LSM6DS_Interface object
*
*/
~LSM6DS_Interface() = default;

/**
* @brief Initialize the sensor and set acc/gyro sensitivities and data rates
*
* @param lsm6ds_settings Struct of acc/gyro sensitivities and data rates settings
* @param I2C_pinout_config Struct of sensor pinout configurations in I2C mode
*
*/
int8_t init(lsm6ds_settings_t lsm6ds_settings, lsm6ds_I2C_pinout_t I2C_pinout_config);

/**
* @brief Initialize the sensor and set acc/gyro sensitivities and data rates
*
* @param lsm6ds_settings Struct of acc/gyro sensitivities and data rates settings
* @param SPI_pinout_config Struct of sensor pinout configurations in SPI mode
*
*/
int8_t init(lsm6ds_settings_t lsm6ds_settings, lsm6ds_SPI_pinout_t SPI_pinout_config);

/**
* @brief Update sensor data if available (Use this function if not using interrupt pins)
*/
void update_data();

/**
* @brief Update sensor data (Use this function when using interrupt pins)
*/
void update_data_ready_interrupt();

/**
* @brief Update sensor data (Use this function if using fifo continuous mode with interrupt pins)
*/
void update_data_fifo_full_interrupt();

/**
* @brief Resets fifo data
*/
void reset_fifo();

/**
* @brief Get accelerometer data array in mg
*/
float* get_acc_data_mg();

/**
* @brief Get gyroscope data array in mdps
*/
float* get_gyro_data_mdps();

private:
std::unique_ptr<LSM6DS_Proxy> lsm6ds_sensor;
};

#endif // __LSM6DS_INTERFACE_HPP__
63 changes: 0 additions & 63 deletions inc/lsm6ds3.h

This file was deleted.

Loading