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