test program for mbed Lab Board

Dependencies:   C12832_lcd LCD_fonts mbed-rtos mbed

Dependents:   Experiment_5

Test program for the mbed application board. It use the mbed rtos to create 5 threads.

/media/uploads/dreschpe/test_rtos.jpg

Two threads are counting, one setup the contrast with pot 1, one is printing a rotating sinwave and the last prints the actual contrast.

Committer:
dreschpe
Date:
Mon Oct 15 21:48:28 2012 +0000
Revision:
0:f6a57b843f79
first test of the lcd driver

Who changed what in which revision?

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