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:
Mon Apr 02 22:37:22 2018 +0000
Revision:
36:771321e70814
Synced with Github repo

Who changed what in which revision?

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