Skip to content

Commit b003d40

Browse files
authored
Merge pull request #72 from peterleif/init-device-struct
ICM_20948_Device_t with _last_bank set to an invalid number
2 parents 3ac7f8b + 34022a2 commit b003d40

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

examples/PortableC/Example999_Portable/Example999_Portable.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ void setup()
7272
WIRE_PORT.setClock(400000);
7373
#endif
7474

75+
// Initialize myICM
76+
ICM_20948_init_struct(&myICM);
77+
7578
// Link the serif
7679
ICM_20948_link_serif(&myICM, &mySerif);
7780

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
@@ -122,6 +122,16 @@ const ICM_20948_Serif_t NullSerif = {
122122
// Private function prototypes
123123

124124
// Function definitions
125+
ICM_20948_Status_e ICM_20948_init_struct(ICM_20948_Device_t *pdev)
126+
{
127+
// Initialize all elements by 0 except for _last_bank
128+
// Initialize _last_bank to 4 (invalid bank number)
129+
// so ICM_20948_set_bank function does not skip issuing bank change operation
130+
static const ICM_20948_Device_t init_device = { ._last_bank = 4 };
131+
*pdev = init_device;
132+
return ICM_20948_Stat_Ok;
133+
}
134+
125135
ICM_20948_Status_e ICM_20948_link_serif(ICM_20948_Device_t *pdev, const ICM_20948_Serif_t *s)
126136
{
127137
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)