mbolivar - I assume there is nothing to stop us just using hardware.c directly. Correct?
Maybe, at some point in the future, factor out from hardware.c the flash functions, and put into their own file so that the Maple library API can use them too?
structuresound - I'd just use hardware.c directly.
All you need to do is pack 4 bytes into an unsigned int, or uint32 to avoid possible confusion.
Packing can be done at the bit level with shifts, and's and or's, or you could try it with a union
. You likely know this, but for the benefit of readers who follow ...
Whenever I use a union
, I always do a quick check to make sure it is going to work the way I want, e.g.
void loop() {
union { uint32 ui; uint8 ub[4]; } u;
if ( sizeof(u) == 4 ) { // Yipee, game on
SerialUSB.print("sizeof(u) is correctly reported as 4 bytes: ");
SerialUSB.println(sizeof(u));
} else {
SerialUSB.print("Unions will not work, sizeof(u) is not 4 bytes, it is reported as: ");
SerialUSB.println(sizeof(u));
}
}
I do the check because the C standard says that the behaviour of unions is implementation defined, so it can vary from compiler to compiler. But, IMHO, if it does work, byte packing using a union is easier to understand than bit packing.
EDIT: WARNING - I have not tested this code.