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:
Fri Dec 29 02:55:34 2017 +0000
Revision:
22:e826f80d8582
PokittoLib with @Spinalcodes direct non-buffered tricks

Who changed what in which revision?

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