Forum: Mikrocontroller und Digitale Elektronik invalid conversion from 'const char*' to 'char' [-fpermissive]


von Obi P. (Gast)


Lesenswert?

Hallo

Ich habe mir vor Kurzem einen TFT Touch Display von Adafruit zugelegt, 
programmiere diesen aber mit Atmel Studio 7 auf einem ATMega2560. Dazu 
habe ich die Beispiel Programme importiert und die Libraries eingefügt. 
Das hat alles funktioniert. Erst als ich Bitmaps benutzen wollte stieß 
ich auf einen Fehler bei dem ich nicht weiß wie ich diesen korrigieren 
sollte.

invalid conversion from 'const char*' to 'char' [-fpermissive] 57

1
/*Begining of Auto generated code by Atmel studio */
2
#include <Arduino.h>
3
4
/*End of auto generated code by Atmel studio */
5
6
/***************************************************
7
  This is our Bitmap drawing example for the Adafruit HX8357 Breakout
8
  ----> http://www.adafruit.com/products/2050
9
10
  Check out the links above for our tutorials and wiring diagrams
11
  These displays use SPI to communicate, 4 or 5 pins are required to
12
  interface (RST is optional)
13
  Adafruit invests time and resources providing this open source code,
14
  please support Adafruit and open-source hardware by purchasing
15
  products from Adafruit!
16
17
  Written by Limor Fried/Ladyada for Adafruit Industries.
18
  MIT license, all text above must be included in any redistribution
19
 ****************************************************/
20
21
22
#include <Adafruit_GFX.h>    // Core graphics library
23
#include "Adafruit_HX8357.h"
24
#include <SPI.h>
25
#include <SD.h>
26
27
//Beginning of Auto generated function prototypes by Atmel Studio
28
void setup(void );
29
void bmpDraw(char filename, uint8_t x, uint16_t y);
30
uint16_t read16(File f);
31
uint32_t read32(File f);
32
33
// TFT display and SD card will share the hardware SPI interface.
34
// Hardware SPI pins are specific to the Arduino board type and
35
// cannot be remapped to alternate pins.  For Arduino Uno,
36
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
37
38
#define TFT_DC 47
39
#define TFT_CS 46
40
41
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
42
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC);
43
44
#define SD_CS 44
45
46
void setup(void) {
47
  Serial.begin(9600);
48
49
  tft.begin(HX8357D);
50
  tft.fillScreen(HX8357_BLUE);
51
  
52
  Serial.print("Initializing SD card...");
53
  if (!SD.begin(SD_CS)) {
54
    Serial.println("failed!");
55
  }
56
  Serial.println("OK!");
57
58
 bmpDraw("jumpers.bmp", 0, 0);                //Hier tritt der Fehler auf
59
}
60
61
void loop() {
62
}
63
64
// This function opens a Windows Bitmap (BMP) file and
65
// displays it at the given coordinates.  It's sped up
66
// by reading many pixels worth of data at a time
67
// (rather than pixel by pixel).  Increasing the buffer
68
// size takes more of the Arduino's precious RAM but
69
// makes loading a little faster.  20 pixels seems a
70
// good balance.
71
72
#define BUFFPIXEL 20
73
74
void bmpDraw(char *filename, uint8_t x, uint16_t y) {
75
76
  File     bmpFile;
77
  int      bmpWidth, bmpHeight;   // W+H in pixels
78
  uint8_t  bmpDepth;              // Bit depth (currently must be 24)
79
  uint32_t bmpImageoffset;        // Start of image data in file
80
  uint32_t rowSize;               // Not always = bmpWidth; may have padding
81
  uint8_t  sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
82
  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer
83
  boolean  goodBmp = false;       // Set to true on valid header parse
84
  boolean  flip    = true;        // BMP is stored bottom-to-top
85
  int      w, h, row, col;
86
  uint8_t  r, g, b;
87
  uint32_t pos = 0, startTime = millis();
88
89
  if((x >= tft.width()) || (y >= tft.height())) return;
90
91
  Serial.println();
92
  Serial.print(F("Loading image '"));
93
  Serial.print(filename);
94
  Serial.println('\'');
95
96
  // Open requested file on SD card
97
  if ((bmpFile = SD.open(filename)) == NULL) {
98
    Serial.print(F("File not found"));
99
    return;
100
  }
101
102
  // Parse BMP header
103
  if(read16(bmpFile) == 0x4D42) { // BMP signature
104
    Serial.print(F("File size: ")); Serial.println(read32(bmpFile));
105
    (void)read32(bmpFile); // Read & ignore creator bytes
106
    bmpImageoffset = read32(bmpFile); // Start of image data
107
    Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
108
    // Read DIB header
109
    Serial.print(F("Header size: ")); Serial.println(read32(bmpFile));
110
    bmpWidth  = read32(bmpFile);
111
    bmpHeight = read32(bmpFile);
112
    if(read16(bmpFile) == 1) { // # planes -- must be '1'
113
      bmpDepth = read16(bmpFile); // bits per pixel
114
      Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
115
      if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
116
117
        goodBmp = true; // Supported BMP format -- proceed!
118
        Serial.print(F("Image size: "));
119
        Serial.print(bmpWidth);
120
        Serial.print('x');
121
        Serial.println(bmpHeight);
122
123
        // BMP rows are padded (if needed) to 4-byte boundary
124
        rowSize = (bmpWidth * 3 + 3) & ~3;
125
126
        // If bmpHeight is negative, image is in top-down order.
127
        // This is not canon but has been observed in the wild.
128
        if(bmpHeight < 0) {
129
          bmpHeight = -bmpHeight;
130
          flip      = false;
131
        }
132
133
        // Crop area to be loaded
134
        w = bmpWidth;
135
        h = bmpHeight;
136
        if((x+w-1) >= tft.width())  w = tft.width()  - x;
137
        if((y+h-1) >= tft.height()) h = tft.height() - y;
138
139
        // Set TFT address window to clipped image bounds
140
        tft.setAddrWindow(x, y, x+w-1, y+h-1);
141
142
        for (row=0; row<h; row++) { // For each scanline...
143
144
          // Seek to start of scan line.  It might seem labor-
145
          // intensive to be doing this on every line, but this
146
          // method covers a lot of gritty details like cropping
147
          // and scanline padding.  Also, the seek only takes
148
          // place if the file position actually needs to change
149
          // (avoids a lot of cluster math in SD library).
150
          if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
151
            pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
152
          else     // Bitmap is stored top-to-bottom
153
            pos = bmpImageoffset + row * rowSize;
154
          if(bmpFile.position() != pos) { // Need seek?
155
            bmpFile.seek(pos);
156
            buffidx = sizeof(sdbuffer); // Force buffer reload
157
          }
158
159
          for (col=0; col<w; col++) { // For each pixel...
160
            // Time to read more pixel data?
161
            if (buffidx >= sizeof(sdbuffer)) { // Indeed
162
              bmpFile.read(sdbuffer, sizeof(sdbuffer));
163
              buffidx = 0; // Set index to beginning
164
            }
165
166
            // Convert pixel from BMP to TFT format, push to display
167
            b = sdbuffer[buffidx++];
168
            g = sdbuffer[buffidx++];
169
            r = sdbuffer[buffidx++];
170
            tft.pushColor(tft.color565(r,g,b));
171
          } // end pixel
172
        } // end scanline
173
        Serial.print(F("Loaded in "));
174
        Serial.print(millis() - startTime);
175
        Serial.println(" ms");
176
      } // end goodBmp
177
    }
178
  }
179
180
  bmpFile.close();
181
  if(!goodBmp) Serial.println(F("BMP format not recognized."));
182
}
183
184
// These read 16- and 32-bit types from the SD card file.
185
// BMP data is stored little-endian, Arduino is little-endian too.
186
// May need to reverse subscript order if porting elsewhere.
187
188
uint16_t read16(File &f) {
189
  uint16_t result;
190
  ((uint8_t *)&result)[0] = f.read(); // LSB
191
  ((uint8_t *)&result)[1] = f.read(); // MSB
192
  return result;
193
}
194
195
uint32_t read32(File &f) {
196
  uint32_t result;
197
  ((uint8_t *)&result)[0] = f.read(); // LSB
198
  ((uint8_t *)&result)[1] = f.read();
199
  ((uint8_t *)&result)[2] = f.read();
200
  ((uint8_t *)&result)[3] = f.read(); // MSB
201
  return result;
202
}

von Peter II (Gast)


Lesenswert?

1
void bmpDraw(char *filename, uint8_t x, uint16_t y) {

passt nicht zu
1
void bmpDraw(char filename, uint8_t x, uint16_t y);

von Frank M. (ukw) (Moderator) Benutzerseite


Lesenswert?

> void bmpDraw(char filename, uint8_t x, uint16_t y);

Da fehlt ein Sternchen vor filename.

von Blackbird (Gast)


Lesenswert?

Obi P. schrieb:
> void bmpDraw(char filename, uint8_t x, uint16_t y);

Der Filename 'filename' besteht nur aus einem einzigen Zeichen?

Oder doch besser so:
1
void bmpDraw(char * filename, uint8_t x, uint16_t y);


Blackbird

von Obi P. (Gast)


Lesenswert?

Vielen Dank für die schnellen Antworten!

Leider werde ich nun von folgenden Fehlern überhäuft:

undefined reference to `SDLib::File::File()'
undefined reference to `SDLib::SD'
undefined reference to `SDLib::SD'
undefined reference to `SDLib::SDClass::open(char const*, unsigned 
char)'
undefined reference to `SDLib::File::operator bool()'
undefined reference to `read16(SDLib::File)'
undefined reference to `read32(SDLib::File)'
undefined reference to `read32(SDLib::File)'
undefined reference to `read32(SDLib::File)'
undefined reference to `read32(SDLib::File)'
undefined reference to `read16(SDLib::File)'
undefined reference to `read16(SDLib::File)'
undefined reference to `read32(SDLib::File)'
undefined reference to `SDLib::File::position()'
undefined reference to `SDLib::File::seek(unsigned long)'
undefined reference to `SDLib::File::read(void*, unsigned int)'
undefined reference to `SDLib::File::close()'
undefined reference to `SDLib::SD'
undefined reference to `SDLib::SD'
undefined reference to `SDLib::SDClass::begin(unsigned char)'


Heißt das, dass eine SD Library nicht gefunden wurde?

von Peter II (Gast)


Lesenswert?

Obi P. schrieb:
> Heißt das, dass eine SD Library nicht gefunden wurde?

ja

von Frank M. (ukw) (Moderator) Benutzerseite


Lesenswert?

Obi P. schrieb:
> Heißt das, dass eine SD Library nicht gefunden wurde?

Ja, oder die Sources dazu. Vermutlich liegen die dort, wo der 
Preprocessor auch die SD.h gefunden hat.

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Obi P. schrieb:
> Heißt das, dass eine SD Library nicht gefunden wurde?

Nicht zwingend, das kann auch bedeuten, daß das Sourcefile, das den 
nicht gefundenen Funktionen enthält, nicht übersetzt wurde oder das das 
Objektfile, das der Compiler aus diesem Sourcefile erzeugt wurde, 
nicht gelinkt hat.

Mit Libraries hat das nichts zu tun, oder hast Du Deinem Linkeraufruf 
etwas wie -lSD hinzugefügt?

von Obi P. (Gast)


Lesenswert?

Nein nicht dass ich wüsste...

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Dann wirst Du Dir die Projekteinstellungen Deines Entwicklungssystems 
ansehen müssen.

Jedes *.c (oder *.cpp)-Sourcefile wird vom Compiler separat übersetzt, 
dabei ensteht eine Objektdatei (üblicherweise *.o oder bei anderen 
Compilern auch *.obj). Der Linker bekommt eine Liste der zum Projekt 
gehörenden Objektdateien übergeben und zusätzlich noch Informationen 
über die zu verwendenden Libraries (wenn Du Funktionen aus math.h 
verwendest, wird die Linkeroption -lm verwendet, was die Verwendung 
Library libm.a zur Folge hat).

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.