From 393eb6c2ba5997c5f1379e1e20519c6b14998200 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Sun, 29 Sep 2013 09:15:24 +1000 Subject: [PATCH] Update usage of PROGMEM to Arduino 1.0.1 --- .gitignore | 1 + gen/genlookup.c | 2 +- libraries/DMD/Bitmap.cpp | 32 ++++++++++++------- libraries/DMD/Bitmap.h | 16 ++++++---- libraries/DMD/DejaVuSans9.h | 2 +- libraries/DMD/DejaVuSansBold9.h | 2 +- libraries/DMD/DejaVuSansItalic9.h | 2 +- libraries/DMD/Mono5x7.h | 2 +- .../examples/RunningFigure/RunningFigure.pde | 2 +- .../RunningFigureISR/RunningFigureISR.pde | 2 +- libraries/LCD/LCD.cpp | 2 +- libraries/LCD/ListField.h | 2 +- .../RTC/examples/AlarmClock/SetMelody.cpp | 2 +- libraries/RTC/examples/TestRTC/TestRTC.pde | 22 ++++++------- 14 files changed, 50 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 7797bdfb..f1f80112 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ backup *.swp +hardware diff --git a/gen/genlookup.c b/gen/genlookup.c index e0f8f163..dad4c91e 100644 --- a/gen/genlookup.c +++ b/gen/genlookup.c @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) // Dump the button mapping table for the selected bit count. bits = 5; - printf("static prog_uint8_t const buttonMappings[] PROGMEM = {\n"); + printf("static uint8_t const buttonMappings[] PROGMEM = {\n"); for (value2 = 0; value2 < (1 << bits); ++value2) { value = value2 << (10 - bits); value3 = value + (1 << (10 - bits)) - 1; diff --git a/libraries/DMD/Bitmap.cpp b/libraries/DMD/Bitmap.cpp index 00fccb7e..0180b2a5 100644 --- a/libraries/DMD/Bitmap.cpp +++ b/libraries/DMD/Bitmap.cpp @@ -47,6 +47,16 @@ * \sa Black, White */ +/** + * \typedef Bitmap::ProgMem + * \brief Type that represents a bitmap within program memory. + */ + +/** + * \typedef Bitmap::Font + * \brief Type that represents a font within program memory. + */ + /** * \var Bitmap::Black * \brief Color value corresponding to "black". @@ -412,14 +422,14 @@ void Bitmap::drawBitmap(int x, int y, const Bitmap &bitmap, Color color) * * \sa drawInvertedBitmap(), fill() */ -void Bitmap::drawBitmap(int x, int y, const prog_uint8_t *bitmap, Color color) +void Bitmap::drawBitmap(int x, int y, Bitmap::ProgMem bitmap, Color color) { uint8_t w = pgm_read_byte(bitmap); uint8_t s = (w + 7) >> 3; uint8_t h = pgm_read_byte(bitmap + 1); Color invColor = !color; for (uint8_t by = 0; by < h; ++by) { - const prog_uint8_t *line = bitmap + 2 + by * s; + const uint8_t *line = ((const uint8_t *)bitmap) + 2 + by * s; uint8_t mask = 0x80; uint8_t value = pgm_read_byte(line); for (uint8_t bx = 0; bx < w; ++bx) { @@ -448,7 +458,7 @@ void Bitmap::drawBitmap(int x, int y, const prog_uint8_t *bitmap, Color color) */ /** - * \fn void Bitmap::drawInvertedBitmap(int x, int y, const prog_uint8_t *bitmap) + * \fn void Bitmap::drawInvertedBitmap(int x, int y, Bitmap::ProgMem bitmap) * \brief Draws \a bitmap at (\a x, \a y) in inverted colors. * * This is a convenience function that is equivalent to @@ -458,14 +468,14 @@ void Bitmap::drawBitmap(int x, int y, const prog_uint8_t *bitmap, Color color) */ /** - * \fn const prog_uint8_t *Bitmap::font() const + * \fn Font Bitmap::font() const * \brief Returns the currently selected font, or null if none selected. * * \sa setFont(), drawText(), drawChar(), charWidth() */ /** - * \fn void Bitmap::setFont(const prog_uint8_t *font) + * \fn void Bitmap::setFont(Font font) * \brief Sets the \a font for use with drawText() and drawChar(). * * \code @@ -590,15 +600,15 @@ int Bitmap::drawChar(int x, int y, char ch) index -= first; uint8_t heightBytes = (height + 7) >> 3;; uint8_t width; - const prog_uint8_t *image; + const uint8_t *image; if (fontIsFixed(_font)) { // Fixed-width font. width = fontWidth(_font); - image = _font + 6 + index * heightBytes * width; + image = ((const uint8_t *)_font) + 6 + index * heightBytes * width; } else { // Variable-width font. width = pgm_read_byte(_font + 6 + index); - image = _font + 6 + count; + image = ((const uint8_t *)_font) + 6 + count; for (uint8_t temp = 0; temp < index; ++temp) { // Scan through all previous characters to find the starting // location for this one. @@ -772,7 +782,7 @@ void Bitmap::fill(int x, int y, int width, int height, Color color) * * \sa drawBitmap(), clear(), invert() */ -void Bitmap::fill(int x, int y, int width, int height, const prog_uint8_t *pattern, Color color) +void Bitmap::fill(int x, int y, int width, int height, Bitmap::ProgMem pattern, Color color) { uint8_t w = pgm_read_byte(pattern); uint8_t s = (w + 7) >> 3; @@ -781,8 +791,8 @@ void Bitmap::fill(int x, int y, int width, int height, const prog_uint8_t *patte return; Color invColor = !color; for (int tempy = 0; tempy < height; ++tempy) { - const prog_uint8_t *startLine = pattern + 2 + (tempy % h) * s; - const prog_uint8_t *line = startLine; + const uint8_t *startLine = ((const uint8_t *)pattern) + 2 + (tempy % h) * s; + const uint8_t *line = startLine; uint8_t mask = 0x80; uint8_t value = pgm_read_byte(line++); int bit = 0; diff --git a/libraries/DMD/Bitmap.h b/libraries/DMD/Bitmap.h index f2be2f0f..db0a2be3 100644 --- a/libraries/DMD/Bitmap.h +++ b/libraries/DMD/Bitmap.h @@ -38,6 +38,8 @@ public: bool isValid() const { return fb != 0; } typedef uint8_t Color; + typedef PGM_VOID_P ProgMem; + typedef PGM_VOID_P Font; static const Color Black = 0; static const Color White = 1; @@ -63,12 +65,12 @@ public: void drawFilledCircle(int centerX, int centerY, int radius, Color color = White); void drawBitmap(int x, int y, const Bitmap &bitmap, Color color = White); - void drawBitmap(int x, int y, const prog_uint8_t *bitmap, Color color = White); + void drawBitmap(int x, int y, Bitmap::ProgMem bitmap, Color color = White); void drawInvertedBitmap(int x, int y, const Bitmap &bitmap); - void drawInvertedBitmap(int x, int y, const prog_uint8_t *bitmap); + void drawInvertedBitmap(int x, int y, Bitmap::ProgMem bitmap); - const prog_uint8_t *font() const { return _font; } - void setFont(const prog_uint8_t *font) { _font = font; } + Font font() const { return _font; } + void setFont(Font font) { _font = font; } Color textColor() const { return _textColor; } void setTextColor(Color color) { _textColor = color; } @@ -85,7 +87,7 @@ public: void copy(int x, int y, int width, int height, Bitmap *dest, int destX, int destY); void fill(int x, int y, int width, int height, Color color); - void fill(int x, int y, int width, int height, const prog_uint8_t *pattern, Color color = White); + void fill(int x, int y, int width, int height, Bitmap::ProgMem pattern, Color color = White); void scroll(int dx, int dy, Color fillColor = Black); void scroll(int x, int y, int width, int height, int dx, int dy, Color fillColor = Black); @@ -101,7 +103,7 @@ private: int _height; int _stride; uint8_t *fb; - const prog_uint8_t *_font; + Font _font; Color _textColor; friend class DMD; @@ -125,7 +127,7 @@ inline void Bitmap::drawInvertedBitmap(int x, int y, const Bitmap &bitmap) drawBitmap(x, y, bitmap, Black); } -inline void Bitmap::drawInvertedBitmap(int x, int y, const prog_uint8_t *bitmap) +inline void Bitmap::drawInvertedBitmap(int x, int y, Bitmap::ProgMem bitmap) { drawBitmap(x, y, bitmap, Black); } diff --git a/libraries/DMD/DejaVuSans9.h b/libraries/DMD/DejaVuSans9.h index f1356dca..8ede679a 100644 --- a/libraries/DMD/DejaVuSans9.h +++ b/libraries/DMD/DejaVuSans9.h @@ -45,7 +45,7 @@ #define DEJAVUSANS9_WIDTH 10 #define DEJAVUSANS9_HEIGHT 10 -static uint8_t DejaVuSans9[] PROGMEM = { +static uint8_t const DejaVuSans9[] PROGMEM = { 0x0F, 0x7A, // size 0x0A, // width 0x0A, // height diff --git a/libraries/DMD/DejaVuSansBold9.h b/libraries/DMD/DejaVuSansBold9.h index 3c139bdd..d4d3721a 100644 --- a/libraries/DMD/DejaVuSansBold9.h +++ b/libraries/DMD/DejaVuSansBold9.h @@ -45,7 +45,7 @@ #define DEJAVUSANSBOLD9_WIDTH 10 #define DEJAVUSANSBOLD9_HEIGHT 10 -static uint8_t DejaVuSansBold9[] PROGMEM = { +static uint8_t const DejaVuSansBold9[] PROGMEM = { 0x12, 0x36, // size 0x0A, // width 0x0A, // height diff --git a/libraries/DMD/DejaVuSansItalic9.h b/libraries/DMD/DejaVuSansItalic9.h index 97c42008..ea36981d 100644 --- a/libraries/DMD/DejaVuSansItalic9.h +++ b/libraries/DMD/DejaVuSansItalic9.h @@ -45,7 +45,7 @@ #define DEJAVUSANSITALIC9_WIDTH 10 #define DEJAVUSANSITALIC9_HEIGHT 10 -static uint8_t DejaVuSansItalic9[] PROGMEM = { +static uint8_t const DejaVuSansItalic9[] PROGMEM = { 0x11, 0xDC, // size 0x0A, // width 0x0A, // height diff --git a/libraries/DMD/Mono5x7.h b/libraries/DMD/Mono5x7.h index f3c82c07..7e6de562 100644 --- a/libraries/DMD/Mono5x7.h +++ b/libraries/DMD/Mono5x7.h @@ -45,7 +45,7 @@ #define MONO5X7_WIDTH 5 #define MONO5X7_HEIGHT 7 -static uint8_t Mono5x7[] PROGMEM = { +static uint8_t const Mono5x7[] PROGMEM = { 0x00, 0x00, // size 0x05, // width 0x07, // height diff --git a/libraries/DMD/examples/RunningFigure/RunningFigure.pde b/libraries/DMD/examples/RunningFigure/RunningFigure.pde index e45e56fe..f517b7e3 100644 --- a/libraries/DMD/examples/RunningFigure/RunningFigure.pde +++ b/libraries/DMD/examples/RunningFigure/RunningFigure.pde @@ -227,7 +227,7 @@ byte const run10[] PROGMEM = { B01000000, B00000000 }; -const prog_uint8_t *frames[] = { +Bitmap::ProgMem frames[] = { run1, run2, run3, diff --git a/libraries/DMD/examples/RunningFigureISR/RunningFigureISR.pde b/libraries/DMD/examples/RunningFigureISR/RunningFigureISR.pde index e60b20bd..7f52b652 100644 --- a/libraries/DMD/examples/RunningFigureISR/RunningFigureISR.pde +++ b/libraries/DMD/examples/RunningFigureISR/RunningFigureISR.pde @@ -227,7 +227,7 @@ byte const run10[] PROGMEM = { B01000000, B00000000 }; -const prog_uint8_t *frames[] = { +Bitmap::ProgMem frames[] = { run1, run2, run3, diff --git a/libraries/LCD/LCD.cpp b/libraries/LCD/LCD.cpp index b6d6b49c..09f3b780 100644 --- a/libraries/LCD/LCD.cpp +++ b/libraries/LCD/LCD.cpp @@ -319,7 +319,7 @@ void LCD::disableScreenSaver() */ // Button mapping table generated by genlookup.c -static prog_uint8_t const buttonMappings[] PROGMEM = { +static unsigned char const buttonMappings[] PROGMEM = { 2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0 }; diff --git a/libraries/LCD/ListField.h b/libraries/LCD/ListField.h index a959be95..283985ff 100644 --- a/libraries/LCD/ListField.h +++ b/libraries/LCD/ListField.h @@ -26,7 +26,7 @@ #include "Field.h" #include -typedef const prog_char *ListItem; +typedef PGM_P ListItem; typedef const PROGMEM ListItem *ListItems; class ListField : public Field { diff --git a/libraries/RTC/examples/AlarmClock/SetMelody.cpp b/libraries/RTC/examples/AlarmClock/SetMelody.cpp index 5054454f..33068593 100644 --- a/libraries/RTC/examples/AlarmClock/SetMelody.cpp +++ b/libraries/RTC/examples/AlarmClock/SetMelody.cpp @@ -49,7 +49,7 @@ static const char item_FourBeeps[] PROGMEM = "Four beeps"; static const char item_Haircut[] PROGMEM = "Shave 'n haircut"; static const char item_SOS[] PROGMEM = "S.O.S."; static const char item_Radio[] PROGMEM = "Radio"; -static ListItem melodyNames[] PROGMEM = { +static ListItem const melodyNames[] PROGMEM = { item_FourBeeps, item_Haircut, item_SOS, diff --git a/libraries/RTC/examples/TestRTC/TestRTC.pde b/libraries/RTC/examples/TestRTC/TestRTC.pde index bf458eb2..7f38aa66 100644 --- a/libraries/RTC/examples/TestRTC/TestRTC.pde +++ b/libraries/RTC/examples/TestRTC/TestRTC.pde @@ -104,7 +104,7 @@ void printDec2(int value) Serial.print((char)('0' + (value % 10))); } -void printProgString(const prog_char *str) +void printProgString(PGM_P str) { for (;;) { char ch = (char)(pgm_read_byte(str)); @@ -309,10 +309,10 @@ void cmdNvram(const char *args) typedef void (*commandFunc)(const char *args); typedef struct { - const prog_char *name; + PGM_P name; commandFunc func; - const prog_char *desc; - const prog_char *args; + PGM_P desc; + PGM_P args; } command_t; const char s_cmdTime[] PROGMEM = "TIME"; const char s_cmdTimeDesc[] PROGMEM = @@ -354,14 +354,11 @@ void cmdHelp(const char *) { int index = 0; for (;;) { - const prog_char *name = (const prog_char *) - (pgm_read_word(&(commands[index].name))); + PGM_P name = (PGM_P)(pgm_read_word(&(commands[index].name))); if (!name) break; - const prog_char *desc = (const prog_char *) - (pgm_read_word(&(commands[index].desc))); - const prog_char *args = (const prog_char *) - (pgm_read_word(&(commands[index].args))); + PGM_P desc = (PGM_P)(pgm_read_word(&(commands[index].desc))); + PGM_P args = (PGM_P)(pgm_read_word(&(commands[index].args))); printProgString(name); if (args) { Serial.print(' '); @@ -376,7 +373,7 @@ void cmdHelp(const char *) } // Match a data-space string where the name comes from PROGMEM. -bool matchString(const prog_char *name, const char *str, int len) +bool matchString(PGM_P name, const char *str, int len) { for (;;) { char ch1 = (char)(pgm_read_byte(name)); @@ -425,8 +422,7 @@ void processCommand(const char *buf) // Find the command and execute it. int index = 0; for (;;) { - const prog_char *name = (const prog_char *) - (pgm_read_word(&(commands[index].name))); + PGM_P name = (PGM_P)(pgm_read_word(&(commands[index].name))); if (!name) break; if (matchString(name, cmd, len)) {