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.
Fork of UniGraphic by
Protocols/SPI16.h@1:ff019d22b275, 2015-02-13 (annotated)
- Committer:
- Geremia
- Date:
- Fri Feb 13 15:25:10 2015 +0000
- Revision:
- 1:ff019d22b275
- Child:
- 4:12ba0ecc2c1f
Added SPI_16, LCD done
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 | 1:ff019d22b275 | 4 | #include "mbed.h" |
Geremia | 1:ff019d22b275 | 5 | #include "Protocols.h" |
Geremia | 1:ff019d22b275 | 6 | //#include "GraphicsDisplay.h" |
Geremia | 1:ff019d22b275 | 7 | |
Geremia | 1:ff019d22b275 | 8 | class SPI16 : public Protocols |
Geremia | 1:ff019d22b275 | 9 | { |
Geremia | 1:ff019d22b275 | 10 | public: |
Geremia | 1:ff019d22b275 | 11 | |
Geremia | 1:ff019d22b275 | 12 | /** Create an SPI 8bit display interface with 3 control pins |
Geremia | 1:ff019d22b275 | 13 | * |
Geremia | 1:ff019d22b275 | 14 | * @param SPI mosi |
Geremia | 1:ff019d22b275 | 15 | * @param SPI miso |
Geremia | 1:ff019d22b275 | 16 | * @param SPI sclk |
Geremia | 1:ff019d22b275 | 17 | * @param CS pin connected to CS of display |
Geremia | 1:ff019d22b275 | 18 | * @param reset pin connected to RESET of display |
Geremia | 1:ff019d22b275 | 19 | * @param DC pin connected to data/command of display |
Geremia | 1:ff019d22b275 | 20 | */ |
Geremia | 1:ff019d22b275 | 21 | SPI16(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC); |
Geremia | 1:ff019d22b275 | 22 | |
Geremia | 1:ff019d22b275 | 23 | protected: |
Geremia | 1:ff019d22b275 | 24 | |
Geremia | 1:ff019d22b275 | 25 | /** Send 8bit command to display controller |
Geremia | 1:ff019d22b275 | 26 | * |
Geremia | 1:ff019d22b275 | 27 | * @note switches spi format 16->8->16, better use wr_cmd16 with NOP in front |
Geremia | 1:ff019d22b275 | 28 | * @param cmd: byte to send |
Geremia | 1:ff019d22b275 | 29 | * |
Geremia | 1:ff019d22b275 | 30 | */ |
Geremia | 1:ff019d22b275 | 31 | virtual void wr_cmd8(unsigned char cmd); |
Geremia | 1:ff019d22b275 | 32 | |
Geremia | 1:ff019d22b275 | 33 | /** Send 8bit data to display controller |
Geremia | 1:ff019d22b275 | 34 | * |
Geremia | 1:ff019d22b275 | 35 | * @note switches spi format 16->8->16, better use wr_data16 with repeated byte (if does not hurt) |
Geremia | 1:ff019d22b275 | 36 | * @param data: byte to send |
Geremia | 1:ff019d22b275 | 37 | * |
Geremia | 1:ff019d22b275 | 38 | */ |
Geremia | 1:ff019d22b275 | 39 | virtual void wr_data8(unsigned char data); |
Geremia | 1:ff019d22b275 | 40 | |
Geremia | 1:ff019d22b275 | 41 | /** Send same 8bit data to display controller multiple times |
Geremia | 1:ff019d22b275 | 42 | * |
Geremia | 1:ff019d22b275 | 43 | * @note switches spi format 16->8->16, better use wr_data16 |
Geremia | 1:ff019d22b275 | 44 | * @param data: byte to send |
Geremia | 1:ff019d22b275 | 45 | * @param count: how many |
Geremia | 1:ff019d22b275 | 46 | * |
Geremia | 1:ff019d22b275 | 47 | */ |
Geremia | 1:ff019d22b275 | 48 | virtual void wr_data8(unsigned char data, unsigned int count); |
Geremia | 1:ff019d22b275 | 49 | |
Geremia | 1:ff019d22b275 | 50 | /** Send array of data bytes to display controller |
Geremia | 1:ff019d22b275 | 51 | * |
Geremia | 1:ff019d22b275 | 52 | * @note switches spi format 16->8->16, better use wr_data16 |
Geremia | 1:ff019d22b275 | 53 | * @param data: unsigned char data array |
Geremia | 1:ff019d22b275 | 54 | * @param lenght: lenght of array |
Geremia | 1:ff019d22b275 | 55 | * |
Geremia | 1:ff019d22b275 | 56 | */ |
Geremia | 1:ff019d22b275 | 57 | virtual void wr_data8buf(unsigned char* data, unsigned int lenght); |
Geremia | 1:ff019d22b275 | 58 | |
Geremia | 1:ff019d22b275 | 59 | /** Send 16bit command to display controller |
Geremia | 1:ff019d22b275 | 60 | * |
Geremia | 1:ff019d22b275 | 61 | * @param cmd: halfword to send |
Geremia | 1:ff019d22b275 | 62 | * |
Geremia | 1:ff019d22b275 | 63 | */ |
Geremia | 1:ff019d22b275 | 64 | virtual void wr_cmd16(unsigned short cmd); |
Geremia | 1:ff019d22b275 | 65 | |
Geremia | 1:ff019d22b275 | 66 | /** Send 16bit data to display controller |
Geremia | 1:ff019d22b275 | 67 | * |
Geremia | 1:ff019d22b275 | 68 | * @param data: halfword to send |
Geremia | 1:ff019d22b275 | 69 | * |
Geremia | 1:ff019d22b275 | 70 | */ |
Geremia | 1:ff019d22b275 | 71 | virtual void wr_data16(unsigned short data); |
Geremia | 1:ff019d22b275 | 72 | |
Geremia | 1:ff019d22b275 | 73 | /** Send same 16bit data to display controller multiple times |
Geremia | 1:ff019d22b275 | 74 | * |
Geremia | 1:ff019d22b275 | 75 | * @param data: halfword to send |
Geremia | 1:ff019d22b275 | 76 | * @param count: how many |
Geremia | 1:ff019d22b275 | 77 | * |
Geremia | 1:ff019d22b275 | 78 | */ |
Geremia | 1:ff019d22b275 | 79 | virtual void wr_data16(unsigned short data, unsigned int count); |
Geremia | 1:ff019d22b275 | 80 | |
Geremia | 1:ff019d22b275 | 81 | /** Send array of data shorts to display controller |
Geremia | 1:ff019d22b275 | 82 | * |
Geremia | 1:ff019d22b275 | 83 | * @param data: unsigned short data array |
Geremia | 1:ff019d22b275 | 84 | * @param lenght: lenght (in shorts) |
Geremia | 1:ff019d22b275 | 85 | * |
Geremia | 1:ff019d22b275 | 86 | */ |
Geremia | 1:ff019d22b275 | 87 | virtual void wr_data16buf(unsigned short* data, unsigned int lenght); |
Geremia | 1:ff019d22b275 | 88 | |
Geremia | 1:ff019d22b275 | 89 | /** HW reset sequence (without display init commands) |
Geremia | 1:ff019d22b275 | 90 | */ |
Geremia | 1:ff019d22b275 | 91 | virtual void hw_reset(); |
Geremia | 1:ff019d22b275 | 92 | |
Geremia | 1:ff019d22b275 | 93 | /** Set ChipSelect high or low |
Geremia | 1:ff019d22b275 | 94 | * @param enable 0/1 |
Geremia | 1:ff019d22b275 | 95 | */ |
Geremia | 1:ff019d22b275 | 96 | virtual void BusEnable(bool enable); |
Geremia | 1:ff019d22b275 | 97 | |
Geremia | 1:ff019d22b275 | 98 | DigitalOut _CS; |
Geremia | 1:ff019d22b275 | 99 | |
Geremia | 1:ff019d22b275 | 100 | private: |
Geremia | 1:ff019d22b275 | 101 | |
Geremia | 1:ff019d22b275 | 102 | SPI _spi; |
Geremia | 1:ff019d22b275 | 103 | DigitalOut _reset; |
Geremia | 1:ff019d22b275 | 104 | DigitalOut _DC; |
Geremia | 1:ff019d22b275 | 105 | |
Geremia | 1:ff019d22b275 | 106 | }; |
Geremia | 1:ff019d22b275 | 107 | #endif |