UniGraphic-Fork for ST7920-LCD-controller and SH1106. Tested with 128x64 LCD with SPI and 128x64-OLED with IIC

Dependents:   UniGraphic-St7920-Test AfficheurUTILECO

Fork of UniGraphic by GraphicsDisplay

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Protocols.h Source File

Protocols.h

Go to the documentation of this file.
00001  /* mbed UniGraphic library - Abstract protocol class
00002  * Copyright (c) 2015 Giuliano Dianda
00003  * Released under the MIT License: http://mbed.org/license/mit
00004  */
00005  
00006 /** @file Protocols.h
00007 */
00008 #ifndef Protocols_H
00009 #define Protocols_H
00010 
00011 #include "mbed.h"
00012 
00013 #define RGB24to16(r,g,b)  (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue
00014 #define BGR2RGB(color) (((color&0x1F)<<11) | (color&0x7E0) | ((color&0xF800)>>11))
00015 
00016 #define FLIP_NONE   0
00017 #define FLIP_X      1
00018 #define FLIP_Y      2
00019 
00020 //#define USE_CS
00021 
00022 /** Protocol types
00023 */
00024 #include "platform.h"
00025 
00026 #if DEVICE_PORTINOUT
00027 enum proto_t {
00028     PAR_8   /**< Parallel 8bit, port pins 0 to 7 */
00029     ,PAR_16 /**< Parallel 16bit, port pins 0 to 15 */
00030     ,BUS_8   /**< Parallel 8bit, scattered pins */
00031     ,BUS_16   /**< Parallel 16bit, scattered pins */
00032     ,SPI_8  /**< SPI 8bit */
00033     ,SPI_16 /**< SPI 16bit */
00034     ,I2C_   /**< I2C */
00035 };
00036 #else 
00037 enum proto_t {
00038     BUS_8   /**< Parallel 8bit, scattered pins */
00039     ,BUS_16   /**< Parallel 16bit, scattered pins */
00040     ,SPI_8  /**< SPI 8bit */
00041     ,SPI_16 /**< SPI 16bit */
00042     ,I2C_   /**< I2C */
00043 };
00044 #endif
00045 
00046 
00047 /** Abstract interface class for spi and parallel protocols
00048 */
00049 class Protocols
00050 {
00051  public:
00052     
00053     /** Send 8bit command to display controller 
00054     *
00055     * @param cmd: byte to send  
00056     *
00057     */   
00058     virtual void wr_cmd8(unsigned char cmd) = 0;
00059     
00060     /** Send 8bit data to display controller 
00061     *
00062     * @param data: byte to send   
00063     *
00064     */   
00065     virtual void wr_data8(unsigned char data) = 0;
00066     
00067     /** Send 2x8bit command to display controller 
00068     *
00069     * @param cmd: halfword to send  
00070     *
00071     */   
00072     virtual void wr_cmd16(unsigned short cmd) = 0;
00073     
00074     /** Send 2x8bit data to display controller 
00075     *
00076     * @param data: halfword to send   
00077     *
00078     */   
00079     virtual void wr_data16(unsigned short data) = 0;
00080     
00081     /** Send 16bit pixeldata to display controller 
00082     *
00083     * @param data: halfword to send   
00084     *
00085     */   
00086     virtual void wr_gram(unsigned short data) = 0;
00087     
00088     /** Send same 16bit pixeldata to display controller multiple times
00089     *
00090     * @param data: halfword to send
00091     * @param count: how many
00092     *
00093     */   
00094     virtual void wr_gram(unsigned short data, unsigned int count) = 0;
00095     
00096     /** Send array of pixeldata shorts to display controller
00097     *
00098     * @param data: unsigned short pixeldata array
00099     * @param lenght: lenght (in shorts)
00100     *
00101     */   
00102     virtual void wr_grambuf(unsigned short* data, unsigned int lenght) = 0;
00103     
00104     /** Read 16bit pixeldata from display controller (with dummy cycle)
00105     *
00106     * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit
00107     * @returns 16bit color
00108     */ 
00109     virtual unsigned short rd_gram(bool convert) = 0;
00110     
00111     /** Read 4x8bit register data (with dummy cycle)
00112     * @param reg the register to read
00113     * @returns data as uint
00114     * 
00115     */ 
00116     virtual unsigned int rd_reg_data32(unsigned char reg) = 0;
00117     
00118     /** Read 3x8bit ExtendedCommands register data
00119     * @param reg the register to read
00120     * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers
00121     * @returns data as uint
00122     * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode
00123     */ 
00124     virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd) = 0;
00125     
00126     /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent
00127     * for PAR protocols: a signle RD bit toggle
00128     * for SPI8: 8clocks
00129     * for SPI16: 16 clocks
00130     */   
00131     virtual void dummyread () = 0;
00132     
00133     /** ILI932x specific, select register for a successive write or read
00134     *
00135     * @param reg register to be selected
00136     * @param forread false = a write next (default), true = a read next
00137     * @note forread only used by SPI protocols
00138     */   
00139     virtual void reg_select(unsigned char reg, bool forread =false) = 0;
00140     
00141     /** ILI932x specific, write register with data
00142     *
00143     * @param reg register to write
00144     * @param data 16bit data
00145     */   
00146     virtual void reg_write(unsigned char reg, unsigned short data) = 0;
00147     
00148     /** ILI932x specific, read register
00149     *
00150     * @param reg register to be read
00151     * @returns 16bit register value
00152     */ 
00153     virtual unsigned short reg_read(unsigned char reg) = 0;
00154     
00155     /** HW reset sequence (without display init commands)   
00156     */
00157     virtual void hw_reset() = 0;
00158     
00159     /** Set ChipSelect high or low
00160     * @param enable 0/1   
00161     */
00162     virtual void BusEnable(bool enable) = 0;
00163 
00164 };
00165 #endif