More news on the latest improvements:
-
New EEPROM class with device abstraction allowing handling of common data types. Default device is the internal EEPROM. https://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/dc/d83/classEEPROM.html. See example sketch CosaEEPROM.ino Cosa/CosaEEPROM.ino at master · mikaelpatel/Cosa · GitHub
-
Refactoring of AT24CXX device driver to implement EEPROM::Device. Support for AT24C32, -64, -128, -256 and -512. See example sketch CosaAT24CXX.ino; uses EEMEM attribute even for external EEPROM. https://github.com/mikaelpatel/Cosa/blob/master/examples/TWI/CosaAT24CXX/CosaAT24CXX.ino.
-
Major update to the online documentation https://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/index.html. Improved detailed description of the classes.
-
Evaluation of different methods of coding bitfield access for C/C++ as alternative to the _BV() and bit set/clear macros (Bits.h). https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaBitfields/CosaBitfields.ino. Bit-field struct definitions are useful for larger bit-fields (> 1 bit) and the compiler can produce better code than with shift/and/or-operators.
First version with shift/and/or-operators.
uint16_t
color16b(uint8_t red, uint8_t green, uint8_t blue)
{
return ((((red >> 3) & 0x1f) << 11) | (((green >> 2) & 0x3f) << 5) | ((blue >> 3) & 0x1f));
}
00000284 <_Z8color16bhhh>:
284: 66 95 lsr r22
286: 66 95 lsr r22
288: 70 e0 ldi r23, 0x00 ; 0
28a: 95 e0 ldi r25, 0x05 ; 5
28c: 66 0f add r22, r22
28e: 77 1f adc r23, r23
290: 9a 95 dec r25
292: e1 f7 brne .-8 ; 0x28c <_Z8color16bhhh+0x8>
294: 46 95 lsr r20
296: 46 95 lsr r20
298: 46 95 lsr r20
29a: 50 e0 ldi r21, 0x00 ; 0
29c: 64 2b or r22, r20
29e: 75 2b or r23, r21
2a0: 38 2f mov r19, r24
2a2: 38 7f andi r19, 0xF8 ; 248
2a4: 20 e0 ldi r18, 0x00 ; 0
2a6: 62 2b or r22, r18
2a8: 73 2b or r23, r19
2aa: cb 01 movw r24, r22
2ac: 08 95 ret
Second version with union bit-field data type and struct member access. Note the order of the fields. AVR is little-endian (LSB to MSB) in struct.
union color16_t {
uint16_t rgb;
struct {
unsigned int blue:5;
unsigned int green:6;
unsigned int red:5;
};
};
uint16_t
color16a(uint8_t red, uint8_t green, uint8_t blue)
{
color16_t c;
c.red = red >> 3;
c.green = green >> 2;
c.blue = blue >> 3;
return (c.rgb);
}
000001e8 <_Z8color16ahhh>:
1e8: 70 e0 ldi r23, 0x00 ; 0
1ea: 75 95 asr r23
1ec: 67 95 ror r22
1ee: 75 95 asr r23
1f0: 67 95 ror r22
1f2: 26 2f mov r18, r22
1f4: 26 95 lsr r18
1f6: 26 95 lsr r18
1f8: 26 95 lsr r18
1fa: 27 70 andi r18, 0x07 ; 7
1fc: 98 2f mov r25, r24
1fe: 98 7f andi r25, 0xF8 ; 248
200: 50 e0 ldi r21, 0x00 ; 0
202: 83 e0 ldi r24, 0x03 ; 3
204: 55 95 asr r21
206: 47 95 ror r20
208: 8a 95 dec r24
20a: e1 f7 brne .-8 ; 0x204 <_Z8color16ahhh+0x1c>
20c: 4f 71 andi r20, 0x1F ; 31
20e: 62 95 swap r22
210: 66 0f add r22, r22
212: 60 7e andi r22, 0xE0 ; 224
214: 86 2f mov r24, r22
216: 84 2b or r24, r20
218: 92 2b or r25, r18
21a: 08 95 ret
- Refactoring of Canvas::color16_t handling to union with bit-field struct after the sandboxing. Improving coding style of bit-fields; Canvas color16_t handling. · mikaelpatel/Cosa@6f2e541 · GitHub
Don't forget to follow the blog. http://cosa-arduino.blogspot.se/
Have fun!