mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
Update usage of PROGMEM to Arduino 1.0.1
This commit is contained in:
parent
6a5ec04068
commit
393eb6c2ba
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
backup
|
||||
*.swp
|
||||
hardware
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -227,7 +227,7 @@ byte const run10[] PROGMEM = {
|
||||
B01000000, B00000000
|
||||
};
|
||||
|
||||
const prog_uint8_t *frames[] = {
|
||||
Bitmap::ProgMem frames[] = {
|
||||
run1,
|
||||
run2,
|
||||
run3,
|
||||
|
@ -227,7 +227,7 @@ byte const run10[] PROGMEM = {
|
||||
B01000000, B00000000
|
||||
};
|
||||
|
||||
const prog_uint8_t *frames[] = {
|
||||
Bitmap::ProgMem frames[] = {
|
||||
run1,
|
||||
run2,
|
||||
run3,
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "Field.h"
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
typedef const prog_char *ListItem;
|
||||
typedef PGM_P ListItem;
|
||||
typedef const PROGMEM ListItem *ListItems;
|
||||
|
||||
class ListField : public Field {
|
||||
|
@ -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,
|
||||
|
@ -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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user