mirror of
https://github.com/adafruit/Adafruit-GFX-Library.git
synced 2024-10-03 18:18:46 -04:00
WIP, constructor disambiguation via enum
This commit is contained in:
parent
cb8c433a61
commit
0107025e4c
@ -291,13 +291,13 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, SPIClass *spiClass,
|
||||
only SPI displays, parallel being a recent addition (but not
|
||||
wanting to break existing code).
|
||||
*/
|
||||
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, bool wide,
|
||||
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, tftBusWidth busWidth,
|
||||
int8_t d0, int8_t wr, int8_t dc, int8_t cs, int8_t rst, int8_t rd) :
|
||||
Adafruit_GFX(w, h), connection(TFT_PARALLEL), _rst(rst), _cs(cs), _dc(dc) {
|
||||
tft8._d0 = d0;
|
||||
tft8._wr = wr;
|
||||
tft8._rd = rd;
|
||||
tft8.wide = wide;
|
||||
tft8.wide = (busWidth == tft16);
|
||||
#if defined(USE_FAST_PINIO)
|
||||
#if defined(HAS_PORT_SET_CLR)
|
||||
#if defined(CORE_TEENSY)
|
||||
@ -363,32 +363,32 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h, bool wide,
|
||||
tft8.rdPortClr = dcPortClr;
|
||||
}
|
||||
// Get pointers to PORT write/read/dir bytes within 32-bit PORT
|
||||
uint8_t dBit = g_APinDescription[d0].ulPin; // d0 bit # in PORT
|
||||
PortGroup *p = (&(PORT->Group[g_APinDescription[d0].ulPort]));
|
||||
uint8_t offset = dBit / 8; // d[7:0] byte # within PORT
|
||||
if(wide) offset &= ~1; // d[15:8] byte # within PORT
|
||||
uint8_t dBit = g_APinDescription[d0].ulPin; // d0 bit # in PORT
|
||||
PortGroup *p = (&(PORT->Group[g_APinDescription[d0].ulPort]));
|
||||
uint8_t offset = dBit / 8; // d[7:0] byte # within PORT
|
||||
if(tft8.wide) offset &= ~1; // d[15:8] byte # within PORT
|
||||
// These are all uint8_t* pointers -- elsewhere they're recast
|
||||
// as necessary if a 'wide' 16-bit interface is in use.
|
||||
tft8.writePort = (volatile uint8_t *)&(p->OUT.reg) + offset;
|
||||
tft8.readPort = (volatile uint8_t *)&(p->IN.reg) + offset;
|
||||
tft8.dirSet = (volatile uint8_t *)&(p->DIRSET.reg) + offset;
|
||||
tft8.dirClr = (volatile uint8_t *)&(p->DIRCLR.reg) + offset;
|
||||
tft8.writePort = (volatile uint8_t *)&(p->OUT.reg) + offset;
|
||||
tft8.readPort = (volatile uint8_t *)&(p->IN.reg) + offset;
|
||||
tft8.dirSet = (volatile uint8_t *)&(p->DIRSET.reg) + offset;
|
||||
tft8.dirClr = (volatile uint8_t *)&(p->DIRCLR.reg) + offset;
|
||||
#endif // end !CORE_TEENSY
|
||||
#else // !HAS_PORT_SET_CLR
|
||||
tft8.wrPort =(PORTreg_t)portOutputRegister(digitalPinToPort(wr));
|
||||
tft8.wrPinMaskSet =digitalPinToBitMask(wr);
|
||||
dcPort =(PORTreg_t)portOutputRegister(digitalPinToPort(dc));
|
||||
dcPinMaskSet =digitalPinToBitMask(dc);
|
||||
tft8.wrPort = (PORTreg_t)portOutputRegister(digitalPinToPort(wr));
|
||||
tft8.wrPinMaskSet = digitalPinToBitMask(wr);
|
||||
dcPort = (PORTreg_t)portOutputRegister(digitalPinToPort(dc));
|
||||
dcPinMaskSet = digitalPinToBitMask(dc);
|
||||
if(cs >= 0) {
|
||||
csPort = (PORTreg_t)portOutputRegister(digitalPinToPort(cs));
|
||||
csPinMaskSet = digitalPinToBitMask(cs);
|
||||
csPort = (PORTreg_t)portOutputRegister(digitalPinToPort(cs));
|
||||
csPinMaskSet = digitalPinToBitMask(cs);
|
||||
} else {
|
||||
// No chip-select line defined; might be permanently tied to GND.
|
||||
// Assign a valid GPIO register (though not used for CS), and an
|
||||
// empty pin bitmask...the nonsense bit-twiddling might be faster
|
||||
// than checking _cs and possibly branching.
|
||||
csPort = dcPort;
|
||||
csPinMaskSet = 0;
|
||||
csPort = dcPort;
|
||||
csPinMaskSet = 0;
|
||||
}
|
||||
if(rd >= 0) { // if read-strobe pin specified...
|
||||
tft8.rdPort =(PORTreg_t)portOutputRegister(digitalPinToPort(rd));
|
||||
@ -1458,7 +1458,6 @@ uint8_t Adafruit_SPITFT::spiRead(void) {
|
||||
// case TFT_PARALLEL:
|
||||
default: // Avoids compiler warning about no return value
|
||||
if(tft8._rd >= 0) {
|
||||
// TO DO: figure out why not working
|
||||
#if defined(USE_FAST_PINIO)
|
||||
TFT_RD_LOW(); // Read line LOW
|
||||
#if defined(__AVR__)
|
||||
|
@ -83,6 +83,16 @@ typedef volatile PORT_t* PORTreg_t; ///< PORT register type
|
||||
#include <Adafruit_ZeroDMA.h>
|
||||
#endif
|
||||
|
||||
// This is kind of a kludge. Needed a way to disambiguate the software SPI
|
||||
// and parallel constructors via their argument lists. Originally tried a
|
||||
// bool as the first argument to the parallel constructor (specifying 8-bit
|
||||
// vs 16-bit interface) but the compiler regards this as equivalent to an
|
||||
// integer and thus still ambiguous. SO...the parallel constructor requires
|
||||
// an enumerated type as the first argument: tft8 (for 8-bit parallel) or
|
||||
// tft16 (for 16-bit)...even though 16-bit isn't fully implemented or tested
|
||||
// and might never be, still needed that disambiguation from soft SPI.
|
||||
enum tftBusWidth { tft8, tft16 }; ///< For first arg to parallel constructor
|
||||
|
||||
// CLASS DEFINITION --------------------------------------------------------
|
||||
|
||||
/*!
|
||||
@ -132,7 +142,7 @@ class Adafruit_SPITFT : public Adafruit_GFX {
|
||||
// pins (d0, wr, dc), 3 optional pins (cs, rst, rd). 16-bit parallel
|
||||
// isn't even fully implemented but the 'wide' flag was added as a
|
||||
// required argument to avoid ambiguity with other constructors.
|
||||
Adafruit_SPITFT(uint16_t w, uint16_t h, bool wide,
|
||||
Adafruit_SPITFT(uint16_t w, uint16_t h, tftBusWidth busWidth,
|
||||
int8_t d0, int8_t wr, int8_t dc,
|
||||
int8_t cs = -1, int8_t rst = -1, int8_t rd = -1);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user