TINF_Test_230418

Dependencies:   mbed

Committer:
Wizo
Date:
Thu Nov 15 18:10:38 2018 +0000
Revision:
0:fbb75c0396c7
TINF_Test_230418

Who changed what in which revision?

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