lcd ili9341

This commit is contained in:
2021-08-17 13:19:31 +02:00
parent a217c5cd93
commit babb031649
9 changed files with 186 additions and 32 deletions

3
reflow_plate_fw/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"C_Cpp.errorSquiggles": "Disabled"
}

View File

@@ -0,0 +1,101 @@
///////////////////////////////////////////////////
// Setup for STM32 Nucleo and ILI9341 display //
///////////////////////////////////////////////////
// Last update by Bodmer: 28/11/19
// STM32 optimised functions are not yet compatible with STM32H743 processor.
// The STM32H743 does work with the slower generic processor drivers
//
// REMINDER - Nucleo-F743ZI and Nucleo-F743ZI2 have different pin port allocations
// and require appropriate selection in IDE. ^---- Note the extra 2 in part number!
// Define STM32 to invoke STM32 optimised driver
#define STM32
// Define the TFT display driver
#define ILI9341_DRIVER
//#define ILI9481_DRIVER
// MOSI and SCK do not need to be defined, connect:
// - Arduino SCK to TFT SCK
// - Arduino MOSI to TFT SDI(may be marked SDA or MOSI)
// Typical Arduino SPI port 1 pins are (SCK=D13, MISO=D12, MOSI=D11) this is port pins PA5, PA6 and PA7 on Nucleo-F767ZI
// SPI port 2 pins are (SCK=D18, MISO=A7, MOSI=D17) this is port pins PB13, PC2 and PB15 on Nucleo-F767ZI
//#define TFT_MOSI PA7
//#define TFT_SCLK PA5
#define TFT_DC PB1
#define TFT_RST PA12
#define TFT_CS PB0
#define TFT_SPI_PORT 1 // SPI 1 maximum clock rate is 55MHz
#define TFT_MOSI PA7
#define TFT_MISO PA6
#define TFT_SCLK PA5
/*
#define TFT_SPI_PORT 2 // SPI 2 maximum clock rate is 27MHz
#define TFT_MOSI D17
#define TFT_MISO A7
#define TFT_SCLK D18
//*/
/*
#define TFT_SPI_PORT 2 // SPI 2 maximum clock rate is 27MHz
#define TFT_MOSI PB15
#define TFT_MISO PC2
#define TFT_SCLK PB13
//*/
/*
#define TFT_SPI_PORT 2 // SPI 2 maximum clock rate is 27MHz
#define TFT_MOSI PB15
#define TFT_MISO PB14
#define TFT_SCLK PB13
//*/
// Can use Ardiuno pin references, arbitrary allocation, TFT_eSPI controls chip select
// #define TFT_CS D5 // Chip select control pin to TFT CS
// #define TFT_DC D6 // Data Command control pin to TFT DC (may be labelled RS = Register Select)
// #define TFT_RST D7 // Reset pin to TFT RST (or RESET)
// Alternatively, we can use STM32 port reference names PXnn
//#define TFT_CS PE11 // Nucleo-F767ZI equivalent of D5
//#define TFT_DC PE9 // Nucleo-F767ZI equivalent of D6
//#define TFT_RST PF13 // Nucleo-F767ZI equivalent of D7
//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to processor reset
// Use an Arduino pin for initial testing as connecting to processor reset
// may not work (pulse too short at power up?)
// Chip select for XPT2046 touch controller
#define TOUCH_CS PB2
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
// STM32 support for smooth fonts via program memory (FLASH) arrays
#define SMOOTH_FONT
// Nucleo-F767ZI has a ~216MHZ CPU clock, this is divided by 4, 8, 16 etc
#define SPI_FREQUENCY 27000000 // 27MHz SPI clock
//#define SPI_FREQUENCY 55000000 // 55MHz is over-clocking ILI9341 but seems to work reliably!
#define SPI_READ_FREQUENCY 15000000 // Reads need a slower SPI clock, probably ends up at 13.75MHz (CPU clock/16)
#define SPI_TOUCH_FREQUENCY 2500000 // Must be very slow
// This has no effect, transactions for STM32 are automatically enabled
#define SUPPORT_TRANSACTIONS

View File

@@ -19,4 +19,8 @@ lib_deps =
bodmer/TFT_eSPI@^2.3.70
lib_ldf_mode = deep+
build_flags =
-D USER_SETUP_LOADED=1
-include include/ILI9341_STM32.h
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D PIO_FRAMEWORK_ARDUINO_USB_FULLSPEED_FULLMODE

View File

@@ -1,11 +1,11 @@
#pragma once
#define LCD_MOSI PA7
#define LCD_SCLK PA5
#define LCD_RES PA12
#define LCD_DC PB1
#define LCD_CS PB0
// #define LCD_MOSI PA7
// #define LCD_SCLK PA5
// #define LCD_RES PA12
// #define LCD_DC PB1
// #define LCD_CS PB0
#define THERM_CS PB4
#define THERM_SO PB5

View File

@@ -1,33 +1,29 @@
#include "lcd.h"
// void initLCD(void)
// {
// }
// void handleLCD(void)
// {
// }
unsigned int rainbow(byte value);
#include <TFT_eSPI.h> // Include the graphics library
TFT_eSPI tft = TFT_eSPI(); // Create object "tft"
TFT_eSprite touch_spr = TFT_eSprite(&tft);
#define WIDTH 240
#define HEIGHT 60
// -------------------------------------------------------------------------
// Setup
// -------------------------------------------------------------------------
void prep_sprite(void)
{
touch_spr.createSprite(WIDTH,HEIGHT);
}
void initLCD(void) {
tft.init();
tft.setRotation(0);
tft.setTextFont(1);
tft.setRotation(2);
tft.setTextFont(2);
tft.fillScreen(TFT_BLACK);
tft.invertDisplay(false);
prep_sprite();
}
// -------------------------------------------------------------------------
@@ -35,7 +31,16 @@ void initLCD(void) {
// -------------------------------------------------------------------------
void handleLCD()
{
//tft.setTextColor(TFT_WHITE);
//tft.setTextPadding(60);
tft.drawString("hello World!", 10, 10);
touch_spr.fillSprite(TFT_BLACK);
uint16_t t_x = 0, t_y = 0;
touch_spr.setTextColor(TFT_WHITE);
touch_spr.setTextDatum(MC_DATUM);
bool pressed = tft.getTouch(&t_x, &t_y);
String touchxy = "touch x=";
touchxy += t_x;
touchxy += ",touch y=";
touchxy += t_y;
touch_spr.drawString(touchxy, WIDTH / 2, HEIGHT / 4, 2);
touch_spr.drawNumber(getLooptime(), WIDTH / 2, (HEIGHT / 4)*2, 2);
touch_spr.pushSprite(1,1);
}

View File

@@ -1,6 +1,8 @@
#include "Arduino.h"
#include "board.h"
#include "status.h"
void initLCD(void);

View File

@@ -5,6 +5,7 @@
#include "thermo.h"
#include "button.h"
#include "heater.h"
#include "status.h"
void setup()
{
@@ -13,10 +14,11 @@ void setup()
initThermo();
initButton();
initHeater();
pinMode(LED_BUILTIN, OUTPUT);
initStatus();
}
void loop()
{
// put your main code here, to run repeatedly:
@@ -24,9 +26,5 @@ void loop()
handleThermo();
handleButton();
handleHeater();
digitalWrite(LED_BUILTIN, 1);
delay(500);
digitalWrite(LED_BUILTIN, 0);
delay(500);
handleStatus();
}

View File

@@ -0,0 +1,32 @@
#include "status.h"
uint64_t timelast = 0;
uint64_t blinkrate = 500;
bool ledstate = false;
uint32_t looptime = 0;
uint32_t looptimelast = 0;
void initStatus(void)
{
pinMode(LED_BUILTIN, OUTPUT);
}
void handleStatus(void)
{
uint64_t timenow = millis();
if(timenow - timelast > blinkrate)
{
timelast = timenow;
ledstate = !ledstate;
digitalWrite(LED_BUILTIN, ledstate);
}
looptime = timenow - looptimelast;
looptimelast = timenow;
}
uint32_t getLooptime(void)
{
return looptime;
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "Arduino.h"
#include "board.h"
void initStatus(void);
void handleStatus(void);
uint32_t getLooptime(void);