PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Embed:
(wiki syntax)
Show/hide line numbers
HWLCD.h
Go to the documentation of this file.
00001 /**************************************************************************/ 00002 /*! 00003 @file HWLCD.h 00004 @author Jonne Valola 00005 00006 @section LICENSE 00007 00008 Software License Agreement (BSD License) 00009 00010 Copyright (c) 2016, Jonne Valola 00011 All rights reserved. 00012 00013 Redistribution and use in source and binary forms, with or without 00014 modification, are permitted provided that the following conditions are met: 00015 1. Redistributions of source code must retain the above copyright 00016 notice, this list of conditions and the following disclaimer. 00017 2. Redistributions in binary form must reproduce the above copyright 00018 notice, this list of conditions and the following disclaimer in the 00019 documentation and/or other materials provided with the distribution. 00020 3. Neither the name of the copyright holders nor the 00021 names of its contributors may be used to endorse or promote products 00022 derived from this software without specific prior written permission. 00023 00024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 00025 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00028 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 /**************************************************************************/ 00036 00037 #ifndef __HWLCD_H__ 00038 #define __HWLCD_H__ 00039 00040 #include "mbed.h" 00041 #include "gpio_api.h" 00042 #include "pinmap.h" 00043 00044 #define write_command write_command_16 00045 #define write_data write_data_16 00046 00047 extern volatile uint32_t *LCD; 00048 00049 namespace Pokitto { 00050 00051 struct SpriteInfo { 00052 const uint8_t* bitmapData; 00053 int16_t x; 00054 int16_t y; 00055 int16_t oldx; 00056 int16_t oldy; 00057 uint8_t w; 00058 uint8_t h; 00059 uint16_t palette[4]; 00060 }; 00061 00062 extern void setDRAMpoint(uint8_t, uint8_t); 00063 extern void pumpDRAMdata(uint16_t*, uint16_t); 00064 extern void initBacklight(); 00065 extern void setBacklight(float); 00066 extern void lcdFillSurface(uint16_t); 00067 extern void lcdPixel(int16_t x, int16_t y, uint16_t c); 00068 extern void setWindow(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2); 00069 extern void lcdTile(int16_t x0, int16_t y0, int16_t width, int16_t height, uint16_t* gfx); 00070 extern void lcdRectangle(int16_t x, int16_t y,int16_t x2, int16_t y2, uint16_t color); 00071 extern void lcdInit(); 00072 extern void lcdSleep(); 00073 extern void lcdWakeUp(); 00074 extern void lcdRefresh(uint8_t *, uint16_t*); 00075 extern void lcdRefreshAB(uint8_t *, uint16_t*); 00076 extern void lcdRefreshMode14(uint8_t *, uint16_t*); 00077 extern void lcdRefreshGB(uint8_t *, uint16_t*); 00078 extern void lcdRefreshMode1(uint8_t* scrbuf, uint8_t updRectX, uint8_t updRectY, uint8_t updRectW, uint8_t updRectH, uint16_t* paletteptr); 00079 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); 00080 extern void lcdRefreshMode2(uint8_t *, uint16_t*); 00081 extern void lcdRefreshMode3(uint8_t *, uint16_t*); 00082 extern void lcdRefreshModeGBC(uint8_t *, uint16_t*); 00083 extern void lcdRefreshMode13(uint8_t *, uint16_t*, uint8_t); 00084 00085 extern void lcdRefreshMode15(uint16_t*, uint8_t*); 00086 00087 00088 /** Update LCD from 1-bit tile mode */ 00089 extern void lcdRefreshT1(uint8_t*, uint8_t*, uint8_t*, uint16_t*); 00090 extern void lcdClear(); 00091 extern void lcdFill(uint16_t); 00092 /** Blit one word of data*/ 00093 extern void blitWord(uint16_t); 00094 00095 /**************************************************************************/ 00096 /** PINS AND PORTS **/ 00097 /**************************************************************************/ 00098 00099 #if POK_BOARDREV == 1 00100 /** 2-layer board version 1.3 **/ 00101 #define LCD_CD_PORT 0 00102 #define LCD_CD_PIN 2 00103 #define LCD_WR_PORT 1 00104 #define LCD_WR_PIN 23 00105 #define LCD_RD_PORT 1 00106 #define LCD_RD_PIN 24 00107 #define LCD_RES_PORT 1 00108 #define LCD_RES_PIN 28 00109 #else 00110 /** 4-layer board version 2.1 **/ 00111 #define LCD_CD_PORT 0 00112 #define LCD_CD_PIN 2 00113 #define LCD_WR_PORT 1 00114 #define LCD_WR_PIN 12 00115 #define LCD_RD_PORT 1 00116 #define LCD_RD_PIN 24 00117 #define LCD_RES_PORT 1 00118 #define LCD_RES_PIN 0 00119 #endif 00120 00121 /**************************************************************************/ 00122 /** LCD CONTROL MACROS **/ 00123 /**************************************************************************/ 00124 00125 #define CLR_RESET LPC_GPIO_PORT->CLR[LCD_RES_PORT] = 1 << LCD_RES_PIN; //RST = (0); // Clear pin 00126 #define SET_RESET LPC_GPIO_PORT->SET[LCD_RES_PORT] = 1 << LCD_RES_PIN; // RST = (1); // Set pin 00127 00128 #define CLR_CD { LPC_GPIO_PORT->CLR[LCD_CD_PORT] = 1 << LCD_CD_PIN; } // RS = (0); // Clear pin 00129 #define SET_CD { LPC_GPIO_PORT->SET[LCD_CD_PORT] = 1 << LCD_CD_PIN; }// RS = (1); // Set pin 00130 00131 #define CLR_WR { LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;__asm("nop");}//__asm("nop");}//WR = (0); // Clear pin 00132 #define CLR_WR_SLOW { LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;__asm("nop");__asm("nop");}//WR = (0); // Clear pin 00133 #define SET_WR LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN; //WR = (1); // Set pin 00134 00135 #define CLR_RD LPC_GPIO_PORT->CLR[LCD_RD_PORT] = 1 << LCD_RD_PIN; //RD = (0); // Clear pin 00136 #define SET_RD LPC_GPIO_PORT->SET[LCD_RD_PORT] = 1 << LCD_RD_PIN; //RD = (1); // Set pin 00137 00138 #define SET_CS //CS tied to ground 00139 #define CLR_CS 00140 00141 #define CLR_CS_CD_SET_RD_WR {CLR_CD; SET_RD; SET_WR;} 00142 #define CLR_CS_SET_CD_RD_WR {SET_CD; SET_RD; SET_WR;} 00143 #define SET_CD_RD_WR {SET_CD; SET_RD; SET_WR;} 00144 #define SET_WR_CS SET_WR; 00145 00146 #define SET_MASK_P2 LPC_GPIO_PORT->MASK[2] = ~(0x7FFF8); //mask P2_3 ...P2_18 00147 #define CLR_MASK_P2 LPC_GPIO_PORT->MASK[2] = 0; // all on 00148 00149 #define TGL_WR_OP(OP) \ 00150 LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN; \ 00151 OP; \ 00152 LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN; 00153 00154 #define TGL_WR \ 00155 LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN; \ 00156 __asm("nop"); \ 00157 LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN; 00158 00159 /**************************************************************************/ 00160 /** SETUP GPIO & DATA **/ 00161 /**************************************************************************/ 00162 00163 static void setup_gpio() 00164 { 00165 /** control lines **/ 00166 LPC_GPIO_PORT->DIR[LCD_CD_PORT] |= (1 << LCD_CD_PIN ); 00167 LPC_GPIO_PORT->DIR[LCD_WR_PORT] |= (1 << LCD_WR_PIN ); 00168 LPC_GPIO_PORT->DIR[LCD_RD_PORT] |= (1 << LCD_RD_PIN ); 00169 LPC_GPIO_PORT->DIR[LCD_RES_PORT] |= (1 << LCD_RES_PIN ); 00170 /** data lines **/ 00171 LPC_GPIO_PORT->DIR[2] |= (0xFFFF << 3); // P2_3...P2_18 as output 00172 00173 pin_mode(P2_3,PullNone); // turn off pull-up 00174 pin_mode(P2_4,PullNone); // turn off pull-up 00175 pin_mode(P2_5,PullNone); // turn off pull-up 00176 pin_mode(P2_6,PullNone); // turn off pull-up 00177 00178 pin_mode(P2_7,PullNone); // turn off pull-up 00179 pin_mode(P2_8,PullNone); // turn off pull-up 00180 pin_mode(P2_9,PullNone); // turn off pull-up 00181 pin_mode(P2_10,PullNone); // turn off pull-up 00182 00183 pin_mode(P2_11,PullNone); // turn off pull-up 00184 pin_mode(P2_12,PullNone); // turn off pull-up 00185 pin_mode(P2_13,PullNone); // turn off pull-up 00186 pin_mode(P2_14,PullNone); // turn off pull-up 00187 00188 pin_mode(P2_15,PullNone); // turn off pull-up 00189 pin_mode(P2_16,PullNone); // turn off pull-up 00190 pin_mode(P2_17,PullNone); // turn off pull-up 00191 pin_mode(P2_18,PullNone); // turn off pull-up 00192 } 00193 00194 00195 00196 00197 #define HI_BYTE(d) (LPC_GPIO->MPIN[1]= (d<<13)) //((d>>8)<<21)) 00198 #define LO_BYTE(d) (LPC_GPIO->MPIN[1]= (d<<21)) //because of mask makes no difference 00199 00200 // Macros to set data bus direction to input/output 00201 #define LCD_GPIO2DATA_SETINPUT GPIO_GPIO2DIR &= ~LCD_DATA_MASK 00202 #define LCD_GPIO2DATA_SETOUTPUT GPIO_GPIO2DIR |= LCD_DATA_MASK 00203 00204 00205 // Basic Color definitions 00206 #define COLOR_BLACK (uint16_t)(0x0000) 00207 #define COLOR_BLUE (uint16_t)(0x001F) 00208 #define COLOR_RED (uint16_t)(0xF800) 00209 #define COLOR_GREEN (uint16_t)(0x07E0) 00210 #define COLOR_CYAN (uint16_t)(0x07FF) 00211 #define COLOR_MAGENTA (uint16_t)(0xF81F) 00212 #define COLOR_YELLOW (uint16_t)(0xFFE0) 00213 #define COLOR_WHITE (uint16_t)(0xFFFF) 00214 00215 // Grayscale Values 00216 #define COLOR_GRAY_15 (uint16_t)(0x0861) // 15 15 15 00217 #define COLOR_GRAY_30 (uint16_t)(0x18E3) // 30 30 30 00218 #define COLOR_GRAY_50 (uint16_t)(0x3186) // 50 50 50 00219 #define COLOR_GRAY_80 (uint16_t)(0x528A) // 80 80 80 00220 #define COLOR_GRAY_128 (uint16_t)(0x8410) // 128 128 128 00221 #define COLOR_GRAY_200 (uint16_t)(0xCE59) // 200 200 200 00222 #define COLOR_GRAY_225 (uint16_t)(0xE71C) // 225 225 225 00223 00224 00225 } // namespace pokitto 00226 #endif // __HWLCD_H_ 00227 00228
Generated on Tue Jul 12 2022 21:03:50 by 1.7.2