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