StopwatchLCD

Dependencies:   mbed

Committer:
martwerl
Date:
Thu Nov 15 18:10:36 2018 +0000
Revision:
0:3b4026dea19d
StopwatchLCD

Who changed what in which revision?

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