@@ -891,6 +891,18 @@ ICM_20948_Status_e inv_icm20948_firmware_load(ICM_20948_Device_t *pdev, const un
891
891
if (pdev -> _firmware_loaded )
892
892
return ICM_20948_Stat_Ok ; // Bail with no error if firmware is already loaded
893
893
894
+ result = ICM_20948_sleep (pdev , false); // Make sure chip is awake
895
+ if (result != ICM_20948_Stat_Ok )
896
+ {
897
+ return result ;
898
+ }
899
+
900
+ result = ICM_20948_low_power (pdev , false); // Make sure chip is not in low power state
901
+ if (result != ICM_20948_Stat_Ok )
902
+ {
903
+ return result ;
904
+ }
905
+
894
906
// Write DMP memory
895
907
896
908
data = data_start ;
@@ -939,6 +951,12 @@ ICM_20948_Status_e inv_icm20948_firmware_load(ICM_20948_Device_t *pdev, const un
939
951
memaddr += write_size ;
940
952
}
941
953
954
+ //Enable LP_EN since we disabled it at begining of this function.
955
+
956
+ result = ICM_20948_low_power (pdev , true); // Put chip into low power state
957
+ if (result != ICM_20948_Stat_Ok )
958
+ return result ;
959
+
942
960
// if(!flag)
943
961
// Serial.println("DMP Firmware was updated successfully..");
944
962
@@ -960,43 +978,24 @@ ICM_20948_Status_e inv_icm20948_write_mems(ICM_20948_Device_t *pdev, unsigned sh
960
978
unsigned char lBankSelected ;
961
979
unsigned char lStartAddrSelected ;
962
980
963
- // unsigned char power_state = inv_icm20948_get_chip_power_state(s);
964
-
965
981
if (!data )
982
+ {
966
983
return ICM_20948_Stat_NoData ;
967
-
968
- // if((power_state & CHIP_AWAKE) == 0) // Wake up chip since it is asleep
969
- // result = inv_icm20948_set_chip_power_state(s, CHIP_AWAKE, 1);
970
-
971
- result = ICM_20948_sleep (pdev , false); // Make sure chip is awake
972
- if (result != ICM_20948_Stat_Ok )
973
- return result ;
974
-
975
- // result |= inv_icm20948_set_chip_power_state(s, CHIP_LP_ENABLE, 0);
976
-
977
- result = ICM_20948_low_power (pdev , false); // Make sure chip is not in low power state
978
- if (result != ICM_20948_Stat_Ok )
979
- return result ;
980
-
981
- // result |= inv_set_bank(s, 0);
984
+ }
982
985
983
986
result = ICM_20948_set_bank (pdev , 0 ); // Set bank 0
984
987
if (result != ICM_20948_Stat_Ok )
988
+ {
985
989
return result ;
990
+ }
986
991
987
992
lBankSelected = (reg >> 8 );
988
993
989
- // if (lBankSelected != s->lLastBankSelected)
990
- // {
991
- // result |= inv_icm20948_write_reg(s, REG_MEM_BANK_SEL, &lBankSelected, 1);
992
- // if (result)
993
- // return result;
994
- // s->lLastBankSelected = lBankSelected;
995
- // }
996
-
997
994
result = ICM_20948_execute_w (pdev , AGB0_REG_MEM_BANK_SEL , & lBankSelected , 1 );
998
995
if (result != ICM_20948_Stat_Ok )
996
+ {
999
997
return result ;
998
+ }
1000
999
1001
1000
while (bytesWritten < length )
1002
1001
{
@@ -1007,42 +1006,29 @@ ICM_20948_Status_e inv_icm20948_write_mems(ICM_20948_Device_t *pdev, unsigned sh
1007
1006
This register must be written prior to each access to initialize the register to the proper starting address.
1008
1007
The address will auto increment during burst transactions. Two consecutive bursts without re-initializing the start address would skip one address. */
1009
1008
1010
- // result |= inv_icm20948_write_reg(s, REG_MEM_START_ADDR, &lStartAddrSelected, 1);
1011
- // if (result)
1012
- // return result;
1013
-
1014
1009
result = ICM_20948_execute_w (pdev , AGB0_REG_MEM_START_ADDR , & lStartAddrSelected , 1 );
1015
1010
if (result != ICM_20948_Stat_Ok )
1011
+ {
1016
1012
return result ;
1013
+ }
1017
1014
1018
- //thisLen = min(INV_MAX_SERIAL_WRITE, length-bytesWritten);
1019
1015
if (length - bytesWritten <= INV_MAX_SERIAL_WRITE )
1020
1016
thisLen = length - bytesWritten ;
1021
1017
else
1022
1018
thisLen = INV_MAX_SERIAL_WRITE ;
1023
1019
1024
1020
/* Write data */
1025
1021
1026
- // result |= inv_icm20948_write_reg(s, REG_MEM_R_W, &data[bytesWritten], thisLen);
1027
- // if (result)
1028
- // return result;
1029
-
1030
1022
result = ICM_20948_execute_w (pdev , AGB0_REG_MEM_R_W , (uint8_t * )& data [bytesWritten ], thisLen );
1031
1023
if (result != ICM_20948_Stat_Ok )
1024
+ {
1032
1025
return result ;
1026
+ }
1033
1027
1034
1028
bytesWritten += thisLen ;
1035
1029
reg += thisLen ;
1036
1030
}
1037
1031
1038
- //Enable LP_EN since we disabled it at begining of this function.
1039
-
1040
- // result |= inv_icm20948_set_chip_power_state(s, CHIP_LP_ENABLE, 1);
1041
-
1042
- result = ICM_20948_low_power (pdev , true); // Put chip into low power state
1043
- if (result != ICM_20948_Stat_Ok )
1044
- return result ;
1045
-
1046
1032
return result ;
1047
1033
}
1048
1034
@@ -1058,50 +1044,27 @@ ICM_20948_Status_e inv_icm20948_read_mems(ICM_20948_Device_t *pdev, unsigned sho
1058
1044
ICM_20948_Status_e result = ICM_20948_Stat_Ok ;
1059
1045
unsigned int bytesWritten = 0 ;
1060
1046
unsigned int thisLen ;
1061
- //unsigned char i;
1062
1047
unsigned char lBankSelected ;
1063
1048
unsigned char lStartAddrSelected ;
1064
1049
1065
- // unsigned char dat[INV_MAX_SERIAL_READ] = {0};
1066
-
1067
- // unsigned char power_state = inv_icm20948_get_chip_power_state(s);
1068
-
1069
1050
if (!data )
1070
- return ICM_20948_Stat_NoData ;
1071
-
1072
- // if((power_state & CHIP_AWAKE) == 0) // Wake up chip since it is asleep
1073
- // result = inv_icm20948_set_chip_power_state(s, CHIP_AWAKE, 1);
1074
-
1075
- result = ICM_20948_sleep (pdev , false); // Make sure chip is awake
1076
- if (result != ICM_20948_Stat_Ok )
1077
- return result ;
1078
-
1079
- // if(check_reg_access_lp_disable(s, reg))
1080
- // result |= inv_icm20948_set_chip_power_state(s, CHIP_LP_ENABLE, 0);
1081
-
1082
- result = ICM_20948_low_power (pdev , false); // Make sure chip is not in low power state
1083
- if (result != ICM_20948_Stat_Ok )
1084
- return result ;
1085
-
1086
- // result |= inv_set_bank(s, 0);
1051
+ {
1052
+ return ICM_20948_Stat_NoData ;
1053
+ }
1087
1054
1088
1055
result = ICM_20948_set_bank (pdev , 0 ); // Set bank 0
1089
1056
if (result != ICM_20948_Stat_Ok )
1057
+ {
1090
1058
return result ;
1059
+ }
1091
1060
1092
1061
lBankSelected = (reg >> 8 );
1093
1062
1094
- // if (lBankSelected != s->lLastBankSelected)
1095
- // {
1096
- // result |= inv_icm20948_write_reg(s, REG_MEM_BANK_SEL, &lBankSelected, 1);
1097
- // if (result)
1098
- // return result;
1099
- // s->lLastBankSelected = lBankSelected;
1100
- // }
1101
-
1102
1063
result = ICM_20948_execute_w (pdev , AGB0_REG_MEM_BANK_SEL , & lBankSelected , 1 );
1103
1064
if (result != ICM_20948_Stat_Ok )
1065
+ {
1104
1066
return result ;
1067
+ }
1105
1068
1106
1069
while (bytesWritten < length )
1107
1070
{
@@ -1112,54 +1075,29 @@ ICM_20948_Status_e inv_icm20948_read_mems(ICM_20948_Device_t *pdev, unsigned sho
1112
1075
This register must be written prior to each access to initialize the register to the proper starting address.
1113
1076
The address will auto increment during burst transactions. Two consecutive bursts without re-initializing the start address would skip one address. */
1114
1077
1115
- // result |= inv_icm20948_write_reg(s, REG_MEM_START_ADDR, &lStartAddrSelected, 1);
1116
- // if (result)
1117
- // return result;
1118
-
1119
1078
result = ICM_20948_execute_w (pdev , AGB0_REG_MEM_START_ADDR , & lStartAddrSelected , 1 );
1120
1079
if (result != ICM_20948_Stat_Ok )
1080
+ {
1121
1081
return result ;
1082
+ }
1122
1083
1123
- //thisLen = min(INV_MAX_SERIAL_READ, length-bytesWritten);
1124
1084
if (length - bytesWritten <= INV_MAX_SERIAL_READ )
1125
1085
thisLen = length - bytesWritten ;
1126
1086
else
1127
1087
thisLen = INV_MAX_SERIAL_READ ;
1128
1088
1129
1089
/* Read data */
1130
1090
1131
- // if(s->base_state.serial_interface == SERIAL_INTERFACE_SPI) {
1132
- // result |= inv_icm20948_read_reg(s, REG_MEM_R_W, &dat[bytesWritten], thisLen);
1133
- // } else {
1134
- // result |= inv_icm20948_read_reg(s, REG_MEM_R_W, &data[bytesWritten], thisLen);
1135
- // }
1136
- // if (result)
1137
- // return result;
1138
-
1139
1091
result = ICM_20948_execute_r (pdev , AGB0_REG_MEM_R_W , & data [bytesWritten ], thisLen );
1140
1092
if (result != ICM_20948_Stat_Ok )
1093
+ {
1141
1094
return result ;
1095
+ }
1142
1096
1143
1097
bytesWritten += thisLen ;
1144
1098
reg += thisLen ;
1145
1099
}
1146
1100
1147
- // if(s->base_state.serial_interface == SERIAL_INTERFACE_SPI) {
1148
- // for (i=0; i< length; i++) {
1149
- // *data= dat[i];
1150
- // data++;
1151
- // }
1152
- // }
1153
-
1154
- //Enable LP_EN if we disabled it at begining of this function.
1155
-
1156
- // if(check_reg_access_lp_disable(s, reg))
1157
- // result |= inv_icm20948_set_chip_power_state(s, CHIP_LP_ENABLE, 1);
1158
-
1159
- result = ICM_20948_low_power (pdev , true); // Put chip into low power state
1160
- if (result != ICM_20948_Stat_Ok )
1161
- return result ;
1162
-
1163
1101
return result ;
1164
1102
}
1165
1103
0 commit comments