diff --git a/libs/miosix-kernel b/libs/miosix-kernel
index 9096c209182fc1c86a1f4f33c9a1546fdad4e0b3..38bea2878c5470f8dd4cdd5792c969a5bf5ab660 160000
--- a/libs/miosix-kernel
+++ b/libs/miosix-kernel
@@ -1 +1 @@
-Subproject commit 9096c209182fc1c86a1f4f33c9a1546fdad4e0b3
+Subproject commit 38bea2878c5470f8dd4cdd5792c969a5bf5ab660
diff --git a/sbs.conf b/sbs.conf
index 1962ae20f79f9ec33e1887c22dadd85ea26548bb..cd6dccc8ea50a1d6603845d59454bfc3c1516cac 100644
--- a/sbs.conf
+++ b/sbs.conf
@@ -483,6 +483,14 @@ Include: %shared %spi
Defines: -DDEBUG
Main: drivers/test-lsm9ds1
+[test-lsm9ds1-class]
+Type: test
+BoardId: stm32f407vg_stm32f4discovery
+BinName: test-lsm9ds1-class
+Include: %shared %spi
+Defines: -DDEBUG
+Main: drivers/test-lsm9ds1-class
+
[test-rls]
Type: test
BoardId: stm32f429zi_skyward_death_stack
diff --git a/src/shared/sensors/LSM9DS1/LSM9DS1_AxelGyro.h b/src/shared/sensors/LSM9DS1/LSM9DS1_AxelGyro.h
index f4799a7ea78e9324d41bbae3bbf94b4646f3bda1..058bc329825ee0d715806727b26aece1bec03e03 100644
--- a/src/shared/sensors/LSM9DS1/LSM9DS1_AxelGyro.h
+++ b/src/shared/sensors/LSM9DS1/LSM9DS1_AxelGyro.h
@@ -105,6 +105,12 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
}
+ void getWhoami()
+ {
+ SPITransaction spi(spislave);
+ uint8_t whoami = spi.read(regMapXLG::WHO_AM_I);
+ TRACE("whoami: 0x%02X\n", whoami);
+ }
bool init() override
@@ -113,34 +119,34 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
switch(axelFSR)
{
case AxelFSR::FS_2:
- axelFSRval = 2.0f;
+ axelSensitivity = 0.061f;
break;
case AxelFSR::FS_4:
- axelFSRval = 4.0f;
+ axelSensitivity = 0.122f;
break;
case AxelFSR::FS_8:
- axelFSRval = 8.0f;
+ axelSensitivity = 0.244f;
break;
case AxelFSR::FS_16:
- axelFSRval = 16.0f;
+ axelSensitivity = 0.732f;
break;
default:
- axelFSRval = 2.0f;
+ axelSensitivity = 0.061f;
break;
}
switch (gyroFSR)
{
case GyroFSR::FS_245:
- gyroFSRval = 245.0f;
+ gyroSensitivity = 8.75f;
break;
case GyroFSR::FS_500:
- gyroFSRval = 500.0f;
+ gyroSensitivity = 17.50f;
break;
case GyroFSR::FS_2000:
- gyroFSRval = 2000.0f;
+ gyroSensitivity = 70.0f;
break;
default:
- gyroFSRval = 245.0f;
+ gyroSensitivity = 8.75f;
break;
}
@@ -165,8 +171,9 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
spi.write(regMapXLG::CTRL_REG9, (CTRL_REG9_VAL|0x02)); //DRDY_mask_bit ON, I2C OFF, FIFO ON
}
else
+ {
spi.write(regMapXLG::CTRL_REG9, CTRL_REG9_VAL); //DRDY_mask_bit ON, I2C OFF, FIFO OFF
-
+ }
//Axel Setup: ODR, FSR defined by constructor, auto anti-aliasing BW (max), LPF2/HPF bypassed and disabled, axel output enabled by default @ startup
@@ -181,17 +188,19 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
//spi.write(regMapXLG::ORIENT_CFG_G, ORIENT_CFG_VAL); //angular rate sign and orientation Setup <--- BOARD DEPENDENT
//Check all the registers have been written correctly
- if(spi.read(regMapXLG::CTRL_REG8)!=CTRL_REG8_VAL) return false;
+ if(spi.read(regMapXLG::CTRL_REG8)!=CTRL_REG8_VAL) {return false;}
if(fifo_enabled)
{
- if(spi.read(regMapXLG::FIFO_CTRL) != (FIFO_CTRL_VAL|fifo_watermark)) return false;
- if(spi.read(regMapXLG::INT1_CTRL) != INT1_CTRL_VAL) return false;
- if(spi.read(regMapXLG::CTRL_REG9) != (CTRL_REG9_VAL| 0x02)) return false;
+ if(spi.read(regMapXLG::FIFO_CTRL) != (FIFO_CTRL_VAL|fifo_watermark)) {return false;}
+ if(spi.read(regMapXLG::INT1_CTRL) != INT1_CTRL_VAL) {return false;}
+ if(spi.read(regMapXLG::CTRL_REG9) != (CTRL_REG9_VAL| 0x02)) {return false;}
}
else
- if(spi.read(regMapXLG::CTRL_REG9) != CTRL_REG9_VAL) return false;
- if(spi.read(regMapXLG::CTRL_REG6_XL) != CTRL_REG6_XL_VAL) return false;
- if(spi.read(regMapXLG::CTRL_REG1_G) != CTRL_REG1_G_VAL) return false;
+ {
+ if(spi.read(regMapXLG::CTRL_REG9) != CTRL_REG9_VAL) {return false;}
+ }
+ if(spi.read(regMapXLG::CTRL_REG6_XL) != CTRL_REG6_XL_VAL) {return false;}
+ if(spi.read(regMapXLG::CTRL_REG1_G) != CTRL_REG1_G_VAL) {return false;}
//@ startup, some samples have to be discarded (datasheet)
@@ -243,14 +252,14 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
// TRACE("LSM9DS1 temp: %02X\n, temp");
mLastAccel =
- Vec3(x_xl * axelFSRval / 0xFFFF,
- y_xl * axelFSRval / 0xFFFF,
- z_xl * axelFSRval / 0xFFFF);
+ Vec3(x_xl / axelSensitivity,
+ y_xl / axelSensitivity,
+ z_xl / axelSensitivity);
mLastGyro =
- Vec3(x_gy * gyroFSRval / 0xFFFF,
- y_gy * gyroFSRval / 0xFFFF,
- z_gy * gyroFSRval / 0xFFFF);
+ Vec3(x_gy / gyroSensitivity,
+ y_gy / gyroSensitivity,
+ z_gy / gyroSensitivity);
mLastTemp = tempZero + temp / tempSensistivity; //25°C + TEMP/S devo castare a float "temp"?
}
@@ -267,22 +276,22 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
//convert & store
for(int i=0; i<fifo_samples; i++ )
{
- uint16_t x_gy = buf[i*12] | buf[i*6 + 1] << 8;
- uint16_t y_gy = buf[i*12 + 2] | buf[i*6 + 3] << 8;
- uint16_t z_gy = buf[i*12 + 4] | buf[i*6 + 5] << 8;
+ uint16_t x_gy = buf[i*12] | buf[i*12 + 1] << 8;
+ uint16_t y_gy = buf[i*12 + 2] | buf[i*12 + 3] << 8;
+ uint16_t z_gy = buf[i*12 + 4] | buf[i*12 + 5] << 8;
- uint16_t x_xl = buf[i*12 + 6] | buf[i*6 + 7] << 8;
- uint16_t y_xl = buf[i*12 + 8] | buf[i*6 + 9] << 8;
- uint16_t z_xl = buf[i*12 + 10] | buf[i*6 + 11] << 8;
+ uint16_t x_xl = buf[i*12 + 6] | buf[i*12 + 7] << 8;
+ uint16_t y_xl = buf[i*12 + 8] | buf[i*12 + 9] << 8;
+ uint16_t z_xl = buf[i*12 + 10] | buf[i*12 + 11] << 8;
gyro_fifo[i] =
- Vec3(x_gy * axelFSRval / 0xFFFF,
- y_gy * axelFSRval / 0xFFFF,
- z_gy * axelFSRval / 0xFFFF);
+ Vec3(x_gy / gyroSensitivity,
+ y_gy / gyroSensitivity,
+ z_gy / gyroSensitivity);
axel_fifo[i] =
- Vec3(x_xl * axelFSRval / 0xFFFF,
- y_xl * axelFSRval / 0xFFFF,
- z_xl * axelFSRval / 0xFFFF);
+ Vec3(x_xl / axelSensitivity,
+ y_xl / axelSensitivity,
+ z_xl / axelSensitivity);
}
}
return true;
@@ -318,8 +327,8 @@ class LSM9DS1_XLG : public GyroSensor, public AccelSensor, public TemperatureSen
GyroFSR gyroFSR;
ODR odr;
- float axelFSRval;
- float gyroFSRval;
+ float axelSensitivity;
+ float gyroSensitivity;
float tempZero = 25.0f;
float tempSensistivity = 16.0f;
static const uint8_t samplesToDiscard = 8; //max possible val
diff --git a/src/tests/drivers/test-lsm9ds1-class.cpp b/src/tests/drivers/test-lsm9ds1-class.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..51c9191f01177bdfa6ec54b047d33e874ea41650
--- /dev/null
+++ b/src/tests/drivers/test-lsm9ds1-class.cpp
@@ -0,0 +1,88 @@
+/**
+ * test LSM9DS1 axel + gyro
+ * Copyright (c) 2020 Skyward Experimental Rocketry
+ * Authors: Andrea Milluzzo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#include "drivers/spi/SPIDriver.h"
+#include "sensors/LSM9DS1/LSM9DS1_AxelGyro.h"
+
+using namespace miosix;
+
+typedef Gpio<GPIOA_BASE, 5> GpioSck; //questi sono i pin SPI per f407_discovery
+typedef Gpio<GPIOA_BASE, 6> GpioMiso;
+typedef Gpio<GPIOA_BASE, 7> GpioMosi;
+
+static const bool FIFO_ENABLED = false;
+
+//SPI
+SPIBus bus(SPI1);
+SPIBusConfig cfg;
+GpioPin cs(GPIOE_BASE, 7);
+
+
+
+int main(){
+
+ cfg.br = SPIBaudRate::DIV_64; //max 10MHz
+
+ {
+ FastInterruptDisableLock dLock;
+
+ RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; //SPI1 ENABLE
+
+ GpioSck::mode(Mode::ALTERNATE);
+ GpioMiso::mode(Mode::ALTERNATE);
+ GpioMosi::mode(Mode::ALTERNATE);
+ cs.mode(Mode::OUTPUT);
+
+ GpioSck::alternateFunction(5);
+ GpioMiso::alternateFunction(5);
+ GpioMosi::alternateFunction(5);
+
+ GpioSck::speed(Speed::_25MHz);
+
+ }
+
+ cs.high();
+
+ LSM9DS1_XLG sensor1(
+ bus,
+ cs,
+ cfg,
+ LSM9DS1_XLG::AxelFSR::FS_8,
+ LSM9DS1_XLG::GyroFSR::FS_245,
+ LSM9DS1_XLG::ODR::ODR_952
+ );
+
+
+
+ sensor1.getWhoami();
+
+ while(1)
+ {
+ Thread::sleep(500);
+ }
+
+
+ return 0;
+}
\ No newline at end of file
diff --git a/src/tests/drivers/test-lsm9ds1.cpp b/src/tests/drivers/test-lsm9ds1.cpp
index bd6d5a8e79eb09b1459ddb7849e608ce1e78cbe7..9b23d2f3177551f329a91da953b5b106645e2270 100644
--- a/src/tests/drivers/test-lsm9ds1.cpp
+++ b/src/tests/drivers/test-lsm9ds1.cpp
@@ -34,6 +34,7 @@ typedef Gpio<GPIOA_BASE, 7> GpioMosi;
static const bool FIFO_ENABLED = false;
Vec3 adata, gdata;
+float tdata;
//SPI
SPIBus bus(SPI1);
@@ -44,9 +45,8 @@ GpioPin cs(GPIOE_BASE, 7);
int main(){
- cfg.br = SPIBaudRate::DIV_256; //max 10MHz
- cfg.cpol = 1;
- cfg.cpha = 1;
+ cfg.br = SPIBaudRate::DIV_64; //max 10MHz
+
{
FastInterruptDisableLock dLock;
@@ -60,12 +60,16 @@ int main(){
GpioSck::alternateFunction(5);
GpioMiso::alternateFunction(5);
GpioMosi::alternateFunction(5);
+
+ GpioSck::speed(Speed::_25MHz);
+
}
cs.high();
LSM9DS1_XLG lsm9ds1(
bus,
cs,
+ cfg,
LSM9DS1_XLG::AxelFSR::FS_8,
LSM9DS1_XLG::GyroFSR::FS_245,
LSM9DS1_XLG::ODR::ODR_952
@@ -80,10 +84,12 @@ int main(){
lsm9ds1.onSimpleUpdate();
adata = *(lsm9ds1.accelDataPtr());
gdata = *(lsm9ds1.gyroDataPtr());
- TRACE("TIMESTAMP:%.3f\taxel:%.3f,%.3f,%.3f\tgyro:%.3f,%.3f,%.3f\n",
+ tdata = *(lsm9ds1.tempDataPtr());
+ TRACE("TIMESTAMP:%lld\t\taxel: %.3f,%.3f,%.3f\t\tgyro: %.3f,%.3f,%.3f\t\ttemp: %.3f\n",
tick-first_tick,
adata.getX(), adata.getY(), adata.getZ(),
- gdata.getX(), gdata.getY(), gdata.getZ());
+ gdata.getX(), gdata.getY(), gdata.getZ(),
+ tdata);
Thread::sleep(500);
}