mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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