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