Please run it on your NUCLEO-L152

Dependencies:   mbed

Committer:
davidprentice
Date:
Wed Sep 18 10:38:19 2019 +0000
Revision:
1:d88d2ad55fac
Parent:
0:b608c7f02f80
Added messages to Serial Terminal (9600 baud)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davidprentice 0:b608c7f02f80 1 #include "Arduino.h"
davidprentice 0:b608c7f02f80 2
davidprentice 0:b608c7f02f80 3 #include <MCUFRIEND_kbv.h>
davidprentice 0:b608c7f02f80 4 MCUFRIEND_kbv tft;
davidprentice 0:b608c7f02f80 5
davidprentice 1:d88d2ad55fac 6 Serial pc(SERIAL_TX, SERIAL_RX);
davidprentice 1:d88d2ad55fac 7
davidprentice 0:b608c7f02f80 8 // Assign human-readable names to some common 16-bit color values:
davidprentice 0:b608c7f02f80 9 #define BLACK 0x0000
davidprentice 0:b608c7f02f80 10 #define BLUE 0x001F
davidprentice 0:b608c7f02f80 11 #define RED 0xF800
davidprentice 0:b608c7f02f80 12 #define GREEN 0x07E0
davidprentice 0:b608c7f02f80 13 #define CYAN 0x07FF
davidprentice 0:b608c7f02f80 14 #define MAGENTA 0xF81F
davidprentice 0:b608c7f02f80 15 #define YELLOW 0xFFE0
davidprentice 0:b608c7f02f80 16 #define WHITE 0xFFFF
davidprentice 0:b608c7f02f80 17 #define GRAY 0x8410
davidprentice 0:b608c7f02f80 18
davidprentice 0:b608c7f02f80 19 uint16_t version = MCUFRIEND_KBV_H_;
davidprentice 0:b608c7f02f80 20
davidprentice 0:b608c7f02f80 21 void setup()
davidprentice 0:b608c7f02f80 22 {
davidprentice 0:b608c7f02f80 23 uint16_t ID = tft.readID(); //
davidprentice 1:d88d2ad55fac 24 pc.printf("\nI have run this on a NUCLEO-F072\n");
davidprentice 1:d88d2ad55fac 25 pc.printf("Please run it on your NUCLEO-L152\n");
davidprentice 1:d88d2ad55fac 26 pc.printf("Found ID = 0x%04X\n", ID);
davidprentice 0:b608c7f02f80 27 tft.begin(ID);
davidprentice 0:b608c7f02f80 28 }
davidprentice 0:b608c7f02f80 29
davidprentice 0:b608c7f02f80 30 void loop()
davidprentice 0:b608c7f02f80 31 {
davidprentice 0:b608c7f02f80 32 static uint8_t aspect = 0;
davidprentice 0:b608c7f02f80 33 const char *aspectname[] = {
davidprentice 0:b608c7f02f80 34 "PORTRAIT", "LANDSCAPE", "PORTRAIT_REV", "LANDSCAPE_REV"
davidprentice 0:b608c7f02f80 35 };
davidprentice 0:b608c7f02f80 36 const char *colorname[] = { "BLUE", "GREEN", "RED", "GRAY" };
davidprentice 0:b608c7f02f80 37 uint16_t colormask[] = { BLUE, GREEN, RED, GRAY };
davidprentice 0:b608c7f02f80 38 uint16_t ID = tft.readID(); //
davidprentice 0:b608c7f02f80 39 tft.setRotation(aspect);
davidprentice 0:b608c7f02f80 40 int width = tft.width();
davidprentice 0:b608c7f02f80 41 int height = tft.height();
davidprentice 0:b608c7f02f80 42 tft.fillScreen(colormask[aspect]);
davidprentice 0:b608c7f02f80 43 tft.drawRect(0, 0, width, height, WHITE);
davidprentice 0:b608c7f02f80 44 tft.drawRect(32, 32, width - 64, height - 64, WHITE);
davidprentice 0:b608c7f02f80 45 tft.setTextSize(2);
davidprentice 0:b608c7f02f80 46 tft.setTextColor(BLACK);
davidprentice 0:b608c7f02f80 47 tft.setCursor(40, 40);
davidprentice 0:b608c7f02f80 48 tft.print("ID=0x");
davidprentice 0:b608c7f02f80 49 tft.println(ID, HEX);
davidprentice 0:b608c7f02f80 50 if (ID == 0xD3D3) tft.print(" w/o");
davidprentice 0:b608c7f02f80 51 tft.setCursor(40, 70);
davidprentice 0:b608c7f02f80 52 tft.print(aspectname[aspect]);
davidprentice 0:b608c7f02f80 53 tft.setCursor(40, 100);
davidprentice 0:b608c7f02f80 54 tft.print(width);
davidprentice 0:b608c7f02f80 55 tft.print(" x ");
davidprentice 0:b608c7f02f80 56 tft.print(height);
davidprentice 0:b608c7f02f80 57 tft.setTextColor(WHITE);
davidprentice 0:b608c7f02f80 58 tft.setCursor(40, 130);
davidprentice 0:b608c7f02f80 59 tft.print(colorname[aspect]);
davidprentice 0:b608c7f02f80 60 tft.setCursor(40, 160);
davidprentice 0:b608c7f02f80 61 tft.setTextSize(1);
davidprentice 0:b608c7f02f80 62 tft.print("MCUFRIEND_KBV_H_ = ");
davidprentice 0:b608c7f02f80 63 tft.print(version);
davidprentice 0:b608c7f02f80 64 if (++aspect > 3) aspect = 0;
davidprentice 0:b608c7f02f80 65 delay(5000);
davidprentice 0:b608c7f02f80 66 }
davidprentice 0:b608c7f02f80 67
davidprentice 0:b608c7f02f80 68 uint32_t millis(void)
davidprentice 0:b608c7f02f80 69 {
davidprentice 0:b608c7f02f80 70 static Timer t;
davidprentice 0:b608c7f02f80 71 static int first = 1;
davidprentice 0:b608c7f02f80 72 if (first) first = 0, t.start();
davidprentice 0:b608c7f02f80 73 return t.read_ms();
davidprentice 0:b608c7f02f80 74 }
davidprentice 0:b608c7f02f80 75
davidprentice 0:b608c7f02f80 76 uint32_t micros(void)
davidprentice 0:b608c7f02f80 77 {
davidprentice 0:b608c7f02f80 78 static Timer t;
davidprentice 0:b608c7f02f80 79 static int first = 1;
davidprentice 0:b608c7f02f80 80 if (first) first = 0, t.start();
davidprentice 0:b608c7f02f80 81 return t.read_us();
davidprentice 0:b608c7f02f80 82 }
davidprentice 0:b608c7f02f80 83
davidprentice 0:b608c7f02f80 84 void main(void)
davidprentice 0:b608c7f02f80 85 {
davidprentice 0:b608c7f02f80 86 setup();
davidprentice 0:b608c7f02f80 87 while (1) {
davidprentice 0:b608c7f02f80 88 loop();
davidprentice 0:b608c7f02f80 89 }
davidprentice 0:b608c7f02f80 90 }