Skip to content

Commit 8bf2fbe

Browse files
committed
Implement ICM_20948_init_struct function that initializes ICM_20948_Device_t with _last_bank set to an invalid number
Refer to: #71
1 parent 486fdbf commit 8bf2fbe

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/ICM_20948.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ICM_20948_Status_e ICM_20948_read_SPI(uint8_t reg, uint8_t *buff, uint32_t len,
1212
// Base
1313
ICM_20948::ICM_20948()
1414
{
15+
status = ICM_20948_init_struct(&_device);
1516
}
1617

1718
void ICM_20948::enableDebugging(Stream &debugPort)

src/util/ICM_20948_C.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ const ICM_20948_Serif_t NullSerif = {
120120
// Private function prototypes
121121

122122
// Function definitions
123+
ICM_20948_Status_e ICM_20948_init_struct(ICM_20948_Device_t *pdev)
124+
{
125+
// Initialize all elements by 0 except for _last_bank
126+
// Initialize _last_bank to 4 (invalid bank number)
127+
// so ICM_20948_set_bank function does not skip issuing bank change operation
128+
static const ICM_20948_Device_t init_device = { ._last_bank = 4 };
129+
*pdev = init_device;
130+
return ICM_20948_Stat_Ok;
131+
}
132+
123133
ICM_20948_Status_e ICM_20948_link_serif(ICM_20948_Device_t *pdev, const ICM_20948_Serif_t *s)
124134
{
125135
if (s == NULL)

src/util/ICM_20948_C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ extern int memcmp(const void *, const void *, size_t); // Avoid compiler warning
184184
uint16_t _dataIntrCtl; // Diagnostics: record the setting of DATA_INTR_CTL
185185
} ICM_20948_Device_t; // Definition of device struct type
186186

187+
ICM_20948_Status_e ICM_20948_init_struct(ICM_20948_Device_t *pdev); // Initialize ICM_20948_Device_t
188+
187189
// ICM_20948_Status_e ICM_20948_Startup( ICM_20948_Device_t* pdev ); // For the time being this performs a standardized startup routine
188190

189191
ICM_20948_Status_e ICM_20948_link_serif(ICM_20948_Device_t *pdev, const ICM_20948_Serif_t *s); // Links a SERIF structure to the device

0 commit comments

Comments
 (0)