PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

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:
Sun Jul 01 06:32:37 2018 +0000
Revision:
52:c04087025cab
Child:
64:1d52d8287c39
PokittoCookie, faster Mode2 and Mode13 added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 52:c04087025cab 1 /**************************************************************************/
Pokitto 52:c04087025cab 2 /*!
Pokitto 52:c04087025cab 3 @file HWLCD.h
Pokitto 52:c04087025cab 4 @author Jonne Valola
Pokitto 52:c04087025cab 5
Pokitto 52:c04087025cab 6 @section LICENSE
Pokitto 52:c04087025cab 7
Pokitto 52:c04087025cab 8 Software License Agreement (BSD License)
Pokitto 52:c04087025cab 9
Pokitto 52:c04087025cab 10 Copyright (c) 2016, Jonne Valola
Pokitto 52:c04087025cab 11 All rights reserved.
Pokitto 52:c04087025cab 12
Pokitto 52:c04087025cab 13 Redistribution and use in source and binary forms, with or without
Pokitto 52:c04087025cab 14 modification, are permitted provided that the following conditions are met:
Pokitto 52:c04087025cab 15 1. Redistributions of source code must retain the above copyright
Pokitto 52:c04087025cab 16 notice, this list of conditions and the following disclaimer.
Pokitto 52:c04087025cab 17 2. Redistributions in binary form must reproduce the above copyright
Pokitto 52:c04087025cab 18 notice, this list of conditions and the following disclaimer in the
Pokitto 52:c04087025cab 19 documentation and/or other materials provided with the distribution.
Pokitto 52:c04087025cab 20 3. Neither the name of the copyright holders nor the
Pokitto 52:c04087025cab 21 names of its contributors may be used to endorse or promote products
Pokitto 52:c04087025cab 22 derived from this software without specific prior written permission.
Pokitto 52:c04087025cab 23
Pokitto 52:c04087025cab 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
Pokitto 52:c04087025cab 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Pokitto 52:c04087025cab 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Pokitto 52:c04087025cab 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
Pokitto 52:c04087025cab 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Pokitto 52:c04087025cab 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Pokitto 52:c04087025cab 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
Pokitto 52:c04087025cab 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Pokitto 52:c04087025cab 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Pokitto 52:c04087025cab 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Pokitto 52:c04087025cab 34 */
Pokitto 52:c04087025cab 35 /**************************************************************************/
Pokitto 52:c04087025cab 36
Pokitto 52:c04087025cab 37 #ifndef __HWLCD_H__
Pokitto 52:c04087025cab 38 #define __HWLCD_H__
Pokitto 52:c04087025cab 39
Pokitto 52:c04087025cab 40 #include "mbed.h"
Pokitto 52:c04087025cab 41 #include "gpio_api.h"
Pokitto 52:c04087025cab 42 #include "pinmap.h"
Pokitto 52:c04087025cab 43
Pokitto 52:c04087025cab 44 #define write_command write_command_16
Pokitto 52:c04087025cab 45 #define write_data write_data_16
Pokitto 52:c04087025cab 46
Pokitto 52:c04087025cab 47 extern volatile uint32_t *LCD;
Pokitto 52:c04087025cab 48
Pokitto 52:c04087025cab 49 namespace Pokitto {
Pokitto 52:c04087025cab 50
Pokitto 52:c04087025cab 51 struct SpriteInfo {
Pokitto 52:c04087025cab 52 const uint8_t* bitmapData;
Pokitto 52:c04087025cab 53 int16_t x;
Pokitto 52:c04087025cab 54 int16_t y;
Pokitto 52:c04087025cab 55 int16_t oldx;
Pokitto 52:c04087025cab 56 int16_t oldy;
Pokitto 52:c04087025cab 57 uint8_t w;
Pokitto 52:c04087025cab 58 uint8_t h;
Pokitto 52:c04087025cab 59 uint16_t palette[4];
Pokitto 52:c04087025cab 60 };
Pokitto 52:c04087025cab 61
Pokitto 52:c04087025cab 62 extern void setDRAMpoint(uint8_t, uint8_t);
Pokitto 52:c04087025cab 63 extern void pumpDRAMdata(uint16_t*, uint16_t);
Pokitto 52:c04087025cab 64 extern void initBacklight();
Pokitto 52:c04087025cab 65 extern void setBacklight(float);
Pokitto 52:c04087025cab 66 extern void lcdFillSurface(uint16_t);
Pokitto 52:c04087025cab 67 extern void lcdPixel(int16_t x, int16_t y, uint16_t c);
Pokitto 52:c04087025cab 68 extern void setWindow(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
Pokitto 52:c04087025cab 69 extern void lcdTile(int16_t x0, int16_t y0, int16_t width, int16_t height, uint16_t* gfx);
Pokitto 52:c04087025cab 70 extern void lcdRectangle(int16_t x, int16_t y,int16_t x2, int16_t y2, uint16_t color);
Pokitto 52:c04087025cab 71 extern void lcdInit();
Pokitto 52:c04087025cab 72 extern void lcdSleep();
Pokitto 52:c04087025cab 73 extern void lcdWakeUp();
Pokitto 52:c04087025cab 74 extern void lcdRefresh(uint8_t *, uint16_t*);
Pokitto 52:c04087025cab 75 extern void lcdRefreshAB(uint8_t *, uint16_t*);
Pokitto 52:c04087025cab 76 extern void lcdRefreshMode14(uint8_t *, uint16_t*);
Pokitto 52:c04087025cab 77 extern void lcdRefreshGB(uint8_t *, uint16_t*);
Pokitto 52:c04087025cab 78 extern void lcdRefreshMode1(uint8_t* scrbuf, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH, uint16_t* paletteptr);
Pokitto 52:c04087025cab 79 extern void lcdRefreshMode1Spr(uint8_t * scrbuf, uint8_t screenx, uint8_t screeny, uint8_t screenw, uint8_t screenh, uint16_t* paletteptr, Pokitto::SpriteInfo* sprites, bool drawSpritesOnly);
Pokitto 52:c04087025cab 80 extern void lcdRefreshMode2(uint8_t *, uint16_t*);
Pokitto 52:c04087025cab 81 extern void lcdRefreshMode3(uint8_t *, uint16_t*);
Pokitto 52:c04087025cab 82 extern void lcdRefreshModeGBC(uint8_t *, uint16_t*);
Pokitto 52:c04087025cab 83 extern void lcdRefreshMode13(uint8_t *, uint16_t*, uint8_t);
Pokitto 52:c04087025cab 84
Pokitto 52:c04087025cab 85 extern void lcdRefreshMode15(uint16_t*, uint8_t*);
Pokitto 52:c04087025cab 86
Pokitto 52:c04087025cab 87
Pokitto 52:c04087025cab 88 /** Update LCD from 1-bit tile mode */
Pokitto 52:c04087025cab 89 extern void lcdRefreshT1(uint8_t*, uint8_t*, uint8_t*, uint16_t*);
Pokitto 52:c04087025cab 90 extern void lcdClear();
Pokitto 52:c04087025cab 91 extern void lcdFill(uint16_t);
Pokitto 52:c04087025cab 92 /** Blit one word of data*/
Pokitto 52:c04087025cab 93 extern void blitWord(uint16_t);
Pokitto 52:c04087025cab 94
Pokitto 52:c04087025cab 95 /**************************************************************************/
Pokitto 52:c04087025cab 96 /** PINS AND PORTS **/
Pokitto 52:c04087025cab 97 /**************************************************************************/
Pokitto 52:c04087025cab 98
Pokitto 52:c04087025cab 99 #if POK_BOARDREV == 1
Pokitto 52:c04087025cab 100 /** 2-layer board version 1.3 **/
Pokitto 52:c04087025cab 101 #define LCD_CD_PORT 0
Pokitto 52:c04087025cab 102 #define LCD_CD_PIN 2
Pokitto 52:c04087025cab 103 #define LCD_WR_PORT 1
Pokitto 52:c04087025cab 104 #define LCD_WR_PIN 23
Pokitto 52:c04087025cab 105 #define LCD_RD_PORT 1
Pokitto 52:c04087025cab 106 #define LCD_RD_PIN 24
Pokitto 52:c04087025cab 107 #define LCD_RES_PORT 1
Pokitto 52:c04087025cab 108 #define LCD_RES_PIN 28
Pokitto 52:c04087025cab 109 #else
Pokitto 52:c04087025cab 110 /** 4-layer board version 2.1 **/
Pokitto 52:c04087025cab 111 #define LCD_CD_PORT 0
Pokitto 52:c04087025cab 112 #define LCD_CD_PIN 2
Pokitto 52:c04087025cab 113 #define LCD_WR_PORT 1
Pokitto 52:c04087025cab 114 #define LCD_WR_PIN 12
Pokitto 52:c04087025cab 115 #define LCD_RD_PORT 1
Pokitto 52:c04087025cab 116 #define LCD_RD_PIN 24
Pokitto 52:c04087025cab 117 #define LCD_RES_PORT 1
Pokitto 52:c04087025cab 118 #define LCD_RES_PIN 0
Pokitto 52:c04087025cab 119 #endif
Pokitto 52:c04087025cab 120
Pokitto 52:c04087025cab 121 /**************************************************************************/
Pokitto 52:c04087025cab 122 /** LCD CONTROL MACROS **/
Pokitto 52:c04087025cab 123 /**************************************************************************/
Pokitto 52:c04087025cab 124
Pokitto 52:c04087025cab 125 #define CLR_RESET LPC_GPIO_PORT->CLR[LCD_RES_PORT] = 1 << LCD_RES_PIN; //RST = (0); // Clear pin
Pokitto 52:c04087025cab 126 #define SET_RESET LPC_GPIO_PORT->SET[LCD_RES_PORT] = 1 << LCD_RES_PIN; // RST = (1); // Set pin
Pokitto 52:c04087025cab 127
Pokitto 52:c04087025cab 128 #define CLR_CD { LPC_GPIO_PORT->CLR[LCD_CD_PORT] = 1 << LCD_CD_PIN; } // RS = (0); // Clear pin
Pokitto 52:c04087025cab 129 #define SET_CD { LPC_GPIO_PORT->SET[LCD_CD_PORT] = 1 << LCD_CD_PIN; }// RS = (1); // Set pin
Pokitto 52:c04087025cab 130
Pokitto 52:c04087025cab 131 #define CLR_WR { LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;__asm("nop");}//__asm("nop");}//WR = (0); // Clear pin
Pokitto 52:c04087025cab 132 #define CLR_WR_SLOW { LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;__asm("nop");__asm("nop");}//WR = (0); // Clear pin
Pokitto 52:c04087025cab 133 #define SET_WR LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN; //WR = (1); // Set pin
Pokitto 52:c04087025cab 134
Pokitto 52:c04087025cab 135 #define CLR_RD LPC_GPIO_PORT->CLR[LCD_RD_PORT] = 1 << LCD_RD_PIN; //RD = (0); // Clear pin
Pokitto 52:c04087025cab 136 #define SET_RD LPC_GPIO_PORT->SET[LCD_RD_PORT] = 1 << LCD_RD_PIN; //RD = (1); // Set pin
Pokitto 52:c04087025cab 137
Pokitto 52:c04087025cab 138 #define SET_CS //CS tied to ground
Pokitto 52:c04087025cab 139 #define CLR_CS
Pokitto 52:c04087025cab 140
Pokitto 52:c04087025cab 141 #define CLR_CS_CD_SET_RD_WR {CLR_CD; SET_RD; SET_WR;}
Pokitto 52:c04087025cab 142 #define CLR_CS_SET_CD_RD_WR {SET_CD; SET_RD; SET_WR;}
Pokitto 52:c04087025cab 143 #define SET_CD_RD_WR {SET_CD; SET_RD; SET_WR;}
Pokitto 52:c04087025cab 144 #define SET_WR_CS SET_WR;
Pokitto 52:c04087025cab 145
Pokitto 52:c04087025cab 146 #define SET_MASK_P2 LPC_GPIO_PORT->MASK[2] = ~(0x7FFF8); //mask P2_3 ...P2_18
Pokitto 52:c04087025cab 147 #define CLR_MASK_P2 LPC_GPIO_PORT->MASK[2] = 0; // all on
Pokitto 52:c04087025cab 148
Pokitto 52:c04087025cab 149 #define TGL_WR_OP(OP) \
Pokitto 52:c04087025cab 150 LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN; \
Pokitto 52:c04087025cab 151 OP; \
Pokitto 52:c04087025cab 152 LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;
Pokitto 52:c04087025cab 153
Pokitto 52:c04087025cab 154 #define TGL_WR \
Pokitto 52:c04087025cab 155 LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN; \
Pokitto 52:c04087025cab 156 __asm("nop"); \
Pokitto 52:c04087025cab 157 LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;
Pokitto 52:c04087025cab 158
Pokitto 52:c04087025cab 159 /**************************************************************************/
Pokitto 52:c04087025cab 160 /** SETUP GPIO & DATA **/
Pokitto 52:c04087025cab 161 /**************************************************************************/
Pokitto 52:c04087025cab 162
Pokitto 52:c04087025cab 163 static void setup_gpio()
Pokitto 52:c04087025cab 164 {
Pokitto 52:c04087025cab 165 /** control lines **/
Pokitto 52:c04087025cab 166 LPC_GPIO_PORT->DIR[LCD_CD_PORT] |= (1 << LCD_CD_PIN );
Pokitto 52:c04087025cab 167 LPC_GPIO_PORT->DIR[LCD_WR_PORT] |= (1 << LCD_WR_PIN );
Pokitto 52:c04087025cab 168 LPC_GPIO_PORT->DIR[LCD_RD_PORT] |= (1 << LCD_RD_PIN );
Pokitto 52:c04087025cab 169 LPC_GPIO_PORT->DIR[LCD_RES_PORT] |= (1 << LCD_RES_PIN );
Pokitto 52:c04087025cab 170 /** data lines **/
Pokitto 52:c04087025cab 171 LPC_GPIO_PORT->DIR[2] |= (0xFFFF << 3); // P2_3...P2_18 as output
Pokitto 52:c04087025cab 172
Pokitto 52:c04087025cab 173 pin_mode(P2_3,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 174 pin_mode(P2_4,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 175 pin_mode(P2_5,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 176 pin_mode(P2_6,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 177
Pokitto 52:c04087025cab 178 pin_mode(P2_7,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 179 pin_mode(P2_8,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 180 pin_mode(P2_9,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 181 pin_mode(P2_10,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 182
Pokitto 52:c04087025cab 183 pin_mode(P2_11,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 184 pin_mode(P2_12,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 185 pin_mode(P2_13,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 186 pin_mode(P2_14,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 187
Pokitto 52:c04087025cab 188 pin_mode(P2_15,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 189 pin_mode(P2_16,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 190 pin_mode(P2_17,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 191 pin_mode(P2_18,PullNone); // turn off pull-up
Pokitto 52:c04087025cab 192 }
Pokitto 52:c04087025cab 193
Pokitto 52:c04087025cab 194
Pokitto 52:c04087025cab 195
Pokitto 52:c04087025cab 196
Pokitto 52:c04087025cab 197 #define HI_BYTE(d) (LPC_GPIO->MPIN[1]= (d<<13)) //((d>>8)<<21))
Pokitto 52:c04087025cab 198 #define LO_BYTE(d) (LPC_GPIO->MPIN[1]= (d<<21)) //because of mask makes no difference
Pokitto 52:c04087025cab 199
Pokitto 52:c04087025cab 200 // Macros to set data bus direction to input/output
Pokitto 52:c04087025cab 201 #define LCD_GPIO2DATA_SETINPUT GPIO_GPIO2DIR &= ~LCD_DATA_MASK
Pokitto 52:c04087025cab 202 #define LCD_GPIO2DATA_SETOUTPUT GPIO_GPIO2DIR |= LCD_DATA_MASK
Pokitto 52:c04087025cab 203
Pokitto 52:c04087025cab 204
Pokitto 52:c04087025cab 205 // Basic Color definitions
Pokitto 52:c04087025cab 206 #define COLOR_BLACK (uint16_t)(0x0000)
Pokitto 52:c04087025cab 207 #define COLOR_BLUE (uint16_t)(0x001F)
Pokitto 52:c04087025cab 208 #define COLOR_RED (uint16_t)(0xF800)
Pokitto 52:c04087025cab 209 #define COLOR_GREEN (uint16_t)(0x07E0)
Pokitto 52:c04087025cab 210 #define COLOR_CYAN (uint16_t)(0x07FF)
Pokitto 52:c04087025cab 211 #define COLOR_MAGENTA (uint16_t)(0xF81F)
Pokitto 52:c04087025cab 212 #define COLOR_YELLOW (uint16_t)(0xFFE0)
Pokitto 52:c04087025cab 213 #define COLOR_WHITE (uint16_t)(0xFFFF)
Pokitto 52:c04087025cab 214
Pokitto 52:c04087025cab 215 // Grayscale Values
Pokitto 52:c04087025cab 216 #define COLOR_GRAY_15 (uint16_t)(0x0861) // 15 15 15
Pokitto 52:c04087025cab 217 #define COLOR_GRAY_30 (uint16_t)(0x18E3) // 30 30 30
Pokitto 52:c04087025cab 218 #define COLOR_GRAY_50 (uint16_t)(0x3186) // 50 50 50
Pokitto 52:c04087025cab 219 #define COLOR_GRAY_80 (uint16_t)(0x528A) // 80 80 80
Pokitto 52:c04087025cab 220 #define COLOR_GRAY_128 (uint16_t)(0x8410) // 128 128 128
Pokitto 52:c04087025cab 221 #define COLOR_GRAY_200 (uint16_t)(0xCE59) // 200 200 200
Pokitto 52:c04087025cab 222 #define COLOR_GRAY_225 (uint16_t)(0xE71C) // 225 225 225
Pokitto 52:c04087025cab 223
Pokitto 52:c04087025cab 224
Pokitto 52:c04087025cab 225 } // namespace pokitto
Pokitto 52:c04087025cab 226 #endif // __HWLCD_H_
Pokitto 52:c04087025cab 227
Pokitto 52:c04087025cab 228