3 #include "sdcard_standard.h"
5 #define MIN(a, b) ((a) < (b) ? (a) : (b))
8 * Read a bitfield from an array of bits (the bit at index 0 being the most-significant bit of the first byte in
11 uint32_t readBitfield(uint8_t *buffer
, unsigned bitIndex
, unsigned bitLen
)
14 unsigned bitInByteOffset
= bitIndex
% 8;
17 buffer
+= bitIndex
/ 8;
19 // Align the bitfield to be read to the top of the buffer
20 bufferByte
= *buffer
<< bitInByteOffset
;
23 unsigned bitsThisLoop
= MIN(8 - bitInByteOffset
, bitLen
);
25 result
= (result
<< bitsThisLoop
) | (bufferByte
>> (8 - bitsThisLoop
));
30 bitLen
-= bitsThisLoop
;