啊,PROGMEM,指针,指向指针的指针,指针的地址...我的头很大。在FLASH中保留一个数据数组(字体) - 在AVR GCC中编程
我有用于所讨论的字体
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等无济于事 - 我总是在屏幕上看到垃圾。
救救我吧!
您是否尝试过审阅http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html的文档? – Jeff
@Jeff我当然了!我认为这更多的是通过我的指针和地址指针。我不知道什么时候告诉编译器从pgmspace读取。 – mriksman