|
@@ -3,17 +3,14 @@
|
|
|
*************************************************************************/
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "DMP_ICM20948.h"
|
|
#include "DMP_ICM20948.h"
|
|
|
-//#include <Wire.h>
|
|
|
|
|
-//#include <SPI.h>
|
|
|
|
|
-//#include <Arduino.h>
|
|
|
|
|
#include <math.h>
|
|
#include <math.h>
|
|
|
-//#include "stm32l4xx_hal.h"
|
|
|
|
|
|
|
|
|
|
// InvenSense drivers and utils
|
|
// InvenSense drivers and utils
|
|
|
#include "Icm20948.h"
|
|
#include "Icm20948.h"
|
|
|
#include "SensorTypes.h"
|
|
#include "SensorTypes.h"
|
|
|
#include "Icm20948MPUFifoControl.h"
|
|
#include "Icm20948MPUFifoControl.h"
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/*************************************************************************
|
|
/*************************************************************************
|
|
|
Variables
|
|
Variables
|
|
|
*************************************************************************/
|
|
*************************************************************************/
|
|
@@ -54,108 +51,8 @@ unsigned long steps;
|
|
|
bool steps_data_ready = false;
|
|
bool steps_data_ready = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
-// Funkcia na nastavenie CS pinu
|
|
|
|
|
-static void CS_Select(void) {
|
|
|
|
|
- HAL_GPIO_WritePin(CHIP_SELECT_PORT, CHIP_SELECT_PIN, GPIO_PIN_RESET);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-static void CS_Deselect(void) {
|
|
|
|
|
- HAL_GPIO_WritePin(CHIP_SELECT_PORT, CHIP_SELECT_PIN, GPIO_PIN_SET);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/*************************************************************************
|
|
|
|
|
- HAL Functions for Arduino
|
|
|
|
|
-*************************************************************************/
|
|
|
|
|
-int spi_master_read_register(uint8_t reg, uint8_t* rbuffer, uint32_t rlen)
|
|
|
|
|
-{
|
|
|
|
|
- //return spi_master_transfer_rx(NULL, reg, rbuffer, rlen);
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- SPI.beginTransaction(SPISettings(com_speed, MSBFIRST, SPI_MODE0));
|
|
|
|
|
- SPI.transfer(0x00);
|
|
|
|
|
- SPI.endTransaction();
|
|
|
|
|
- */
|
|
|
|
|
- uint8_t dummy = 0x00;
|
|
|
|
|
- uint8_t status = HAL_SPI_Transmit(&SPI_INSTANCE, &dummy, 1, HAL_MAX_DELAY);
|
|
|
|
|
- if (status != HAL_OK) return status;
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- digitalWrite(chipSelectPin, LOW);
|
|
|
|
|
- SPI.beginTransaction(SPISettings(com_speed, MSBFIRST, SPI_MODE0));
|
|
|
|
|
- SPI.transfer(((reg & 0x7F) | 0x80));
|
|
|
|
|
- for (uint32_t indi = 0; indi < rlen; indi++)
|
|
|
|
|
- {
|
|
|
|
|
- *(rbuffer + indi) = SPI.transfer(0x00);
|
|
|
|
|
- }
|
|
|
|
|
- SPI.endTransaction();
|
|
|
|
|
- digitalWrite(chipSelectPin, HIGH);
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
-#ifdef HAL_SPI_MODULE_ENABLED
|
|
|
|
|
-
|
|
|
|
|
- CS_Select();
|
|
|
|
|
-
|
|
|
|
|
- // 3. Adresovanie registra
|
|
|
|
|
- uint8_t cmd = (reg & 0x7F) | 0x80;
|
|
|
|
|
- status = HAL_SPI_Transmit(&SPI_INSTANCE, &cmd, 1, HAL_MAX_DELAY);
|
|
|
|
|
-
|
|
|
|
|
- // 4. Čítanie dát
|
|
|
|
|
- for (uint32_t indi = 0; indi < rlen; indi++) {
|
|
|
|
|
- uint8_t rx = 0x00;
|
|
|
|
|
- status = HAL_SPI_TransmitReceive(&SPI_INSTANCE, &rx, &rbuffer[indi], 1, HAL_MAX_DELAY);
|
|
|
|
|
- if (status != HAL_OK) {
|
|
|
|
|
- CS_Deselect();
|
|
|
|
|
- return status;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 5. Chip select HIGH
|
|
|
|
|
- CS_Deselect();
|
|
|
|
|
-
|
|
|
|
|
-#endif // HAL_SPI_MODULE_ENABLED
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-int spi_master_write_register(uint8_t reg, const uint8_t* wbuffer, uint32_t wlen)
|
|
|
|
|
-{
|
|
|
|
|
-
|
|
|
|
|
-#ifdef HAL_SPI_MODULE_ENABLED
|
|
|
|
|
-
|
|
|
|
|
- HAL_StatusTypeDef status;
|
|
|
|
|
- uint8_t dummy = 0x00;
|
|
|
|
|
- uint8_t addr = (reg & 0x7F) | 0x00;
|
|
|
|
|
-
|
|
|
|
|
- // 1. Dummy transfer (pôvodne SPI.transfer(0x00) mimo transakcie)
|
|
|
|
|
- status = HAL_SPI_Transmit(&SPI_INSTANCE, &dummy, 1, HAL_MAX_DELAY);
|
|
|
|
|
- if (status != HAL_OK) return -1;
|
|
|
|
|
-
|
|
|
|
|
- // 2. Chip Select LOW
|
|
|
|
|
- CS_Select();
|
|
|
|
|
-
|
|
|
|
|
- // 3. Odoslanie adresy registra
|
|
|
|
|
- status = HAL_SPI_Transmit(&SPI_INSTANCE, &addr, 1, HAL_MAX_DELAY);
|
|
|
|
|
- if (status != HAL_OK) {
|
|
|
|
|
- CS_Deselect();
|
|
|
|
|
- return -2;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // 4. Odoslanie všetkých dát
|
|
|
|
|
- if (wlen > 0) {
|
|
|
|
|
- status = HAL_SPI_Transmit(&SPI_INSTANCE, (uint8_t*)wbuffer, wlen, HAL_MAX_DELAY);
|
|
|
|
|
- if (status != HAL_OK) {
|
|
|
|
|
- CS_Deselect();
|
|
|
|
|
- return -3;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // 5. Chip Select HIGH
|
|
|
|
|
- CS_Deselect();
|
|
|
|
|
-
|
|
|
|
|
-#endif // HAL_SPI_MODULE_ENABLED
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
int i2c_master_write_register(uint8_t address, uint8_t reg, uint32_t len, const uint8_t *data)
|
|
int i2c_master_write_register(uint8_t address, uint8_t reg, uint32_t len, const uint8_t *data)
|
|
|
{
|
|
{
|
|
@@ -214,18 +111,6 @@ int i2c_master_read_register(uint8_t address, uint8_t reg, uint32_t len, uint8_t
|
|
|
*************************************************************************/
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
inv_icm20948_t icm_device;
|
|
inv_icm20948_t icm_device;
|
|
|
-int rc = 0;
|
|
|
|
|
-static const uint8_t EXPECTED_WHOAMI[] = { 0xEA }; /* WHOAMI value for ICM20948 or derivative */
|
|
|
|
|
-#define AK0991x_DEFAULT_I2C_ADDR 0x0C
|
|
|
|
|
-#define AK0991x_SECONDARY_I2C_ADDR 0x0E /* The secondary I2C address for AK0991x Magnetometers */
|
|
|
|
|
-
|
|
|
|
|
-#define ICM_I2C_ADDR_REVA 0x68 /* I2C slave address for INV device on Rev A board */
|
|
|
|
|
-#define ICM_I2C_ADDR_REVB 0x69 /* I2C slave address for INV device on Rev B board */
|
|
|
|
|
-
|
|
|
|
|
-#define AD0_VAL 1 // The value of the last bit of the I2C address.
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-#define THREE_AXES 3
|
|
|
|
|
static int unscaled_bias[THREE_AXES * 2];
|
|
static int unscaled_bias[THREE_AXES * 2];
|
|
|
|
|
|
|
|
static const float cfg_mounting_matrix[9] = {
|
|
static const float cfg_mounting_matrix[9] = {
|
|
@@ -263,37 +148,31 @@ int load_dmp3(void)
|
|
|
void inv_icm20948_sleep_us(int us)
|
|
void inv_icm20948_sleep_us(int us)
|
|
|
{
|
|
{
|
|
|
// delayMicroseconds(us);
|
|
// delayMicroseconds(us);
|
|
|
- while(us--)
|
|
|
|
|
|
|
+ while(us--) /// !!! very weak implementation
|
|
|
__ASM volatile ("NOP");
|
|
__ASM volatile ("NOP");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void inv_icm20948_sleep(int ms)
|
|
void inv_icm20948_sleep(int ms)
|
|
|
{
|
|
{
|
|
|
- //delay(ms);
|
|
|
|
|
HAL_Delay(ms);
|
|
HAL_Delay(ms);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
uint64_t inv_icm20948_get_time_us(void)
|
|
uint64_t inv_icm20948_get_time_us(void)
|
|
|
{
|
|
{
|
|
|
- //return micros();
|
|
|
|
|
return HAL_GetTick()*1000;
|
|
return HAL_GetTick()*1000;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-void initiliaze_SPI(void)
|
|
|
|
|
-{
|
|
|
|
|
- CS_Deselect();
|
|
|
|
|
- uint8_t dummy = 0x00;
|
|
|
|
|
- HAL_SPI_Transmit(&SPI_INSTANCE, &dummy, 1, HAL_MAX_DELAY);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
void initiliaze_I2C(void)
|
|
void initiliaze_I2C(void)
|
|
|
{
|
|
{
|
|
|
|
|
+#ifdef HAL_I2C_MODULE_ENABLED
|
|
|
I2C_Address = I2C_ADDRESS;
|
|
I2C_Address = I2C_ADDRESS;
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool is_interface_SPI = false;
|
|
bool is_interface_SPI = false;
|
|
|
|
|
+
|
|
|
void set_comm_interface(DMP_ICM20948Settings settings)
|
|
void set_comm_interface(DMP_ICM20948Settings settings)
|
|
|
{
|
|
{
|
|
|
is_interface_SPI = IS_SPI;
|
|
is_interface_SPI = IS_SPI;
|
|
@@ -652,7 +531,7 @@ void DMP_ICM20948::init(DMP_ICM20948Settings settings)
|
|
|
inv_icm20948_register_aux_compass(&icm_device, INV_ICM20948_COMPASS_ID_AK09916, AK0991x_DEFAULT_I2C_ADDR);
|
|
inv_icm20948_register_aux_compass(&icm_device, INV_ICM20948_COMPASS_ID_AK09916, AK0991x_DEFAULT_I2C_ADDR);
|
|
|
|
|
|
|
|
// Setup the icm20948 device
|
|
// Setup the icm20948 device
|
|
|
- rc = icm20948_sensor_setup();
|
|
|
|
|
|
|
+ int rc = icm20948_sensor_setup();
|
|
|
|
|
|
|
|
if (icm_device.selftest_done && !icm_device.offset_done)
|
|
if (icm_device.selftest_done && !icm_device.offset_done)
|
|
|
{
|
|
{
|