112 lines
3.7 KiB
Arduino
112 lines
3.7 KiB
Arduino
// Teensy 4.1 + 4.0" ST7796S 480x320 TFT bring-up sketch.
|
|
//
|
|
// Phase 1 of plans/teensy41_signer_port.md. Fills the screen with a few color
|
|
// blocks and draws text, to verify the display wiring before porting the CYD
|
|
// display driver.
|
|
//
|
|
// Pin assignment (from firmware/teensy41/WIRING.md):
|
|
// cs = Teensy pin 5 (software CS)
|
|
// reset = Teensy pin 6
|
|
// dc/rs = Teensy pin 7
|
|
// led = Teensy pin 8 (backlight)
|
|
// sdi (mosi) = Teensy pin 11 (SPI0 MOSI)
|
|
// sdo (miso) = Teensy pin 12 (SPI0 MISO)
|
|
// sck = Teensy pin 13 (SPI0 SCK)
|
|
// vcc = 3V3, gnd = GND
|
|
//
|
|
// Build / upload:
|
|
// arduino-cli compile --fqbn teensy:avr:teensy41 firmware/teensy41/tft_test
|
|
// arduino-cli upload -p /dev/ttyACM0 --fqbn teensy:avr:teensy41 firmware/teensy41/tft_test
|
|
//
|
|
// Exit criterion: screen fills with color blocks and shows readable text.
|
|
|
|
#include <ST7796_t3.h>
|
|
#include <SPI.h>
|
|
|
|
// Pin map — must match firmware/teensy41/WIRING.md
|
|
#define TFT_CS 5
|
|
#define TFT_RST 6
|
|
#define TFT_DC 7 // dc/rs on the display silkscreen
|
|
#define TFT_BL 8 // led (backlight)
|
|
|
|
// ST7796_t3 hardware-SPI constructor: (CS, RS/DC, RST)
|
|
// MOSI/MISO/SCK come from SPI0 (Teensy pins 11/12/13).
|
|
ST7796_t3 tft = ST7796_t3(TFT_CS, TFT_DC, TFT_RST);
|
|
|
|
// 16-bit RGB565 colors
|
|
#define C_BLACK 0x0000
|
|
#define C_WHITE 0xFFFF
|
|
#define C_RED 0xF800
|
|
#define C_GREEN 0x07E0
|
|
#define C_BLUE 0x001F
|
|
#define C_YELLOW 0xFFE0
|
|
#define C_CYAN 0x07FF
|
|
#define C_MAGENTA 0xF81F
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
while (!Serial && millis() < 4000) ;
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
|
|
// Backlight on, full brightness
|
|
pinMode(TFT_BL, OUTPUT);
|
|
digitalWrite(TFT_BL, HIGH);
|
|
|
|
Serial.println("ST7796S TFT bring-up: init...");
|
|
// init() with the *rotated* dimensions (320x480 portrait) so the library
|
|
// takes its zero-offset branch. Calling init(480,320) then setRotation(1)
|
|
// computes a negative colstart and the image is offset off the panel.
|
|
tft.init(320, 480); // portrait 320x480
|
|
tft.setRotation(1); // 1 = portrait, rotated 90° CW from native landscape
|
|
Serial.print("width="); Serial.print(tft.width());
|
|
Serial.print(" height="); Serial.println(tft.height());
|
|
|
|
// 1) Full black fill (clears any garbage)
|
|
tft.fillScreen(C_BLACK);
|
|
|
|
// 2) Four quadrant color blocks so we can see the whole panel lights up
|
|
int w = tft.width();
|
|
int h = tft.height();
|
|
tft.fillRect(0, 0, w / 2, h / 2, C_RED);
|
|
tft.fillRect(w / 2, 0, w / 2, h / 2, C_GREEN);
|
|
tft.fillRect(0, h / 2, w / 2, h / 2, C_BLUE);
|
|
tft.fillRect(w / 2, h / 2, w / 2, h / 2, C_YELLOW);
|
|
delay(1500);
|
|
|
|
// 3) White background + text
|
|
tft.fillScreen(C_WHITE);
|
|
tft.setTextColor(C_BLACK, C_WHITE);
|
|
tft.setTextSize(3);
|
|
tft.setCursor(10, 10);
|
|
tft.print("Teensy 4.1");
|
|
tft.setCursor(10, 50);
|
|
tft.print("ST7796S 320x480 portrait");
|
|
tft.setCursor(10, 90);
|
|
tft.print("TFT bring-up OK");
|
|
|
|
tft.setTextSize(2);
|
|
tft.setCursor(10, 140);
|
|
tft.setTextColor(C_BLUE, C_WHITE);
|
|
tft.print("n_signer hardware signer");
|
|
tft.setCursor(10, 170);
|
|
tft.print("display + touch port");
|
|
|
|
// 4) A few color swatches along the bottom so we can judge color rendering
|
|
int sw = w / 6;
|
|
int sy = h - 40;
|
|
tft.fillRect(sw * 0, sy, sw, 30, C_RED);
|
|
tft.fillRect(sw * 1, sy, sw, 30, C_GREEN);
|
|
tft.fillRect(sw * 2, sy, sw, 30, C_BLUE);
|
|
tft.fillRect(sw * 3, sy, sw, 30, C_YELLOW);
|
|
tft.fillRect(sw * 4, sy, sw, 30, C_CYAN);
|
|
tft.fillRect(sw * 5, sy, sw, 30, C_MAGENTA);
|
|
|
|
Serial.println("ST7796S TFT bring-up: done. Screen should show text + color swatches.");
|
|
}
|
|
|
|
void loop() {
|
|
// slow steady blink = idle, display is static
|
|
digitalWrite(LED_BUILTIN, HIGH); delay(1000);
|
|
digitalWrite(LED_BUILTIN, LOW); delay(1000);
|
|
}
|