LED

Dependents:   LED_PWM_ansteuerung

Committer:
schoeni_91
Date:
Tue May 03 15:53:37 2016 +0000
Revision:
0:cbf905d4103b
f?r Rudi

Who changed what in which revision?

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