LCD library for Akizuki AQM1248A graphic LCD module

Dependents:   FRDM_MAG3110 Nucleo_AQM1248A Nucleo_AQM1248A_GT20L16J1Y

Fork of C12832_lcd by Peter Drescher

see http://mbed.org/users/masato/code/Nucleo_AQM1248A/

Committer:
masato
Date:
Tue Jun 02 12:22:56 2015 +0000
Revision:
13:3a94a79194b6
Parent:
11:0145579c487f
add MISO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
masato 11:0145579c487f 1 /*
masato 11:0145579c487f 2 * mbed library for the Akizuki AQM1248A 128*48 pixel LCD
masato 11:0145579c487f 3 * derived from C12832_lcd
masato 11:0145579c487f 4 * Copyright (c) 2014 Masato YAMANISHI
masato 11:0145579c487f 5 * Released under the MIT License: http://mbed.org/license/mit
masato 11:0145579c487f 6 */
masato 11:0145579c487f 7
dreschpe 0:4bbc531be6e2 8 /* mbed library for the mbed Lab Board 128*32 pixel LCD
dreschpe 0:4bbc531be6e2 9 * use C12832 controller
dreschpe 0:4bbc531be6e2 10 * Copyright (c) 2012 Peter Drescher - DC2PD
dreschpe 0:4bbc531be6e2 11 * Released under the MIT License: http://mbed.org/license/mit
dreschpe 0:4bbc531be6e2 12 *
dreschpe 0:4bbc531be6e2 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dreschpe 0:4bbc531be6e2 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dreschpe 0:4bbc531be6e2 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dreschpe 0:4bbc531be6e2 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dreschpe 0:4bbc531be6e2 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dreschpe 0:4bbc531be6e2 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
dreschpe 0:4bbc531be6e2 19 * THE SOFTWARE.
dreschpe 0:4bbc531be6e2 20 */
dreschpe 0:4bbc531be6e2 21
dreschpe 0:4bbc531be6e2 22 #ifndef C12832_H
dreschpe 0:4bbc531be6e2 23 #define C12832_H
dreschpe 0:4bbc531be6e2 24
dreschpe 0:4bbc531be6e2 25 #include "mbed.h"
dreschpe 0:4bbc531be6e2 26 #include "GraphicsDisplay.h"
dreschpe 0:4bbc531be6e2 27
dreschpe 1:66dd8afbfd06 28 /** optional Defines :
dreschpe 0:4bbc531be6e2 29 * #define debug_lcd 1 enable infos to PC_USB
dreschpe 0:4bbc531be6e2 30 */
masato 11:0145579c487f 31
masato 11:0145579c487f 32 #define BPP 1 // Bits per pixel
masato 11:0145579c487f 33 #define WIDTH 128
masato 11:0145579c487f 34 #define HEIGHT 48
masato 11:0145579c487f 35 #define PAGES (HEIGHT/8) // 6
masato 11:0145579c487f 36 #define BUFFER_SIZE (WIDTH*HEIGHT/8)
dreschpe 0:4bbc531be6e2 37
dreschpe 0:4bbc531be6e2 38 // some defines for the DMA use
dreschpe 0:4bbc531be6e2 39 #define DMA_CHANNEL_ENABLE 1
dreschpe 0:4bbc531be6e2 40 #define DMA_TRANSFER_TYPE_M2P (1UL << 11)
dreschpe 0:4bbc531be6e2 41 #define DMA_CHANNEL_TCIE (1UL << 31)
dreschpe 0:4bbc531be6e2 42 #define DMA_CHANNEL_SRC_INC (1UL << 26)
dreschpe 0:4bbc531be6e2 43 #define DMA_MASK_IE (1UL << 14)
dreschpe 0:4bbc531be6e2 44 #define DMA_MASK_ITC (1UL << 15)
dreschpe 0:4bbc531be6e2 45 #define DMA_SSP1_TX (1UL << 2)
dreschpe 0:4bbc531be6e2 46 #define DMA_SSP0_TX (0)
dreschpe 0:4bbc531be6e2 47 #define DMA_DEST_SSP1_TX (2UL << 6)
dreschpe 0:4bbc531be6e2 48 #define DMA_DEST_SSP0_TX (0UL << 6)
dreschpe 0:4bbc531be6e2 49
dreschpe 1:66dd8afbfd06 50 /** Draw mode
dreschpe 1:66dd8afbfd06 51 * NORMAl
dreschpe 1:66dd8afbfd06 52 * XOR set pixel by xor the screen
dreschpe 1:66dd8afbfd06 53 */
dreschpe 0:4bbc531be6e2 54 enum {NORMAL,XOR};
dreschpe 0:4bbc531be6e2 55
dreschpe 7:0f5a3b0f3cab 56 /** Bitmap
dreschpe 7:0f5a3b0f3cab 57 */
dreschpe 7:0f5a3b0f3cab 58 struct Bitmap{
dreschpe 7:0f5a3b0f3cab 59 int xSize;
dreschpe 7:0f5a3b0f3cab 60 int ySize;
dreschpe 7:0f5a3b0f3cab 61 int Byte_in_Line;
dreschpe 7:0f5a3b0f3cab 62 char* data;
dreschpe 7:0f5a3b0f3cab 63 };
dreschpe 7:0f5a3b0f3cab 64
masato 11:0145579c487f 65 class aqm1248a_lcd : public GraphicsDisplay
dreschpe 0:4bbc531be6e2 66 {
dreschpe 0:4bbc531be6e2 67 public:
masato 11:0145579c487f 68 /** Create a aqm1248a object connected to SPI1
dreschpe 0:4bbc531be6e2 69 *
dreschpe 0:4bbc531be6e2 70 */
dreschpe 0:4bbc531be6e2 71
masato 11:0145579c487f 72 aqm1248a_lcd(const char* name = "LCD");
dreschpe 0:4bbc531be6e2 73
dreschpe 0:4bbc531be6e2 74 /** Get the width of the screen in pixel
dreschpe 0:4bbc531be6e2 75 *
dreschpe 0:4bbc531be6e2 76 * @param
dreschpe 0:4bbc531be6e2 77 * @returns width of screen in pixel
dreschpe 0:4bbc531be6e2 78 *
dreschpe 0:4bbc531be6e2 79 */
dreschpe 0:4bbc531be6e2 80 virtual int width();
dreschpe 0:4bbc531be6e2 81
dreschpe 0:4bbc531be6e2 82 /** Get the height of the screen in pixel
dreschpe 0:4bbc531be6e2 83 *
dreschpe 0:4bbc531be6e2 84 * @returns height of screen in pixel
dreschpe 0:4bbc531be6e2 85 *
dreschpe 0:4bbc531be6e2 86 */
dreschpe 0:4bbc531be6e2 87 virtual int height();
dreschpe 0:4bbc531be6e2 88
dreschpe 0:4bbc531be6e2 89 /** Draw a pixel at x,y black or white
dreschpe 0:4bbc531be6e2 90 *
dreschpe 0:4bbc531be6e2 91 * @param x horizontal position
dreschpe 0:4bbc531be6e2 92 * @param y vertical position
dreschpe 0:4bbc531be6e2 93 * @param colour ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 94 */
dreschpe 0:4bbc531be6e2 95 virtual void pixel(int x, int y,int colour);
dreschpe 0:4bbc531be6e2 96
dreschpe 0:4bbc531be6e2 97 /** draw a circle
dreschpe 0:4bbc531be6e2 98 *
dreschpe 0:4bbc531be6e2 99 * @param x0,y0 center
dreschpe 0:4bbc531be6e2 100 * @param r radius
dreschpe 0:4bbc531be6e2 101 * @param colour ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 102 *
dreschpe 0:4bbc531be6e2 103 */
dreschpe 0:4bbc531be6e2 104 void circle(int x, int y, int r, int colour);
dreschpe 0:4bbc531be6e2 105
dreschpe 0:4bbc531be6e2 106 /** draw a filled circle
dreschpe 0:4bbc531be6e2 107 *
dreschpe 0:4bbc531be6e2 108 * @param x0,y0 center
dreschpe 0:4bbc531be6e2 109 * @param r radius
dreschpe 0:4bbc531be6e2 110 * @param color ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 111 *
dreschpe 0:4bbc531be6e2 112 * use circle with different radius,
dreschpe 0:4bbc531be6e2 113 * can miss some pixel
dreschpe 0:4bbc531be6e2 114 */
dreschpe 0:4bbc531be6e2 115 void fillcircle(int x, int y, int r, int colour);
dreschpe 0:4bbc531be6e2 116
dreschpe 0:4bbc531be6e2 117 /** draw a 1 pixel line
dreschpe 0:4bbc531be6e2 118 *
dreschpe 0:4bbc531be6e2 119 * @param x0,y0 start point
dreschpe 0:4bbc531be6e2 120 * @param x1,y1 stop point
dreschpe 0:4bbc531be6e2 121 * @param color ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 122 *
dreschpe 0:4bbc531be6e2 123 */
dreschpe 0:4bbc531be6e2 124 void line(int x0, int y0, int x1, int y1, int colour);
dreschpe 1:66dd8afbfd06 125
dreschpe 0:4bbc531be6e2 126 /** draw a rect
dreschpe 1:66dd8afbfd06 127 *
dreschpe 1:66dd8afbfd06 128 * @param x0,y0 top left corner
dreschpe 1:66dd8afbfd06 129 * @param x1,y1 down right corner
dreschpe 1:66dd8afbfd06 130 * @param color 1 set pixel ,0 erase pixel
dreschpe 1:66dd8afbfd06 131 * *
dreschpe 1:66dd8afbfd06 132 */
dreschpe 1:66dd8afbfd06 133 void rect(int x0, int y0, int x1, int y1, int colour);
dreschpe 1:66dd8afbfd06 134
dreschpe 1:66dd8afbfd06 135 /** draw a filled rect
dreschpe 1:66dd8afbfd06 136 *
dreschpe 1:66dd8afbfd06 137 * @param x0,y0 top left corner
dreschpe 1:66dd8afbfd06 138 * @param x1,y1 down right corner
dreschpe 1:66dd8afbfd06 139 * @param color 1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 140 *
dreschpe 0:4bbc531be6e2 141 */
dreschpe 1:66dd8afbfd06 142 void fillrect(int x0, int y0, int x1, int y1, int colour);
dreschpe 1:66dd8afbfd06 143
dreschpe 1:66dd8afbfd06 144 /** copy display buffer to lcd
dreschpe 1:66dd8afbfd06 145 *
dreschpe 1:66dd8afbfd06 146 */
dreschpe 1:66dd8afbfd06 147
dreschpe 0:4bbc531be6e2 148 void copy_to_lcd(void);
dreschpe 0:4bbc531be6e2 149
dreschpe 0:4bbc531be6e2 150 /** set the orienation of the screen
dreschpe 1:66dd8afbfd06 151 *
dreschpe 1:66dd8afbfd06 152 */
dreschpe 1:66dd8afbfd06 153
dreschpe 1:66dd8afbfd06 154 //void set_orientation(unsigned int o);
dreschpe 0:4bbc531be6e2 155
dreschpe 1:66dd8afbfd06 156 /** set the contrast of the screen
dreschpe 1:66dd8afbfd06 157 *
dreschpe 1:66dd8afbfd06 158 * @param o contrast 0-63
dreschpe 1:66dd8afbfd06 159 */
dreschpe 0:4bbc531be6e2 160
dreschpe 0:4bbc531be6e2 161 void set_contrast(unsigned int o);
dreschpe 1:66dd8afbfd06 162
dreschpe 1:66dd8afbfd06 163 /** read the contrast level
dreschpe 1:66dd8afbfd06 164 *
dreschpe 1:66dd8afbfd06 165 */
dreschpe 1:66dd8afbfd06 166 unsigned int get_contrast(void);
dreschpe 1:66dd8afbfd06 167
dreschpe 1:66dd8afbfd06 168
dreschpe 1:66dd8afbfd06 169
dreschpe 1:66dd8afbfd06 170 /** invert the screen
dreschpe 1:66dd8afbfd06 171 *
dreschpe 1:66dd8afbfd06 172 * @param o = 0 normal, 1 invert
dreschpe 1:66dd8afbfd06 173 */
dreschpe 0:4bbc531be6e2 174 void invert(unsigned int o);
dreschpe 1:66dd8afbfd06 175
dreschpe 1:66dd8afbfd06 176 /** clear the screen
dreschpe 1:66dd8afbfd06 177 *
dreschpe 1:66dd8afbfd06 178 */
dreschpe 1:66dd8afbfd06 179 virtual void cls(void);
dreschpe 1:66dd8afbfd06 180
dreschpe 1:66dd8afbfd06 181 /** set the drawing mode
dreschpe 1:66dd8afbfd06 182 *
dreschpe 1:66dd8afbfd06 183 * @param mode NORMAl or XOR
dreschpe 1:66dd8afbfd06 184 */
dreschpe 1:66dd8afbfd06 185
dreschpe 1:66dd8afbfd06 186 void setmode(int mode);
dreschpe 1:66dd8afbfd06 187
dreschpe 6:6b96b16aad47 188 virtual int columns(void);
dreschpe 1:66dd8afbfd06 189
dreschpe 1:66dd8afbfd06 190 /** calculate the max number of columns
dreschpe 1:66dd8afbfd06 191 *
dreschpe 1:66dd8afbfd06 192 * @returns max column
dreschpe 1:66dd8afbfd06 193 * depends on actual font size
dreschpe 1:66dd8afbfd06 194 *
dreschpe 1:66dd8afbfd06 195 */
dreschpe 6:6b96b16aad47 196 virtual int rows(void);
dreschpe 1:66dd8afbfd06 197
dreschpe 1:66dd8afbfd06 198 /** put a char on the screen
dreschpe 1:66dd8afbfd06 199 *
dreschpe 1:66dd8afbfd06 200 * @param value char to print
dreschpe 1:66dd8afbfd06 201 * @returns printed char
dreschpe 1:66dd8afbfd06 202 *
dreschpe 1:66dd8afbfd06 203 */
dreschpe 6:6b96b16aad47 204 virtual int _putc(int value);
dreschpe 1:66dd8afbfd06 205
dreschpe 1:66dd8afbfd06 206 /** draw a character on given position out of the active font to the LCD
dreschpe 1:66dd8afbfd06 207 *
dreschpe 1:66dd8afbfd06 208 * @param x x-position of char (top left)
dreschpe 1:66dd8afbfd06 209 * @param y y-position
dreschpe 1:66dd8afbfd06 210 * @param c char to print
dreschpe 1:66dd8afbfd06 211 *
dreschpe 1:66dd8afbfd06 212 */
dreschpe 1:66dd8afbfd06 213 virtual void character(int x, int y, int c);
dreschpe 1:66dd8afbfd06 214
dreschpe 1:66dd8afbfd06 215 /** setup cursor position
dreschpe 1:66dd8afbfd06 216 *
dreschpe 1:66dd8afbfd06 217 * @param x x-position (top left)
dreschpe 1:66dd8afbfd06 218 * @param y y-position
dreschpe 1:66dd8afbfd06 219 */
dreschpe 6:6b96b16aad47 220 virtual void locate(int x, int y);
dreschpe 3:468cdccff7af 221
dreschpe 3:468cdccff7af 222 /** setup auto update of screen
dreschpe 3:468cdccff7af 223 *
dreschpe 3:468cdccff7af 224 * @param up 1 = on , 0 = off
dreschpe 3:468cdccff7af 225 * if switched off the program has to call copy_to_lcd()
dreschpe 3:468cdccff7af 226 * to update screen from framebuffer
dreschpe 3:468cdccff7af 227 */
dreschpe 5:0f53e522a2bf 228 void set_auto_up(unsigned int up);
dreschpe 1:66dd8afbfd06 229
dreschpe 3:468cdccff7af 230 /** get status of the auto update function
dreschpe 3:468cdccff7af 231 *
dreschpe 3:468cdccff7af 232 * @returns if auto update is on
dreschpe 3:468cdccff7af 233 */
dreschpe 5:0f53e522a2bf 234 unsigned int get_auto_up(void);
dreschpe 0:4bbc531be6e2 235
dreschpe 0:4bbc531be6e2 236 /** Vars */
dreschpe 0:4bbc531be6e2 237 SPI _spi;
dreschpe 0:4bbc531be6e2 238 DigitalOut _reset;
dreschpe 0:4bbc531be6e2 239 DigitalOut _A0;
dreschpe 0:4bbc531be6e2 240 DigitalOut _CS;
dreschpe 0:4bbc531be6e2 241 unsigned char* font;
dreschpe 0:4bbc531be6e2 242 unsigned int draw_mode;
dreschpe 0:4bbc531be6e2 243
dreschpe 0:4bbc531be6e2 244
dreschpe 1:66dd8afbfd06 245 /** select the font to use
dreschpe 1:66dd8afbfd06 246 *
dreschpe 1:66dd8afbfd06 247 * @param f pointer to font array
dreschpe 1:66dd8afbfd06 248 *
dreschpe 1:66dd8afbfd06 249 * font array can created with GLCD Font Creator from http://www.mikroe.com
dreschpe 1:66dd8afbfd06 250 * you have to add 4 parameter at the beginning of the font array to use:
dreschpe 1:66dd8afbfd06 251 * - the number of byte / char
dreschpe 1:66dd8afbfd06 252 * - the vertial size in pixel
dreschpe 1:66dd8afbfd06 253 * - the horizontal size in pixel
dreschpe 1:66dd8afbfd06 254 * - the number of byte per vertical line
dreschpe 1:66dd8afbfd06 255 * you also have to change the array to char[]
dreschpe 1:66dd8afbfd06 256 *
dreschpe 1:66dd8afbfd06 257 */
dreschpe 1:66dd8afbfd06 258 void set_font(unsigned char* f);
dreschpe 7:0f5a3b0f3cab 259
dreschpe 7:0f5a3b0f3cab 260 /** print bitmap to buffer
dreschpe 7:0f5a3b0f3cab 261 *
dreschpe 7:0f5a3b0f3cab 262 * @param bm Bitmap in flash
dreschpe 7:0f5a3b0f3cab 263 * @param x x start
dreschpe 7:0f5a3b0f3cab 264 * @param y y start
dreschpe 7:0f5a3b0f3cab 265 *
dreschpe 7:0f5a3b0f3cab 266 */
dreschpe 0:4bbc531be6e2 267
dreschpe 7:0f5a3b0f3cab 268 void print_bm(Bitmap bm, int x, int y);
dreschpe 0:4bbc531be6e2 269
dreschpe 0:4bbc531be6e2 270 protected:
dreschpe 0:4bbc531be6e2 271
dreschpe 0:4bbc531be6e2 272 /** draw a horizontal line
dreschpe 0:4bbc531be6e2 273 *
dreschpe 0:4bbc531be6e2 274 * @param x0 horizontal start
dreschpe 0:4bbc531be6e2 275 * @param x1 horizontal stop
dreschpe 0:4bbc531be6e2 276 * @param y vertical position
dreschpe 0:4bbc531be6e2 277 * @param ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 278 *
dreschpe 0:4bbc531be6e2 279 */
dreschpe 0:4bbc531be6e2 280 void hline(int x0, int x1, int y, int colour);
dreschpe 0:4bbc531be6e2 281
dreschpe 0:4bbc531be6e2 282 /** draw a vertical line
dreschpe 0:4bbc531be6e2 283 *
dreschpe 0:4bbc531be6e2 284 * @param x horizontal position
dreschpe 0:4bbc531be6e2 285 * @param y0 vertical start
dreschpe 0:4bbc531be6e2 286 * @param y1 vertical stop
dreschpe 0:4bbc531be6e2 287 * @param ,1 set pixel ,0 erase pixel
dreschpe 0:4bbc531be6e2 288 */
dreschpe 0:4bbc531be6e2 289 void vline(int y0, int y1, int x, int colour);
dreschpe 0:4bbc531be6e2 290
dreschpe 0:4bbc531be6e2 291 /** Init the C12832 LCD controller
dreschpe 0:4bbc531be6e2 292 *
dreschpe 0:4bbc531be6e2 293 */
dreschpe 0:4bbc531be6e2 294 void lcd_reset();
dreschpe 0:4bbc531be6e2 295
dreschpe 0:4bbc531be6e2 296 /** Write data to the LCD controller
dreschpe 0:4bbc531be6e2 297 *
dreschpe 0:4bbc531be6e2 298 * @param dat data written to LCD controller
dreschpe 0:4bbc531be6e2 299 *
dreschpe 0:4bbc531be6e2 300 */
dreschpe 0:4bbc531be6e2 301 void wr_dat(unsigned char value);
dreschpe 0:4bbc531be6e2 302
dreschpe 0:4bbc531be6e2 303 /** Write a command the LCD controller
dreschpe 0:4bbc531be6e2 304 *
dreschpe 0:4bbc531be6e2 305 * @param cmd: command to be written
dreschpe 0:4bbc531be6e2 306 *
dreschpe 0:4bbc531be6e2 307 */
dreschpe 0:4bbc531be6e2 308 void wr_cmd(unsigned char value);
dreschpe 1:66dd8afbfd06 309
dreschpe 0:4bbc531be6e2 310 void wr_cnt(unsigned char cmd);
dreschpe 0:4bbc531be6e2 311
dreschpe 0:4bbc531be6e2 312 unsigned int orientation;
dreschpe 0:4bbc531be6e2 313 unsigned int char_x;
dreschpe 0:4bbc531be6e2 314 unsigned int char_y;
masato 11:0145579c487f 315 unsigned char buffer[BUFFER_SIZE];
dreschpe 1:66dd8afbfd06 316 unsigned int contrast;
dreschpe 3:468cdccff7af 317 unsigned int auto_up;
dreschpe 0:4bbc531be6e2 318
dreschpe 0:4bbc531be6e2 319 };
dreschpe 0:4bbc531be6e2 320
dreschpe 0:4bbc531be6e2 321
dreschpe 0:4bbc531be6e2 322
dreschpe 0:4bbc531be6e2 323
dreschpe 0:4bbc531be6e2 324 #endif