Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Fork of UniGraphic by GraphicsDisplay

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SPI16.h Source File

SPI16.h

00001 #ifndef SPI16_H
00002 #define SPI16_H
00003 
00004 #include "mbed.h"
00005 #include "Protocols.h "
00006 //#include "GraphicsDisplay.h"
00007 
00008 /** SPI 16bit interface
00009 */
00010 class SPI16 : public Protocols
00011 {
00012  public:
00013 
00014     /** Create an SPI 8bit display interface with 3 control pins
00015     *
00016     * @param SPI mosi
00017     * @param SPI miso
00018     * @param SPI sclk
00019     * @param CS pin connected to CS of display
00020     * @param reset pin connected to RESET of display
00021     * @param DC pin connected to data/command of display
00022     */ 
00023     SPI16(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC=NC);
00024  
00025 protected:
00026    
00027     /** Send 8bit command to display controller 
00028     *
00029     * @note switches spi format 16->8->16, better use wr_cmd16 with NOP in front 
00030     * @param cmd: byte to send  
00031     *
00032     */   
00033     virtual void wr_cmd8(unsigned char cmd);
00034     
00035     /** Send 8bit data to display controller 
00036     *
00037     * @note switches spi format 16->8->16, better use wr_data16 with repeated byte (if does not hurt)
00038     * @param data: byte to send   
00039     *
00040     */   
00041     virtual void wr_data8(unsigned char data);
00042     
00043     /** Send 2x8bit command to display controller 
00044     *
00045     * @param cmd: halfword to send  
00046     * @note in SPI_16 mode a single 16bit transfer will be done
00047     */   
00048     virtual void wr_cmd16(unsigned short cmd);
00049     
00050     /** Send 2x8bit data to display controller 
00051     *
00052     * @param data: halfword to send   
00053     * @note in SPI_16 mode a single 16bit transfer will be done
00054     */   
00055     virtual void wr_data16(unsigned short data);
00056     
00057     /** Send 16bit pixeldata to display controller 
00058     *
00059     * @param data: halfword to send   
00060     *
00061     */   
00062     virtual void wr_gram(unsigned short data);
00063     
00064     /** Send same 16bit pixeldata to display controller multiple times
00065     *
00066     * @param data: halfword to send
00067     * @param count: how many
00068     *
00069     */   
00070     virtual void wr_gram(unsigned short data, unsigned int count);
00071     
00072     /** Send array of pixeldata shorts to display controller
00073     *
00074     * @param data: unsigned short pixeldata array
00075     * @param lenght: lenght (in shorts)
00076     *
00077     */   
00078     virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
00079     
00080     /** Read 16bit pixeldata from display controller (with dummy cycle)
00081     *
00082     * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit
00083     * @returns 16bit color
00084     */ 
00085     virtual unsigned short rd_gram(bool convert);
00086     
00087     /** Read 4x8bit register data (with dummy cycle)
00088     * @param reg the register to read
00089     * @returns data as uint
00090     * 
00091     */ 
00092     virtual unsigned int rd_reg_data32(unsigned char reg);
00093     
00094     /** Read 3x8bit ExtendedCommands register data
00095     * @param reg the register to read
00096     * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers
00097     * @returns data as uint
00098     * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode
00099     */ 
00100     virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd);
00101     
00102     /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent
00103     * for PAR protocols: a signle RD bit toggle
00104     * for SPI8: 8clocks
00105     * for SPI16: 16 clocks
00106     */   
00107     virtual void dummyread ();
00108     
00109     /** ILI932x specific, select register for a successive write or read
00110     *
00111     * @param reg register to be selected
00112     * @param forread false = a write next (default), true = a read next
00113     * @note forread only used by SPI protocols
00114     */   
00115     virtual void reg_select(unsigned char reg, bool forread =false);
00116     
00117     /** ILI932x specific, write register with data
00118     *
00119     * @param reg register to write
00120     * @param data 16bit data
00121     */   
00122     virtual void reg_write(unsigned char reg, unsigned short data);
00123     
00124     /** ILI932x specific, read register
00125     *
00126     * @param reg register to be read
00127     * @returns 16bit register value
00128     */ 
00129     virtual unsigned short reg_read(unsigned char reg);
00130     
00131     /** HW reset sequence (without display init commands)   
00132     */
00133     virtual void hw_reset();
00134     
00135     /** Set ChipSelect high or low
00136     * @param enable 0/1   
00137     */
00138     virtual void BusEnable(bool enable);
00139   
00140     DigitalOut _CS;
00141 
00142 private:
00143 
00144     SPI _spi;
00145     DigitalOut _reset;
00146     DigitalOut _DC;
00147   
00148 };
00149 #endif