Louis Mayencourt / Mbed OS NRFBOY
Committer:
lmayencou
Date:
Fri Jan 06 22:10:20 2017 +0000
Revision:
1:c53e766082b4
Child:
2:e3ef9f476913
display circle and hello on SPI screen !

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lmayencou 1:c53e766082b4 1 #include "abstractarduboy.h"
lmayencou 1:c53e766082b4 2
lmayencou 1:c53e766082b4 3 SPI _spi(p30, p31, p29); // mosi, miso, sclk
lmayencou 1:c53e766082b4 4
lmayencou 1:c53e766082b4 5 DigitalOut _cs(p3);
lmayencou 1:c53e766082b4 6 DigitalOut _dc(p28);
lmayencou 1:c53e766082b4 7 DigitalOut _rst(p4);
lmayencou 1:c53e766082b4 8
lmayencou 1:c53e766082b4 9 class MbedBoy : public AbstractArduboy, Stream
lmayencou 1:c53e766082b4 10 {
lmayencou 1:c53e766082b4 11 public:
lmayencou 1:c53e766082b4 12 MbedBoy(){};
lmayencou 1:c53e766082b4 13
lmayencou 1:c53e766082b4 14 void start()
lmayencou 1:c53e766082b4 15 {
lmayencou 1:c53e766082b4 16 // init SPI
lmayencou 1:c53e766082b4 17 _spi.format(8,3);
lmayencou 1:c53e766082b4 18 _spi.frequency(1000000);
lmayencou 1:c53e766082b4 19
lmayencou 1:c53e766082b4 20 // init pin LCD
lmayencou 1:c53e766082b4 21 _dc = 0;
lmayencou 1:c53e766082b4 22 _cs = 0;
lmayencou 1:c53e766082b4 23 _rst = 1;
lmayencou 1:c53e766082b4 24 wait_ms(1);
lmayencou 1:c53e766082b4 25 _rst = 0;
lmayencou 1:c53e766082b4 26 wait_ms(10);
lmayencou 1:c53e766082b4 27 _rst = 1;
lmayencou 1:c53e766082b4 28
lmayencou 1:c53e766082b4 29 bootLCD();
lmayencou 1:c53e766082b4 30 }
lmayencou 1:c53e766082b4 31
lmayencou 1:c53e766082b4 32 long getTime()
lmayencou 1:c53e766082b4 33 {
lmayencou 1:c53e766082b4 34 return time(NULL);
lmayencou 1:c53e766082b4 35 }
lmayencou 1:c53e766082b4 36
lmayencou 1:c53e766082b4 37 void drawScreen(const unsigned char *image)
lmayencou 1:c53e766082b4 38 {
lmayencou 1:c53e766082b4 39 for (int i = 0; i < (HEIGHT*WIDTH)/8; i++)
lmayencou 1:c53e766082b4 40 {
lmayencou 1:c53e766082b4 41 _spi.write(image[i]);
lmayencou 1:c53e766082b4 42 }
lmayencou 1:c53e766082b4 43 }
lmayencou 1:c53e766082b4 44
lmayencou 1:c53e766082b4 45 uint8_t getInput()
lmayencou 1:c53e766082b4 46 {
lmayencou 1:c53e766082b4 47
lmayencou 1:c53e766082b4 48 }
lmayencou 1:c53e766082b4 49
lmayencou 1:c53e766082b4 50 void LCDCommandMode()
lmayencou 1:c53e766082b4 51 {
lmayencou 1:c53e766082b4 52 _cs = 1;
lmayencou 1:c53e766082b4 53 _dc = 0;
lmayencou 1:c53e766082b4 54 _cs = 0;
lmayencou 1:c53e766082b4 55 }
lmayencou 1:c53e766082b4 56
lmayencou 1:c53e766082b4 57 void LCDDataMode()
lmayencou 1:c53e766082b4 58 {
lmayencou 1:c53e766082b4 59 _dc = 1;
lmayencou 1:c53e766082b4 60 _cs = 0;
lmayencou 1:c53e766082b4 61 }
lmayencou 1:c53e766082b4 62
lmayencou 1:c53e766082b4 63 void bootLCD()
lmayencou 1:c53e766082b4 64 {
lmayencou 1:c53e766082b4 65 LCDCommandMode();
lmayencou 1:c53e766082b4 66 _spi.write(0xAE); // Display Off
lmayencou 1:c53e766082b4 67 _spi.write(0XD5); // Set Display Clock Divisor v
lmayencou 1:c53e766082b4 68 _spi.write(0xF0); // 0x80 is default
lmayencou 1:c53e766082b4 69 _spi.write(0xA8); // Set Multiplex Ratio v
lmayencou 1:c53e766082b4 70 _spi.write(0x3F);
lmayencou 1:c53e766082b4 71 _spi.write(0xD3); // Set Display Offset v
lmayencou 1:c53e766082b4 72 _spi.write(0x0);
lmayencou 1:c53e766082b4 73 _spi.write(0x40); // Set Start Line (0)
lmayencou 1:c53e766082b4 74 _spi.write(0x8D); // Charge Pump Setting v
lmayencou 1:c53e766082b4 75 _spi.write(0x14); // Enable
lmayencou 1:c53e766082b4 76 // why are we running this next pair twice?
lmayencou 1:c53e766082b4 77 _spi.write(0x20); // Set Memory Mode v
lmayencou 1:c53e766082b4 78 _spi.write(0x00); // Horizontal Addressing
lmayencou 1:c53e766082b4 79 _spi.write(0xA1); // Set Segment Re-map (A0) | (b0001)
lmayencou 1:c53e766082b4 80 _spi.write(0xC8); // Set COM Output Scan Direction
lmayencou 1:c53e766082b4 81 _spi.write(0xDA); // Set COM Pins v
lmayencou 1:c53e766082b4 82 _spi.write(0x12);
lmayencou 1:c53e766082b4 83 _spi.write(0x81); // Set Contrast v
lmayencou 1:c53e766082b4 84 _spi.write(0xCF);
lmayencou 1:c53e766082b4 85 _spi.write(0xD9); // Set Precharge
lmayencou 1:c53e766082b4 86 _spi.write(0xF1);
lmayencou 1:c53e766082b4 87 _spi.write(0xDB); // Set VCom Detect
lmayencou 1:c53e766082b4 88 _spi.write(0x40);
lmayencou 1:c53e766082b4 89 _spi.write(0xA4); // Entire Display ON
lmayencou 1:c53e766082b4 90 _spi.write(0xA6); // Set normal/inverse display
lmayencou 1:c53e766082b4 91 _spi.write(0xAF); // Display On
lmayencou 1:c53e766082b4 92
lmayencou 1:c53e766082b4 93 LCDCommandMode();
lmayencou 1:c53e766082b4 94 _spi.write(0x20); // set display mode
lmayencou 1:c53e766082b4 95 _spi.write(0x00); // horizontal addressing mode
lmayencou 1:c53e766082b4 96
lmayencou 1:c53e766082b4 97 _spi.write(0x21); // set col address
lmayencou 1:c53e766082b4 98 _spi.write(0x00);
lmayencou 1:c53e766082b4 99 _spi.write(COLUMN_ADDRESS_END);
lmayencou 1:c53e766082b4 100
lmayencou 1:c53e766082b4 101 _spi.write(0x22); // set page address
lmayencou 1:c53e766082b4 102 _spi.write(0x00);
lmayencou 1:c53e766082b4 103 _spi.write(PAGE_ADDRESS_END);
lmayencou 1:c53e766082b4 104
lmayencou 1:c53e766082b4 105 LCDDataMode();
lmayencou 1:c53e766082b4 106 }
lmayencou 1:c53e766082b4 107
lmayencou 1:c53e766082b4 108 // Stream implementation - provides printf() interface
lmayencou 1:c53e766082b4 109 // You would otherwise be forced to use writeChar()
lmayencou 1:c53e766082b4 110 virtual int _putc(int value) { return writeChar(value); };
lmayencou 1:c53e766082b4 111 virtual int _getc() { return -1; };
lmayencou 1:c53e766082b4 112
lmayencou 1:c53e766082b4 113 };