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