Phoenard
PHNDisplayHardware.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 This file is part of the Phoenard Arduino library
5 Copyright (c) 2014 Phoenard
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
76 #include <Arduino.h>
77 #include "PHNCore.h"
78 
79 #ifndef PHN_DISPLAY_HARDWARE_H_
80 #define PHN_DISPLAY_HARDWARE_H_
81 
88 #define LCD_AUTO_INITIALIZE 0
89 
94 #define LCD_OUTPUT_SERIAL 0
95 
97 typedef uint16_t color_t;
98 
103 #define LCD_CMD_START_OSC 0x00
104 #define LCD_CMD_DRIV_OUT_CTRL 0x01
105 #define LCD_CMD_DRIV_WAV_CTRL 0x02
106 #define LCD_CMD_ENTRY_MOD 0x03
107 #define LCD_CMD_RESIZE_CTRL 0x04
108 #define LCD_CMD_DISP_CTRL1 0x07
109 #define LCD_CMD_DISP_CTRL2 0x08
110 #define LCD_CMD_DISP_CTRL3 0x09
111 #define LCD_CMD_DISP_CTRL4 0x0A
112 #define LCD_CMD_RGB_DISP_IF_CTRL1 0x0C
113 #define LCD_CMD_FRM_MARKER_POS 0x0D
114 #define LCD_CMD_RGB_DISP_IF_CTRL2 0x0F
115 #define LCD_CMD_POW_CTRL1 0x10
116 #define LCD_CMD_POW_CTRL2 0x11
117 #define LCD_CMD_POW_CTRL3 0x12
118 #define LCD_CMD_POW_CTRL4 0x13
119 #define LCD_CMD_GRAM_HOR_AD 0x20
120 #define LCD_CMD_GRAM_VER_AD 0x21
121 #define LCD_CMD_RW_GRAM 0x22
122 #define LCD_CMD_POW_CTRL7 0x29
123 #define LCD_CMD_FRM_RATE_COL_CTRL 0x2B
124 #define LCD_CMD_GAMMA_CTRL1 0x30
125 #define LCD_CMD_GAMMA_CTRL2 0x31
126 #define LCD_CMD_GAMMA_CTRL3 0x32
127 #define LCD_CMD_GAMMA_CTRL4 0x35
128 #define LCD_CMD_GAMMA_CTRL5 0x36
129 #define LCD_CMD_GAMMA_CTRL6 0x37
130 #define LCD_CMD_GAMMA_CTRL7 0x38
131 #define LCD_CMD_GAMMA_CTRL8 0x39
132 #define LCD_CMD_GAMMA_CTRL9 0x3C
133 #define LCD_CMD_GAMMA_CTRL10 0x3D
134 #define LCD_CMD_HOR_START_AD 0x50
135 #define LCD_CMD_HOR_END_AD 0x51
136 #define LCD_CMD_VER_START_AD 0x52
137 #define LCD_CMD_VER_END_AD 0x53
138 #define LCD_CMD_GATE_SCAN_CTRL1 0x60
139 #define LCD_CMD_GATE_SCAN_CTRL2 0x61
140 #define LCD_CMD_GATE_SCAN_CTRL3 0x6A
141 #define LCD_CMD_PART_IMG1_DISP_POS 0x80
142 #define LCD_CMD_PART_IMG1_START_AD 0x81
143 #define LCD_CMD_PART_IMG1_END_AD 0x82
144 #define LCD_CMD_PART_IMG2_DISP_POS 0x83
145 #define LCD_CMD_PART_IMG2_START_AD 0x84
146 #define LCD_CMD_PART_IMG2_END_AD 0x85
147 #define LCD_CMD_PANEL_IF_CTRL1 0x90
148 #define LCD_CMD_PANEL_IF_CTRL2 0x92
149 #define LCD_CMD_PANEL_IF_CTRL3 0x93
150 #define LCD_CMD_PANEL_IF_CTRL4 0x95
151 #define LCD_CMD_PANEL_IF_CTRL5 0x97
152 #define LCD_CMD_PANEL_IF_CTRL6 0x98
153 
154 
155 
160 #define BLACK 0x0000
161 #define WHITE 0xFFFF
162 #define GRAY 0x8410
163 #define GRAY_DARK 0x4208
164 #define GRAY_LIGHT 0xC618
165 #define BLUE 0x001F
166 #define RED 0xF800
167 #define GREEN 0x07E0
168 #define CYAN 0x07FF
169 #define MAGENTA 0xF81F
170 #define YELLOW 0xFFE0
171 #define ORANGE 0xFC00
172 
173 
178 #define BLACK_8BIT 0x00
179 #define WHITE_8BIT 0xFF
180 #define GRAY_8BIT 0xD5
181 #define GRAY_LIGHT_8BIT 0xF6
182 #define YELLOW_8BIT 0xEE
183 #define ORANGE_8BIT 0xE4
184 #define RED_8BIT 0xE0
185 #define GREEN_8BIT 0xC7
186 #define BLUE_8BIT 0x9E
187 #define CYAN_8BIT 0xDF
188 #define PURPLE_8BIT 0xDC
189 
190 
195 #define DIR_RIGHT_WRAP_DOWN 0x08
196 #define DIR_DOWN_WRAP_DOWN 0x20
197 #define DIR_LEFT_WRAP_DOWN 0x38
198 #define DIR_UP_WRAP_DOWN 0x10
199 #define DIR_RIGHT_WRAP_UP 0x18
200 #define DIR_DOWN_WRAP_UP 0x00
201 #define DIR_LEFT_WRAP_UP 0x28
202 #define DIR_UP_WRAP_UP 0x30
203 #define DIR_RIGHT DIR_RIGHT_WRAP_DOWN
204 #define DIR_DOWN DIR_DOWN_WRAP_DOWN
205 #define DIR_LEFT DIR_LEFT_WRAP_DOWN
206 #define DIR_UP DIR_UP_WRAP_DOWN
207 
208 
210 #define COLOR8TO16(color) ((uint16_t) ((color & 0xFF) | ((color) << 8)))
211 
213 extern const unsigned char phn_font_5x7[] PROGMEM;
214 
216 namespace PHNDisplayHW {
217 
219  const uint16_t WIDTH = 320;
221  const uint16_t HEIGHT = 240;
223  const uint32_t PIXELS = ((uint32_t) WIDTH * (uint32_t) HEIGHT);
225  const uint16_t WIDTH_SLIDER = (WIDTH + 32);
227  const float PRESSURE_MIN = 0.0F;
229  const float PRESSURE_MAX = 1.0F;
231  const float PRESSURE_THRESHOLD = 0.2F;
232 
234  void init();
236  void writeData(uint16_t data);
238  void writeCommand(uint8_t cmd);
240  void writeRegister(uint8_t cmd, uint16_t arg);
242  uint16_t readData();
244  uint16_t readRegister(uint8_t cmd);
246  void setCursor(uint16_t x, uint16_t y, uint8_t direction);
248  void setCursor(uint16_t x, uint16_t y);
250  void setViewport(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
252  color_t color565(uint8_t r, uint8_t g, uint8_t b);
254  color_t colorAverage(color_t colorA, color_t colorB);
256  color_t colorLerp(color_t colorA, color_t colorB, float f);
258  uint8_t color565Red(color_t color);
260  uint8_t color565Green(color_t color);
262  uint8_t color565Blue(color_t color);
264  void readTouch(uint16_t *analogX, uint16_t *analogY, uint16_t *analogZ1, uint16_t *analogZ2);
266  void readTouch(uint16_t *touch_x, uint16_t *touch_y, float *pressure);
267 }
268 
270 namespace PHNDisplay8Bit {
272  void writePixel(uint8_t color);
274  void writePixels(uint8_t color, uint32_t length);
276  void writePixelLines(uint8_t color, uint8_t lines);
278  void drawLine(uint16_t x, uint16_t y, uint32_t length, uint8_t direction, uint8_t color);
280  void drawRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t color);
282  void fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t color);
284  void fill(uint8_t color);
285 
287  void colorTest();
288 
290  void writeString(uint16_t x, uint16_t y, uint8_t scale, const char* text, uint8_t color0, uint8_t color1);
292  void writeChar(uint16_t x, uint16_t y, uint8_t scale, char c, uint8_t color0, uint8_t color1);
293 
295  void writeFont_1bit(uint16_t x, uint16_t y, uint8_t scale, const uint8_t* data, uint8_t color0, uint8_t color1);
296 
298  void writeImage_1bit(uint16_t x, uint16_t y, uint8_t width, uint8_t height,
299  uint8_t scale, const uint8_t* data, uint8_t direction, uint8_t color0, uint8_t color1);
300 }
301 
303 namespace PHNDisplay16Bit {
305  void writePixel(uint16_t color);
307  uint16_t readPixel(uint16_t x, uint16_t y);
309  void writePixels(uint16_t color, uint32_t length);
311  void writePixels(uint16_t* colorData, uint16_t length);
313  void drawLine(uint16_t x, uint16_t y, uint32_t length, uint8_t direction, uint16_t color);
315  void fill(uint16_t color);
316 
318  void colorTest();
319 
321  void writeString(uint16_t x, uint16_t y, uint8_t scale, const char* text, uint16_t color0, uint16_t color1);
323  void writeChar(uint16_t x, uint16_t y, uint8_t scale, char c, uint16_t color0, uint16_t color1);
324 
326  void writeFont_1bit(uint16_t x, uint16_t y, uint8_t scale, const uint8_t* data, uint16_t color0, uint16_t color1);
327 
329  void writeImage_1bit(uint16_t x, uint16_t y, uint8_t width, uint8_t height,
330  uint8_t scale, const uint8_t* data, uint8_t direction, uint16_t color0, uint16_t color1);
331 }
332 
334 #if LCD_OUTPUT_SERIAL
335 namespace PHNDisplaySerial {
336  void writeCommand(uint8_t cmd);
337  void writeData(uint16_t arg);
338  void writeData(uint16_t arg, uint32_t cnt);
339 }
340 #endif
341 
344 #endif
void writeFont_1bit(uint16_t x, uint16_t y, uint8_t scale, const uint8_t *data, uint8_t color0, uint8_t color1)
Draws a 5x7 1-bit font character, the font data must be stored in FLASH.
Definition: PHNDisplayHardware.cpp:515
void fill(uint16_t color)
Fills the entire screen with 16-bit color.
Definition: PHNDisplayHardware.cpp:598
void writePixel(uint8_t color)
Writes out a single 8-bit color pixel.
Definition: PHNDisplayHardware.cpp:418
void writeRegister(uint8_t cmd, uint16_t arg)
Writes a command, and an argument, to the LCD display, to set up a register.
Definition: PHNDisplayHardware.cpp:182
const uint16_t WIDTH
The display width.
Definition: PHNDisplayHardware.h:219
void colorTest()
Fills the screen with all possible 16-bit colors (65536 of them)
Definition: PHNDisplayHardware.cpp:603
16-bit display (drawing) logic for full color
Definition: PHNDisplayHardware.cpp:524
const float PRESSURE_THRESHOLD
Pressure value above which a press should be detected.
Definition: PHNDisplayHardware.h:231
uint8_t color565Red(color_t color)
Obtains the RED component of a 16-bit 565 color.
Definition: PHNDisplayHardware.cpp:288
const float PRESSURE_MIN
Minimum possible pressure value.
Definition: PHNDisplayHardware.h:227
void setCursor(uint16_t x, uint16_t y, uint8_t direction)
Sets up the register of the LCD to update the cursor coordinates.
Definition: PHNDisplayHardware.cpp:215
void writePixels(uint8_t color, uint32_t length)
Writes out many 8-bit color pixels in bulk, length is the amount of pixels to write out...
Definition: PHNDisplayHardware.cpp:434
uint16_t readPixel(uint16_t x, uint16_t y)
Reads a single 16-bit color pixel at [x, y].
Definition: PHNDisplayHardware.cpp:530
const uint16_t HEIGHT
The display height.
Definition: PHNDisplayHardware.h:221
uint16_t readRegister(uint8_t cmd)
Writes a command, then reads the response from the LCD display.
Definition: PHNDisplayHardware.cpp:210
void writePixels(uint16_t color, uint32_t length)
Writes out many 16-bit color pixels in bulk, length is the amount of pixels to write out...
Definition: PHNDisplayHardware.cpp:545
color_t colorAverage(color_t colorA, color_t colorB)
Calculates the average of two 16-bit 565 colors.
Definition: PHNDisplayHardware.cpp:273
void fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t color)
Filling rectangle with 8-bit color.
Definition: PHNDisplayHardware.cpp:469
void writeCommand(uint8_t cmd)
Writes a single command to the LCD display.
Definition: PHNDisplayHardware.cpp:159
void writeChar(uint16_t x, uint16_t y, uint8_t scale, char c, uint8_t color0, uint8_t color1)
Draws a Character to the screen using the standard font.
Definition: PHNDisplayHardware.cpp:511
uint8_t color565Blue(color_t color)
Obtains the BLUE component of a 16-bit 565 color.
Definition: PHNDisplayHardware.cpp:296
8-bit display (drawing) logic for size and speed optimization freaks
Definition: PHNDisplayHardware.cpp:416
const float PRESSURE_MAX
Maximum possible pressure value.
Definition: PHNDisplayHardware.h:229
void writeString(uint16_t x, uint16_t y, uint8_t scale, const char *text, uint8_t color0, uint8_t color1)
Draws a String to the screen using the standard font.
Definition: PHNDisplayHardware.cpp:507
void writePixelLines(uint8_t color, uint8_t lines)
Writes out many 8-bit color pixels in bulk, specifying how many lines to fill.
Definition: PHNDisplayHardware.cpp:453
void writeData(uint16_t data)
Writes a single word of data to the LCD display.
Definition: PHNDisplayHardware.cpp:143
void writePixel(uint16_t color)
Writes out a single 16-bit color pixel.
Definition: PHNDisplayHardware.cpp:526
const uint16_t WIDTH_SLIDER
The display width that takes the slider into account.
Definition: PHNDisplayHardware.h:225
uint16_t color_t
Definition of the 16-bit 565 color type.
Definition: PHNDisplayHardware.h:97
const unsigned char phn_font_5x7[] PROGMEM
The default 5x7 font that is stored in program memory.
Definition: PHNDisplayFont.cpp:31
void drawLine(uint16_t x, uint16_t y, uint32_t length, uint8_t direction, uint16_t color)
Drawing a line with 16-bit color.
Definition: PHNDisplayHardware.cpp:591
void drawRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t color)
Drawing a rectangle with 8-bit color.
Definition: PHNDisplayHardware.cpp:462
color_t color565(uint8_t r, uint8_t g, uint8_t b)
Converts RGB color into the 16-bit 565-color format used by the display.
Definition: PHNDisplayHardware.cpp:262
const uint32_t PIXELS
The total amount of pixels of the display.
Definition: PHNDisplayHardware.h:223
Pinout information for the Phoenard hardware components.
void fill(uint8_t color)
Fills the entire screen with 8-bit color.
Definition: PHNDisplayHardware.cpp:476
Main display hardware functions are contained here.
Definition: PHNDisplayHardware.cpp:97
void init()
Resets and then initializes the LCD screen registers for first use.
Definition: PHNDisplayHardware.cpp:106
void writeImage_1bit(uint16_t x, uint16_t y, uint8_t width, uint8_t height, uint8_t scale, const uint8_t *data, uint8_t direction, uint8_t color0, uint8_t color1)
Drawing 1-bit images stored in RAM (not FLASH!)
Definition: PHNDisplayHardware.cpp:519
uint16_t readData()
Reads a single word of data from the LCD display.
Definition: PHNDisplayHardware.cpp:187
void colorTest()
Fills the screen with all possible 8-bit colors (256 of them)
Definition: PHNDisplayHardware.cpp:481
void writeString(uint16_t x, uint16_t y, uint8_t scale, const char *text, uint16_t color0, uint16_t color1)
Draws a String to the screen using the standard font.
Definition: PHNDisplayHardware.cpp:632
void setViewport(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
Sets the viewport for the display.
Definition: PHNDisplayHardware.cpp:234
uint8_t color565Green(color_t color)
Obtains the GREEN component of a 16-bit 565 color.
Definition: PHNDisplayHardware.cpp:292
void writeImage_1bit(uint16_t x, uint16_t y, uint8_t width, uint8_t height, uint8_t scale, const uint8_t *data, uint8_t direction, uint16_t color0, uint16_t color1)
Drawing 1-bit images stored in RAM (not FLASH!)
Definition: PHNDisplayHardware.cpp:659
void drawLine(uint16_t x, uint16_t y, uint32_t length, uint8_t direction, uint8_t color)
Drawing a line with 8-bit color.
Definition: PHNDisplayHardware.cpp:457
void readTouch(uint16_t *analogX, uint16_t *analogY, uint16_t *analogZ1, uint16_t *analogZ2)
Reads raw touchscreen input information.
Definition: PHNDisplayHardware.cpp:312
void writeFont_1bit(uint16_t x, uint16_t y, uint8_t scale, const uint8_t *data, uint16_t color0, uint16_t color1)
Draws a 5x7 1-bit font character, the font data must be stored in FLASH.
Definition: PHNDisplayHardware.cpp:651
void writeChar(uint16_t x, uint16_t y, uint8_t scale, char c, uint16_t color0, uint16_t color1)
Draws a Character to the screen using the standard font.
Definition: PHNDisplayHardware.cpp:647
color_t colorLerp(color_t colorA, color_t colorB, float f)
Performs linear interpolation between two 16-but 565 colors.
Definition: PHNDisplayHardware.cpp:280