Skip to content

Commit 486fdbf

Browse files
authored
Merge pull request #70 from sparkfun/release_candidate
v1.2.7 - adding DMP PROGMEM support for old AVR platforms like the ATmega2560
2 parents d0b72df + e346076 commit 486fdbf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun 9DoF IMU Breakout - ICM 20948 - Arduino Library
2-
version=1.2.6
2+
version=1.2.7
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
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 for: src/util/ICM_20948_C.c

+21
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
* Provide such images by mean of a byte array
88
*/
99
#if defined(ICM_20948_USE_DMP) // Only include the 14301 Bytes of DMP if ICM_20948_USE_DMP is defined
10+
11+
#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) // Store the DMP firmware in PROGMEM on older AVR (ATmega) platforms
12+
#define ICM_20948_USE_PROGMEM_FOR_DMP
13+
#include <avr/pgmspace.h>
14+
const uint8_t dmp3_image[] PROGMEM = {
15+
#else
1016
const uint8_t dmp3_image[] = {
17+
#endif
18+
1119
#include "icm20948_img.dmp3a.h"
1220
};
1321
#endif
@@ -1249,6 +1257,9 @@ ICM_20948_Status_e inv_icm20948_firmware_load(ICM_20948_Device_t *pdev, const un
12491257
data = data_start;
12501258
size = size_start;
12511259
memaddr = load_addr;
1260+
#ifdef ICM_20948_USE_PROGMEM_FOR_DMP
1261+
unsigned char data_not_pg[INV_MAX_SERIAL_READ]; // Suggested by @HyperKokichi in Issue #63
1262+
#endif
12521263
while (size > 0)
12531264
{
12541265
//write_size = min(size, INV_MAX_SERIAL_WRITE); // Write in chunks of INV_MAX_SERIAL_WRITE
@@ -1261,7 +1272,12 @@ ICM_20948_Status_e inv_icm20948_firmware_load(ICM_20948_Device_t *pdev, const un
12611272
// Moved across a bank
12621273
write_size = (memaddr & 0xff) + write_size - 0x100;
12631274
}
1275+
#ifdef ICM_20948_USE_PROGMEM_FOR_DMP
1276+
memcpy_P(data_not_pg, data, write_size); // Suggested by @HyperKokichi in Issue #63
1277+
result = inv_icm20948_write_mems(pdev, memaddr, write_size, (unsigned char *)data_not_pg);
1278+
#else
12641279
result = inv_icm20948_write_mems(pdev, memaddr, write_size, (unsigned char *)data);
1280+
#endif
12651281
if (result != ICM_20948_Stat_Ok)
12661282
return result;
12671283
data += write_size;
@@ -1289,7 +1305,12 @@ ICM_20948_Status_e inv_icm20948_firmware_load(ICM_20948_Device_t *pdev, const un
12891305
result = inv_icm20948_read_mems(pdev, memaddr, write_size, data_cmp);
12901306
if (result != ICM_20948_Stat_Ok)
12911307
flag++; // Error, DMP not written correctly
1308+
#ifdef ICM_20948_USE_PROGMEM_FOR_DMP
1309+
memcpy_P(data_not_pg, data, write_size); // Suggested by @HyperKokichi in Issue #63
1310+
if (memcmp(data_cmp, data_not_pg, write_size))
1311+
#else
12921312
if (memcmp(data_cmp, data, write_size)) // Compare the data
1313+
#endif
12931314
return ICM_20948_Stat_DMPVerifyFail;
12941315
data += write_size;
12951316
size -= write_size;

0 commit comments

Comments
 (0)