Skip to content

Commit 72c2d3b

Browse files
committed
Remove redundant sleeps and low powers from DMP upload
1 parent 552b502 commit 72c2d3b

File tree

2 files changed

+40
-102
lines changed

2 files changed

+40
-102
lines changed

src/util/ICM_20948_C.c

Lines changed: 39 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,18 @@ ICM_20948_Status_e inv_icm20948_firmware_load(ICM_20948_Device_t *pdev, const un
891891
if(pdev->_firmware_loaded)
892892
return ICM_20948_Stat_Ok; // Bail with no error if firmware is already loaded
893893

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+
894906
// Write DMP memory
895907

896908
data = data_start;
@@ -939,6 +951,12 @@ ICM_20948_Status_e inv_icm20948_firmware_load(ICM_20948_Device_t *pdev, const un
939951
memaddr += write_size;
940952
}
941953

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+
942960
// if(!flag)
943961
// Serial.println("DMP Firmware was updated successfully..");
944962

@@ -960,43 +978,24 @@ ICM_20948_Status_e inv_icm20948_write_mems(ICM_20948_Device_t *pdev, unsigned sh
960978
unsigned char lBankSelected;
961979
unsigned char lStartAddrSelected;
962980

963-
// unsigned char power_state = inv_icm20948_get_chip_power_state(s);
964-
965981
if(!data)
982+
{
966983
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+
}
982985

983986
result = ICM_20948_set_bank(pdev, 0); // Set bank 0
984987
if (result != ICM_20948_Stat_Ok)
988+
{
985989
return result;
990+
}
986991

987992
lBankSelected = (reg >> 8);
988993

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-
997994
result = ICM_20948_execute_w(pdev, AGB0_REG_MEM_BANK_SEL, &lBankSelected, 1);
998995
if (result != ICM_20948_Stat_Ok)
996+
{
999997
return result;
998+
}
1000999

10011000
while (bytesWritten < length)
10021001
{
@@ -1007,42 +1006,29 @@ ICM_20948_Status_e inv_icm20948_write_mems(ICM_20948_Device_t *pdev, unsigned sh
10071006
This register must be written prior to each access to initialize the register to the proper starting address.
10081007
The address will auto increment during burst transactions. Two consecutive bursts without re-initializing the start address would skip one address. */
10091008

1010-
// result |= inv_icm20948_write_reg(s, REG_MEM_START_ADDR, &lStartAddrSelected, 1);
1011-
// if (result)
1012-
// return result;
1013-
10141009
result = ICM_20948_execute_w(pdev, AGB0_REG_MEM_START_ADDR, &lStartAddrSelected, 1);
10151010
if (result != ICM_20948_Stat_Ok)
1011+
{
10161012
return result;
1013+
}
10171014

1018-
//thisLen = min(INV_MAX_SERIAL_WRITE, length-bytesWritten);
10191015
if (length-bytesWritten <= INV_MAX_SERIAL_WRITE)
10201016
thisLen = length-bytesWritten;
10211017
else
10221018
thisLen = INV_MAX_SERIAL_WRITE;
10231019

10241020
/* Write data */
10251021

1026-
// result |= inv_icm20948_write_reg(s, REG_MEM_R_W, &data[bytesWritten], thisLen);
1027-
// if (result)
1028-
// return result;
1029-
10301022
result = ICM_20948_execute_w(pdev, AGB0_REG_MEM_R_W, (uint8_t *)&data[bytesWritten], thisLen);
10311023
if (result != ICM_20948_Stat_Ok)
1024+
{
10321025
return result;
1026+
}
10331027

10341028
bytesWritten += thisLen;
10351029
reg += thisLen;
10361030
}
10371031

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-
10461032
return result;
10471033
}
10481034

@@ -1058,50 +1044,27 @@ ICM_20948_Status_e inv_icm20948_read_mems(ICM_20948_Device_t *pdev, unsigned sho
10581044
ICM_20948_Status_e result = ICM_20948_Stat_Ok;
10591045
unsigned int bytesWritten = 0;
10601046
unsigned int thisLen;
1061-
//unsigned char i;
10621047
unsigned char lBankSelected;
10631048
unsigned char lStartAddrSelected;
10641049

1065-
// unsigned char dat[INV_MAX_SERIAL_READ] = {0};
1066-
1067-
// unsigned char power_state = inv_icm20948_get_chip_power_state(s);
1068-
10691050
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+
}
10871054

10881055
result = ICM_20948_set_bank(pdev, 0); // Set bank 0
10891056
if (result != ICM_20948_Stat_Ok)
1057+
{
10901058
return result;
1059+
}
10911060

10921061
lBankSelected = (reg >> 8);
10931062

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-
11021063
result = ICM_20948_execute_w(pdev, AGB0_REG_MEM_BANK_SEL, &lBankSelected, 1);
11031064
if (result != ICM_20948_Stat_Ok)
1065+
{
11041066
return result;
1067+
}
11051068

11061069
while (bytesWritten < length)
11071070
{
@@ -1112,54 +1075,29 @@ ICM_20948_Status_e inv_icm20948_read_mems(ICM_20948_Device_t *pdev, unsigned sho
11121075
This register must be written prior to each access to initialize the register to the proper starting address.
11131076
The address will auto increment during burst transactions. Two consecutive bursts without re-initializing the start address would skip one address. */
11141077

1115-
// result |= inv_icm20948_write_reg(s, REG_MEM_START_ADDR, &lStartAddrSelected, 1);
1116-
// if (result)
1117-
// return result;
1118-
11191078
result = ICM_20948_execute_w(pdev, AGB0_REG_MEM_START_ADDR, &lStartAddrSelected, 1);
11201079
if (result != ICM_20948_Stat_Ok)
1080+
{
11211081
return result;
1082+
}
11221083

1123-
//thisLen = min(INV_MAX_SERIAL_READ, length-bytesWritten);
11241084
if (length-bytesWritten <= INV_MAX_SERIAL_READ)
11251085
thisLen = length-bytesWritten;
11261086
else
11271087
thisLen = INV_MAX_SERIAL_READ;
11281088

11291089
/* Read data */
11301090

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-
11391091
result = ICM_20948_execute_r(pdev, AGB0_REG_MEM_R_W, &data[bytesWritten], thisLen);
11401092
if (result != ICM_20948_Stat_Ok)
1093+
{
11411094
return result;
1095+
}
11421096

11431097
bytesWritten += thisLen;
11441098
reg += thisLen;
11451099
}
11461100

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-
11631101
return result;
11641102
}
11651103

src/util/ICM_20948_C.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C"
2525
extern int memcmp(const void *, const void *, size_t); // Avoid compiler warnings
2626

2727
// Define if the DMP will be supported
28-
// Note: you must have 93KBytes of memory available to store the DMP firmware!
28+
// Note: you must have 14290 Bytes of program memory available to store the DMP firmware!
2929
#define ICM_20948_USE_DMP // Uncomment this line to enable DMP support.
3030

3131
#define ICM_20948_I2C_ADDR_AD0 0x68 // Or 0x69 when AD0 is high

0 commit comments

Comments
 (0)