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