.
Protocols/SPI16.h@28:2b562717a864, 2015-11-28 (annotated)
- Committer:
- Geremia
- Date:
- Sat Nov 28 17:54:09 2015 +0000
- Revision:
- 28:2b562717a864
- Parent:
- 20:14daa48ffd4c
fix ILI932x spi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 1:ff019d22b275 | 1 | #ifndef SPI16_H |
Geremia | 1:ff019d22b275 | 2 | #define SPI16_H |
Geremia | 1:ff019d22b275 | 3 | |
Geremia | 28:2b562717a864 | 4 | #define NDEBUG // avoid MBED_ASSERT to halt process when PinName DC==NC |
Geremia | 28:2b562717a864 | 5 | |
Geremia | 1:ff019d22b275 | 6 | #include "mbed.h" |
Geremia | 1:ff019d22b275 | 7 | #include "Protocols.h" |
Geremia | 1:ff019d22b275 | 8 | //#include "GraphicsDisplay.h" |
Geremia | 1:ff019d22b275 | 9 | |
Geremia | 6:8356d48a07db | 10 | /** SPI 16bit interface |
Geremia | 6:8356d48a07db | 11 | */ |
Geremia | 1:ff019d22b275 | 12 | class SPI16 : public Protocols |
Geremia | 1:ff019d22b275 | 13 | { |
Geremia | 1:ff019d22b275 | 14 | public: |
Geremia | 1:ff019d22b275 | 15 | |
Geremia | 1:ff019d22b275 | 16 | /** Create an SPI 8bit display interface with 3 control pins |
Geremia | 1:ff019d22b275 | 17 | * |
Geremia | 1:ff019d22b275 | 18 | * @param SPI mosi |
Geremia | 1:ff019d22b275 | 19 | * @param SPI miso |
Geremia | 1:ff019d22b275 | 20 | * @param SPI sclk |
Geremia | 1:ff019d22b275 | 21 | * @param CS pin connected to CS of display |
Geremia | 1:ff019d22b275 | 22 | * @param reset pin connected to RESET of display |
Geremia | 1:ff019d22b275 | 23 | * @param DC pin connected to data/command of display |
Geremia | 1:ff019d22b275 | 24 | */ |
Geremia | 20:14daa48ffd4c | 25 | SPI16(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC=NC); |
Geremia | 1:ff019d22b275 | 26 | |
Geremia | 1:ff019d22b275 | 27 | protected: |
Geremia | 1:ff019d22b275 | 28 | |
Geremia | 1:ff019d22b275 | 29 | /** Send 8bit command to display controller |
Geremia | 1:ff019d22b275 | 30 | * |
Geremia | 1:ff019d22b275 | 31 | * @note switches spi format 16->8->16, better use wr_cmd16 with NOP in front |
Geremia | 1:ff019d22b275 | 32 | * @param cmd: byte to send |
Geremia | 1:ff019d22b275 | 33 | * |
Geremia | 1:ff019d22b275 | 34 | */ |
Geremia | 1:ff019d22b275 | 35 | virtual void wr_cmd8(unsigned char cmd); |
Geremia | 1:ff019d22b275 | 36 | |
Geremia | 1:ff019d22b275 | 37 | /** Send 8bit data to display controller |
Geremia | 1:ff019d22b275 | 38 | * |
Geremia | 1:ff019d22b275 | 39 | * @note switches spi format 16->8->16, better use wr_data16 with repeated byte (if does not hurt) |
Geremia | 1:ff019d22b275 | 40 | * @param data: byte to send |
Geremia | 1:ff019d22b275 | 41 | * |
Geremia | 1:ff019d22b275 | 42 | */ |
Geremia | 1:ff019d22b275 | 43 | virtual void wr_data8(unsigned char data); |
Geremia | 1:ff019d22b275 | 44 | |
Geremia | 4:12ba0ecc2c1f | 45 | /** Send 2x8bit command to display controller |
Geremia | 1:ff019d22b275 | 46 | * |
Geremia | 1:ff019d22b275 | 47 | * @param cmd: halfword to send |
Geremia | 4:12ba0ecc2c1f | 48 | * @note in SPI_16 mode a single 16bit transfer will be done |
Geremia | 1:ff019d22b275 | 49 | */ |
Geremia | 1:ff019d22b275 | 50 | virtual void wr_cmd16(unsigned short cmd); |
Geremia | 1:ff019d22b275 | 51 | |
Geremia | 4:12ba0ecc2c1f | 52 | /** Send 2x8bit data to display controller |
Geremia | 4:12ba0ecc2c1f | 53 | * |
Geremia | 4:12ba0ecc2c1f | 54 | * @param data: halfword to send |
Geremia | 4:12ba0ecc2c1f | 55 | * @note in SPI_16 mode a single 16bit transfer will be done |
Geremia | 4:12ba0ecc2c1f | 56 | */ |
Geremia | 4:12ba0ecc2c1f | 57 | virtual void wr_data16(unsigned short data); |
Geremia | 4:12ba0ecc2c1f | 58 | |
Geremia | 4:12ba0ecc2c1f | 59 | /** Send 16bit pixeldata to display controller |
Geremia | 1:ff019d22b275 | 60 | * |
Geremia | 1:ff019d22b275 | 61 | * @param data: halfword to send |
Geremia | 1:ff019d22b275 | 62 | * |
Geremia | 1:ff019d22b275 | 63 | */ |
Geremia | 4:12ba0ecc2c1f | 64 | virtual void wr_gram(unsigned short data); |
Geremia | 1:ff019d22b275 | 65 | |
Geremia | 4:12ba0ecc2c1f | 66 | /** Send same 16bit pixeldata to display controller multiple times |
Geremia | 1:ff019d22b275 | 67 | * |
Geremia | 1:ff019d22b275 | 68 | * @param data: halfword to send |
Geremia | 1:ff019d22b275 | 69 | * @param count: how many |
Geremia | 1:ff019d22b275 | 70 | * |
Geremia | 1:ff019d22b275 | 71 | */ |
Geremia | 4:12ba0ecc2c1f | 72 | virtual void wr_gram(unsigned short data, unsigned int count); |
Geremia | 1:ff019d22b275 | 73 | |
Geremia | 4:12ba0ecc2c1f | 74 | /** Send array of pixeldata shorts to display controller |
Geremia | 1:ff019d22b275 | 75 | * |
Geremia | 4:12ba0ecc2c1f | 76 | * @param data: unsigned short pixeldata array |
Geremia | 1:ff019d22b275 | 77 | * @param lenght: lenght (in shorts) |
Geremia | 1:ff019d22b275 | 78 | * |
Geremia | 1:ff019d22b275 | 79 | */ |
Geremia | 4:12ba0ecc2c1f | 80 | virtual void wr_grambuf(unsigned short* data, unsigned int lenght); |
Geremia | 1:ff019d22b275 | 81 | |
Geremia | 5:b222a9461d6b | 82 | /** Read 16bit pixeldata from display controller (with dummy cycle) |
Geremia | 5:b222a9461d6b | 83 | * |
Geremia | 11:b842b8e332cb | 84 | * @param convert true/false. Convert 18bit to 16bit, some controllers returns 18bit |
Geremia | 5:b222a9461d6b | 85 | * @returns 16bit color |
Geremia | 5:b222a9461d6b | 86 | */ |
Geremia | 11:b842b8e332cb | 87 | virtual unsigned short rd_gram(bool convert); |
Geremia | 5:b222a9461d6b | 88 | |
Geremia | 7:bb0383b91104 | 89 | /** Read 4x8bit register data (with dummy cycle) |
Geremia | 7:bb0383b91104 | 90 | * @param reg the register to read |
Geremia | 7:bb0383b91104 | 91 | * @returns data as uint |
Geremia | 7:bb0383b91104 | 92 | * |
Geremia | 7:bb0383b91104 | 93 | */ |
Geremia | 7:bb0383b91104 | 94 | virtual unsigned int rd_reg_data32(unsigned char reg); |
Geremia | 7:bb0383b91104 | 95 | |
Geremia | 7:bb0383b91104 | 96 | /** Read 3x8bit ExtendedCommands register data |
Geremia | 7:bb0383b91104 | 97 | * @param reg the register to read |
Geremia | 7:bb0383b91104 | 98 | * @param SPIreadenablecmd vendor/device specific cmd to read EXTC registers |
Geremia | 7:bb0383b91104 | 99 | * @returns data as uint |
Geremia | 7:bb0383b91104 | 100 | * @note EXTC regs (0xB0 to 0xFF) are read/write registers but needs special cmd to be read in SPI mode |
Geremia | 7:bb0383b91104 | 101 | */ |
Geremia | 7:bb0383b91104 | 102 | virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd); |
Geremia | 7:bb0383b91104 | 103 | |
Geremia | 20:14daa48ffd4c | 104 | /** ILI932x specific, does a dummy read cycle, number of bits is protocol dependent |
Geremia | 20:14daa48ffd4c | 105 | * for PAR protocols: a signle RD bit toggle |
Geremia | 20:14daa48ffd4c | 106 | * for SPI8: 8clocks |
Geremia | 20:14daa48ffd4c | 107 | * for SPI16: 16 clocks |
Geremia | 20:14daa48ffd4c | 108 | */ |
Geremia | 20:14daa48ffd4c | 109 | virtual void dummyread (); |
Geremia | 20:14daa48ffd4c | 110 | |
Geremia | 20:14daa48ffd4c | 111 | /** ILI932x specific, select register for a successive write or read |
Geremia | 20:14daa48ffd4c | 112 | * |
Geremia | 20:14daa48ffd4c | 113 | * @param reg register to be selected |
Geremia | 20:14daa48ffd4c | 114 | * @param forread false = a write next (default), true = a read next |
Geremia | 20:14daa48ffd4c | 115 | * @note forread only used by SPI protocols |
Geremia | 20:14daa48ffd4c | 116 | */ |
Geremia | 20:14daa48ffd4c | 117 | virtual void reg_select(unsigned char reg, bool forread =false); |
Geremia | 20:14daa48ffd4c | 118 | |
Geremia | 20:14daa48ffd4c | 119 | /** ILI932x specific, write register with data |
Geremia | 20:14daa48ffd4c | 120 | * |
Geremia | 20:14daa48ffd4c | 121 | * @param reg register to write |
Geremia | 20:14daa48ffd4c | 122 | * @param data 16bit data |
Geremia | 20:14daa48ffd4c | 123 | */ |
Geremia | 20:14daa48ffd4c | 124 | virtual void reg_write(unsigned char reg, unsigned short data); |
Geremia | 20:14daa48ffd4c | 125 | |
Geremia | 20:14daa48ffd4c | 126 | /** ILI932x specific, read register |
Geremia | 20:14daa48ffd4c | 127 | * |
Geremia | 20:14daa48ffd4c | 128 | * @param reg register to be read |
Geremia | 20:14daa48ffd4c | 129 | * @returns 16bit register value |
Geremia | 20:14daa48ffd4c | 130 | */ |
Geremia | 20:14daa48ffd4c | 131 | virtual unsigned short reg_read(unsigned char reg); |
Geremia | 20:14daa48ffd4c | 132 | |
Geremia | 1:ff019d22b275 | 133 | /** HW reset sequence (without display init commands) |
Geremia | 1:ff019d22b275 | 134 | */ |
Geremia | 1:ff019d22b275 | 135 | virtual void hw_reset(); |
Geremia | 1:ff019d22b275 | 136 | |
Geremia | 1:ff019d22b275 | 137 | /** Set ChipSelect high or low |
Geremia | 1:ff019d22b275 | 138 | * @param enable 0/1 |
Geremia | 1:ff019d22b275 | 139 | */ |
Geremia | 1:ff019d22b275 | 140 | virtual void BusEnable(bool enable); |
Geremia | 1:ff019d22b275 | 141 | |
Geremia | 1:ff019d22b275 | 142 | DigitalOut _CS; |
Geremia | 1:ff019d22b275 | 143 | |
Geremia | 1:ff019d22b275 | 144 | private: |
Geremia | 1:ff019d22b275 | 145 | |
Geremia | 1:ff019d22b275 | 146 | SPI _spi; |
Geremia | 1:ff019d22b275 | 147 | DigitalOut _reset; |
Geremia | 1:ff019d22b275 | 148 | DigitalOut _DC; |
Geremia | 1:ff019d22b275 | 149 | |
Geremia | 1:ff019d22b275 | 150 | }; |
Geremia | 1:ff019d22b275 | 151 | #endif |