Skip to content

Commit 0ea7dfb

Browse files
authored
Merge pull request #22 from markisch:feature-createCharPgm
Add a PROGMEM variant createCharPgm()
2 parents a024179 + 6d42a6d commit 0ea7dfb

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ autoscroll KEYWORD2
2929
noAutoscroll KEYWORD2
3030
setBacklight KEYWORD2
3131
createChar KEYWORD2
32+
createChar_P KEYWORD2
3233
setCursor KEYWORD2
3334
write KEYWORD2
35+
command KEYWORD2
3436

3537
#######################################
3638
# Instances (KEYWORD2)

src/LiquidCrystal_PCF8574.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,21 @@ void LiquidCrystal_PCF8574::createChar(int location, byte charmap[])
237237
} // createChar()
238238

239239

240+
#ifdef __AVR__
241+
// Allows us to fill the first 8 CGRAM locations
242+
// with custom characters stored in PROGMEM
243+
void LiquidCrystal_PCF8574::createChar_P(uint8_t location, const byte *charmap) {
244+
PGM_P p = reinterpret_cast<PGM_P>(charmap);
245+
location &= 0x7; // we only have 8 locations 0-7
246+
_send(0x40 | (location << 3));
247+
for (int i = 0; i < 8; i++) {
248+
byte c = pgm_read_byte(p++);
249+
write(c);
250+
}
251+
} // createCharPgm()
252+
#endif
253+
254+
240255
/* The write function is needed for derivation from the Print class. */
241256
inline size_t LiquidCrystal_PCF8574::write(uint8_t ch)
242257
{

src/LiquidCrystal_PCF8574.h

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class LiquidCrystal_PCF8574 : public Print
5858
void leftToRight();
5959
void rightToLeft();
6060
void createChar(int, byte[]);
61+
#ifdef __AVR__
62+
void createChar_P(uint8_t, const byte *);
63+
inline void createChar(uint8_t n, const byte *data) {
64+
createChar_P(n, data);
65+
};
66+
#endif
6167

6268
// plus functions from LCDAPI:
6369
void clear(); // same as init()

0 commit comments

Comments
 (0)