PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
spinal
Date:
Sun Oct 15 18:03:02 2017 +0000
Revision:
11:02ad9c807a21
Parent:
10:8cde5d0bafad
fixed 4color refreshRegion code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 0:e8b8f36b4505 1 /**************************************************************************/
Pokitto 0:e8b8f36b4505 2 /*!
Pokitto 0:e8b8f36b4505 3 @file PokittoDisplay.h
Pokitto 0:e8b8f36b4505 4 @author Jonne Valola
Pokitto 0:e8b8f36b4505 5
Pokitto 0:e8b8f36b4505 6 @section LICENSE
Pokitto 0:e8b8f36b4505 7
Pokitto 0:e8b8f36b4505 8 Software License Agreement (BSD License)
Pokitto 0:e8b8f36b4505 9
Pokitto 0:e8b8f36b4505 10 Copyright (c) 2016, Jonne Valola
Pokitto 0:e8b8f36b4505 11 All rights reserved.
Pokitto 0:e8b8f36b4505 12
Pokitto 0:e8b8f36b4505 13 Redistribution and use in source and binary forms, with or without
Pokitto 0:e8b8f36b4505 14 modification, are permitted provided that the following conditions are met:
Pokitto 0:e8b8f36b4505 15 1. Redistributions of source code must retain the above copyright
Pokitto 0:e8b8f36b4505 16 notice, this list of conditions and the following disclaimer.
Pokitto 0:e8b8f36b4505 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 0:e8b8f36b4505 18 notice, this list of conditions and the following disclaimer in the
Pokitto 0:e8b8f36b4505 19 documentation and/or other materials provided with the distribution.
Pokitto 0:e8b8f36b4505 20 3. Neither the name of the copyright holders nor the
Pokitto 0:e8b8f36b4505 21 names of its contributors may be used to endorse or promote products
Pokitto 0:e8b8f36b4505 22 derived from this software without specific prior written permission.
Pokitto 0:e8b8f36b4505 23
Pokitto 0:e8b8f36b4505 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 0:e8b8f36b4505 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 0:e8b8f36b4505 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 0:e8b8f36b4505 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 0:e8b8f36b4505 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 0:e8b8f36b4505 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 0:e8b8f36b4505 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 0:e8b8f36b4505 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 0:e8b8f36b4505 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 0:e8b8f36b4505 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 0:e8b8f36b4505 34 */
Pokitto 0:e8b8f36b4505 35 /**************************************************************************/
Pokitto 0:e8b8f36b4505 36
Pokitto 0:e8b8f36b4505 37
Pokitto 0:e8b8f36b4505 38
Pokitto 0:e8b8f36b4505 39 /* THE SEGMENT BELOW PERTAINS TO CIRCLE DRAWING FUNCTIONS ONLY
Pokitto 0:e8b8f36b4505 40 *
Pokitto 0:e8b8f36b4505 41 This is the core graphics library for all our displays, providing a common
Pokitto 0:e8b8f36b4505 42 set of graphics primitives (points, lines, circles, etc.). It needs to be
Pokitto 0:e8b8f36b4505 43 paired with a hardware-specific library for each display device we carry
Pokitto 0:e8b8f36b4505 44 (to handle the lower-level functions).
Pokitto 0:e8b8f36b4505 45 Adafruit invests time and resources providing this open source code, please
Pokitto 0:e8b8f36b4505 46 support Adafruit & open-source hardware by purchasing products from Adafruit!
Pokitto 0:e8b8f36b4505 47 Copyright (c) 2013 Adafruit Industries. All rights reserved.
Pokitto 0:e8b8f36b4505 48 Redistribution and use in source and binary forms, with or without
Pokitto 0:e8b8f36b4505 49 modification, are permitted provided that the following conditions are met:
Pokitto 0:e8b8f36b4505 50 - Redistributions of source code must retain the above copyright notice,
Pokitto 0:e8b8f36b4505 51 this list of conditions and the following disclaimer.
Pokitto 0:e8b8f36b4505 52 - Redistributions in binary form must reproduce the above copyright notice,
Pokitto 0:e8b8f36b4505 53 this list of conditions and the following disclaimer in the documentation
Pokitto 0:e8b8f36b4505 54 and/or other materials provided with the distribution.
Pokitto 0:e8b8f36b4505 55 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Pokitto 0:e8b8f36b4505 56 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Pokitto 0:e8b8f36b4505 57 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Pokitto 0:e8b8f36b4505 58 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
Pokitto 0:e8b8f36b4505 59 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Pokitto 0:e8b8f36b4505 60 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Pokitto 0:e8b8f36b4505 61 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Pokitto 0:e8b8f36b4505 62 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Pokitto 0:e8b8f36b4505 63 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Pokitto 0:e8b8f36b4505 64 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Pokitto 0:e8b8f36b4505 65 POSSIBILITY OF SUCH DAMAGE.
Pokitto 0:e8b8f36b4505 66 */
Pokitto 0:e8b8f36b4505 67
Pokitto 0:e8b8f36b4505 68 #ifndef POKITTODISPLAY_H
Pokitto 0:e8b8f36b4505 69 #define POKITTODISPLAY_H
Pokitto 0:e8b8f36b4505 70
Pokitto 0:e8b8f36b4505 71 #include <stdint.h>
Pokitto 0:e8b8f36b4505 72 #include "Pokitto_settings.h"
Pokitto 0:e8b8f36b4505 73 #include "PokittoGlobs.h"
Pokitto 0:e8b8f36b4505 74 #include "PokittoFonts.h"
Pokitto 0:e8b8f36b4505 75 #include "PokittoPalettes.h"
Pokitto 0:e8b8f36b4505 76
Pokitto 0:e8b8f36b4505 77 // Basic Color definitions
Pokitto 0:e8b8f36b4505 78 #define COLOR_BLACK (uint16_t)(0x0000)
Pokitto 0:e8b8f36b4505 79 #define COLOR_BLUE (uint16_t)(0x001F)
Pokitto 0:e8b8f36b4505 80 #define COLOR_RED (uint16_t)(0xF800)
Pokitto 0:e8b8f36b4505 81 #define COLOR_GREEN (uint16_t)(0x07E0)
Pokitto 0:e8b8f36b4505 82 #define COLOR_CYAN (uint16_t)(0x07FF)
Pokitto 0:e8b8f36b4505 83 #define COLOR_MAGENTA (uint16_t)(0xF81F)
Pokitto 0:e8b8f36b4505 84 #define COLOR_YELLOW (uint16_t)(0xFFE0)
Pokitto 0:e8b8f36b4505 85 #define COLOR_WHITE (uint16_t)(0xFFFF)
Pokitto 0:e8b8f36b4505 86
Pokitto 0:e8b8f36b4505 87 // Grayscale Values
Pokitto 0:e8b8f36b4505 88 #define COLOR_GRAY_15 (uint16_t)(0x0861) // 15 15 15
Pokitto 0:e8b8f36b4505 89 #define COLOR_GRAY_30 (uint16_t)(0x18E3) // 30 30 30
Pokitto 0:e8b8f36b4505 90 #define COLOR_GRAY_50 (uint16_t)(0x3186) // 50 50 50
Pokitto 0:e8b8f36b4505 91 #define COLOR_GRAY_80 (uint16_t)(0x528A) // 80 80 80
Pokitto 0:e8b8f36b4505 92 #define COLOR_GRAY_128 (uint16_t)(0x8410) // 128 128 128
Pokitto 0:e8b8f36b4505 93 #define COLOR_GRAY_200 (uint16_t)(0xCE59) // 200 200 200
Pokitto 0:e8b8f36b4505 94 #define COLOR_GRAY_225 (uint16_t)(0xE71C) // 225 225 225
Pokitto 0:e8b8f36b4505 95
Pokitto 0:e8b8f36b4505 96 /** The tables below are palettes, that resemble the Pico 8 palette*/
Pokitto 0:e8b8f36b4505 97
Pokitto 0:e8b8f36b4505 98 enum defcolors {
Pokitto 0:e8b8f36b4505 99 C_BLACK,
Pokitto 0:e8b8f36b4505 100 C_DARKBLUE,
Pokitto 0:e8b8f36b4505 101 C_PURPLE,
Pokitto 0:e8b8f36b4505 102 C_DARKGREEN,
Pokitto 0:e8b8f36b4505 103
Pokitto 0:e8b8f36b4505 104 C_BROWN,
Pokitto 0:e8b8f36b4505 105 C_DARKBROWN,
Pokitto 0:e8b8f36b4505 106 C_LIGHTGRAY,
Pokitto 0:e8b8f36b4505 107 C_WHITE,
Pokitto 0:e8b8f36b4505 108
Pokitto 0:e8b8f36b4505 109 C_RED,
Pokitto 0:e8b8f36b4505 110 C_ORANGE,
Pokitto 0:e8b8f36b4505 111 C_YELLOW,
Pokitto 0:e8b8f36b4505 112 C_GREEN,
Pokitto 0:e8b8f36b4505 113
Pokitto 0:e8b8f36b4505 114 C_BLUE,
Pokitto 0:e8b8f36b4505 115 C_DARKGRAY,
Pokitto 0:e8b8f36b4505 116 C_PINK,
Pokitto 0:e8b8f36b4505 117 C_PEACH
Pokitto 0:e8b8f36b4505 118 };
Pokitto 0:e8b8f36b4505 119
Pokitto 2:968589ca3484 120 const uint16_t def565palette[16] = {
Pokitto 0:e8b8f36b4505 121 //kind of like pico8 palette
Pokitto 0:e8b8f36b4505 122 0,0x194a,0x792a,0x42a,
Pokitto 0:e8b8f36b4505 123 0xaa86,0x5aa9,0xc618,0xff9d,
Pokitto 0:e8b8f36b4505 124 0xf809,0xfd00,0xff84,0x72a,
Pokitto 0:e8b8f36b4505 125 0x2d7f,0x83b3,0xfbb5,0xfe75
Pokitto 0:e8b8f36b4505 126 };
Pokitto 0:e8b8f36b4505 127
Pokitto 0:e8b8f36b4505 128 #define PALETTE_SIZE 16
Pokitto 0:e8b8f36b4505 129 #include <stdint.h>
Pokitto 0:e8b8f36b4505 130 #include <stdlib.h>
Pokitto 0:e8b8f36b4505 131 #include <string.h>
Pokitto 0:e8b8f36b4505 132
Pokitto 0:e8b8f36b4505 133
Pokitto 0:e8b8f36b4505 134 namespace Pokitto {
Pokitto 0:e8b8f36b4505 135
Pokitto 0:e8b8f36b4505 136 class Display {
Pokitto 0:e8b8f36b4505 137 public:
Pokitto 0:e8b8f36b4505 138 Display();
Pokitto 0:e8b8f36b4505 139
Pokitto 0:e8b8f36b4505 140 // PROPERTIES
Pokitto 0:e8b8f36b4505 141 private:
Pokitto 0:e8b8f36b4505 142 static uint8_t* canvas;
Pokitto 0:e8b8f36b4505 143 static uint8_t bpp;
Pokitto 0:e8b8f36b4505 144 static uint8_t m_colordepth;
Pokitto 0:e8b8f36b4505 145 public:
Pokitto 0:e8b8f36b4505 146 static uint8_t width;
Pokitto 0:e8b8f36b4505 147 static uint8_t height;
Pokitto 0:e8b8f36b4505 148 static uint8_t screenbuffer[];
Pokitto 0:e8b8f36b4505 149
Pokitto 0:e8b8f36b4505 150 // PROPERTIES
Pokitto 0:e8b8f36b4505 151 static void setColorDepth(uint8_t);
Pokitto 0:e8b8f36b4505 152 static uint8_t getColorDepth();
Pokitto 0:e8b8f36b4505 153 static uint8_t getBitsPerPixel();
Pokitto 0:e8b8f36b4505 154 static uint16_t getWidth();
Pokitto 0:e8b8f36b4505 155 static uint16_t getHeight();
Pokitto 0:e8b8f36b4505 156 static uint8_t getNumberOfColors();
Pokitto 0:e8b8f36b4505 157
Pokitto 0:e8b8f36b4505 158 // IMPORTANT PUBLIC STATE MEMBERS
Pokitto 0:e8b8f36b4505 159 /** Selected font */
Pokitto 0:e8b8f36b4505 160 static const unsigned char * font;
Pokitto 0:e8b8f36b4505 161 /** Set if screen is cleared between updates or not*/
Pokitto 0:e8b8f36b4505 162 static uint8_t persistence;
Pokitto 0:e8b8f36b4505 163 /** Selected drawing color */
Pokitto 0:e8b8f36b4505 164 static uint16_t color;
Pokitto 0:e8b8f36b4505 165 /** Selected background color */
Pokitto 0:e8b8f36b4505 166 static uint16_t bgcolor;
Pokitto 0:e8b8f36b4505 167 /** Selected invisible color */
Pokitto 0:e8b8f36b4505 168 static uint16_t invisiblecolor;
Pokitto 0:e8b8f36b4505 169 /** Direct unbuffered color */
Pokitto 0:e8b8f36b4505 170 static uint16_t directcolor;
Pokitto 0:e8b8f36b4505 171 /** Direct unbuffered background color */
Pokitto 0:e8b8f36b4505 172 static uint16_t directbgcolor;
Pokitto 0:e8b8f36b4505 173 /** set color with a command */
Pokitto 0:e8b8f36b4505 174 static void setColor(uint8_t);
Pokitto 0:e8b8f36b4505 175 /** set color and bgcolor with a command */
Pokitto 0:e8b8f36b4505 176 static void setColor(uint8_t,uint8_t);
Pokitto 0:e8b8f36b4505 177 /** set invisiblecolor with a command */
Pokitto 0:e8b8f36b4505 178 static void setInvisibleColor(uint16_t);
Pokitto 0:e8b8f36b4505 179 /** get color */
Pokitto 0:e8b8f36b4505 180 static uint8_t getColor();
Pokitto 0:e8b8f36b4505 181 /** get background color */
Pokitto 0:e8b8f36b4505 182 static uint8_t getBgColor();
Pokitto 0:e8b8f36b4505 183 /** get invisible color */
Pokitto 0:e8b8f36b4505 184 static uint16_t getInvisibleColor();
Pokitto 0:e8b8f36b4505 185
Pokitto 0:e8b8f36b4505 186
Pokitto 0:e8b8f36b4505 187 /** Initialize display */
Pokitto 0:e8b8f36b4505 188 static void begin();
Pokitto 0:e8b8f36b4505 189 /** Clear display buffer */
Pokitto 0:e8b8f36b4505 190 static void clear();
Pokitto 0:e8b8f36b4505 191 /** Scroll by x lines */
Pokitto 0:e8b8f36b4505 192 static void scroll(int16_t);
Pokitto 0:e8b8f36b4505 193 /** Fill display buffer */
Pokitto 0:e8b8f36b4505 194 static void fillScreen(uint16_t);
spinal 10:8cde5d0bafad 195
spinal 10:8cde5d0bafad 196 static void updateRegion(int16_t x, int16_t y,int16_t x2, int16_t y2);
spinal 10:8cde5d0bafad 197
Pokitto 0:e8b8f36b4505 198 /** Send display buffer to display hardware */
Pokitto 0:e8b8f36b4505 199 static void update();
Pokitto 0:e8b8f36b4505 200 /** Forced update of LCD display memory with a given pixel buffer */
Pokitto 0:e8b8f36b4505 201 static void lcdRefresh(unsigned char*);
Pokitto 0:e8b8f36b4505 202 /** Clear LCD hardware memory */
Pokitto 0:e8b8f36b4505 203 static void clearLCD();
Pokitto 0:e8b8f36b4505 204 /** Fill LCD hardware memory */
Pokitto 0:e8b8f36b4505 205 static void fillLCD(uint16_t);
Pokitto 0:e8b8f36b4505 206 /** Show Pokitto logo at startup*/
Pokitto 0:e8b8f36b4505 207 static void showLogo();
Pokitto 0:e8b8f36b4505 208 /** Point to another screenbuffer instead of the default one */
Pokitto 0:e8b8f36b4505 209 static void setFrameBufferTo(uint8_t*);
Pokitto 0:e8b8f36b4505 210
Pokitto 0:e8b8f36b4505 211 // COLORS AND PALETTE
Pokitto 0:e8b8f36b4505 212 public:
Pokitto 0:e8b8f36b4505 213 /** set default palette */
Pokitto 0:e8b8f36b4505 214 static void setDefaultPalette();
Pokitto 0:e8b8f36b4505 215 /** master palette */
Pokitto 0:e8b8f36b4505 216 static uint16_t palette[PALETTE_SIZE];
Pokitto 0:e8b8f36b4505 217 /** runtime palette pointer */
Pokitto 0:e8b8f36b4505 218 static uint16_t *paletteptr;
Pokitto 0:e8b8f36b4505 219 /** convert RGB to 565 color value */
Pokitto 0:e8b8f36b4505 220 static uint16_t RGBto565(uint8_t,uint8_t,uint8_t);
Pokitto 0:e8b8f36b4505 221 /** linear interpolation between colors */
Pokitto 0:e8b8f36b4505 222 static uint16_t interpolateColor(uint16_t, uint16_t, uint8_t);
Pokitto 0:e8b8f36b4505 223 /** load an R,G,B triplet palette */
Pokitto 0:e8b8f36b4505 224 static void loadRGBPalette(const unsigned char*);
Pokitto 0:e8b8f36b4505 225 /** load a ready-made 565 palette */
Pokitto 0:e8b8f36b4505 226 static void load565Palette(const uint16_t*);
Pokitto 0:e8b8f36b4505 227 /** rotate palette by step */
Pokitto 0:e8b8f36b4505 228 static void rotatePalette(int8_t);
Pokitto 0:e8b8f36b4505 229 /** tween between two palettes **/
Pokitto 0:e8b8f36b4505 230 static void tweenPalette(uint16_t*, const uint16_t*, const uint16_t*, uint8_t);
Pokitto 0:e8b8f36b4505 231
Pokitto 0:e8b8f36b4505 232 // DIRECT DRAWING (NO BUFFERING)
Pokitto 0:e8b8f36b4505 233 /** Direct pixel (not through display buffer) */
Pokitto 0:e8b8f36b4505 234 static void directPixel(int16_t,int16_t,uint16_t);
spinal 9:570fdd653f1d 235 /** Direct tile 16bit (not through display buffer) */
spinal 9:570fdd653f1d 236 static void directTile(int16_t x, int16_t y, int16_t x2, int16_t y2, uint16_t* gfx);
Pokitto 0:e8b8f36b4505 237 /** Direct rectangle (not through display buffer) */
Pokitto 0:e8b8f36b4505 238 static void directRectangle(int16_t, int16_t,int16_t, int16_t, uint16_t);
Pokitto 0:e8b8f36b4505 239 /** Set the cursor for printing to a certain screen position */
Pokitto 0:e8b8f36b4505 240 static void setCursor(int16_t,int16_t);
Pokitto 0:e8b8f36b4505 241 /** direct bitmap to screen (no buffering) */
Pokitto 0:e8b8f36b4505 242 static void directBitmap(int16_t,int16_t,const uint8_t*, uint8_t,uint8_t);
Pokitto 0:e8b8f36b4505 243
Pokitto 0:e8b8f36b4505 244
Pokitto 0:e8b8f36b4505 245 // DRAWING METHODS
Pokitto 0:e8b8f36b4505 246 /** Draw pixel at various bit depths */
Pokitto 0:e8b8f36b4505 247 static void drawPixel(int16_t,int16_t);
Pokitto 0:e8b8f36b4505 248 /** Draw pixel with specific color index at various bit depths */
Pokitto 0:e8b8f36b4505 249 static void drawPixel(int16_t x,int16_t y, uint8_t col);
Pokitto 0:e8b8f36b4505 250 /** Get pixel at various bit depths */
Pokitto 0:e8b8f36b4505 251 static uint8_t getPixel(int16_t,int16_t);
Pokitto 0:e8b8f36b4505 252 /** Draw line **/
Pokitto 0:e8b8f36b4505 253 static void drawLine(int16_t,int16_t,int16_t,int16_t);
Pokitto 0:e8b8f36b4505 254 /** Clip line with screen boundaries, returns 0 if whole line is out of bounds */
Pokitto 0:e8b8f36b4505 255 static uint8_t clipLine(int16_t*, int16_t*, int16_t*, int16_t*);
Pokitto 0:e8b8f36b4505 256 /** Draw a column real fast */
Pokitto 0:e8b8f36b4505 257 static void drawColumn(int16_t, int16_t, int16_t);
Pokitto 0:e8b8f36b4505 258 /** Map a 1-bit column real fast */
Pokitto 0:e8b8f36b4505 259 static void map1BitColumn(int16_t, int16_t, int16_t, const uint8_t*, uint16_t);
Pokitto 0:e8b8f36b4505 260 /** Draw a row real fast */
Pokitto 0:e8b8f36b4505 261 static void drawRow(int16_t, int16_t, int16_t);
Pokitto 0:e8b8f36b4505 262 /** Legacy drawColumn name, for compatibility - macros are not OK because of scope problems */
Pokitto 0:e8b8f36b4505 263 static void drawFastVLine(int16_t, int16_t, int16_t);
Pokitto 0:e8b8f36b4505 264 /** Legacy drawRow name, for compatibility - macros are not OK because of scope problems */
Pokitto 0:e8b8f36b4505 265 static void drawFastHLine(int16_t, int16_t, int16_t);
Pokitto 0:e8b8f36b4505 266 /** Draw rectangle (edges only) */
Pokitto 0:e8b8f36b4505 267 static void drawRectangle(int16_t,int16_t,int16_t,int16_t);
Pokitto 0:e8b8f36b4505 268 /** Fill rectangle */
Pokitto 0:e8b8f36b4505 269 static void fillRectangle(int16_t,int16_t,int16_t,int16_t);
Pokitto 0:e8b8f36b4505 270 /** GB compatibility fillRect */
Pokitto 0:e8b8f36b4505 271 static void fillRect(int16_t x, int16_t y, int16_t w, int16_t h);
Pokitto 0:e8b8f36b4505 272 /** GB compatibility drawRect */
Pokitto 0:e8b8f36b4505 273 static void drawRect(int16_t x, int16_t y, int16_t w, int16_t h);
Pokitto 0:e8b8f36b4505 274
Pokitto 0:e8b8f36b4505 275 // Functions lifted from Adafruit GFX library (see PokittoDisplay.h for license //
Pokitto 0:e8b8f36b4505 276 /** Draw circle */
Pokitto 0:e8b8f36b4505 277 static void drawCircle(int16_t x0, int16_t y0, int16_t r);
Pokitto 0:e8b8f36b4505 278 /** Draw circle helper */
Pokitto 0:e8b8f36b4505 279 static void drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername);
Pokitto 0:e8b8f36b4505 280 /** Fill circle */
Pokitto 0:e8b8f36b4505 281 static void fillCircle(int16_t x0, int16_t y0, int16_t r);
Pokitto 0:e8b8f36b4505 282 /** Fill circle helper*/
Pokitto 0:e8b8f36b4505 283 static void fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint16_t cornername, int16_t delta);
Pokitto 0:e8b8f36b4505 284 /** draw triangle */
Pokitto 0:e8b8f36b4505 285 static void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
Pokitto 0:e8b8f36b4505 286 /** Fill triangle*/
Pokitto 0:e8b8f36b4505 287 static void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
Pokitto 0:e8b8f36b4505 288 /** Draw rounded rectangle */
Pokitto 0:e8b8f36b4505 289 static void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius);
Pokitto 0:e8b8f36b4505 290 /** Fill rounded rectangle */
Pokitto 0:e8b8f36b4505 291 static void fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius);
Pokitto 0:e8b8f36b4505 292
Pokitto 0:e8b8f36b4505 293 // BITMAPS !
Pokitto 0:e8b8f36b4505 294 /** Draw monochromatic bitmap. Used in font rendering */
Pokitto 0:e8b8f36b4505 295 static void drawMonoBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t index);
Pokitto 0:e8b8f36b4505 296 /** Draw bitmap */
Pokitto 0:e8b8f36b4505 297 static void drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap);
Pokitto 0:e8b8f36b4505 298 /** Draw RLE bitmap */
Pokitto 0:e8b8f36b4505 299 static void drawRleBitmap(int16_t x, int16_t y, const uint8_t* bitmap);
Pokitto 0:e8b8f36b4505 300 /** Draw animated bitmap frame */
Pokitto 0:e8b8f36b4505 301 static void drawBitmap(int16_t x, int16_t y, const uint8_t* bitmap, uint8_t frame);
Pokitto 0:e8b8f36b4505 302 /** Draw bitmap flipped on x-axis*/
Pokitto 0:e8b8f36b4505 303 static void drawBitmapXFlipped(int16_t x, int16_t y, const uint8_t* bitmap);
Pokitto 0:e8b8f36b4505 304 /** Draw bitmap with options */
Pokitto 0:e8b8f36b4505 305 static void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, uint8_t rotation, uint8_t flip);
Pokitto 0:e8b8f36b4505 306 /** Get pointer to the screen buffer - GB compatibility */
Pokitto 0:e8b8f36b4505 307 static uint8_t* getBuffer();
Pokitto 0:e8b8f36b4505 308 /** Get pixel in a monochromatic bitmap - GB compatibility */
Pokitto 0:e8b8f36b4505 309 static uint8_t getBitmapPixel(const uint8_t*, uint16_t, uint16_t);
Pokitto 0:e8b8f36b4505 310 /** Optimized functions for drawing bit columns - used in raytracing */
Pokitto 0:e8b8f36b4505 311 static void draw4BitColumn(int16_t x, int16_t y, uint8_t h, uint8_t* bitmap);
Pokitto 0:e8b8f36b4505 312
Pokitto 0:e8b8f36b4505 313 // PRINTING
Pokitto 0:e8b8f36b4505 314 /** direct character to screen (no buffering) */
Pokitto 0:e8b8f36b4505 315 static int directChar(int16_t, int16_t, uint16_t);
Pokitto 0:e8b8f36b4505 316 /** character to screenbuffer */
Pokitto 0:e8b8f36b4505 317 static int bufferChar(int16_t, int16_t, uint16_t);
Pokitto 0:e8b8f36b4505 318 /** set the active font */
Pokitto 0:e8b8f36b4505 319 static void setFont(const unsigned char * f);
Pokitto 0:e8b8f36b4505 320 /** font dimensions */
Pokitto 0:e8b8f36b4505 321 static uint8_t fontWidth, fontHeight;
Pokitto 0:e8b8f36b4505 322 /** text wrapping */
Pokitto 0:e8b8f36b4505 323 static bool textWrap;
Pokitto 0:e8b8f36b4505 324 /** GB compatibility drawChar */
Pokitto 0:e8b8f36b4505 325 static void drawChar(int8_t x, int8_t y, unsigned char c, uint8_t size);
Pokitto 0:e8b8f36b4505 326
Pokitto 0:e8b8f36b4505 327 static void enableDirectPrinting(uint8_t m);
Pokitto 0:e8b8f36b4505 328 static bool isDirectPrintingEnabled();
Pokitto 0:e8b8f36b4505 329 static int print_char(uint8_t x, uint8_t y, unsigned char c);
Pokitto 0:e8b8f36b4505 330 static void set_cursor(uint8_t, uint8_t);
Pokitto 0:e8b8f36b4505 331 static void write(uint8_t);
Pokitto 0:e8b8f36b4505 332 static void write(const char *str);
Pokitto 0:e8b8f36b4505 333 static void write(const uint8_t *buffer, uint8_t size);
Pokitto 0:e8b8f36b4505 334 static void print(const char[]);
Pokitto 0:e8b8f36b4505 335 static void print(char, int base = 0);
Pokitto 0:e8b8f36b4505 336 static void print(unsigned char, int base = 0);
Pokitto 0:e8b8f36b4505 337 static void print(int, int base = 10);
Pokitto 0:e8b8f36b4505 338 static void print(unsigned int, int base = 10);
Pokitto 0:e8b8f36b4505 339 static void print(long, int base = 10);
Pokitto 0:e8b8f36b4505 340 static void print(unsigned long, int base = 10);
Pokitto 0:e8b8f36b4505 341 static void print(double, int base = 2);
Pokitto 0:e8b8f36b4505 342 static void print(uint8_t, uint8_t, const char[]);
Pokitto 0:e8b8f36b4505 343 static void print(uint8_t, uint8_t, char, int = 0);
Pokitto 0:e8b8f36b4505 344 static void print(uint8_t, uint8_t, unsigned char, int = 0);
Pokitto 0:e8b8f36b4505 345 static void print(uint8_t, uint8_t, int, int = 10);
Pokitto 0:e8b8f36b4505 346 static void print(uint8_t, uint8_t, unsigned int, int = 10);
Pokitto 0:e8b8f36b4505 347 static void print(uint8_t, uint8_t, long, int = 10);
Pokitto 0:e8b8f36b4505 348 static void print(uint8_t, uint8_t, unsigned long, int = 10);
Pokitto 0:e8b8f36b4505 349 static void print(uint8_t, uint8_t, double, int = 2);
Pokitto 0:e8b8f36b4505 350 static void println(uint8_t, uint8_t, const char[]);
Pokitto 0:e8b8f36b4505 351 static void println(uint8_t, uint8_t, char, int = 0);
Pokitto 0:e8b8f36b4505 352 static void println(uint8_t, uint8_t, unsigned char, int = 0);
Pokitto 0:e8b8f36b4505 353 static void println(uint8_t, uint8_t, int, int = 10);
Pokitto 0:e8b8f36b4505 354 static void println(uint8_t, uint8_t, unsigned int, int = 10);
Pokitto 0:e8b8f36b4505 355 static void println(uint8_t, uint8_t, long, int = 10);
Pokitto 0:e8b8f36b4505 356 static void println(uint8_t, uint8_t, unsigned long, int = 10);
Pokitto 0:e8b8f36b4505 357 static void println(uint8_t, uint8_t, double, int = 2);
Pokitto 0:e8b8f36b4505 358 static void println(uint8_t, uint8_t);
Pokitto 0:e8b8f36b4505 359 static void println(const char[]);
Pokitto 0:e8b8f36b4505 360 static void println(char, int = 0);
Pokitto 0:e8b8f36b4505 361 static void println(unsigned char, int = 0);
Pokitto 0:e8b8f36b4505 362 static void println(int, int = 10);
Pokitto 0:e8b8f36b4505 363 static void println(unsigned int, int = 10);
Pokitto 0:e8b8f36b4505 364 static void println(long, int = 10 );
Pokitto 0:e8b8f36b4505 365 static void println(unsigned long, int = 10);
Pokitto 0:e8b8f36b4505 366 static void println(double, int = 2);
Pokitto 0:e8b8f36b4505 367 static void println(void);
Pokitto 0:e8b8f36b4505 368
Pokitto 0:e8b8f36b4505 369 static int16_t cursorX,cursorY;
Pokitto 0:e8b8f36b4505 370 static uint8_t fontSize;
Pokitto 0:e8b8f36b4505 371 static int8_t adjustCharStep, adjustLineStep;
Pokitto 0:e8b8f36b4505 372 static bool fixedWidthFont;
Pokitto 0:e8b8f36b4505 373
Pokitto 0:e8b8f36b4505 374 static void inc_txtline();
Pokitto 0:e8b8f36b4505 375 static void printNumber(unsigned long, uint8_t);
Pokitto 0:e8b8f36b4505 376 static void printFloat(double, uint8_t);
Pokitto 0:e8b8f36b4505 377
Pokitto 0:e8b8f36b4505 378 /** Tiled mode functions **/
Pokitto 0:e8b8f36b4505 379
Pokitto 0:e8b8f36b4505 380 static void loadTileset(const uint8_t*);
Pokitto 0:e8b8f36b4505 381
Pokitto 0:e8b8f36b4505 382 static void setTileBufferTo(uint8_t*);
Pokitto 0:e8b8f36b4505 383 static void clearTileBuffer();
Pokitto 0:e8b8f36b4505 384 static void shiftTileBuffer(int8_t,int8_t);
Pokitto 0:e8b8f36b4505 385
Pokitto 0:e8b8f36b4505 386 static void setTile(uint16_t,uint8_t);
Pokitto 0:e8b8f36b4505 387 static uint8_t getTile(uint16_t);
Pokitto 0:e8b8f36b4505 388 static uint8_t getTile(uint8_t,uint8_t);
Pokitto 0:e8b8f36b4505 389
Pokitto 0:e8b8f36b4505 390
Pokitto 0:e8b8f36b4505 391
Pokitto 0:e8b8f36b4505 392 private:
Pokitto 0:e8b8f36b4505 393 static uint8_t m_mode;
Pokitto 0:e8b8f36b4505 394 static uint16_t m_w,m_h; // store these for faster access when switching printing modes
Pokitto 0:e8b8f36b4505 395 /** Pointer to screen buffer */
Pokitto 0:e8b8f36b4505 396 static uint8_t* m_scrbuf;
Pokitto 0:e8b8f36b4505 397 /** Pointer to tileset */
Pokitto 0:e8b8f36b4505 398 static uint8_t* m_tileset;
Pokitto 0:e8b8f36b4505 399 /** Pointer to tilebuffer */
Pokitto 0:e8b8f36b4505 400 static uint8_t* m_tilebuf;
Pokitto 0:e8b8f36b4505 401 /** Pointer to tilecolorbuffer */
Pokitto 0:e8b8f36b4505 402 static uint8_t* m_tilecolorbuf;
Pokitto 0:e8b8f36b4505 403
Pokitto 0:e8b8f36b4505 404 };
Pokitto 0:e8b8f36b4505 405
Pokitto 0:e8b8f36b4505 406 }
Pokitto 0:e8b8f36b4505 407
Pokitto 0:e8b8f36b4505 408 #endif // POKITTODISPLAY_H
Pokitto 0:e8b8f36b4505 409
Pokitto 0:e8b8f36b4505 410
Pokitto 0:e8b8f36b4505 411
Pokitto 0:e8b8f36b4505 412