Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 class C12832_LCD : public GraphicsDisplay 00045 { 00046 public: 00047 // Create a C12832_LCD object connected to SPI1 00048 C12832_LCD(const char* name = "LCD"); 00049 00050 /** Get the width of the screen in pixel 00051 * @returns width of screen in pixel */ 00052 virtual int width(); 00053 00054 /** Get the height of the screen in pixel 00055 @returns height of screen in pixel */ 00056 virtual int height(); 00057 00058 /** Draw a pixel at x,y black or white 00059 * @param x horizontal position 00060 * @param y vertical position 00061 * @param colour ,1 set pixel ,0 erase pixel */ 00062 virtual void pixel(int x, int y,int colour); 00063 00064 /** draw a circle 00065 * @param x0,y0 center 00066 * @param r radius 00067 * @param colour ,1 set pixel ,0 erase pixel */ 00068 void circle(int x, int y, int r, int colour); 00069 00070 /** draw a filled circle 00071 * @param x0,y0 center 00072 * @param r radius 00073 * @param color ,1 set pixel ,0 erase pixel 00074 * use circle with different radius, 00075 * can miss some pixel */ 00076 void fillcircle(int x, int y, int r, int colour); 00077 00078 /** draw a 1 pixel line 00079 * @param x0,y0 start point 00080 * @param x1,y1 stop point 00081 * @param color ,1 set pixel ,0 erase pixel */ 00082 void line(int x0, int y0, int x1, int y1, int colour); 00083 00084 /** draw a rect 00085 * @param x0,y0 top left corner 00086 * @param x1,y1 down right corner 00087 * @param color 1 set pixel ,0 erase pixel */ 00088 void rect(int x0, int y0, int x1, int y1, int colour); 00089 00090 /** draw a filled rect 00091 * @param x0,y0 top left corner 00092 * @param x1,y1 down right corner 00093 * @param color 1 set pixel ,0 erase pixel */ 00094 void fillrect(int x0, int y0, int x1, int y1, int colour); 00095 00096 /** copy display buffer to lcd */ 00097 void copy_to_lcd(void); 00098 00099 // set the orienation of the screen 00100 00101 // void set_orientation(unsigned int o); 00102 00103 /** set the contrast of the screen 00104 @param o contrast 0-63 */ 00105 void set_contrast(unsigned int o); 00106 00107 /** read the contrast level */ 00108 unsigned int get_contrast(void); 00109 00110 /** invert the screen 00111 @param o = 0 normal, 1 invert */ 00112 void invert(unsigned int o); 00113 00114 /** clear the screen */ 00115 virtual void cls(void); 00116 00117 /** set the drawing mode 00118 * @param mode NORMAl or XOR */ 00119 void setmode(int mode); 00120 00121 int columns(void); 00122 /** calculate the max number of columns 00123 * @returns max column 00124 * depends on actual font size */ 00125 00126 int rows(void); 00127 00128 /** put a char on the screen 00129 * @param value char to print 00130 * @returns printed char */ 00131 int _putc(int value); 00132 00133 /** draw a character on given position out of the active font to the LCD 00134 * @param x x-position of char (top left) 00135 * @param y y-position 00136 * @param c char to print */ 00137 virtual void character(int x, int y, int c); 00138 00139 /** setup cursor position 00140 * @param x x-position (top left) 00141 * @param y y-position */ 00142 void locate(int x, int y); 00143 00144 /** setup auto update of screen 00145 * @param up 1 = on , 0 = off 00146 * if switched off the program has to call copy_to_lcd() 00147 * to update screen from framebuffer */ 00148 void C12832_LCD::set_auto_up(unsigned int up); 00149 00150 /** get status of the auto update function 00151 * @returns if auto update is on */ 00152 unsigned int C12832_LCD::get_auto_up(void); 00153 00154 /** Vars */ 00155 SPI _spi; 00156 DigitalOut _reset; 00157 DigitalOut _A0; 00158 DigitalOut _CS; 00159 unsigned char* font; 00160 unsigned int draw_mode; 00161 00162 00163 /** select the font to use 00164 * 00165 * @param f pointer to font array 00166 * 00167 * font array can created with GLCD Font Creator from http://www.mikroe.com 00168 * you have to add 4 parameter at the beginning of the font array to use: 00169 * - the number of byte / char 00170 * - the vertial size in pixel 00171 * - the horizontal size in pixel 00172 * - the number of byte per vertical line 00173 * you also have to change the array to char[] 00174 * 00175 */ 00176 void set_font(unsigned char* f); 00177 00178 00179 protected: 00180 00181 /** draw a horizontal line 00182 * 00183 * @param x0 horizontal start 00184 * @param x1 horizontal stop 00185 * @param y vertical position 00186 * @param ,1 set pixel ,0 erase pixel 00187 * 00188 */ 00189 void hline(int x0, int x1, int y, int colour); 00190 00191 /** draw a vertical line 00192 * 00193 * @param x horizontal position 00194 * @param y0 vertical start 00195 * @param y1 vertical stop 00196 * @param ,1 set pixel ,0 erase pixel 00197 */ 00198 void vline(int y0, int y1, int x, int colour); 00199 00200 /** Init the C12832 LCD controller 00201 * 00202 */ 00203 void lcd_reset(); 00204 00205 /** Write data to the LCD controller 00206 * 00207 * @param dat data written to LCD controller 00208 * 00209 */ 00210 void wr_dat(unsigned char value); 00211 00212 /** Write a command the LCD controller 00213 * 00214 * @param cmd: command to be written 00215 * 00216 */ 00217 void wr_cmd(unsigned char value); 00218 00219 void wr_cnt(unsigned char cmd); 00220 00221 unsigned int orientation; 00222 unsigned int char_x; 00223 unsigned int char_y; 00224 unsigned char buffer[512]; 00225 unsigned int contrast; 00226 unsigned int auto_up; 00227 00228 }; 00229 00230 00231 00232 00233 #endif 00234
Generated on Wed Jul 13 2022 02:59:11 by
