Skip to content

Commit 670b801

Browse files
authored
Merge pull request #2 from cparata/master
Fix warnings and align driver to the other MEMS component driver
2 parents 2674b0b + ec2f80e commit 670b801

5 files changed

Lines changed: 739 additions & 813 deletions

File tree

keywords.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ ACC_EnableFreeFallDetection KEYWORD2
5454
ACC_DisableFreeFallDetection KEYWORD2
5555
ACC_SetFreeFallThreshold KEYWORD2
5656
ACC_SetFreeFallDuration KEYWORD2
57-
ACC_GetFreeFallThreshold KEYWORD2
5857

5958
ACC_EnableWakeUpDetection KEYWORD2
6059
ACC_DisableWakeUpDetection KEYWORD2

src/ISM330DHCXSensor.cpp

Lines changed: 34 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ISM330DHCXSensor::ISM330DHCXSensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c)
2626
* @param cs_pin the chip select pin
2727
* @param spi_speed the SPI speed
2828
*/
29-
ISM330DHCXSensor::ISM330DHCXSensor(SPIClass *spi, int cs_spi, uint32_t spi_speed) : dev_spi(spi), cs_pin(cs_pin), spi_speed(spi_speed)
29+
ISM330DHCXSensor::ISM330DHCXSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed) : dev_spi(spi), cs_pin(cs_pin), spi_speed(spi_speed)
3030
{
3131
reg_ctx.write_reg = ISM330DHCX_io_write;
3232
reg_ctx.read_reg = ISM330DHCX_io_read;
@@ -38,13 +38,6 @@ ISM330DHCXSensor::ISM330DHCXSensor(SPIClass *spi, int cs_spi, uint32_t spi_speed
3838
dev_i2c = NULL;
3939
address = 0;
4040

41-
/* Enable SPI 3-Wires on the component */
42-
uint8_t data = 0x0C;
43-
44-
if (WriteReg(ISM330DHCX_CTRL3_C, data) != ISM330DHCX_OK) {
45-
return ;
46-
}
47-
4841
if (Init() != ISM330DHCX_OK) {
4942
return ;
5043
}
@@ -360,19 +353,19 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_SetFullScale(int32_t FullScale)
360353
* @param value pointer where the raw values are written
361354
* @retval 0 in case of success, an error code otherwise
362355
*/
363-
ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_GetAxesRaw(ISM330DHCX_AxesRaw_t *Value)
356+
ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_GetAxesRaw(int16_t *Value)
364357
{
365-
ism330dhcx_axis3bit16_t data_raw;
358+
axis3bit16_t data_raw;
366359

367360
/*Read raw data values */
368361
if (ism330dhcx_acceleration_raw_get(&reg_ctx, data_raw.u8bit) != ISM330DHCX_OK) {
369362
return ISM330DHCX_ERROR;
370363
}
371364

372365
/*Formatting data */
373-
Value->x = data_raw.i16bit[0];
374-
Value->y = data_raw.i16bit[1];
375-
Value->z = data_raw.i16bit[2];
366+
Value[0] = data_raw.i16bit[0];
367+
Value[1] = data_raw.i16bit[1];
368+
Value[2] = data_raw.i16bit[2];
376369

377370
return ISM330DHCX_OK;
378371
}
@@ -382,25 +375,25 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_GetAxesRaw(ISM330DHCX_AxesRaw_t *V
382375
* @param acceleration pointer where the axes are written
383376
* @retval 0 in case of success, an error code otherwise
384377
*/
385-
ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_GetAxes(ISM330DHCX_Axes_t *Acceleration)
378+
ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_GetAxes(int32_t *Acceleration)
386379
{
387380
float sensitivity = 0.0f;
388-
ISM330DHCX_AxesRaw_t data_raw;
381+
int16_t data_raw[3];
389382

390383
/* Get actualSensitivity */
391384
if (ACC_GetSensitivity(&sensitivity) != ISM330DHCX_OK) {
392385
return ISM330DHCX_ERROR;
393386
}
394387

395388
/*Get Data Raw*/
396-
if (ACC_GetAxesRaw(&data_raw) != ISM330DHCX_OK) {
389+
if (ACC_GetAxesRaw(data_raw) != ISM330DHCX_OK) {
397390
return ISM330DHCX_ERROR;
398391
}
399392

400393
/*Calculate data */
401-
Acceleration->x = (int32_t)((float) data_raw.x * sensitivity);
402-
Acceleration->y = (int32_t)((float) data_raw.y * sensitivity);
403-
Acceleration->z = (int32_t)((float) data_raw.z * sensitivity);
394+
Acceleration[0] = (int32_t)((float) data_raw[0] * sensitivity);
395+
Acceleration[1] = (int32_t)((float) data_raw[1] * sensitivity);
396+
Acceleration[2] = (int32_t)((float) data_raw[2] * sensitivity);
404397

405398
return ISM330DHCX_OK;
406399
}
@@ -484,7 +477,7 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_GetSensitivity(float *Sensitivity
484477
ret = ISM330DHCX_ERROR;
485478
break;
486479
}
487-
return ISM330DHCX_OK;
480+
return ret;
488481
}
489482

490483
/**
@@ -635,7 +628,6 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_GetFullScale(int32_t *FullScale)
635628
*/
636629
ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_SetFullScale(int32_t FullScale)
637630
{
638-
ISM330DHCXStatusTypeDef ret = ISM330DHCX_OK;
639631
ism330dhcx_fs_g_t new_fs;
640632

641633
new_fs = (FullScale <= 125) ? ISM330DHCX_125dps
@@ -658,19 +650,19 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_SetFullScale(int32_t FullScale)
658650
* @param value pointer where the raw values are written
659651
* @retval 0 in case of success, an error code otherwise
660652
*/
661-
ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_GetAxesRaw(ISM330DHCX_AxesRaw_t *Value)
653+
ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_GetAxesRaw(int16_t *Value)
662654
{
663-
ism330dhcx_axis3bit16_t data_raw;
655+
axis3bit16_t data_raw;
664656

665657
/* Read raw data values */
666658
if (ism330dhcx_angular_rate_raw_get(&reg_ctx, data_raw.u8bit) != ISM330DHCX_OK) {
667659
return ISM330DHCX_ERROR;
668660
}
669661

670662
/* Format the data */
671-
Value->x = data_raw.i16bit[0];
672-
Value->y = data_raw.i16bit[1];
673-
Value->z = data_raw.i16bit[2];
663+
Value[0] = data_raw.i16bit[0];
664+
Value[1] = data_raw.i16bit[1];
665+
Value[2] = data_raw.i16bit[2];
674666

675667
return ISM330DHCX_OK;
676668
}
@@ -680,13 +672,13 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_GetAxesRaw(ISM330DHCX_AxesRaw_t *
680672
* @param acceleration pointer where the axes are written
681673
* @retval 0 in case of success, an error code otherwise
682674
*/
683-
ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_GetAxes(ISM330DHCX_Axes_t *AngularRate)
675+
ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_GetAxes(int32_t *AngularRate)
684676
{
685677
float sensitivity;
686-
ISM330DHCX_AxesRaw_t raw_data;
678+
int16_t raw_data[3];
687679

688680
/*Read raw data values */
689-
if (GYRO_GetAxesRaw(&raw_data) != ISM330DHCX_OK) {
681+
if (GYRO_GetAxesRaw(raw_data) != ISM330DHCX_OK) {
690682
return ISM330DHCX_ERROR;
691683
}
692684

@@ -695,9 +687,9 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_GetAxes(ISM330DHCX_Axes_t *Angula
695687
return ISM330DHCX_ERROR;
696688
}
697689

698-
AngularRate->x = (int32_t)((float) raw_data.x) * sensitivity;
699-
AngularRate->y = (int32_t)((float) raw_data.y) * sensitivity;
700-
AngularRate->z = (int32_t)((float) raw_data.z) * sensitivity;
690+
AngularRate[0] = (int32_t)((float) raw_data[0] * sensitivity);
691+
AngularRate[1] = (int32_t)((float) raw_data[1] * sensitivity);
692+
AngularRate[2] = (int32_t)((float) raw_data[2] * sensitivity);
701693

702694
return ISM330DHCX_OK;
703695
}
@@ -859,7 +851,7 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_Get_SelfTest(uint8_t *SelfStatus)
859851
break;
860852
}
861853

862-
return ISM330DHCX_OK;
854+
return ret;
863855
}
864856

865857
/**
@@ -943,7 +935,7 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::GYRO_Get_SelfTest(uint8_t *SelfStatus)
943935
break;
944936
}
945937

946-
return ISM330DHCX_OK;
938+
return ret;
947939
}
948940

949941
/**
@@ -1118,73 +1110,6 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_SetFreeFallDuration(uint8_t Durati
11181110
return ISM330DHCX_OK;
11191111
}
11201112

1121-
/*
1122-
* @brief Get the Threshold for the Free Fall event
1123-
* @param Threshold pointer
1124-
* @retval 0 in case of success, an error code otherwise
1125-
*/
1126-
ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_GetFreeFallThreshold(uint8_t *Threshold)
1127-
{
1128-
ISM330DHCXStatusTypeDef ret = ISM330DHCX_OK;
1129-
ism330dhcx_ff_ths_t ff_th;
1130-
1131-
/* Read actual full scale */
1132-
if (ism330dhcx_ff_threshold_get(&reg_ctx, &ff_th) != ISM330DHCX_OK) {
1133-
return ISM330DHCX_ERROR;
1134-
}
1135-
1136-
switch (ff_th) {
1137-
case ISM330DHCX_FF_TSH_156mg:
1138-
*Threshold = 0;
1139-
break;
1140-
1141-
case ISM330DHCX_FF_TSH_219mg:
1142-
*Threshold = 1;
1143-
break;
1144-
1145-
case ISM330DHCX_FF_TSH_250mg:
1146-
*Threshold = 2;
1147-
break;
1148-
1149-
case ISM330DHCX_FF_TSH_312mg:
1150-
*Threshold = 3;
1151-
break;
1152-
1153-
case ISM330DHCX_FF_TSH_344mg:
1154-
*Threshold = 4;
1155-
break;
1156-
1157-
case ISM330DHCX_FF_TSH_406mg:
1158-
*Threshold = 5;
1159-
break;
1160-
case ISM330DHCX_FF_TSH_469mg:
1161-
*Threshold = 6;
1162-
break;
1163-
case ISM330DHCX_FF_TSH_500mg:
1164-
*Threshold = 7;
1165-
break;
1166-
default:
1167-
ret = ISM330DHCX_ERROR;
1168-
break;
1169-
}
1170-
1171-
return ret;
1172-
}
1173-
1174-
/*
1175-
* @brief Get the Duration for the Free Fall event
1176-
* @param Duration pointer
1177-
* @retval 0 in case of success, an error code otherwise
1178-
*/
1179-
ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_GetFreeFallDuration(uint8_t *Duration)
1180-
{
1181-
if (ism330dhcx_ff_dur_get(&reg_ctx, Duration) != ISM330DHCX_OK) {
1182-
return ISM330DHCX_ERROR;
1183-
}
1184-
1185-
return ISM330DHCX_OK;
1186-
}
1187-
11881113
/*
11891114
* @brief Enable the detection of the Wake Up event
11901115
* @retval 0 in case of success, an error code otherwise
@@ -1331,7 +1256,6 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::ACC_EnableSingleTapDetection(ISM330DHC
13311256
ISM330DHCXStatusTypeDef ret = ISM330DHCX_OK;
13321257
ism330dhcx_pin_int1_route_t val1;
13331258
ism330dhcx_pin_int2_route_t val2;
1334-
ism330dhcx_wake_up_ths_t wkup;
13351259

13361260
/* Output Data Rate selection */
13371261
if (ACC_SetOutputDataRate(417.0f) != ISM330DHCX_OK) {
@@ -2162,7 +2086,7 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::FIFO_Get_Data(uint8_t *Data)
21622086
* @param Acceleration FIFO accelerometer axes [mg]
21632087
* @retval 0 in case of success, an error code otherwise
21642088
*/
2165-
ISM330DHCXStatusTypeDef ISM330DHCXSensor::FIFO_ACC_Get_Axes(ISM330DHCX_Axes_t *Acceleration)
2089+
ISM330DHCXStatusTypeDef ISM330DHCXSensor::FIFO_ACC_Get_Axes(int32_t *Acceleration)
21662090
{
21672091
uint8_t data[6];
21682092
int16_t data_raw[3];
@@ -2185,9 +2109,9 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::FIFO_ACC_Get_Axes(ISM330DHCX_Axes_t *A
21852109
acceleration_float[1] = (float)data_raw[1] * sensitivity;
21862110
acceleration_float[2] = (float)data_raw[2] * sensitivity;
21872111

2188-
Acceleration->x = (int32_t)acceleration_float[0];
2189-
Acceleration->y = (int32_t)acceleration_float[1];
2190-
Acceleration->z = (int32_t)acceleration_float[2];
2112+
Acceleration[0] = (int32_t)acceleration_float[0];
2113+
Acceleration[1] = (int32_t)acceleration_float[1];
2114+
Acceleration[2] = (int32_t)acceleration_float[2];
21912115

21922116
return ISM330DHCX_OK;
21932117
}
@@ -2197,7 +2121,7 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::FIFO_ACC_Get_Axes(ISM330DHCX_Axes_t *A
21972121
* @param AngularVelocity FIFO gyroscope axes [mDPS]
21982122
* @retval 0 in case of success, an error code otherwise
21992123
*/
2200-
ISM330DHCXStatusTypeDef ISM330DHCXSensor::FIFO_GYRO_Get_Axes(ISM330DHCX_Axes_t *AngularVelocity)
2124+
ISM330DHCXStatusTypeDef ISM330DHCXSensor::FIFO_GYRO_Get_Axes(int32_t *AngularVelocity)
22012125
{
22022126
uint8_t data[6];
22032127
int16_t data_raw[3];
@@ -2220,9 +2144,9 @@ ISM330DHCXStatusTypeDef ISM330DHCXSensor::FIFO_GYRO_Get_Axes(ISM330DHCX_Axes_t *
22202144
angular_velocity_float[1] = (float)data_raw[1] * sensitivity;
22212145
angular_velocity_float[2] = (float)data_raw[2] * sensitivity;
22222146

2223-
AngularVelocity->x = (int32_t)angular_velocity_float[0];
2224-
AngularVelocity->y = (int32_t)angular_velocity_float[1];
2225-
AngularVelocity->z = (int32_t)angular_velocity_float[2];
2147+
AngularVelocity[0] = (int32_t)angular_velocity_float[0];
2148+
AngularVelocity[1] = (int32_t)angular_velocity_float[1];
2149+
AngularVelocity[2] = (int32_t)angular_velocity_float[2];
22262150

22272151
return ISM330DHCX_OK;
22282152
}

0 commit comments

Comments
 (0)