Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:27:58 2016 +0000
Revision:
0:6c56fb4bc5f0
Moving to library for sharing updates

Who changed what in which revision?

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