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

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HWLCD.h Source File

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 extern void lcdRefreshMixMode(const uint8_t *, const uint16_t*, const uint8_t*);
00085 extern void lcdRefreshMode64(uint8_t *, uint16_t*);
00086 
00087 extern void lcdRefreshMode15(uint16_t*, uint8_t*);
00088 
00089 
00090 /** Update LCD from 1-bit tile mode */
00091 extern void lcdRefreshT1(uint8_t*, uint8_t*, uint8_t*, uint16_t*);
00092 extern void lcdClear();
00093 extern void lcdFill(uint16_t);
00094 /** Blit one word of data*/
00095 extern void blitWord(uint16_t);
00096 
00097 /**************************************************************************/
00098 /**                          PINS AND PORTS                              **/
00099 /**************************************************************************/
00100 
00101 #if POK_BOARDREV == 1
00102 /** 2-layer board version 1.3 **/
00103  #define LCD_CD_PORT           0
00104  #define LCD_CD_PIN            2
00105  #define LCD_WR_PORT           1
00106  #define LCD_WR_PIN            23
00107  #define LCD_RD_PORT           1
00108  #define LCD_RD_PIN            24
00109  #define LCD_RES_PORT          1
00110  #define LCD_RES_PIN           28
00111 #else
00112 /** 4-layer board version 2.1 **/
00113  #define LCD_CD_PORT           0
00114  #define LCD_CD_PIN            2
00115  #define LCD_WR_PORT           1
00116  #define LCD_WR_PIN            12
00117  #define LCD_RD_PORT           1
00118  #define LCD_RD_PIN            24
00119  #define LCD_RES_PORT          1
00120  #define LCD_RES_PIN           0
00121 #endif
00122 
00123 /**************************************************************************/
00124 /**                          LCD CONTROL MACROS                          **/
00125 /**************************************************************************/
00126 
00127 #define CLR_RESET LPC_GPIO_PORT->CLR[LCD_RES_PORT] = 1 << LCD_RES_PIN; //RST = (0); // Clear pin
00128 #define SET_RESET LPC_GPIO_PORT->SET[LCD_RES_PORT] = 1 << LCD_RES_PIN; // RST = (1); // Set pin
00129 
00130 #define CLR_CD { LPC_GPIO_PORT->CLR[LCD_CD_PORT] = 1 << LCD_CD_PIN; } // RS = (0); // Clear pin
00131 #define SET_CD { LPC_GPIO_PORT->SET[LCD_CD_PORT] = 1 << LCD_CD_PIN; }// RS = (1); // Set pin
00132 
00133 #define CLR_WR { LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;__asm("nop");}//__asm("nop");}//WR = (0); // Clear pin
00134 #define CLR_WR_SLOW { LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;__asm("nop");__asm("nop");}//WR = (0); // Clear pin
00135 #define SET_WR LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN; //WR = (1); // Set pin
00136 
00137 #define CLR_RD LPC_GPIO_PORT->CLR[LCD_RD_PORT] = 1 << LCD_RD_PIN; //RD = (0); // Clear pin
00138 #define SET_RD LPC_GPIO_PORT->SET[LCD_RD_PORT] = 1 << LCD_RD_PIN; //RD = (1); // Set pin
00139 
00140 #define SET_CS  //CS tied to ground
00141 #define CLR_CS
00142 
00143 #define CLR_CS_CD_SET_RD_WR {CLR_CD; SET_RD; SET_WR;}
00144 #define CLR_CS_SET_CD_RD_WR {SET_CD; SET_RD; SET_WR;}
00145 #define SET_CD_RD_WR {SET_CD; SET_RD; SET_WR;}
00146 #define SET_WR_CS SET_WR;
00147 
00148 #define SET_MASK_P2 LPC_GPIO_PORT->MASK[2] = ~(0x7FFF8); //mask P2_3 ...P2_18
00149 #define CLR_MASK_P2 LPC_GPIO_PORT->MASK[2] = 0; // all on
00150 
00151 #define TGL_WR_OP(OP)                           \
00152   LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;            \
00153   OP;                                   \
00154   LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN;            
00155 
00156 #define TGL_WR                              \
00157   LPC_GPIO_PORT->CLR[LCD_WR_PORT] = 1 << LCD_WR_PIN;            \
00158   __asm("nop");                             \
00159   LPC_GPIO_PORT->SET[LCD_WR_PORT] = 1 << LCD_WR_PIN;            
00160 
00161 /**************************************************************************/
00162 /**                          SETUP GPIO & DATA                           **/
00163 /**************************************************************************/
00164 
00165 static void setup_gpio()
00166 {
00167     /** control lines **/
00168     LPC_GPIO_PORT->DIR[LCD_CD_PORT] |= (1  << LCD_CD_PIN );
00169     LPC_GPIO_PORT->DIR[LCD_WR_PORT] |= (1  << LCD_WR_PIN );
00170     LPC_GPIO_PORT->DIR[LCD_RD_PORT] |= (1  << LCD_RD_PIN );
00171     LPC_GPIO_PORT->DIR[LCD_RES_PORT] |= (1  << LCD_RES_PIN );
00172     /** data lines **/
00173     LPC_GPIO_PORT->DIR[2] |= (0xFFFF  << 3);  // P2_3...P2_18 as output
00174 
00175     pin_mode(P2_3,PullNone); // turn off pull-up
00176     pin_mode(P2_4,PullNone); // turn off pull-up
00177     pin_mode(P2_5,PullNone); // turn off pull-up
00178     pin_mode(P2_6,PullNone); // turn off pull-up
00179 
00180     pin_mode(P2_7,PullNone); // turn off pull-up
00181     pin_mode(P2_8,PullNone); // turn off pull-up
00182     pin_mode(P2_9,PullNone); // turn off pull-up
00183     pin_mode(P2_10,PullNone); // turn off pull-up
00184 
00185     pin_mode(P2_11,PullNone); // turn off pull-up
00186     pin_mode(P2_12,PullNone); // turn off pull-up
00187     pin_mode(P2_13,PullNone); // turn off pull-up
00188     pin_mode(P2_14,PullNone); // turn off pull-up
00189 
00190     pin_mode(P2_15,PullNone); // turn off pull-up
00191     pin_mode(P2_16,PullNone); // turn off pull-up
00192     pin_mode(P2_17,PullNone); // turn off pull-up
00193     pin_mode(P2_18,PullNone); // turn off pull-up
00194 }
00195 
00196 
00197 
00198 
00199 #define HI_BYTE(d) (LPC_GPIO->MPIN[1]= (d<<13)) //((d>>8)<<21))
00200 #define LO_BYTE(d) (LPC_GPIO->MPIN[1]= (d<<21)) //because of mask makes no difference
00201 
00202 // Macros to set data bus direction to input/output
00203 #define LCD_GPIO2DATA_SETINPUT  GPIO_GPIO2DIR &= ~LCD_DATA_MASK
00204 #define LCD_GPIO2DATA_SETOUTPUT GPIO_GPIO2DIR |= LCD_DATA_MASK
00205 
00206 
00207 // Basic Color definitions
00208 #define COLOR_BLACK                         (uint16_t)(0x0000)
00209 #define COLOR_BLUE                          (uint16_t)(0x001F)
00210 #define COLOR_RED                           (uint16_t)(0xF800)
00211 #define COLOR_GREEN                         (uint16_t)(0x07E0)
00212 #define COLOR_CYAN                          (uint16_t)(0x07FF)
00213 #define COLOR_MAGENTA                       (uint16_t)(0xF81F)
00214 #define COLOR_YELLOW                        (uint16_t)(0xFFE0)
00215 #define COLOR_WHITE                         (uint16_t)(0xFFFF)
00216 
00217 // Grayscale Values
00218 #define COLOR_GRAY_15                       (uint16_t)(0x0861)    //  15  15  15
00219 #define COLOR_GRAY_30                       (uint16_t)(0x18E3)    //  30  30  30
00220 #define COLOR_GRAY_50                       (uint16_t)(0x3186)    //  50  50  50
00221 #define COLOR_GRAY_80                       (uint16_t)(0x528A)    //  80  80  80
00222 #define COLOR_GRAY_128                      (uint16_t)(0x8410)    // 128 128 128
00223 #define COLOR_GRAY_200                      (uint16_t)(0xCE59)    // 200 200 200
00224 #define COLOR_GRAY_225                      (uint16_t)(0xE71C)    // 225 225 225
00225 
00226 
00227 } // namespace pokitto
00228 #endif // __HWLCD_H_
00229 
00230