PokittoLib with changes to lcd refresh etc.

Dependents:   Pokittris

Fork of Pokitto by Pokitto Community Team

This is a fork by user @Spinal, and is used in Pokittris for testing. Do not import this to your own program.

Committer:
spinal
Date:
Sun Oct 15 16:50:56 2017 +0000
Revision:
10:8cde5d0bafad
Parent:
9:570fdd653f1d
updated the draw routines a little in pokitto lib, I hope it didn't break anything else

Who changed what in which revision?

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