Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SPI8.h
00001 #ifndef SPI8_H 00002 #define SPI8_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 8bit interface 00011 */ 00012 class SPI8 : 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 SPI8(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 * @param cmd: byte to send 00032 * 00033 */ 00034 virtual void wr_cmd8(unsigned char cmd); 00035 00036 /** Send 8bit data to display controller 00037 * 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 */ 00047 virtual void wr_cmd16(unsigned short cmd); 00048 00049 /** Send 2x8bit data to display controller 00050 * 00051 * @param data: halfword to send 00052 * 00053 */ 00054 virtual void wr_data16(unsigned short data); 00055 00056 /** Send 16bit pixeldata to display controller 00057 * 00058 * @param data: halfword to send 00059 * 00060 */ 00061 virtual void wr_gram(unsigned short data); 00062 00063 /** Send same 16bit pixeldata to display controller multiple times 00064 * 00065 * @param data: halfword to send 00066 * @param count: how many 00067 * 00068 */ 00069 virtual void wr_gram(unsigned short data, unsigned int count); 00070 00071 /** Send array of pixeldata shorts to display controller 00072 * 00073 * @param data: unsigned short pixeldata array 00074 * @param lenght: lenght (in shorts) 00075 * 00076 */ 00077 virtual void wr_grambuf(unsigned short* data, unsigned int lenght); 00078 00079 /** Read 16bit pixeldata from display controller (with dummy cycle) 00080 * 00081 * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit 00082 * @returns 16bit color 00083 */ 00084 virtual unsigned short rd_gram(bool convert); 00085 00086 /** Read 4x8bit register data (with dummy cycle) 00087 * @param reg the register to read 00088 * @returns data as uint 00089 * 00090 */ 00091 virtual unsigned int rd_reg_data32(unsigned char reg); 00092 00093 /** Read 3x8bit ExtendedCommands register data 00094 * @param reg the register to read 00095 * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers 00096 * @returns data as uint 00097 * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode 00098 */ 00099 virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); 00100 00101 /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent 00102 * for PAR protocols: a signle RD bit toggle 00103 * for SPI8: 8clocks 00104 * for SPI16: 16 clocks 00105 */ 00106 virtual void dummyread (); 00107 00108 /** ILI932x specific, select register for a successive write or read 00109 * 00110 * @param reg register to be selected 00111 * @param forread false = a write next (default), true = a read next 00112 * @note forread only used by SPI protocols 00113 */ 00114 virtual void reg_select(unsigned char reg, bool forread =false); 00115 00116 /** ILI932x specific, write register with data 00117 * 00118 * @param reg register to write 00119 * @param data 16bit data 00120 */ 00121 virtual void reg_write(unsigned char reg, unsigned short data); 00122 00123 /** ILI932x specific, read register 00124 * 00125 * @param reg register to be read 00126 * @returns 16bit register value 00127 */ 00128 virtual unsigned short reg_read(unsigned char reg); 00129 00130 /** HW reset sequence (without display init commands) 00131 */ 00132 virtual void hw_reset(); 00133 00134 /** Set ChipSelect high or low 00135 * @param enable 0/1 00136 */ 00137 virtual void BusEnable(bool enable); 00138 00139 DigitalOut _CS; 00140 00141 private: 00142 00143 SPI _spi; 00144 DigitalOut _reset; 00145 DigitalOut _DC; 00146 00147 }; 00148 #endif
Generated on Fri Jul 15 2022 13:58:04 by
