From 3ac7f8b7244a35dbcd03872d6a935e95347a3225 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Sun, 30 May 2021 11:44:59 +0100 Subject: [PATCH 1/5] Fix to allow the DMP code to compile on Apollo3 v2 --- library.properties | 2 +- src/util/ICM_20948_C.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index bf7d5a0..b0dab8f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun 9DoF IMU Breakout - ICM 20948 - Arduino Library -version=1.2.7 +version=1.2.8 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Use the low-power high-resolution ICM 20948 9 DoF IMU from Invensense with I2C or SPI. Version 1.2 of the library includes support for the InvenSense Digital Motion Processor (DMP™). diff --git a/src/util/ICM_20948_C.c b/src/util/ICM_20948_C.c index 44d6ac4..fd10b27 100644 --- a/src/util/ICM_20948_C.c +++ b/src/util/ICM_20948_C.c @@ -8,7 +8,9 @@ */ #if defined(ICM_20948_USE_DMP) // Only include the 14301 Bytes of DMP if ICM_20948_USE_DMP is defined -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) // Store the DMP firmware in PROGMEM on older AVR (ATmega) platforms +#if defined(ARDUINO_ARCH_MBED) // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM +const uint8_t dmp3_image[] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) // Store the DMP firmware in PROGMEM on older AVR (ATmega) platforms #define ICM_20948_USE_PROGMEM_FOR_DMP #include const uint8_t dmp3_image[] PROGMEM = { From 8bf2fbe6e083504281cbfaed002ce2ba7c9acda8 Mon Sep 17 00:00:00 2001 From: Etsushi Nozaki Date: Mon, 7 Jun 2021 17:30:42 +0900 Subject: [PATCH 2/5] Implement ICM_20948_init_struct function that initializes ICM_20948_Device_t with _last_bank set to an invalid number Refer to: https://github.com/sparkfun/SparkFun_ICM-20948_ArduinoLibrary/issues/71 --- src/ICM_20948.cpp | 1 + src/util/ICM_20948_C.c | 10 ++++++++++ src/util/ICM_20948_C.h | 2 ++ 3 files changed, 13 insertions(+) diff --git a/src/ICM_20948.cpp b/src/ICM_20948.cpp index 1f534c2..0e19913 100644 --- a/src/ICM_20948.cpp +++ b/src/ICM_20948.cpp @@ -12,6 +12,7 @@ ICM_20948_Status_e ICM_20948_read_SPI(uint8_t reg, uint8_t *buff, uint32_t len, // Base ICM_20948::ICM_20948() { + status = ICM_20948_init_struct(&_device); } void ICM_20948::enableDebugging(Stream &debugPort) diff --git a/src/util/ICM_20948_C.c b/src/util/ICM_20948_C.c index 44d6ac4..2fa711f 100644 --- a/src/util/ICM_20948_C.c +++ b/src/util/ICM_20948_C.c @@ -120,6 +120,16 @@ const ICM_20948_Serif_t NullSerif = { // Private function prototypes // Function definitions +ICM_20948_Status_e ICM_20948_init_struct(ICM_20948_Device_t *pdev) +{ + // Initialize all elements by 0 except for _last_bank + // Initialize _last_bank to 4 (invalid bank number) + // so ICM_20948_set_bank function does not skip issuing bank change operation + static const ICM_20948_Device_t init_device = { ._last_bank = 4 }; + *pdev = init_device; + return ICM_20948_Stat_Ok; +} + ICM_20948_Status_e ICM_20948_link_serif(ICM_20948_Device_t *pdev, const ICM_20948_Serif_t *s) { if (s == NULL) diff --git a/src/util/ICM_20948_C.h b/src/util/ICM_20948_C.h index 088a714..c732ebc 100644 --- a/src/util/ICM_20948_C.h +++ b/src/util/ICM_20948_C.h @@ -184,6 +184,8 @@ extern int memcmp(const void *, const void *, size_t); // Avoid compiler warning uint16_t _dataIntrCtl; // Diagnostics: record the setting of DATA_INTR_CTL } ICM_20948_Device_t; // Definition of device struct type + ICM_20948_Status_e ICM_20948_init_struct(ICM_20948_Device_t *pdev); // Initialize ICM_20948_Device_t + // ICM_20948_Status_e ICM_20948_Startup( ICM_20948_Device_t* pdev ); // For the time being this performs a standardized startup routine 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 From 34022a2365d75c75ae515fa81915f11b1e983932 Mon Sep 17 00:00:00 2001 From: Etsushi Nozaki Date: Mon, 7 Jun 2021 17:31:11 +0900 Subject: [PATCH 3/5] Update the Portable C example to use ICM_20948_init_struct --- examples/PortableC/Example999_Portable/Example999_Portable.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/PortableC/Example999_Portable/Example999_Portable.ino b/examples/PortableC/Example999_Portable/Example999_Portable.ino index d1e59dc..92a49c5 100644 --- a/examples/PortableC/Example999_Portable/Example999_Portable.ino +++ b/examples/PortableC/Example999_Portable/Example999_Portable.ino @@ -72,6 +72,9 @@ void setup() WIRE_PORT.setClock(400000); #endif + // Initialize myICM + ICM_20948_init_struct(&myICM); + // Link the serif ICM_20948_link_serif(&myICM, &mySerif); From 787f5dc5dc815c7a97ae8b52d2c502e9844c0941 Mon Sep 17 00:00:00 2001 From: spacecheese <12695808+spacecheese@users.noreply.github.com> Date: Thu, 15 Jul 2021 13:55:04 +0100 Subject: [PATCH 4/5] Don't include pgmspace header on linux targets --- src/util/ICM_20948_C.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/ICM_20948_C.c b/src/util/ICM_20948_C.c index 9c2f4cf..356e44f 100644 --- a/src/util/ICM_20948_C.c +++ b/src/util/ICM_20948_C.c @@ -10,7 +10,7 @@ #if defined(ARDUINO_ARCH_MBED) // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM const uint8_t dmp3_image[] = { -#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) // Store the DMP firmware in PROGMEM on older AVR (ATmega) platforms +#elif (defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)) && !defined(__linux__) // Store the DMP firmware in PROGMEM on older AVR (ATmega) platforms #define ICM_20948_USE_PROGMEM_FOR_DMP #include const uint8_t dmp3_image[] PROGMEM = { From 5ee49bcdf155a439f1184d2fcda1f6ffe51f9af7 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Mon, 26 Jul 2021 08:33:07 +0100 Subject: [PATCH 5/5] Update Example999_Portable.ino --- examples/PortableC/Example999_Portable/Example999_Portable.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/PortableC/Example999_Portable/Example999_Portable.ino b/examples/PortableC/Example999_Portable/Example999_Portable.ino index 92a49c5..ad58aa3 100644 --- a/examples/PortableC/Example999_Portable/Example999_Portable.ino +++ b/examples/PortableC/Example999_Portable/Example999_Portable.ino @@ -205,7 +205,6 @@ ICM_20948_Status_e my_read_i2c(uint8_t reg, uint8_t *buff, uint32_t len, void *u buff[i] = WIRE_PORT.read(); } } - WIRE_PORT.endTransmission(); return ICM_20948_Stat_Ok; }