Jonne Valola / PokittoLib Featured

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Committer:
Pokitto
Date:
Fri Sep 14 07:40:24 2018 +0000
Revision:
56:71e4c6b1efb4
Child:
61:123aefc978a7
Child:
64:1d52d8287c39
added printf

Who changed what in which revision?

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