Hallo,
ich habe ein kleines Problem mit PROGMEM und dem Auslesen innerhalb
einer Funktion. Bekomme da einfach nicht die richtigen Werte. Kompiler
meckert an der Stelle leider nicht.
1 #include <avr/pgmspace.h>
2 const uint8_t PROGMEM colorGreenBlue [ NUM_LEDS ][ 3 ] =
3 {
4 { 0x00 , 0xff , 0x00 },
5 { 0x00 , 0xff , 0x48 },
6 { 0x00 , 0xff , 0x90 },
7 { 0x00 , 0xff , 0xd8 },
8 { 0x00 , 0xd8 , 0xff },
9 { 0x00 , 0x90 , 0xff },
10 { 0x00 , 0x48 , 0xff },
11 { 0x00 , 0x00 , 0xff }
12 };
13
14 void leds_loadPattern ( struct cRGB * newPattern , const uint8_t * pattern , const uint8_t SIZE_OF_PATTERN )
15 {
16 for ( uint8_t i = 0 ; i < SIZE_OF_PATTERN ; i ++ ) {
17 newPattern [ i ]. r = pgm_read_byte ( pattern [ i ][ 0 ]);
18 newPattern [ i ]. g = pgm_read_byte ( pattern [ i ][ 1 ]);
19 newPattern [ i ]. b = pgm_read_byte ( pattern [ i ][ 2 ]);
20 }
21 }
22
23 // Aufruf innerhalb einer Funktion
24 struct cRGB color [ NUM_LEDS ];
25 leds_loadPattern ( color , ( uint8_t * ) colorWheel , NUM_LEDS );
von
Peter II (Gast)
23.01.2016 00:17
wenn ich die Doku richtig lesen fehlt ein &
http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
1 newPattern [ i ]. r = pgm_read_byte ( & pattern [ i ][ 0 ]);
1 void leds_loadPattern ( struct cRGB * newPattern , const uint8_t * pattern , const uint8_t SIZE_OF_PATTERN )
2 {
3 for ( uint8_t i = 0 ; i < SIZE_OF_PATTERN ; i ++ ) {
4 newPattern [ i ]. r = pgm_read_byte ( & ( pattern [ i ][ 0 ]));
5 newPattern [ i ]. g = pgm_read_byte ( & ( pattern [ i ][ 1 ]));
6 newPattern [ i ]. b = pgm_read_byte ( & ( pattern [ i ][ 2 ]));
7 }
8 }
9
10 // Aufruf
11 leds_loadPattern ( color , ( uint8_t * ) colorWheel , numLeds );
Bekomme hier noch den Fehler, welches sich auf die 3 Zeilen in der
for-Schleife beziehen
subscripted value is neither array nor pointer nor vector
Edit: So gehts 1 newPattern [ i ]. r = pgm_read_byte ( & ( pattern [ i * 3 + 0 ]));
Du hast ja auch beim Aufruf der Funktion explizit aus einem
2-dimensionalen ein 1-dimensionales gemacht.
1 #define NUM_LEDS 8
2
3 struct cRGB { uint8_t r , g , b ; };
4
5 typedef struct
6 {
7 struct cRGB rgb [ NUM_LEDS ];
8 } pattern_t ;
9
10 const __flash pattern_t colorGreenBlue =
11 {
12 {
13 { 0x00 , 0xff , 0x00 },
14 { 0x00 , 0xff , 0x48 },
15 { 0x00 , 0xff , 0x90 },
16 { 0x00 , 0xff , 0xd8 },
17 { 0x00 , 0xd8 , 0xff },
18 { 0x00 , 0x90 , 0xff },
19 { 0x00 , 0x48 , 0xff },
20 { 0x00 , 0x00 , 0xff }
21 }
22 };
23
24 void leds_loadPattern ( pattern_t * pattern , const __flash pattern_t * pattern0 )
25 {
26 * pattern = * pattern0 ;
27 }
28
29 void Aufruf_innerhalb_einer_Funktion ( void )
30 {
31 pattern_t color ;
32 leds_loadPattern ( & color , & colorGreenBlue );
33 }
Klappt jetzt alles?
Für neue Projekte empfehle ich __flash
https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html
Gruß Max
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.