啊,PROGMEM,指针,指向指针的指针,指针的地址......我的头晕了。
我有相关字体的数据数组
const uint8_t dejaVuSans9ptBitmaps[] =
{
/* @0 ' ' (5 pixels wide) */
0x00, /* */
0x00, /* */
...
我在其中添加了 PROGMEM
const uint8_t dejaVuSans9ptBitmaps[] PROGMEM =
这在另一个类似的结构中被引用;
const FONT_INFO dejaVuSans9ptFontInfo = {
13,
' ',
'~',
dejaVuSans9ptDescriptors,
dejaVuSans9ptBitmaps,
};
结构定义为;
typedef struct {
const uint8_t height;
const uint8_t startChar;
const uint8_t endChar;
const FONT_CHAR_INFO* charInfo;
const uint8_t* data;
} FONT_INFO;
我是否正确假设这需要更改为;
typedef struct {
const uint8_t height;
const uint8_t startChar;
const uint8_t endChar;
const FONT_CHAR_INFO* charInfo;
const PGM_P data;
} FONT_INFO;
当我这样做时,它抱怨说
warning: pointer targets in initialization differ in signedness
对于 FONT_INFO 变量中的这一特定行;
const FONT_INFO dejaVuSans9ptFontInfo = {
13,
' ',
'~',
dejaVuSans9ptDescriptors,
--> dejaVuSans9ptBitmaps, <--
};
然后使用函数绘制;
void drawString(uint16_t x, uint16_t y, uint16_t color, const FONT_INFO *fontInfo, char *str) {
...
drawCharBitmap(currentX, y, color, &fontInfo->data[charOffset], charWidth, fontInfo->height);
...
最后绘制字形;
void drawCharBitmap(const uint16_t xPixel, const uint16_t yPixel, uint16_t color, const uint8_t *glyph, uint8_t cols, uint8_t rows) {
...
if (glyph[indexIntoGlyph] & (0X80)) drawPixel(currentX, currentY, color);
...
我在我头上:/谁能给我一些指导?我花了几个小时尝试使用 PGM_P 和 pgm_read_byte 等都无济于事 - 我总是在屏幕上看到垃圾。
救我!