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.

Dependents:   testUniGraphic_150217 maze_TFT_MMA8451Q TFT_test_frdm-kl25z TFT_test_NUCLEO-F411RE ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers I2C_bus.h Source File

I2C_bus.h

00001 #ifndef I2C_bus_H
00002 #define I2C_bus_H
00003 
00004 #include "mbed.h"
00005 #include "Protocols.h "
00006 
00007 /** I2C interface
00008 */
00009 class I2C_bus : public Protocols
00010 {
00011  public:
00012 
00013     /** Create an I2C display interface 
00014     *
00015     * @param I2C frquency
00016     * @param I2C address
00017     * @param I2C pin sda
00018     * @param I2C pin scl
00019     */ 
00020     I2C_bus(int Hz, int address,PinName sda, PinName scl);
00021  
00022 protected:
00023    
00024     /** Send 8bit command to display controller 
00025     *
00026     * @param cmd: byte to send  
00027     *
00028     */   
00029     virtual void wr_cmd8(unsigned char cmd);
00030     
00031     /** Send 8bit data to display controller 
00032     *
00033     * @param data: byte to send   
00034     *
00035     */   
00036     virtual void wr_data8(unsigned char data);
00037     
00038     /** Send 2x8bit command to display controller 
00039     *
00040     * @param cmd: halfword to send  
00041     * @note in SPI_16 mode a single 16bit transfer will be done
00042     */   
00043     virtual void wr_cmd16(unsigned short cmd);
00044     
00045     /** Send 2x8bit data to display controller 
00046     *
00047     * @param data: halfword to send   
00048     * @note in SPI_16 mode a single 16bit transfer will be done
00049     */   
00050     virtual void wr_data16(unsigned short data);
00051     
00052     /** Send 16bit pixeldata to display controller 
00053     *
00054     * @param data: halfword to send   
00055     *
00056     */   
00057     virtual void wr_gram(unsigned short data);
00058     
00059     /** Send same 16bit pixeldata to display controller multiple times
00060     *
00061     * @param data: halfword to send
00062     * @param count: how many
00063     *
00064     */   
00065     virtual void wr_gram(unsigned short data, unsigned int count);
00066     
00067     /** Send array of pixeldata shorts to display controller
00068     *
00069     * @param data: unsigned short pixeldata array
00070     * @param lenght: lenght (in shorts)
00071     *
00072     */   
00073     virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
00074     
00075     /** Read 16bit pixeldata from display controller (with dummy cycle)
00076     *
00077     * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit
00078     * @returns 16bit color
00079     */ 
00080     virtual unsigned short rd_gram(bool convert);
00081     
00082     /** Read 4x8bit register data (
00083     *   reading from display ia I2C is not implemented in most controllers !
00084     * 
00085     */ 
00086     virtual unsigned int rd_reg_data32(unsigned char reg);
00087     
00088     /** Read 3x8bit ExtendedCommands register data
00089     *   reading from display ia I2C is not implemented in most controllers !
00090     */ 
00091     virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd);
00092     
00093     /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent
00094     *   reading from display ia I2C is not implemented in most controllers !
00095     */   
00096     virtual void dummyread ();
00097     
00098     /** ILI932x specific, select register for a successive write or read
00099     *
00100     *   reading from display ia I2C is not implemented in most controllers !
00101     */   
00102     virtual void reg_select(unsigned char reg, bool forread =false);
00103     
00104     /** ILI932x specific, write register with data
00105     *
00106     * @param reg register to write
00107     * @param data 16bit data
00108     *  not implemented for I2C !
00109     */   
00110     virtual void reg_write(unsigned char reg, unsigned short data);
00111     
00112     /** ILI932x specific, read register
00113     *
00114     * @param reg register to be read
00115     * @returns 16bit register value
00116     *  not implemented for I2C !
00117     */ 
00118     virtual unsigned short reg_read(unsigned char reg);
00119     
00120     /** HW reset sequence (without display init commands)
00121     *  most I2C displays have no reset signal !   
00122     */
00123     virtual void hw_reset();
00124     
00125     /** Set ChipSelect high or low
00126     * @param enable 0/1   
00127     *  not implemented for I2C !
00128     */
00129     virtual void BusEnable(bool enable);
00130 
00131 private:
00132 
00133     I2C _i2c;
00134     int _address;
00135     
00136 };
00137 
00138 
00139 #endif