|
| 1 | +/*! |
| 2 | + @file main.cpp |
| 3 | + @author Gavin Lyons |
| 4 | + @brief Example cpp file for st7735 library. Tests Hello World |
| 5 | + @note See USER OPTIONS 0-3 in SETUP function |
| 6 | + @test |
| 7 | + -# Test103 write out Hello world on 128x160 display |
| 8 | +*/ |
| 9 | + |
| 10 | +// Section :: libraries |
| 11 | +#include "pico/time.h" |
| 12 | +#include "pico/stdlib.h" |
| 13 | +#include "hardware/spi.h" |
| 14 | +#include "displaylib_16/st7735.hpp" |
| 15 | + |
| 16 | + |
| 17 | +/// @cond |
| 18 | + |
| 19 | +#ifdef dislib16_ADVANCED_SCREEN_BUFFER_ENABLE |
| 20 | +#pragma message("gll: dislib16_ADVANCED_SCREEN_BUFFER_ENABLE is defined. This example is not for that mode") |
| 21 | +#endif |
| 22 | + |
| 23 | +// Section :: Globals |
| 24 | +ST7735_TFT myTFT; |
| 25 | + |
| 26 | +// Section :: Function Headers |
| 27 | +void Setup(void); // setup + user options |
| 28 | +void Test103(void); |
| 29 | +void EndTests(void); |
| 30 | + |
| 31 | +// Section :: MAIN loop |
| 32 | +int main(void) |
| 33 | +{ |
| 34 | + Setup(); |
| 35 | + Test103(); |
| 36 | + EndTests(); |
| 37 | +} |
| 38 | +// *** End OF MAIN ** |
| 39 | + |
| 40 | +// Section :: Function Space |
| 41 | + |
| 42 | +void Setup(void) |
| 43 | +{ |
| 44 | + stdio_init_all(); // optional for error messages , Initialize chosen serial port, default 38400 baud |
| 45 | + MILLISEC_DELAY(1000); |
| 46 | + printf("TFT Start\r\n"); |
| 47 | + |
| 48 | +//*************** USER OPTION 0 SPI_SPEED + TYPE *********** |
| 49 | + bool bhardwareSPI = true; // true for hardware spi, false for software |
| 50 | + |
| 51 | + if (bhardwareSPI == true) { // hw spi |
| 52 | + uint32_t TFT_SCLK_FREQ = 8000 ; // Spi freq in KiloHertz , 1000 = 1Mhz |
| 53 | + myTFT.TFTInitSPIType(TFT_SCLK_FREQ, spi0); |
| 54 | + } else { // sw spi |
| 55 | + uint16_t SWSPICommDelay = 0; // optional SW SPI GPIO delay in uS |
| 56 | + myTFT.TFTInitSPIType(SWSPICommDelay); |
| 57 | + } |
| 58 | +//********************************************************* |
| 59 | +// ******** USER OPTION 1 GPIO ********* |
| 60 | +// NOTE if using Hardware SPI clock and data pins will be tied to |
| 61 | +// the chosen interface eg Spi0 CLK=18 DIN=19) |
| 62 | + int8_t SDIN_TFT = 19; |
| 63 | + int8_t SCLK_TFT = 18; |
| 64 | + int8_t DC_TFT = 3; |
| 65 | + int8_t CS_TFT = 2 ; |
| 66 | + int8_t RST_TFT = 4; |
| 67 | + myTFT.setupGPIO(RST_TFT, DC_TFT, CS_TFT, SCLK_TFT, SDIN_TFT); |
| 68 | +//********************************************************** |
| 69 | + |
| 70 | +// ****** USER OPTION 2 Screen Setup ****** |
| 71 | + uint8_t OFFSET_COL = 0; // 2, These offsets can be adjusted for any issues-> |
| 72 | + uint8_t OFFSET_ROW = 0; // 3, with screen manufacture tolerance/defects |
| 73 | + uint16_t TFT_WIDTH = 128;// Screen width in pixels |
| 74 | + uint16_t TFT_HEIGHT = 160; // Screen height in pixels |
| 75 | + myTFT.TFTInitScreenSize(OFFSET_COL, OFFSET_ROW , TFT_WIDTH , TFT_HEIGHT); |
| 76 | +// ****************************************** |
| 77 | + |
| 78 | +// ******** USER OPTION 3 PCB_TYPE ************************** |
| 79 | + myTFT.TFTInitPCBType(myTFT.TFT_ST7735S_Black); // pass enum,multi choice,see README |
| 80 | +//********************************************************** |
| 81 | +} |
| 82 | + |
| 83 | +void Test103(void) { |
| 84 | + myTFT.setRotation(myTFT.Degrees_0); |
| 85 | + myTFT.fillScreen(myTFT.C_BLACK); |
| 86 | + myTFT.setTextColor(myTFT.C_RED, myTFT.C_BLACK); |
| 87 | + myTFT.setCursor(5,5); |
| 88 | + myTFT.setFont(font_default); |
| 89 | + myTFT.print("Hello World"); |
| 90 | + MILLISEC_DELAY(5000); |
| 91 | + myTFT.fillScreen(myTFT.C_BLACK); |
| 92 | + MILLISEC_DELAY(1000); |
| 93 | +} |
| 94 | + |
| 95 | +void EndTests(void) |
| 96 | +{ |
| 97 | + myTFT.TFTPowerDown(); |
| 98 | + printf("TFT: Tests Over"); |
| 99 | +} |
| 100 | + |
| 101 | + |
| 102 | +/// @endcond |
0 commit comments