From 55d595b8278084100b9f5ada2c71386534c90dfd Mon Sep 17 00:00:00 2001 From: Thomas Friedrichsmeier Date: Mon, 22 Jan 2018 18:48:08 +0100 Subject: [PATCH] Code and documentation cleanups regarding connection setup. (#10) * Clean up pin definitions, and document them. - Move pin defintions to top of header - Remove some dead code - Remove some AVR-board specific connection/setup advice - Fix a few things that were obviously wrong in the examples (without testing, though) * Small fix --- Adafruit_TFTLCD_8bit_STM32.cpp | 5 +- Adafruit_TFTLCD_8bit_STM32.h | 80 ++++++++---------------- README.txt | 4 ++ examples/FolderBrowser/FolderBrowser.ino | 35 +---------- examples/graphicstest/graphicstest.ino | 4 -- examples/rotationtest/rotationtest.ino | 16 ----- examples/tftbmp/tftbmp.ino | 29 +-------- 7 files changed, 36 insertions(+), 137 deletions(-) diff --git a/Adafruit_TFTLCD_8bit_STM32.cpp b/Adafruit_TFTLCD_8bit_STM32.cpp index 1333d45..d1f8706 100644 --- a/Adafruit_TFTLCD_8bit_STM32.cpp +++ b/Adafruit_TFTLCD_8bit_STM32.cpp @@ -1,6 +1,3 @@ -// IMPORTANT: LIBRARY MUST BE SPECIFICALLY CONFIGURED FOR EITHER TFT SHIELD -// OR BREAKOUT BOARD USAGE. SEE RELEVANT COMMENTS IN Adafruit_TFTLCD_8bit_STM32.h - // Graphics library by ladyada/adafruit with init code from Rossum // MIT license @@ -15,7 +12,7 @@ gpio_reg_map * cntrlRegs; gpio_reg_map * dataRegs; /*****************************************************************************/ -// Constructor for shield (fixed LCD control lines) +// Constructor /*****************************************************************************/ Adafruit_TFTLCD_8bit_STM32 :: Adafruit_TFTLCD_8bit_STM32(void) : Adafruit_GFX(TFTWIDTH, TFTHEIGHT) diff --git a/Adafruit_TFTLCD_8bit_STM32.h b/Adafruit_TFTLCD_8bit_STM32.h index 340c562..04d8436 100644 --- a/Adafruit_TFTLCD_8bit_STM32.h +++ b/Adafruit_TFTLCD_8bit_STM32.h @@ -1,17 +1,37 @@ -// IMPORTANT: SEE COMMENTS @ LINE 15 REGARDING SHIELD VS BREAKOUT BOARD USAGE. - // Graphics library by ladyada/adafruit with init code from Rossum // MIT license #ifndef _ADAFRUIT_TFTLCD_8BIT_STM32_H_ #define _ADAFRUIT_TFTLCD_8BIT_STM32_H_ - #include #include -//#define USE_MAPLE_MINI_PINOUT // for use with maple mini +/*****************************************************************************/ +// Define pins and Output Data Registers +/*****************************************************************************/ +// Data port +#define TFT_DATA_PORT GPIOB +// Data bits/pins +#define TFT_DATA_SHIFT 0 // take the lower bits/pins 0..7 +//#define TFT_DATA_SHIFT 8 // take the higher bits/pins 8..15 + +//Control pins |RD |WR |RS |CS |RST| +#define TFT_CNTRL_PORT GPIOA +#define TFT_RD PA0 +#define TFT_WR PA1 +#define TFT_RS PA2 +#define TFT_CS PA3 + +#define TFT_RD_MASK BIT0 // digitalPinToBitMask(TFT_RD) // +#define TFT_WR_MASK BIT1 // digitalPinToBitMask(TFT_WR) // +#define TFT_RS_MASK BIT2 // digitalPinToBitMask(TFT_RS) // +#define TFT_CS_MASK BIT3 // digitalPinToBitMask(TFT_CS) // + +#define TFT_RST PB10 + +#define SLOW_WRITE 0 // set to 1 for legacy slow write (using individual digitalWrite()s /*****************************************************************************/ // LCD controller chip identifiers @@ -43,51 +63,11 @@ #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF -/*****************************************************************************/ -// Define pins and Output Data Registers -/*****************************************************************************/ -// Data port -#define TFT_DATA_PORT GPIOB -// Data bits -#define TFT_DATA_SHIFT 0 // take the lower bits 0..8 -//#define TFT_DATA_SHIFT 8 // take the higher bits 7..15 - -#if 0 -//#warning "Using maple mini pinout" -//Control pins |RD |WR |RS |CS |RST| -#define TFT_CNTRL_PORT GPIOA -#define TFT_RD PB11 -#define TFT_WR PA10 -#define TFT_RS PA9 -#define TFT_CS PA8 - -#define TFT_WR_MASK BIT10 // digitalPinToBitMask(TFT_WR) // -#define TFT_RS_MASK BIT9 // digitalPinToBitMask(TFT_RS) // -#define TFT_CS_MASK BIT8 // digitalPinToBitMask(TFT_CS) // - -#define TFT_RST PB10 - -#else - -//Control pins |RD |WR |RS |CS |RST| -#define TFT_CNTRL_PORT GPIOA -#define TFT_RD PA0 -#define TFT_WR PA1 -#define TFT_RS PA2 -#define TFT_CS PA3 -#define TFT_RD_MASK BIT0 // digitalPinToBitMask(TFT_RD) // -#define TFT_WR_MASK BIT1 // digitalPinToBitMask(TFT_WR) // -#define TFT_RS_MASK BIT2 // digitalPinToBitMask(TFT_RS) // -#define TFT_CS_MASK BIT3 // digitalPinToBitMask(TFT_CS) // - -#define TFT_RST PB10 - -#endif // end of control pin configuration #define RD_ACTIVE digitalWrite(TFT_RD, LOW) #define RD_IDLE digitalWrite(TFT_RD, HIGH) -#if 0 +#if SLOW_WRITE // use old definition, standard bit toggling, low speed #define WR_ACTIVE digitalWrite(TFT_WR, LOW) #define WR_IDLE digitalWrite(TFT_WR, HIGH) @@ -123,7 +103,7 @@ extern gpio_reg_map * dataRegs; #define setWriteDir() ( dataRegs->CRL = 0x33333333 ) // set the lower 8 bits as output // set pins to output the 8 bit value - #if 0 // slow write + #if SLOW_WRITE inline void write8(uint8_t c) { /*Serial.print(" write8: "); Serial.print(c,HEX); Serial.write(',');*/ digitalWrite(PB0, (c&BIT0)?HIGH:LOW); digitalWrite(PB1, (c&BIT1)?HIGH:LOW); @@ -146,7 +126,7 @@ extern gpio_reg_map * dataRegs; #define setWriteDir() ( dataRegs->CRH = 0x33333333 ) // set the lower 8 bits as output // set pins to output the 8 bit value - #if 0 // slow write + #if SLOW_WRITE inline void write8(uint8_t c) { /*Serial.print(" write8: "); Serial.print(c,HEX); Serial.write(',');*/ digitalWrite(PB8, (c&BIT0)?HIGH:LOW); digitalWrite(PB9, (c&BIT1)?HIGH:LOW); @@ -170,12 +150,6 @@ extern gpio_reg_map * dataRegs; #define swap(a, b) { int16_t t = a; a = b; b = t; } -/*****************************************************************************/ -// **** IF USING THE LCD BREAKOUT BOARD, COMMENT OUT THIS NEXT LINE. **** -// **** IF USING THE LCD SHIELD, LEAVE THE LINE ENABLED: **** - -//#define USE_ADAFRUIT_SHIELD_PINOUT 1 - /*****************************************************************************/ class Adafruit_TFTLCD_8bit_STM32 : public Adafruit_GFX { diff --git a/README.txt b/README.txt index c9cc0df..0cac466 100644 --- a/README.txt +++ b/README.txt @@ -9,3 +9,7 @@ How to use: - Place the Adafruit_TFT library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. - Also requires the Adafruit_GFX library for Arduino. https://github.com/adafruit/Adafruit-GFX-Library . Alternatively, you can change Adafruit_TFTLCD_8bit_STM32.h to #include , instead. + +- Pin connections can be configured near the top of Adafruit_TFTLCD_8bit_STM32.h . Note that the data lines have to be on consequtive pins of the same output register (PB0...PB7, by default). + To use the higher pins (PX8..PX15), set TFT_DATA_SHIFT to 8. The four control pins must all be one output register (the same as the data pins, or a different one), but can be freely + assigned within the register. The TFT reset line can be assigned, freely. diff --git a/examples/FolderBrowser/FolderBrowser.ino b/examples/FolderBrowser/FolderBrowser.ino index b50d223..71ee570 100644 --- a/examples/FolderBrowser/FolderBrowser.ino +++ b/examples/FolderBrowser/FolderBrowser.ino @@ -1,32 +1,8 @@ -// BMP-loading example specifically for the TFTLCD breakout board. -// If using the Arduino shield, use the tftbmp_shield.pde sketch instead! -// If using an Arduino Mega make sure to use its hardware SPI pins, OR make -// sure the SD library is configured for 'soft' SPI in the file Sd2Card.h. - #include // Hardware-specific library #include #include -// The control pins for the LCD can be assigned to any digital or -// analog pins...but we'll use the analog pins as this allows us to -// double up the pins with the touch screen (see the TFT paint example). -#define LCD_CS A3 // Chip Select goes to Analog 3 -#define LCD_CD A2 // Command/Data goes to Analog 2 -#define LCD_WR A1 // LCD Write goes to Analog 1 -#define LCD_RD A0 // LCD Read goes to Analog 0 - -// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: -// For the Arduino Uno, Duemilanove, Diecimila, etc.: -// D0 connects to digital pin 8 (Notice these are -// D1 connects to digital pin 9 NOT in order!) -// D2 connects to digital pin 2 -// D3 connects to digital pin 3 -// D4 connects to digital pin 4 -// D5 connects to digital pin 5 -// D6 connects to digital pin 6 -// D7 connects to digital pin 7 -// For the Arduino Mega, use digital pins 22 through 29 -// (on the 2-row header at the end of the board). +// See for connection details of the display. Use hardware SPI pins for SPI // For Arduino Uno/Duemilanove, etc // connect the SD card with DI going to pin 11, DO going to pin 12 and SCK going to pin 13 (standard) @@ -36,8 +12,7 @@ // In the SD card, place 24 bit color BMP files (be sure they are 24-bit!) // There are examples in the sketch folder -// our TFT wiring -Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A4); +Adafruit_TFTLCD_8bit_STM32 tft; void setup() { @@ -60,12 +35,6 @@ void setup() } else { Serial.print(F("Unknown LCD driver chip: ")); Serial.println(identifier, HEX); - Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); - Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT")); - Serial.println(F("should appear in the library header (Adafruit_TFT.h).")); - Serial.println(F("If using the breakout board, it should NOT be #defined!")); - Serial.println(F("Also if using the breakout, double-check that all wiring")); - Serial.println(F("matches the tutorial.")); return; } diff --git a/examples/graphicstest/graphicstest.ino b/examples/graphicstest/graphicstest.ino index 6100952..e5053d5 100644 --- a/examples/graphicstest/graphicstest.ino +++ b/examples/graphicstest/graphicstest.ino @@ -1,9 +1,5 @@ #include -// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY -// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. -// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. - #include // Hardware-specific library diff --git a/examples/rotationtest/rotationtest.ino b/examples/rotationtest/rotationtest.ino index 67b5b00..ce6babb 100644 --- a/examples/rotationtest/rotationtest.ino +++ b/examples/rotationtest/rotationtest.ino @@ -1,7 +1,3 @@ -// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY -// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD. -// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP. - #include // Hardware-specific library // check the pin connections in the header file. @@ -25,12 +21,6 @@ void setup(void) { delay(6000); Serial.println(F("TFT LCD test")); -#ifdef USE_ADAFRUIT_SHIELD_PINOUT - Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout")); -#else - Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout")); -#endif - tft.reset(); uint16_t identifier = tft.readID(); @@ -48,12 +38,6 @@ void setup(void) { } else { Serial.print(F("Unknown LCD driver chip: ")); Serial.println(identifier, HEX); - Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); - Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT")); - Serial.println(F("should appear in the library header (Adafruit_TFT.h).")); - Serial.println(F("If using the breakout board, it should NOT be #defined!")); - Serial.println(F("Also if using the breakout, double-check that all wiring")); - Serial.println(F("matches the tutorial.")); return; } diff --git a/examples/tftbmp/tftbmp.ino b/examples/tftbmp/tftbmp.ino index b50d223..45a529e 100644 --- a/examples/tftbmp/tftbmp.ino +++ b/examples/tftbmp/tftbmp.ino @@ -1,32 +1,8 @@ -// BMP-loading example specifically for the TFTLCD breakout board. -// If using the Arduino shield, use the tftbmp_shield.pde sketch instead! -// If using an Arduino Mega make sure to use its hardware SPI pins, OR make -// sure the SD library is configured for 'soft' SPI in the file Sd2Card.h. - #include // Hardware-specific library #include #include -// The control pins for the LCD can be assigned to any digital or -// analog pins...but we'll use the analog pins as this allows us to -// double up the pins with the touch screen (see the TFT paint example). -#define LCD_CS A3 // Chip Select goes to Analog 3 -#define LCD_CD A2 // Command/Data goes to Analog 2 -#define LCD_WR A1 // LCD Write goes to Analog 1 -#define LCD_RD A0 // LCD Read goes to Analog 0 - -// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: -// For the Arduino Uno, Duemilanove, Diecimila, etc.: -// D0 connects to digital pin 8 (Notice these are -// D1 connects to digital pin 9 NOT in order!) -// D2 connects to digital pin 2 -// D3 connects to digital pin 3 -// D4 connects to digital pin 4 -// D5 connects to digital pin 5 -// D6 connects to digital pin 6 -// D7 connects to digital pin 7 -// For the Arduino Mega, use digital pins 22 through 29 -// (on the 2-row header at the end of the board). +// See for connection details of the display. Use hardware SPI pins for SPI // For Arduino Uno/Duemilanove, etc // connect the SD card with DI going to pin 11, DO going to pin 12 and SCK going to pin 13 (standard) @@ -36,8 +12,7 @@ // In the SD card, place 24 bit color BMP files (be sure they are 24-bit!) // There are examples in the sketch folder -// our TFT wiring -Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A4); +Adafruit_TFTLCD_8bit_STM32 tft; void setup() {