Lib for the LCD display on mbed lab Board
Fork of C12832_lcd by
Embed:
(wiki syntax)
Show/hide line numbers
C12832_lcd.h
00001 /* mbed library for the mbed Lab Board 128*32 pixel LCD 00002 * use C12832 controller 00003 * Copyright (c) 2012 Peter Drescher - DC2PD 00004 * Released under the MIT License: http://mbed.org/license/mit 00005 * 00006 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00007 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00008 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00009 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00010 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00011 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00012 * THE SOFTWARE. 00013 */ 00014 00015 #ifndef C12832_H 00016 #define C12832_H 00017 00018 #include "mbed.h" 00019 #include "GraphicsDisplay.h" 00020 00021 00022 /** optional Defines : 00023 * #define debug_lcd 1 enable infos to PC_USB 00024 */ 00025 00026 // some defines for the DMA use 00027 #define DMA_CHANNEL_ENABLE 1 00028 #define DMA_TRANSFER_TYPE_M2P (1UL << 11) 00029 #define DMA_CHANNEL_TCIE (1UL << 31) 00030 #define DMA_CHANNEL_SRC_INC (1UL << 26) 00031 #define DMA_MASK_IE (1UL << 14) 00032 #define DMA_MASK_ITC (1UL << 15) 00033 #define DMA_SSP1_TX (1UL << 2) 00034 #define DMA_SSP0_TX (0) 00035 #define DMA_DEST_SSP1_TX (2UL << 6) 00036 #define DMA_DEST_SSP0_TX (0UL << 6) 00037 00038 /** Draw mode 00039 * NORMAl 00040 * XOR set pixel by xor the screen 00041 */ 00042 enum {NORMAL,XOR}; 00043 00044 /** Bitmap 00045 */ 00046 struct Bitmap{ 00047 int xSize; 00048 int ySize; 00049 int Byte_in_Line; 00050 char* data; 00051 }; 00052 00053 class C12832_LCD : public GraphicsDisplay 00054 { 00055 public: 00056 /** Create a C12832_LCD object connected to SPI1 00057 * 00058 */ 00059 00060 C12832_LCD(const char* name = "LCD"); 00061 00062 /** Get the width of the screen in pixel 00063 * 00064 * @param 00065 * @returns width of screen in pixel 00066 * 00067 */ 00068 virtual int width(); 00069 00070 /** Get the height of the screen in pixel 00071 * 00072 * @returns height of screen in pixel 00073 * 00074 */ 00075 virtual int height(); 00076 00077 /** Draw a pixel at x,y black or white 00078 * 00079 * @param x horizontal position 00080 * @param y vertical position 00081 * @param colour ,1 set pixel ,0 erase pixel 00082 */ 00083 virtual void pixel(int x, int y,int colour); 00084 00085 /** draw a circle 00086 * 00087 * @param x0,y0 center 00088 * @param r radius 00089 * @param colour ,1 set pixel ,0 erase pixel 00090 * 00091 */ 00092 void circle(int x, int y, int r, int colour); 00093 00094 /** draw a filled circle 00095 * 00096 * @param x0,y0 center 00097 * @param r radius 00098 * @param color ,1 set pixel ,0 erase pixel 00099 * 00100 * use circle with different radius, 00101 * can miss some pixel 00102 */ 00103 void fillcircle(int x, int y, int r, int colour); 00104 00105 /** draw a 1 pixel line 00106 * 00107 * @param x0,y0 start point 00108 * @param x1,y1 stop point 00109 * @param color ,1 set pixel ,0 erase pixel 00110 * 00111 */ 00112 void line(int x0, int y0, int x1, int y1, int colour); 00113 00114 /** draw a rect 00115 * 00116 * @param x0,y0 top left corner 00117 * @param x1,y1 down right corner 00118 * @param color 1 set pixel ,0 erase pixel 00119 * * 00120 */ 00121 void rect(int x0, int y0, int x1, int y1, int colour); 00122 00123 /** draw a filled rect 00124 * 00125 * @param x0,y0 top left corner 00126 * @param x1,y1 down right corner 00127 * @param color 1 set pixel ,0 erase pixel 00128 * 00129 */ 00130 void fillrect(int x0, int y0, int x1, int y1, int colour); 00131 00132 /** copy display buffer to lcd 00133 * 00134 */ 00135 00136 void copy_to_lcd(void); 00137 00138 /** set the orienation of the screen 00139 * 00140 */ 00141 00142 //void set_orientation(unsigned int o); 00143 00144 /** set the contrast of the screen 00145 * 00146 * @param o contrast 0-63 00147 */ 00148 00149 void set_contrast(unsigned int o); 00150 00151 /** read the contrast level 00152 * 00153 */ 00154 unsigned int get_contrast(void); 00155 00156 00157 00158 /** invert the screen 00159 * 00160 * @param o = 0 normal, 1 invert 00161 */ 00162 void invert(unsigned int o); 00163 00164 /** clear the screen 00165 * 00166 */ 00167 virtual void cls(void); 00168 00169 /** set the drawing mode 00170 * 00171 * @param mode NORMAl or XOR 00172 */ 00173 00174 void setmode(int mode); 00175 00176 virtual int columns(void); 00177 00178 /** calculate the max number of columns 00179 * 00180 * @returns max column 00181 * depends on actual font size 00182 * 00183 */ 00184 virtual int rows(void); 00185 00186 /** put a char on the screen 00187 * 00188 * @param value char to print 00189 * @returns printed char 00190 * 00191 */ 00192 virtual int _putc(int value); 00193 00194 /** draw a character on given position out of the active font to the LCD 00195 * 00196 * @param x x-position of char (top left) 00197 * @param y y-position 00198 * @param c char to print 00199 * 00200 */ 00201 virtual void character(int x, int y, int c); 00202 00203 /** setup cursor position 00204 * 00205 * @param x x-position (top left) 00206 * @param y y-position 00207 */ 00208 virtual void locate(int x, int y); 00209 00210 /** setup auto update of screen 00211 * 00212 * @param up 1 = on , 0 = off 00213 * if switched off the program has to call copy_to_lcd() 00214 * to update screen from framebuffer 00215 */ 00216 void set_auto_up(unsigned int up); 00217 00218 /** get status of the auto update function 00219 * 00220 * @returns if auto update is on 00221 */ 00222 unsigned int get_auto_up(void); 00223 00224 /** Vars */ 00225 SPI _spi; 00226 DigitalOut _reset; 00227 DigitalOut _A0; 00228 DigitalOut _CS; 00229 unsigned char* font; 00230 unsigned int draw_mode; 00231 00232 00233 /** select the font to use 00234 * 00235 * @param f pointer to font array 00236 * 00237 * font array can created with GLCD Font Creator from http://www.mikroe.com 00238 * you have to add 4 parameter at the beginning of the font array to use: 00239 * - the number of byte / char 00240 * - the vertial size in pixel 00241 * - the horizontal size in pixel 00242 * - the number of byte per vertical line 00243 * you also have to change the array to char[] 00244 * 00245 */ 00246 void set_font(unsigned char* f); 00247 00248 /** print bitmap to buffer 00249 * 00250 * @param bm Bitmap in flash 00251 * @param x x start 00252 * @param y y start 00253 * 00254 */ 00255 00256 void print_bm(Bitmap bm, int x, int y); 00257 00258 00259 protected: 00260 00261 /** draw a horizontal line 00262 * 00263 * @param x0 horizontal start 00264 * @param x1 horizontal stop 00265 * @param y vertical position 00266 * @param ,1 set pixel ,0 erase pixel 00267 * 00268 */ 00269 void hline(int x0, int x1, int y, int colour); 00270 00271 /** draw a vertical line 00272 * 00273 * @param x horizontal position 00274 * @param y0 vertical start 00275 * @param y1 vertical stop 00276 * @param ,1 set pixel ,0 erase pixel 00277 */ 00278 void vline(int y0, int y1, int x, int colour); 00279 00280 /** Init the C12832 LCD controller 00281 * 00282 */ 00283 void lcd_reset(); 00284 00285 /** Write data to the LCD controller 00286 * 00287 * @param dat data written to LCD controller 00288 * 00289 */ 00290 void wr_dat(unsigned char value); 00291 00292 /** Write a command the LCD controller 00293 * 00294 * @param cmd: command to be written 00295 * 00296 */ 00297 void wr_cmd(unsigned char value); 00298 00299 void wr_cnt(unsigned char cmd); 00300 00301 unsigned int orientation; 00302 unsigned int char_x; 00303 unsigned int char_y; 00304 unsigned char buffer[512]; 00305 unsigned int contrast; 00306 unsigned int auto_up; 00307 00308 }; 00309 00310 00311 00312 00313 #endif
Generated on Thu Jul 14 2022 00:16:30 by 1.7.2