Skip to content

Commit

Permalink
Code and documentation cleanups regarding connection setup. (#10)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tfry-git authored and stevstrong committed Jan 22, 2018
1 parent 49f8ba5 commit 55d595b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 137 deletions.
5 changes: 1 addition & 4 deletions 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

Expand All @@ -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)
Expand Down
80 changes: 27 additions & 53 deletions 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 <Adafruit_GFX.h>

#include <libmaple/gpio.h>

//#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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 {

Expand Down
4 changes: 4 additions & 0 deletions README.txt
Expand Up @@ -9,3 +9,7 @@ How to use:
- Place the Adafruit_TFT library folder your <arduinosketchfolder>/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 <Adafruit_GFX_AS.h>, 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.
35 changes: 2 additions & 33 deletions 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 <Adafruit_TFTLCD_8bit_STM32.h> // Hardware-specific library
#include <SD.h>
#include <SPI.h>

// 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 <Adafruit_TFTLCD_8bit_STM32.h> 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)
Expand All @@ -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()
{
Expand All @@ -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;
}

Expand Down
4 changes: 0 additions & 4 deletions examples/graphicstest/graphicstest.ino
@@ -1,9 +1,5 @@
#include <Arduino.h>

// 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 <Adafruit_TFTLCD_8bit_STM32.h> // Hardware-specific library


Expand Down
16 changes: 0 additions & 16 deletions 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 <Adafruit_TFTLCD_8bit_STM32.h> // Hardware-specific library

// check the pin connections in the header file.
Expand All @@ -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();
Expand All @@ -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;
}

Expand Down
29 changes: 2 additions & 27 deletions 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 <Adafruit_TFTLCD_8bit_STM32.h> // Hardware-specific library
#include <SD.h>
#include <SPI.h>

// 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 <Adafruit_TFTLCD_8bit_STM32.h> 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)
Expand All @@ -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()
{
Expand Down

0 comments on commit 55d595b

Please sign in to comment.