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 GraphicsDisplay

Committer:
Geremia
Date:
Thu Feb 12 22:22:47 2015 +0000
Revision:
0:75ec1b3cde17
Child:
1:ff019d22b275
Initial tests, LCD par and spi ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 0:75ec1b3cde17 1 #include "SPI8.h"
Geremia 0:75ec1b3cde17 2
Geremia 0:75ec1b3cde17 3 //#define USE_CS
Geremia 0:75ec1b3cde17 4
Geremia 0:75ec1b3cde17 5 SPI8::SPI8(PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC)
Geremia 0:75ec1b3cde17 6 : _CS(CS), _spi(mosi, miso, sclk), _reset(reset), _DC(DC)
Geremia 0:75ec1b3cde17 7 {
Geremia 0:75ec1b3cde17 8 _reset = 1;
Geremia 0:75ec1b3cde17 9 _DC=1;
Geremia 0:75ec1b3cde17 10 _CS=1;
Geremia 0:75ec1b3cde17 11 _spi.format(8,0); // 8 bit spi mode 0
Geremia 0:75ec1b3cde17 12 // _spi.frequency(12000000); // 10 Mhz SPI clock, 12mhz for F411
Geremia 0:75ec1b3cde17 13 _spi.frequency(10000000);
Geremia 0:75ec1b3cde17 14 hw_reset();
Geremia 0:75ec1b3cde17 15 }
Geremia 0:75ec1b3cde17 16
Geremia 0:75ec1b3cde17 17 void SPI8::wr_cmd(unsigned char cmd)
Geremia 0:75ec1b3cde17 18 {
Geremia 0:75ec1b3cde17 19 #ifdef USE_CS
Geremia 0:75ec1b3cde17 20 _CS = 0;
Geremia 0:75ec1b3cde17 21 #endif
Geremia 0:75ec1b3cde17 22 _DC.write(0); // 0=cmd
Geremia 0:75ec1b3cde17 23 _spi.write(cmd); // write 8bit
Geremia 0:75ec1b3cde17 24 #ifdef USE_CS
Geremia 0:75ec1b3cde17 25 _CS = 1;
Geremia 0:75ec1b3cde17 26 #endif
Geremia 0:75ec1b3cde17 27 }
Geremia 0:75ec1b3cde17 28 void SPI8::wr_data8(unsigned char data8)
Geremia 0:75ec1b3cde17 29 {
Geremia 0:75ec1b3cde17 30 #ifdef USE_CS
Geremia 0:75ec1b3cde17 31 _CS = 0;
Geremia 0:75ec1b3cde17 32 #endif
Geremia 0:75ec1b3cde17 33 _DC.write(1); // 1=data
Geremia 0:75ec1b3cde17 34 _spi.write(data8); // write 8bit
Geremia 0:75ec1b3cde17 35 #ifdef USE_CS
Geremia 0:75ec1b3cde17 36 _CS = 1;
Geremia 0:75ec1b3cde17 37 #endif
Geremia 0:75ec1b3cde17 38 }
Geremia 0:75ec1b3cde17 39 void SPI8::wr_data8(unsigned char data8, unsigned int count)
Geremia 0:75ec1b3cde17 40 {
Geremia 0:75ec1b3cde17 41 #ifdef USE_CS
Geremia 0:75ec1b3cde17 42 _CS = 0;
Geremia 0:75ec1b3cde17 43 #endif
Geremia 0:75ec1b3cde17 44 _DC.write(1); // 1=data
Geremia 0:75ec1b3cde17 45 while(count)
Geremia 0:75ec1b3cde17 46 {
Geremia 0:75ec1b3cde17 47 _spi.write(data8); // write 8bit
Geremia 0:75ec1b3cde17 48 count--;
Geremia 0:75ec1b3cde17 49 }
Geremia 0:75ec1b3cde17 50 #ifdef USE_CS
Geremia 0:75ec1b3cde17 51 _CS = 1;
Geremia 0:75ec1b3cde17 52 #endif
Geremia 0:75ec1b3cde17 53 }
Geremia 0:75ec1b3cde17 54 void SPI8::wr_data8buf(unsigned char* data8, unsigned int lenght)
Geremia 0:75ec1b3cde17 55 {
Geremia 0:75ec1b3cde17 56 #ifdef USE_CS
Geremia 0:75ec1b3cde17 57 _CS = 0;
Geremia 0:75ec1b3cde17 58 #endif
Geremia 0:75ec1b3cde17 59 _DC.write(1); // 1=data
Geremia 0:75ec1b3cde17 60 while(lenght)
Geremia 0:75ec1b3cde17 61 {
Geremia 0:75ec1b3cde17 62 _spi.write(*data8++); // write 8bit
Geremia 0:75ec1b3cde17 63 // data8++;
Geremia 0:75ec1b3cde17 64 lenght--;
Geremia 0:75ec1b3cde17 65 }
Geremia 0:75ec1b3cde17 66 #ifdef USE_CS
Geremia 0:75ec1b3cde17 67 _CS = 1;
Geremia 0:75ec1b3cde17 68 #endif
Geremia 0:75ec1b3cde17 69 }
Geremia 0:75ec1b3cde17 70 void SPI8::hw_reset()
Geremia 0:75ec1b3cde17 71 {
Geremia 0:75ec1b3cde17 72 wait_ms(15);
Geremia 0:75ec1b3cde17 73 _DC = 1;
Geremia 0:75ec1b3cde17 74 // _CS = 1;
Geremia 0:75ec1b3cde17 75 _CS = 0;
Geremia 0:75ec1b3cde17 76 _reset = 0; // display reset
Geremia 0:75ec1b3cde17 77 wait_us(50);
Geremia 0:75ec1b3cde17 78 _reset = 1; // end reset
Geremia 0:75ec1b3cde17 79 wait_ms(15);
Geremia 0:75ec1b3cde17 80 #ifndef USE_CS
Geremia 0:75ec1b3cde17 81 _CS=0; // put CS low now and forever
Geremia 0:75ec1b3cde17 82 #endif
Geremia 0:75ec1b3cde17 83 }
Geremia 0:75ec1b3cde17 84 void SPI8::BusEnable(bool enable)
Geremia 0:75ec1b3cde17 85 {
Geremia 0:75ec1b3cde17 86 _CS = enable ? 0:1;
Geremia 0:75ec1b3cde17 87 }