32 #if defined(__AVR__) || defined(TEENSYDUINO)
35 #define regtype volatile uint8_t
36 #define regsize uint8_t
38 #define cbi(reg, bitmask) *reg &= ~bitmask
39 #define sbi(reg, bitmask) *reg |= bitmask
40 #define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask);
41 #define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask);
43 #elif defined(__SAM3X8E__)
46 #define prog_uchar const unsigned char
47 #define pgm_read_byte(x) (*((char *)x))
48 #define pgm_read_word(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
49 #define pgm_read_byte_near(x) (*((char *)x))
50 #define pgm_read_byte_far(x) (*((char *)x))
54 #define pgm_read_word_near(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
55 #define pgm_read_word_far(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x))))
59 #define prog_uchar byte
61 #define regtype volatile uint32_t
62 #define regsize uint16_t
65 #define swap(a, b) {int16_t buf = a; a = b; b = buf;}
67 #define BITMASK_FONT 1
68 #define ANTIALIASED_FONT 2
69 #define HEADER_LENGTH 5
71 #define SCROLL_SMOOTH 1
72 #define SCROLL_CLEAN 2
74 #define FILL_TOPDOWN 0
75 #define FILL_LEFTRIGHT 0
76 #define FILL_DOWNTOP 1
77 #define FILL_RIGHTLEFT 2
79 #define ORIGIN_RELATIVE true // origin relative to a current scroll position
80 #define ORIGIN_ABSOLUTE false // origin matches physical device pixel coordinates
84 #define PORTRAIT_FLIP 2
85 #define LANDSCAPE_FLIP 3
87 #define ipart(X) ((int16_t)(X))
88 #define round(X) ((uint16_t)(((double)(X))+0.5))
89 #define fpart(X) (((double)(X))-(double)ipart(X))
90 #define rfpart(X) (1.0-fpart(X))
92 extern regtype *registerCS;
93 extern regsize bitmaskCS;
95 #define chipSelect() cbi(registerCS, bitmaskCS)
96 #define chipDeselect() sbi(registerCS, bitmaskCS)
104 RGB(uint8_t r, uint8_t g, uint8_t b);
107 RGB convert565toRGB(uint16_t color);
108 uint16_t convertRGBto565(
RGB color);
109 uint16_t convertTo565();
116 int16_t deviceHeight;
126 boolean relativeOrigin;
129 prog_uchar* currentFont;
136 uint8_t fillDirection;
137 boolean antialiasing;
139 boolean scrollSupported;
140 boolean scrollEnabled;
142 int16_t currentScroll;
144 boolean scrollCleanMode;
146 void printString(int16_t xx, int16_t yy, String text,
boolean clean, int8_t kerning[] = NULL);
147 void drawGlyph(int16_t fontType,
boolean clean, int16_t xx, int16_t yy,
148 int16_t height, prog_uchar* data, int16_t ptr, int16_t length);
150 virtual void setRegion(int16_t x1, int16_t y1, int16_t x2, int16_t y2) {};
151 void setCurrentPixel(
RGB color);
152 void setCurrentPixel(int16_t color);
153 void fill(
int b, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
154 virtual void quickFill(
int b, int16_t x1, int16_t y1, int16_t x2, int16_t y2) {};
155 void putColor(int16_t x, int16_t y,
boolean steep,
double weight);
156 RGB computeColor(
RGB,
double weight);
157 RGB computeColor(
RGB fg, uint8_t opacity);
161 void hLine(int16_t x1, int16_t y1, int16_t x2);
162 void vLine(int16_t x1, int16_t y1, int16_t y2);
164 virtual void deviceWriteData(uint8_t hi, uint8_t lo) {};
166 virtual void scrollCmd() {};
168 virtual void drawCircleAntialiaced(int16_t x, int16_t y, int16_t radius,
boolean bordermode);
169 virtual void drawFatLineAntialiased(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
170 virtual void drawLineAntialiased(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
171 virtual void drawRoundRectangleAntialiased(int16_t x, int16_t y, int16_t width, int16_t height, int16_t rx, int16_t ry,
boolean bordermode);
173 int16_t* loadFileBytes(String);
207 antialiasing =
false;
223 scrollEnabled = enable;
231 return scrollEnabled & scrollSupported;
266 relativeOrigin =
true;
273 relativeOrigin =
false;
281 return relativeOrigin;
309 inline void setColor(uint8_t r, uint8_t g, uint8_t b) {
371 void drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
380 void drawCircle(int16_t x, int16_t y, int16_t radius);
398 void drawOval(int16_t x, int16_t y, int16_t width, int16_t height);
414 void drawRectangle(int16_t x, int16_t y, int16_t width, int16_t height);
429 void drawRoundRectangle(int16_t x, int16_t y, int16_t width, int16_t height, int16_t r);
437 void fillCircle(int16_t x, int16_t y, int16_t radius);
449 void fillOval(int16_t x, int16_t y, int16_t width, int16_t height);
468 void fillRectangle(int16_t x, int16_t y, int16_t width, int16_t height);
482 void fillRoundRectangle(int16_t x, int16_t y, int16_t width, int16_t height, int16_t r);
496 int8_t
drawBitmap(int16_t x, int16_t y, int16_t width, int16_t height, prog_uint16_t* data);
519 void drawIcon(int16_t xx, int16_t yy, prog_uchar data[]);
530 void cleanIcon(int16_t xx, int16_t yy, prog_uchar data[]);
543 int8_t
loadBitmap(int16_t x, int16_t y, int16_t width, int16_t height, String path);
547 void scroll(int16_t dy, int16_t x1, int16_t x2, int8_t flags);
557 void scroll(int16_t dy, int8_t flags);
564 int setFont(prog_uchar font[]);
581 void print(int16_t xx, int16_t yy, String text, int8_t kerning[] = NULL);
599 void cleanText(int16_t xx, int16_t yy, String text, int8_t kerning[] = NULL);
620 int16_t
getTextWidth(String text, int8_t kerning[] = NULL);
630 BitStream (uint8_t* src_buffer,
size_t byte_size, int8_t offset = 0) {
633 size = byte_size + (offset>>3);
637 return ((bitpos + 1) >> 3) >= size;
640 uint8_t testCurrentByte() {
641 uint8_t res = (uint8_t)pgm_read_byte_near(data + (bitpos>>3));
646 uint8_t res = (uint8_t)(pgm_read_byte_near(data + (bitpos>>3)) & (uint8_t)( (uint16_t)0x80 >> (bitpos & 7) ));
651 uint8_t readBits(uint8_t len) {
653 uint16_t end_offset = (bitpos + len - 1)>>3;
654 if ( end_offset >= size ) {
659 uint16_t byte_offset = bitpos >> 3;
660 if (byte_offset == end_offset) {
661 uint16_t x = pgm_read_byte_near(data + byte_offset);
662 i = (uint8_t)(x >> (8 - ((bitpos & 7) + len))) & ((1 << len) - 1);
664 uint16_t x = ((uint16_t)pgm_read_byte_near(data + byte_offset) << 8) + pgm_read_byte_near(data + end_offset);
665 i = (uint8_t)(x >> (16 - ((bitpos & 7) + len))) & ((1 << len) - 1);
671 uint16_t readNumber() {
677 if ( readBit() == 0 ) {
678 uint8_t bits = readBits(ctr);
685 uint8_t bits = readBits(ctr);
692 return (uint16_t)count;
void drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
int16_t getTextWidth(String text, int8_t kerning[]=NULL)
void setOrientation(uint8_t orientation)
void drawIcon(int16_t xx, int16_t yy, prog_uchar data[])
void fillRoundRectangle(int16_t x, int16_t y, int16_t width, int16_t height, int16_t r)
int16_t getTextLineHeight()
void setBackground(RGB color)
int setFont(prog_uchar font[])
void drawPixel(int16_t x, int16_t y)
int8_t drawCompressedBitmap(int16_t x, int16_t y, uint8_t *data)
int8_t loadBitmap(int16_t x, int16_t y, int16_t width, int16_t height, String path)
void setColor(uint8_t r, uint8_t g, uint8_t b)
int8_t drawBitmap(int16_t x, int16_t y, int16_t width, int16_t height, prog_uint16_t *data)
void setLineWidth(double width)
virtual void enableAntialiasing(boolean enable)
void drawRoundRectangle(int16_t x, int16_t y, int16_t width, int16_t height, int16_t r)
void print(int16_t xx, int16_t yy, String text, int8_t kerning[]=NULL)
int16_t getTextBaseline()
void drawRectangle(int16_t x, int16_t y, int16_t width, int16_t height)
void setBackground(uint8_t r, uint8_t g, uint8_t b)
void scroll(int16_t dy, int16_t x1, int16_t x2, int8_t flags)
boolean isOriginRelative()
void cleanText(int16_t xx, int16_t yy, String text, int8_t kerning[]=NULL)
void fillRectangle(int16_t x, int16_t y, int16_t width, int16_t height)
void enableScroll(boolean enable)
void drawCircle(int16_t x, int16_t y, int16_t radius)
void cleanIcon(int16_t xx, int16_t yy, prog_uchar data[])
void fillCircle(int16_t x, int16_t y, int16_t radius)
virtual void setFillDirection(uint8_t direction)
void fillOval(int16_t x, int16_t y, int16_t width, int16_t height)
void drawOval(int16_t x, int16_t y, int16_t width, int16_t height)
PixelsBase(uint16_t width, uint16_t height)
RGB getPixel(int16_t x, int16_t y)