Menu/joystick/HMC5883L/MMA7660/application board program

Fork of C12832_lcd by Peter Drescher

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers C12832_lcd.h Source File

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 // #include "TextDisplay.h"       //I added this took it out for now
00021 
00022 
00023 /** optional Defines :
00024   * #define debug_lcd  1  enable infos to PC_USB
00025   */
00026 
00027 // some defines for the DMA use
00028 #define DMA_CHANNEL_ENABLE      1
00029 #define DMA_TRANSFER_TYPE_M2P   (1UL << 11)
00030 #define DMA_CHANNEL_TCIE        (1UL << 31)
00031 #define DMA_CHANNEL_SRC_INC     (1UL << 26)
00032 #define DMA_MASK_IE             (1UL << 14)
00033 #define DMA_MASK_ITC            (1UL << 15)
00034 #define DMA_SSP1_TX             (1UL << 2)
00035 #define DMA_SSP0_TX             (0)
00036 #define DMA_DEST_SSP1_TX        (2UL << 6)
00037 #define DMA_DEST_SSP0_TX        (0UL << 6)
00038 
00039 /** Draw mode
00040   * NORMAl
00041   * XOR set pixel by xor the screen
00042   */
00043 enum {NORMAL,XOR};
00044 
00045 class C12832_LCD : public GraphicsDisplay
00046 {
00047 public:
00048     /** Create a C12832_LCD object connected to SPI1
00049       *
00050       */
00051 
00052     C12832_LCD(const char* name = "LCD");
00053 
00054     /** Get the width of the screen in pixel
00055       *
00056       * @param
00057       * @returns width of screen in pixel
00058       *
00059       */
00060     virtual int width();
00061 
00062     /** Get the height of the screen in pixel
00063      *
00064      * @returns height of screen in pixel
00065      *
00066      */
00067     virtual int height();
00068 
00069     /** Draw a pixel at x,y black or white
00070      *
00071      * @param x horizontal position
00072      * @param y vertical position
00073      * @param colour ,1 set pixel ,0 erase pixel
00074      */
00075     virtual void pixel(int x, int y,int colour);
00076 
00077     /** draw a circle
00078       *
00079       * @param x0,y0 center
00080       * @param r radius
00081       * @param colour ,1 set pixel ,0 erase pixel
00082       *
00083       */
00084     void circle(int x, int y, int r, int colour);
00085 
00086     /** draw a filled circle
00087      *
00088      * @param x0,y0 center
00089      * @param r radius
00090      * @param color ,1 set pixel ,0 erase pixel
00091      *
00092      * use circle with different radius,
00093      * can miss some pixel
00094      */
00095     void fillcircle(int x, int y, int r, int colour);
00096 
00097     /** draw a 1 pixel line
00098       *
00099       * @param x0,y0 start point
00100       * @param x1,y1 stop point
00101       * @param color ,1 set pixel ,0 erase pixel
00102       *
00103       */
00104     void line(int x0, int y0, int x1, int y1, int colour);
00105 
00106     /** draw a rect
00107     *
00108     * @param x0,y0 top left corner
00109     * @param x1,y1 down right corner
00110     * @param color 1 set pixel ,0 erase pixel
00111     *                                                   *
00112     */
00113     void rect(int x0, int y0, int x1, int y1, int colour);
00114 
00115     /** draw a filled rect
00116       *
00117       * @param x0,y0 top left corner
00118       * @param x1,y1 down right corner
00119       * @param color 1 set pixel ,0 erase pixel
00120       *
00121       */
00122     void fillrect(int x0, int y0, int x1, int y1, int colour);
00123 
00124     /** copy display buffer to lcd
00125       *
00126       */
00127 
00128     void copy_to_lcd(void);
00129 
00130     /** set the orienation of the screen
00131       *
00132       */
00133 
00134     //void set_orientation(unsigned int o);
00135 
00136     /** set the contrast of the screen
00137       *
00138       * @param o contrast 0-63
00139       */
00140 
00141     void set_contrast(unsigned int o);
00142 
00143     /** read the contrast level
00144       *
00145       */
00146     unsigned int get_contrast(void);
00147 
00148 
00149 
00150     /** invert the screen
00151       *
00152       * @param o = 0 normal, 1 invert
00153       */
00154     void invert(unsigned int o);
00155 
00156     /** clear the screen
00157        *
00158        */
00159     virtual void cls(void);
00160 
00161     /** set the drawing mode
00162       *
00163       * @param mode NORMAl or XOR
00164       */
00165 
00166     void setmode(int mode);
00167 
00168     int columns(void);
00169 
00170     /** calculate the max number of columns
00171      *
00172      * @returns max column
00173      * depends on actual font size
00174      *
00175      */
00176     int rows(void);
00177 
00178     /** put a char on the screen
00179      *
00180      * @param value char to print
00181      * @returns printed char
00182      *
00183      */
00184     int _putc(int value);
00185 
00186     /** draw a character on given position out of the active font to the LCD
00187      *
00188      * @param x x-position of char (top left)
00189      * @param y y-position
00190      * @param c char to print
00191      *
00192      */
00193     virtual void character(int x, int y, int c);
00194 
00195     /** setup cursor position
00196      *
00197      * @param x x-position (top left)
00198      * @param y y-position
00199      */
00200     void locate(int x, int y);
00201     
00202     /** setup auto update of screen 
00203       *
00204       * @param up 1 = on , 0 = off
00205       * if switched off the program has to call copy_to_lcd() 
00206       * to update screen from framebuffer
00207       */
00208     void C12832_LCD::set_auto_up(unsigned int up);
00209 
00210     /** get status of the auto update function
00211       *
00212       *  @returns if auto update is on
00213       */
00214     unsigned int C12832_LCD::get_auto_up(void);
00215 
00216     /** Vars     */
00217     SPI _spi;
00218     DigitalOut _reset;
00219     DigitalOut _A0;
00220     DigitalOut _CS;
00221     unsigned char* font;
00222     unsigned int draw_mode;
00223 
00224 
00225     /** select the font to use
00226       *
00227       * @param f pointer to font array
00228       *
00229       *   font array can created with GLCD Font Creator from http://www.mikroe.com
00230       *   you have to add 4 parameter at the beginning of the font array to use:
00231       *   - the number of byte / char
00232       *   - the vertial size in pixel
00233       *   - the horizontal size in pixel
00234       *   - the number of byte per vertical line
00235       *   you also have to change the array to char[]
00236       *
00237       */
00238     void set_font(unsigned char* f);
00239 
00240 
00241 protected:
00242 
00243     /** draw a horizontal line
00244       *
00245       * @param x0 horizontal start
00246       * @param x1 horizontal stop
00247       * @param y vertical position
00248       * @param ,1 set pixel ,0 erase pixel
00249       *
00250       */
00251     void hline(int x0, int x1, int y, int colour);
00252 
00253     /** draw a vertical line
00254      *
00255      * @param x horizontal position
00256      * @param y0 vertical start
00257      * @param y1 vertical stop
00258      * @param ,1 set pixel ,0 erase pixel
00259      */
00260     void vline(int y0, int y1, int x, int colour);
00261 
00262     /** Init the C12832 LCD controller
00263      *
00264      */
00265     void lcd_reset();
00266 
00267     /** Write data to the LCD controller
00268      *
00269      * @param dat data written to LCD controller
00270      *
00271      */
00272     void wr_dat(unsigned char value);
00273 
00274     /** Write a command the LCD controller
00275       *
00276       * @param cmd: command to be written
00277       *
00278       */
00279     void wr_cmd(unsigned char value);
00280 
00281     void wr_cnt(unsigned char cmd);
00282 
00283     unsigned int orientation;
00284     unsigned int char_x;
00285     unsigned int char_y;
00286     unsigned char buffer[512];
00287     unsigned int contrast;
00288     unsigned int auto_up;
00289 
00290 };
00291 
00292 
00293 
00294 
00295 #endif