From d0d932bd0c34f11d8404b31d585453e5fb03c0dd Mon Sep 17 00:00:00 2001 From: nerc0s Date: Thu, 22 Aug 2024 12:16:52 +0200 Subject: [PATCH] FIRST COMMIT --- .gitignore | 1 + .idea/.gitignore | 8 + .idea/editor.xml | 585 ++++++++++++++++++++++ .idea/misc.xml | 20 + include/README | 39 ++ lib/Adafruit_GC9A01A/Adafruit_GC9A01A.cpp | 280 +++++++++++ lib/Adafruit_GC9A01A/Adafruit_GC9A01A.h | 121 +++++ lib/Adafruit_GC9A01A/README.md | 18 + lib/Adafruit_GC9A01A/library.properties | 10 + lib/README | 46 ++ platformio.ini | 17 + src/main.cpp | 104 ++++ test/README | 11 + 13 files changed, 1260 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/editor.xml create mode 100644 .idea/misc.xml create mode 100644 include/README create mode 100644 lib/Adafruit_GC9A01A/Adafruit_GC9A01A.cpp create mode 100644 lib/Adafruit_GC9A01A/Adafruit_GC9A01A.h create mode 100644 lib/Adafruit_GC9A01A/README.md create mode 100644 lib/Adafruit_GC9A01A/library.properties create mode 100644 lib/README create mode 100644 platformio.ini create mode 100644 src/main.cpp create mode 100644 test/README diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..6bcce32 --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,585 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..218beea --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,20 @@ + + + + + + + + + + \ No newline at end of file diff --git a/include/README b/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/Adafruit_GC9A01A/Adafruit_GC9A01A.cpp b/lib/Adafruit_GC9A01A/Adafruit_GC9A01A.cpp new file mode 100644 index 0000000..8da36f1 --- /dev/null +++ b/lib/Adafruit_GC9A01A/Adafruit_GC9A01A.cpp @@ -0,0 +1,280 @@ +/*! + * @file Adafruit_GC9A01A.cpp + * + * @mainpage GC9A01A TFT Display library for Adafruit_GFX + * + * @section intro_sec Introduction + * + * Library to provide GC9A01A display driver support in Adafruit_GFX. + * + * These displays use SPI to communicate, 4 or 5 pins are required + * to interface (RST is optional). + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * @section dependencies Dependencies + * + * This library depends on + * Adafruit_GFX being present on your system. Please make sure you have + * installed the latest version before using this library. + * + * @section author Author + * + * Written by Limor "ladyada" Fried for Adafruit Industries. + * GC9A01A adaptation by Phil "PaintYourDragon" Burgess. + * + * @section license License + * + * BSD license, all text here must be included in any redistribution. + * + */ + +#include "Adafruit_GC9A01A.h" +#ifndef ARDUINO_STM32_FEATHER +#include "pins_arduino.h" +#ifndef RASPI +#include "wiring_private.h" +#endif +#endif +#include + +#if defined(ARDUINO_ARCH_ARC32) || defined(ARDUINO_MAXIM) +#define SPI_DEFAULT_FREQ 16000000 +// Teensy 3.0, 3.1/3.2, 3.5, 3.6 +#elif defined(__MK20DX128__) || defined(__MK20DX256__) || \ + defined(__MK64FX512__) || defined(__MK66FX1M0__) +#define SPI_DEFAULT_FREQ 40000000 +#elif defined(__AVR__) || defined(TEENSYDUINO) +#define SPI_DEFAULT_FREQ 8000000 +#elif defined(ESP8266) || defined(ESP32) +#define SPI_DEFAULT_FREQ 40000000 +#elif defined(RASPI) +#define SPI_DEFAULT_FREQ 80000000 +#elif defined(ARDUINO_ARCH_STM32F1) +#define SPI_DEFAULT_FREQ 36000000 +#else +#define SPI_DEFAULT_FREQ 24000000 ///< Default SPI data clock frequency +#endif + +#define MADCTL_MY 0x80 ///< Bottom to top +#define MADCTL_MX 0x40 ///< Right to left +#define MADCTL_MV 0x20 ///< Reverse Mode +#define MADCTL_ML 0x10 ///< LCD refresh Bottom to top +#define MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order +#define MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order +#define MADCTL_MH 0x04 ///< LCD refresh right to left + +/*! + @brief Instantiate Adafruit GC9A01A driver with software SPI + @param cs Chip select pin # + @param dc Data/Command pin # + @param mosi SPI MOSI pin # + @param sclk SPI Clock pin # + @param rst Reset pin # (optional, pass -1 if unused) + @param miso SPI MISO pin # (optional, pass -1 if unused) +*/ +Adafruit_GC9A01A::Adafruit_GC9A01A(int8_t cs, int8_t dc, int8_t mosi, + int8_t sclk, int8_t rst, int8_t miso) + : Adafruit_SPITFT(GC9A01A_TFTWIDTH, GC9A01A_TFTHEIGHT, cs, dc, mosi, sclk, + rst, miso) {} + +/*! + @brief Instantiate Adafruit GC9A01A driver with hardware SPI using the + default SPI peripheral. + @param cs Chip select pin # (OK to pass -1 if CS tied to GND). + @param dc Data/Command pin # (required). + @param rst Reset pin # (optional, pass -1 if unused). +*/ +Adafruit_GC9A01A::Adafruit_GC9A01A(int8_t cs, int8_t dc, int8_t rst) + : Adafruit_SPITFT(GC9A01A_TFTWIDTH, GC9A01A_TFTHEIGHT, cs, dc, rst) {} + +#if !defined(ESP8266) +/*! + @brief Instantiate Adafruit GC9A01A driver with hardware SPI using + a specific SPI peripheral (not necessarily default). + @param spiClass Pointer to SPI peripheral (e.g. &SPI or &SPI1). + @param dc Data/Command pin # (required). + @param cs Chip select pin # (optional, pass -1 if unused and + CS is tied to GND). + @param rst Reset pin # (optional, pass -1 if unused). +*/ +Adafruit_GC9A01A::Adafruit_GC9A01A(SPIClass *spiClass, int8_t dc, int8_t cs, + int8_t rst) + : Adafruit_SPITFT(GC9A01A_TFTWIDTH, GC9A01A_TFTHEIGHT, spiClass, cs, dc, + rst) {} +#endif // end !ESP8266 + +/*! + @brief Instantiate Adafruit GC9A01A driver using parallel interface. + @param busWidth If tft16 (enumeration in Adafruit_SPITFT.h), is a + 16-bit interface, else 8-bit. + @param d0 Data pin 0 (MUST be a byte- or word-aligned LSB of a + PORT register -- pins 1-n are extrapolated from this). + @param wr Write strobe pin # (required). + @param dc Data/Command pin # (required). + @param cs Chip select pin # (optional, pass -1 if unused and CS + is tied to GND). + @param rst Reset pin # (optional, pass -1 if unused). + @param rd Read strobe pin # (optional, pass -1 if unused). +*/ +Adafruit_GC9A01A::Adafruit_GC9A01A(tftBusWidth busWidth, int8_t d0, int8_t wr, + int8_t dc, int8_t cs, int8_t rst, int8_t rd) + : Adafruit_SPITFT(GC9A01A_TFTWIDTH, GC9A01A_TFTHEIGHT, busWidth, d0, wr, dc, + cs, rst, rd) {} + +// clang-format off +// Initialization sequence came from some early code provided by the +// manufacturer. Many of these registers are undocumented, some might +// be unnecessary, just playing along... +static const uint8_t PROGMEM initcmd[] = { + GC9A01A_INREGEN2, 0, + 0xEB, 1, 0x14, // ? + GC9A01A_INREGEN1, 0, + GC9A01A_INREGEN2, 0, + 0xEB, 1, 0x14, // ? + 0x84, 1, 0x40, // ? + 0x85, 1, 0xFF, // ? + 0x86, 1, 0xFF, // ? + 0x87, 1, 0xFF, // ? + 0x88, 1, 0x0A, // ? + 0x89, 1, 0x21, // ? + 0x8A, 1, 0x00, // ? + 0x8B, 1, 0x80, // ? + 0x8C, 1, 0x01, // ? + 0x8D, 1, 0x01, // ? + 0x8E, 1, 0xFF, // ? + 0x8F, 1, 0xFF, // ? + 0xB6, 2, 0x00, 0x00, // ? + GC9A01A_MADCTL, 1, MADCTL_MX | MADCTL_BGR, + GC9A01A_COLMOD, 1, 0x05, + 0x90, 4, 0x08, 0x08, 0x08, 0x08, // ? + 0xBD, 1, 0x06, // ? + 0xBC, 1, 0x00, // ? + 0xFF, 3, 0x60, 0x01, 0x04, // ? + GC9A01A1_POWER2, 1, 0x13, + GC9A01A1_POWER3, 1, 0x13, + GC9A01A1_POWER4, 1, 0x22, + 0xBE, 1, 0x11, // ? + 0xE1, 2, 0x10, 0x0E, // ? + 0xDF, 3, 0x21, 0x0c, 0x02, // ? + GC9A01A_GAMMA1, 6, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2A, + GC9A01A_GAMMA2, 6, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6F, + GC9A01A_GAMMA3, 6, 0x45, 0x09, 0x08, 0x08, 0x26, 0x2A, + GC9A01A_GAMMA4, 6, 0x43, 0x70, 0x72, 0x36, 0x37, 0x6F, + 0xED, 2, 0x1B, 0x0B, // ? + 0xAE, 1, 0x77, // ? + 0xCD, 1, 0x63, // ? + // Unsure what this line (from manufacturer's boilerplate code) is + // meant to do, but users reported issues, seems to work OK without: + //0x70, 9, 0x07, 0x07, 0x04, 0x0E, 0x0F, 0x09, 0x07, 0x08, 0x03, // ? + GC9A01A_FRAMERATE, 1, 0x34, + 0x62, 12, 0x18, 0x0D, 0x71, 0xED, 0x70, 0x70, // ? + 0x18, 0x0F, 0x71, 0xEF, 0x70, 0x70, + 0x63, 12, 0x18, 0x11, 0x71, 0xF1, 0x70, 0x70, // ? + 0x18, 0x13, 0x71, 0xF3, 0x70, 0x70, + 0x64, 7, 0x28, 0x29, 0xF1, 0x01, 0xF1, 0x00, 0x07, // ? + 0x66, 10, 0x3C, 0x00, 0xCD, 0x67, 0x45, 0x45, 0x10, 0x00, 0x00, 0x00, // ? + 0x67, 10, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, 0x54, 0x10, 0x32, 0x98, // ? + 0x74, 7, 0x10, 0x85, 0x80, 0x00, 0x00, 0x4E, 0x00, // ? + 0x98, 2, 0x3e, 0x07, // ? + GC9A01A_TEON, 0, + GC9A01A_INVON, 0, + GC9A01A_SLPOUT, 0x80, // Exit sleep + GC9A01A_DISPON, 0x80, // Display on + 0x00 // End of list +}; +// clang-format on + +/*! + @brief Initialize GC9A01A chip. Connects to the GC9A01A over SPI + and sends initialization commands. + @param freq Desired SPI clock frequency +*/ +void Adafruit_GC9A01A::begin(uint32_t freq) { + + if (!freq) + freq = SPI_DEFAULT_FREQ; + initSPI(freq); + + if (_rst < 0) { // If no hardware reset pin... + sendCommand(GC9A01A_SWRESET); // Engage software reset + delay(150); + } + + uint8_t cmd, x, numArgs; + const uint8_t *addr = initcmd; + while ((cmd = pgm_read_byte(addr++)) > 0) { + x = pgm_read_byte(addr++); + numArgs = x & 0x7F; + sendCommand(cmd, addr, numArgs); + addr += numArgs; + if (x & 0x80) + delay(150); + } + + _width = GC9A01A_TFTWIDTH; + _height = GC9A01A_TFTHEIGHT; +} + +/*! + @brief Set origin of (0,0) and orientation of TFT display + @param m The index for rotation, from 0-3 inclusive +*/ +void Adafruit_GC9A01A::setRotation(uint8_t m) { + rotation = m % 4; // can't be higher than 3 + switch (rotation) { + case 0: + m = (MADCTL_MX | MADCTL_BGR); + _width = GC9A01A_TFTWIDTH; + _height = GC9A01A_TFTHEIGHT; + break; + case 1: + m = (MADCTL_MV | MADCTL_BGR); + _width = GC9A01A_TFTHEIGHT; + _height = GC9A01A_TFTWIDTH; + break; + case 2: + m = (MADCTL_MY | MADCTL_BGR); + _width = GC9A01A_TFTWIDTH; + _height = GC9A01A_TFTHEIGHT; + break; + case 3: + m = (MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR); + _width = GC9A01A_TFTHEIGHT; + _height = GC9A01A_TFTWIDTH; + break; + } + + sendCommand(GC9A01A_MADCTL, &m, 1); +} + +/*! + @brief Enable/Disable display color inversion + @param invert True to invert, False to have normal color +*/ +void Adafruit_GC9A01A::invertDisplay(bool invert) { + sendCommand(invert ? GC9A01A_INVON : GC9A01A_INVOFF); +} + +/*! + @brief Set the "address window" - the rectangle we will write to RAM + with the next chunk of SPI data. The GC9A01A will automatically + wrap the data as each row is filled. + @param x1 TFT memory 'x' origin + @param y1 TFT memory 'y' origin + @param w Width of rectangle + @param h Height of rectangle +*/ +void Adafruit_GC9A01A::setAddrWindow(uint16_t x1, uint16_t y1, uint16_t w, + uint16_t h) { + uint16_t x2 = (x1 + w - 1), y2 = (y1 + h - 1); + writeCommand(GC9A01A_CASET); // Column address set + SPI_WRITE16(x1); + SPI_WRITE16(x2); + writeCommand(GC9A01A_RASET); // Row address set + SPI_WRITE16(y1); + SPI_WRITE16(y2); + writeCommand(GC9A01A_RAMWR); // Write to RAM +} diff --git a/lib/Adafruit_GC9A01A/Adafruit_GC9A01A.h b/lib/Adafruit_GC9A01A/Adafruit_GC9A01A.h new file mode 100644 index 0000000..e235d2f --- /dev/null +++ b/lib/Adafruit_GC9A01A/Adafruit_GC9A01A.h @@ -0,0 +1,121 @@ +/*! + * @file Adafruit_GC9A01A.h + * + * Library to provide GC9A01A display driver support in Adafruit_GFX. + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * This library depends on + * Adafruit_GFX being present on your system. Please make sure you have + * installed the latest version before using this library. + * + * Written by Limor "ladyada" Fried for Adafruit Industries. + * GC9A01A adaptation by Phil "PaintYourDragon" Burgess. + * + * BSD license, all text here must be included in any redistribution. + * + */ + +#pragma once + +#include "Adafruit_GFX.h" +#include "Arduino.h" +#include "Print.h" +#include +#include +#include + +#define GC9A01A_TFTWIDTH 240 ///< Display width in pixels +#define GC9A01A_TFTHEIGHT 240 ///< Display height in pixels + +#define GC9A01A_SWRESET 0x01 ///< Software Reset (maybe, not documented) +#define GC9A01A_RDDID 0x04 ///< Read display identification information +#define GC9A01A_RDDST 0x09 ///< Read Display Status +#define GC9A01A_SLPIN 0x10 ///< Enter Sleep Mode +#define GC9A01A_SLPOUT 0x11 ///< Sleep Out +#define GC9A01A_PTLON 0x12 ///< Partial Mode ON +#define GC9A01A_NORON 0x13 ///< Normal Display Mode ON +#define GC9A01A_INVOFF 0x20 ///< Display Inversion OFF +#define GC9A01A_INVON 0x21 ///< Display Inversion ON +#define GC9A01A_DISPOFF 0x28 ///< Display OFF +#define GC9A01A_DISPON 0x29 ///< Display ON +#define GC9A01A_CASET 0x2A ///< Column Address Set +#define GC9A01A_RASET 0x2B ///< Row Address Set +#define GC9A01A_RAMWR 0x2C ///< Memory Write +#define GC9A01A_PTLAR 0x30 ///< Partial Area +#define GC9A01A_VSCRDEF 0x33 ///< Vertical Scrolling Definition +#define GC9A01A_TEOFF 0x34 ///< Tearing Effect Line OFF +#define GC9A01A_TEON 0x35 ///< Tearing Effect Line ON +#define GC9A01A_MADCTL 0x36 ///< Memory Access Control +#define GC9A01A_VSCRSADD 0x37 ///< Vertical Scrolling Start Address +#define GC9A01A_IDLEOFF 0x38 ///< Idle mode OFF +#define GC9A01A_IDLEON 0x39 ///< Idle mode ON +#define GC9A01A_COLMOD 0x3A ///< Pixel Format Set +#define GC9A01A_CONTINUE 0x3C ///< Write Memory Continue +#define GC9A01A_TEARSET 0x44 ///< Set Tear Scanline +#define GC9A01A_GETLINE 0x45 ///< Get Scanline +#define GC9A01A_SETBRIGHT 0x51 ///< Write Display Brightness +#define GC9A01A_SETCTRL 0x53 ///< Write CTRL Display +#define GC9A01A1_POWER7 0xA7 ///< Power Control 7 +#define GC9A01A_TEWC 0xBA ///< Tearing effect width control +#define GC9A01A1_POWER1 0xC1 ///< Power Control 1 +#define GC9A01A1_POWER2 0xC3 ///< Power Control 2 +#define GC9A01A1_POWER3 0xC4 ///< Power Control 3 +#define GC9A01A1_POWER4 0xC9 ///< Power Control 4 +#define GC9A01A_RDID1 0xDA ///< Read ID 1 +#define GC9A01A_RDID2 0xDB ///< Read ID 2 +#define GC9A01A_RDID3 0xDC ///< Read ID 3 +#define GC9A01A_FRAMERATE 0xE8 ///< Frame rate control +#define GC9A01A_SPI2DATA 0xE9 ///< SPI 2DATA control +#define GC9A01A_INREGEN2 0xEF ///< Inter register enable 2 +#define GC9A01A_GAMMA1 0xF0 ///< Set gamma 1 +#define GC9A01A_GAMMA2 0xF1 ///< Set gamma 2 +#define GC9A01A_GAMMA3 0xF2 ///< Set gamma 3 +#define GC9A01A_GAMMA4 0xF3 ///< Set gamma 4 +#define GC9A01A_IFACE 0xF6 ///< Interface control +#define GC9A01A_INREGEN1 0xFE ///< Inter register enable 1 + +// Color definitions +#define GC9A01A_BLACK 0x0000 ///< 0, 0, 0 +#define GC9A01A_NAVY 0x000F ///< 0, 0, 123 +#define GC9A01A_DARKGREEN 0x03E0 ///< 0, 125, 0 +#define GC9A01A_DARKCYAN 0x03EF ///< 0, 125, 123 +#define GC9A01A_MAROON 0x7800 ///< 123, 0, 0 +#define GC9A01A_PURPLE 0x780F ///< 123, 0, 123 +#define GC9A01A_OLIVE 0x7BE0 ///< 123, 125, 0 +#define GC9A01A_LIGHTGREY 0xC618 ///< 198, 195, 198 +#define GC9A01A_DARKGREY 0x7BEF ///< 123, 125, 123 +#define GC9A01A_BLUE 0x001F ///< 0, 0, 255 +#define GC9A01A_GREEN 0x07E0 ///< 0, 255, 0 +#define GC9A01A_CYAN 0x07FF ///< 0, 255, 255 +#define GC9A01A_RED 0xF800 ///< 255, 0, 0 +#define GC9A01A_MAGENTA 0xF81F ///< 255, 0, 255 +#define GC9A01A_YELLOW 0xFFE0 ///< 255, 255, 0 +#define GC9A01A_WHITE 0xFFFF ///< 255, 255, 255 +#define GC9A01A_ORANGE 0xFD20 ///< 255, 165, 0 +#define GC9A01A_GREENYELLOW 0xAFE5 ///< 173, 255, 41 +#define GC9A01A_PINK 0xFC18 ///< 255, 130, 198 + +/*! +@brief Class to manage hardware interface with GC9A01A chipset. +*/ +class Adafruit_GC9A01A : public Adafruit_SPITFT { +public: + Adafruit_GC9A01A(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, + int8_t _RST = -1, int8_t _MISO = -1); + Adafruit_GC9A01A(int8_t _CS, int8_t _DC, int8_t _RST = -1); +#if !defined(ESP8266) + Adafruit_GC9A01A(SPIClass *spiClass, int8_t dc, int8_t cs = -1, + int8_t rst = -1); +#endif // end !ESP8266 + Adafruit_GC9A01A(tftBusWidth busWidth, int8_t d0, int8_t wr, int8_t dc, + int8_t cs = -1, int8_t rst = -1, int8_t rd = -1); + + void begin(uint32_t freq = 0); + void setRotation(uint8_t r); + void invertDisplay(bool i); + + void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h); +}; diff --git a/lib/Adafruit_GC9A01A/README.md b/lib/Adafruit_GC9A01A/README.md new file mode 100644 index 0000000..50e8895 --- /dev/null +++ b/lib/Adafruit_GC9A01A/README.md @@ -0,0 +1,18 @@ +# GC9A01A Arduino Library + +Library to provide GC9A01A display driver support in Adafruit_GFX. + +Adafruit invests time and resources providing this open source code, +please support Adafruit and open-source hardware by purchasing +products from Adafruit! + +Written by Limor Fried/Ladyada for Adafruit Industries. +GC9A01A adaptation by Phil "PaintYourDragon" Burgess. +BSD license, all text above must be included in any redistribution + +Requires the Adafruit_GFX library for Arduino. + +EXTRAS FOLDER: Adafruit_Arcada_FeatherM4.h file can be used with +Adafruit_Arcada library to make the M4_Eyes sketch compile on Adafruit +Feather M4 with this display (second display has not been tested, +would require setting up a second SPI SERCOM, but in theory it should work). diff --git a/lib/Adafruit_GC9A01A/library.properties b/lib/Adafruit_GC9A01A/library.properties new file mode 100644 index 0000000..d6ec775 --- /dev/null +++ b/lib/Adafruit_GC9A01A/library.properties @@ -0,0 +1,10 @@ +name=Adafruit GC9A01A +version=1.1.1 +author=Adafruit +maintainer=Adafruit +sentence=Library for GC9A01A displays +paragraph=Library for GC9A01A displays +category=Display +url=https://github.com/Adafruit/Adafruit_GC9A01A +architectures=* +depends=Adafruit GFX Library diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..2593a33 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..a78f279 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,17 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:megaatmega2560] +platform = atmelavr +board = megaatmega2560 +framework = arduino +lib_deps = + adafruit/Adafruit GFX Library@^1.11.10 + evert-arias/EasyButton@^2.0.3 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..9dd6e2c --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,104 @@ +#include +#include +// #include "../lib/Adafruit_GC9A01A.h" +#include +#include "../lib/Adafruit_GC9A01A/Adafruit_GC9A01A.h" +#include + + +#define TFT_DC 7 +#define TFT_CS 53 +#define TFT_RST 8 +#define TFT_MOSI 51 +#define TFT_SCLK 52 + +#define char_x 10 +#define char_y 10 +#define screen_x 240 +#define screen_y 240 + +const int buttonPin_1 = 39; +const int buttonPin_2 = 41; +const int buttonPin_3 = 43; + +EasyButton btn_1(buttonPin_1); +EasyButton btn_2(buttonPin_2); +EasyButton btn_3(buttonPin_3); + + +Adafruit_GC9A01A tft(TFT_CS, TFT_DC,TFT_MOSI,TFT_SCLK,TFT_RST); + +const int init_i = 30; +int i = init_i; +char iChar[6]; +char iChar2[6]; +int cursor_x = 0; +int cursor_y = 0; + +void print_i() { + itoa(i,iChar,10); + if(i < 10) { + tft.setCursor((screen_x / 2)-(char_x*5 * 1.6), (screen_y / 2)-(char_y*5 * 0.6)); + iChar2[0] = ' '; + iChar2[1] = iChar[0]; + iChar2[2] = ' '; + tft.println(iChar2); + } + else if(i >= 10 and i < 100) { + tft.setCursor((screen_x / 2)-(char_x*5 * 1.1), (screen_y / 2)-(char_y*5 * 0.6)); + tft.println(iChar); + } + + // tft.println(iChar); + // Serial.println(iChar); +} + +void btn_1_click() { + // Serial.println("Btn_1 !"); + if(i > 0){ + i--; + } + print_i(); +} + +void btn_2_click() { + // Serial.println("Btn_2 !"); + if(i > 0){ + i = init_i; + } + print_i(); +} + +void btn_3_click() { + // Serial.println("Btn_3 !"); + if(i < init_i){ + i++; + } + print_i(); +} + +void setup() { + Serial.begin(9600); + Serial.println("GC9A01A Test!"); + + btn_1.begin(); + btn_2.begin(); + btn_3.begin(); + + btn_1.onPressed(btn_1_click); + btn_2.onPressed(btn_2_click); + btn_3.onPressed(btn_3_click); + + tft.begin(); + tft.setAddrWindow(0,0,240,240); + tft.fillScreen(GC9A01A_BLACK); + tft.setTextColor(GC9A01A_WHITE,GC9A01A_BLACK); + tft.setTextSize(char_x,char_y); + print_i(); +} + +void loop() { + btn_1.read(); + btn_2.read(); + btn_3.read(); +} \ No newline at end of file diff --git a/test/README b/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html