This is the final version of Mini Gateway for Automation and Security desgined for Renesas GR Peach Design Contest

Dependencies:   GR-PEACH_video GraphicsFramework HTTPServer R_BSP mbed-rpc mbed-rtos Socket lwip-eth lwip-sys lwip FATFileSystem

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LCD.h Source File

LCD.h

00001 
00002 #ifndef MBED_LCD_H
00003 #define MBED_LCD_H
00004 
00005 #if DEVICE_PORTINOUT
00006 #include "PAR8.h"
00007 #include "PAR16.h"
00008 #endif
00009 
00010 #include "BUS8.h"
00011 #include "SPI8.h"
00012 #include "SPI16.h"
00013 #include "Protocols.h "
00014 
00015 #include "GraphicsDisplay.h"
00016 
00017 // undefine the KL43Z and KL46Z LCD macro
00018 #ifdef LCD
00019 #undef LCD
00020 #endif
00021 
00022 /** Draw mode
00023   * NORMAl
00024   * XOR set pixel by xor the screen
00025   */
00026 //enum {NORMAL,XOR};
00027 
00028 /** Mirror mode */
00029 enum mirror_t {X,Y,XY,NONE};
00030 
00031 
00032 /** A common base class for monochrome Display
00033 */
00034 class LCD : public GraphicsDisplay
00035 {
00036 
00037 public:         
00038           
00039     /** Create a monochrome LCD Parallel Port interface
00040     * @param name The name used by the parent class to access the interface
00041     */
00042     LCD(proto_t displayproto,PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
00043     
00044     /** Create a monochrome LCD Parallel Bus interface
00045     * @param name The name used by the parent class to access the interface
00046     */
00047     LCD(proto_t displayproto,PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
00048     
00049     /** Create a monochrome LCD SPI interface
00050     * @param name The name used by the parent class to access the interface
00051     */
00052     LCD(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
00053     
00054     /** Destructor
00055     * will free framebuffer
00056     */
00057     virtual ~LCD();
00058     
00059 
00060     
00061 /////// functions that come for free, but can be overwritten///////////////////////////////////////////////////
00062 /////// ----------------------------------------------------///////////////////////////////////////////////////
00063 
00064     /** Draw a pixel in the specified color.
00065     * @param x is the horizontal offset to this pixel.
00066     * @param y is the vertical offset to this pixel.
00067     * @param color defines the color for the pixel.
00068     */
00069     virtual void pixel(int x, int y, unsigned short color);
00070 
00071     /** Set the window, which controls where items are written to the screen.
00072     * When something hits the window width, it wraps back to the left side
00073     * and down a row. If the initial write is outside the window, it will
00074     * be captured into the window when it crosses a boundary.
00075     * @param x is the left edge in pixels.
00076     * @param y is the top edge in pixels.
00077     * @param w is the window width in pixels.
00078     * @param h is the window height in pixels.
00079     */
00080     virtual void window(int x, int y, int w, int h);
00081     
00082     /** Read pixel color at location
00083     * @param x is the horizontal offset to this pixel.
00084     * @param y is the vertical offset to this pixel.
00085     * @returns 16bit color, 0000=Black(pixel set), FFFF=White(pixel clear).
00086     */
00087     virtual unsigned short pixelread(int x, int y);
00088 
00089     /** Push a single pixel into the window and increment position.
00090     * You must first call window() then push pixels in loop.
00091     * @param color is the pixel color.
00092     */
00093     virtual void window_pushpixel(unsigned short color);
00094     
00095     /** Push some pixels of the same color into the window and increment position.
00096     * You must first call window() then push pixels.
00097     * @param color is the pixel color.
00098     * @param count: how many
00099     */
00100     virtual void window_pushpixel(unsigned short color, unsigned int count);
00101     
00102     /** Push array of pixel colors into the window and increment position.
00103     * You must first call window() then push pixels.
00104     * @param color is the pixel color.
00105     */
00106     virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght);
00107  
00108     /** Framebuffer is used, it needs to be sent to LCD from time to time
00109     */
00110     virtual void copy_to_lcd();
00111     
00112     /** set the contrast of the screen
00113       *
00114       * @param o contrast 0-63
00115       * @note may be overrided in case of not standard command
00116       */
00117     virtual void set_contrast(int o);
00118 
00119     /** read the contrast level
00120       *
00121       */
00122     int get_contrast(void);
00123 
00124     /** display inverted colors
00125       *
00126       * @param o = 0 normal, 1 invert
00127       */
00128     void invert(unsigned char o);
00129 
00130     /** clear the entire screen
00131     * The inherited one sets windomax then fill with background color
00132     * We override it to speedup
00133     */
00134     virtual void cls();
00135     
00136     /** Set the orientation of the screen
00137     *  x,y: 0,0 is always top left 
00138     *
00139     * @param o direction to use the screen (0-3)
00140     * 0 = -90°
00141     * 1 = default 0°
00142     * 2 = +90°
00143     * 3 = +180°
00144     *
00145     */  
00146     void set_orientation(int o);
00147     
00148     /** Set ChipSelect high or low
00149     * @param enable 0/1   
00150     */
00151     virtual void BusEnable(bool enable);
00152     
00153     /** get display X size in pixels (native, orientation independent)
00154     * @returns X size in pixels
00155     */
00156     int sizeX();
00157 
00158     /** get display Y size in pixels (native, orientation independent)
00159     * @returns Y size in pixels
00160     */
00161     int sizeY();
00162     
00163 ////////////////////////////////////////////////////////////////////////////////    
00164     // not implemented yet
00165 //////////////////////////////////////////////////////////////////
00166   //  virtual unsigned short pixelread(int x, int y){return 0;};
00167     virtual void window4read(int x, int y, int w, int h){};
00168     void setscrollarea (int startY, int areasize){};
00169     void scroll (int lines){};
00170     void scrollreset(){};
00171     void FastWindow(bool enable){};
00172     
00173     unsigned int tftID;
00174     
00175     
00176     
00177     
00178 protected:
00179 
00180     /** set mirror mode
00181       * @note may be overridden by specific display init class in case of not standard cmds or inverted wiring 
00182       * @param mode NONE, X, Y, XY 
00183       */
00184     virtual void mirrorXY(mirror_t mode);
00185 
00186 ////// functions needed by parent class ///////////////////////////////////////
00187 ////// -------------------------------- ///////////////////////////////////////
00188 
00189     /** Send 8bit command to display controller 
00190     *
00191     * @param cmd: byte to send  
00192     * @note if protocol is SPI16, it will insert NOP cmd before, so if cmd is a 2byte cmd, the second cmd will be broken. Use wr_cmd16 for 2bytes cmds
00193     */   
00194     void wr_cmd8(unsigned char cmd);
00195     
00196     /** Send 8bit data to display controller 
00197     *
00198     * @param data: byte to send   
00199     *
00200     */   
00201     void wr_data8(unsigned char data);
00202     
00203     /** Send 16bit command to display controller 
00204     *
00205     * @param cmd: halfword to send  
00206     *
00207     */   
00208     void wr_cmd16(unsigned short cmd);
00209     
00210     /** Send same 16bit pixeldata to display controller multiple times
00211     *
00212     * @param data: halfword to send
00213     * @param count: how many
00214     *
00215     */   
00216     virtual void wr_gram(unsigned short data, unsigned int count);
00217     
00218     /** Send array of pixeldata shorts to display controller
00219     *
00220     * @param data: unsigned short pixeldata array
00221     * @param lenght: lenght (in shorts)
00222     *
00223     */   
00224     virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
00225     
00226     /** HW reset sequence (without display init commands)   
00227     */
00228     void hw_reset();
00229   
00230     int draw_mode;
00231     int contrast;
00232     
00233 private:
00234 
00235     Protocols* proto;
00236     unsigned char *buffer;
00237     unsigned short *buffer16;
00238     const int screensize_X;
00239     const int screensize_Y;
00240     const int _LCDPAGES;
00241     const int _IC_X_SEGS;
00242     const int _IC_Y_COMS;
00243     const int _IC_PAGES;
00244     
00245     int page_offset;
00246     int col_offset;
00247     // pixel location
00248     int cur_x;
00249     int cur_y;
00250     // window location
00251     int win_x1;
00252     int win_x2;
00253     int win_y1;
00254     int win_y2;
00255     int orientation;
00256     bool useNOP;
00257 };
00258 
00259 #endif