*falls over*

This commit is contained in:
ladyada 2018-07-14 15:21:57 -04:00
parent df54898306
commit 5614790a99
6 changed files with 401 additions and 26 deletions

View File

@ -70,6 +70,13 @@ POSSIBILITY OF SUCH DAMAGE.
#define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; }
#endif
/**************************************************************************/
/*!
@brief Instatiate a GFX context for graphics! Can only be done by a superclass
@param w Display width, in pixels
@param h Display height, in pixels
*/
/**************************************************************************/
Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h):
WIDTH(w), HEIGHT(h)
{
@ -351,7 +358,6 @@ void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,
@param y0 Center-point y coordinate
@param r Radius of circle
@param cornername Mask bit #1 or bit #2 to indicate which quarters of the circle we're doing
@param delta Offset from center-point, used for round-rects
@param color 16-bit 5-6-5 Color to draw with
*/
/**************************************************************************/
@ -837,7 +843,7 @@ void Adafruit_GFX::drawGrayscaleBitmap(int16_t x, int16_t y,
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param bitmap byte array with grayscale bitmap
@param mast byte array with mask bitmap
@param mask byte array with mask bitmap
@param w Width of bitmap in pixels
@param h Height of bitmap in pixels
*/
@ -869,7 +875,7 @@ void Adafruit_GFX::drawGrayscaleBitmap(int16_t x, int16_t y,
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param bitmap byte array with grayscale bitmap
@param mast byte array with mask bitmap
@param mask byte array with mask bitmap
@param w Width of bitmap in pixels
@param h Height of bitmap in pixels
*/
@ -1475,12 +1481,31 @@ void Adafruit_GFX::invertDisplay(boolean i) {
}
/***************************************************************************/
// code for the GFX button UI element
/**************************************************************************/
/*!
@brief Create a simple drawn button UI element
*/
/**************************************************************************/
Adafruit_GFX_Button::Adafruit_GFX_Button(void) {
_gfx = 0;
}
/**************************************************************************/
/*!
@brief Initialize button with our desired color/size/settings
@param gfx Pointer to our display so we can draw to it!
@param x The X coordinate of the center of the button
@param y The Y coordinate of the center of the button
@param w Width of the buttton
@param h Height of the buttton
@param outline Color of the outline (16-bit 5-6-5 standard)
@param fill Color of the button fill (16-bit 5-6-5 standard)
@param textcolor Color of the button label (16-bit 5-6-5 standard)
@param label Ascii string of the text inside the button
@param textsize The font magnification of the label text
*/
/**************************************************************************/
// Classic initButton() function: pass center & size
void Adafruit_GFX_Button::initButton(
Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h,
@ -1492,7 +1517,21 @@ void Adafruit_GFX_Button::initButton(
textcolor, label, textsize);
}
// Newer function instead accepts upper-left corner & size
/**************************************************************************/
/*!
@brief Initialize button with our desired color/size/settings, with upper-left coordinates
@param gfx Pointer to our display so we can draw to it!
@param x1 The X coordinate of the Upper-Left corner of the button
@param y1 The Y coordinate of the Upper-Left corner of the button
@param w Width of the buttton
@param h Height of the buttton
@param outline Color of the outline (16-bit 5-6-5 standard)
@param fill Color of the button fill (16-bit 5-6-5 standard)
@param textcolor Color of the button label (16-bit 5-6-5 standard)
@param label Ascii string of the text inside the button
@param textsize The font magnification of the label text
*/
/**************************************************************************/
void Adafruit_GFX_Button::initButtonUL(
Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h,
uint16_t outline, uint16_t fill, uint16_t textcolor,
@ -1510,6 +1549,12 @@ void Adafruit_GFX_Button::initButtonUL(
strncpy(_label, label, 9);
}
/**************************************************************************/
/*!
@brief Draw the button on the screen
@param inverted Whether to draw with fill/text swapped to indicate 'pressed'
*/
/**************************************************************************/
void Adafruit_GFX_Button::drawButton(boolean inverted) {
uint16_t fill, outline, text;
@ -1534,18 +1579,52 @@ void Adafruit_GFX_Button::drawButton(boolean inverted) {
_gfx->print(_label);
}
/**************************************************************************/
/*!
@brief Helper to let us know if a coordinate is within the bounds of the button
@param x The X coordinate to check
@param y The Y coordinate to check
@returns True if within button graphics outline
*/
/**************************************************************************/
boolean Adafruit_GFX_Button::contains(int16_t x, int16_t y) {
return ((x >= _x1) && (x < (_x1 + _w)) &&
(y >= _y1) && (y < (_y1 + _h)));
}
/**************************************************************************/
/*!
@brief Sets the state of the button, should be done by some touch function
@param p True for pressed, false for not.
*/
/**************************************************************************/
void Adafruit_GFX_Button::press(boolean p) {
laststate = currstate;
currstate = p;
}
/**************************************************************************/
/*!
@brief Query whether the button is currently pressed
@returns True if pressed
*/
/**************************************************************************/
boolean Adafruit_GFX_Button::isPressed() { return currstate; }
/**************************************************************************/
/*!
@brief Query whether the button was pressed since we last checked state
@returns True if was not-pressed before, now is.
*/
/**************************************************************************/
boolean Adafruit_GFX_Button::justPressed() { return (currstate && !laststate); }
/**************************************************************************/
/*!
@brief Query whether the button was released since we last checked state
@returns True if was pressed before, now is not.
*/
/**************************************************************************/
boolean Adafruit_GFX_Button::justReleased() { return (!currstate && laststate); }
// -------------------------------------------------------------------------
@ -1567,6 +1646,13 @@ boolean Adafruit_GFX_Button::justReleased() { return (!currstate && laststate);
// scanline pad).
// NOT EXTENSIVELY TESTED YET. MAY CONTAIN WORST BUGS KNOWN TO HUMANKIND.
/**************************************************************************/
/*!
@brief Instatiate a GFX 1-bit canvas context for graphics
@param w Display width, in pixels
@param h Display height, in pixels
*/
/**************************************************************************/
GFXcanvas1::GFXcanvas1(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) {
uint16_t bytes = ((w + 7) / 8) * h;
if((buffer = (uint8_t *)malloc(bytes))) {
@ -1574,14 +1660,33 @@ GFXcanvas1::GFXcanvas1(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) {
}
}
/**************************************************************************/
/*!
@brief Delete the canvas, free memory
*/
/**************************************************************************/
GFXcanvas1::~GFXcanvas1(void) {
if(buffer) free(buffer);
}
/**************************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**************************************************************************/
uint8_t* GFXcanvas1::getBuffer(void) {
return buffer;
}
/**************************************************************************/
/*!
@brief Draw a pixel to the canvas framebuffer
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) {
#ifdef __AVR__
// Bitmask tables of 0x80>>X and ~(0x80>>X), because X>>Y is slow on AVR
@ -1622,6 +1727,12 @@ void GFXcanvas1::drawPixel(int16_t x, int16_t y, uint16_t color) {
}
}
/**************************************************************************/
/*!
@brief Fill the framebuffer completely with one color
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas1::fillScreen(uint16_t color) {
if(buffer) {
uint16_t bytes = ((WIDTH + 7) / 8) * HEIGHT;
@ -1629,6 +1740,13 @@ void GFXcanvas1::fillScreen(uint16_t color) {
}
}
/**************************************************************************/
/*!
@brief Instatiate a GFX 8-bit canvas context for graphics
@param w Display width, in pixels
@param h Display height, in pixels
*/
/**************************************************************************/
GFXcanvas8::GFXcanvas8(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) {
uint32_t bytes = w * h;
if((buffer = (uint8_t *)malloc(bytes))) {
@ -1636,14 +1754,34 @@ GFXcanvas8::GFXcanvas8(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) {
}
}
/**************************************************************************/
/*!
@brief Delete the canvas, free memory
*/
/**************************************************************************/
GFXcanvas8::~GFXcanvas8(void) {
if(buffer) free(buffer);
}
/**************************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**************************************************************************/
uint8_t* GFXcanvas8::getBuffer(void) {
return buffer;
}
/**************************************************************************/
/*!
@brief Draw a pixel to the canvas framebuffer
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas8::drawPixel(int16_t x, int16_t y, uint16_t color) {
if(buffer) {
if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return;
@ -1670,6 +1808,12 @@ void GFXcanvas8::drawPixel(int16_t x, int16_t y, uint16_t color) {
}
}
/**************************************************************************/
/*!
@brief Fill the framebuffer completely with one color
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas8::fillScreen(uint16_t color) {
if(buffer) {
memset(buffer, color, WIDTH * HEIGHT);
@ -1711,6 +1855,13 @@ void GFXcanvas8::writeFastHLine(int16_t x, int16_t y,
memset(buffer + y * WIDTH + x, color, w);
}
/**************************************************************************/
/*!
@brief Instatiate a GFX 16-bit canvas context for graphics
@param w Display width, in pixels
@param h Display height, in pixels
*/
/**************************************************************************/
GFXcanvas16::GFXcanvas16(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) {
uint32_t bytes = w * h * 2;
if((buffer = (uint16_t *)malloc(bytes))) {
@ -1718,14 +1869,33 @@ GFXcanvas16::GFXcanvas16(uint16_t w, uint16_t h) : Adafruit_GFX(w, h) {
}
}
/**************************************************************************/
/*!
@brief Delete the canvas, free memory
*/
/**************************************************************************/
GFXcanvas16::~GFXcanvas16(void) {
if(buffer) free(buffer);
}
/**************************************************************************/
/*!
@brief Get a pointer to the internal buffer memory
@returns A pointer to the allocated buffer
*/
/**************************************************************************/
uint16_t* GFXcanvas16::getBuffer(void) {
return buffer;
}
/**************************************************************************/
/*!
@brief Draw a pixel to the canvas framebuffer
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas16::drawPixel(int16_t x, int16_t y, uint16_t color) {
if(buffer) {
if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return;
@ -1752,6 +1922,12 @@ void GFXcanvas16::drawPixel(int16_t x, int16_t y, uint16_t color) {
}
}
/**************************************************************************/
/*!
@brief Fill the framebuffer completely with one color
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void GFXcanvas16::fillScreen(uint16_t color) {
if(buffer) {
uint8_t hi = color >> 8, lo = color & 0xFF;

View File

@ -9,6 +9,7 @@
#endif
#include "gfxfont.h"
/// A generic graphics superclass that can handle all sorts of drawing. At a minimum you can subclass and provide drawPixel(). At a maximum you can do a ton of overriding to optimize. Used for any/all Adafruit displays!
class Adafruit_GFX : public Print {
public:
@ -16,7 +17,7 @@ class Adafruit_GFX : public Print {
Adafruit_GFX(int16_t w, int16_t h); // Constructor
// This MUST be defined by the subclass:
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; ///< Virtual drawPixel() function to draw to the screen/framebuffer/etc, must be overridden in subclass. @param x X coordinate. @param y Y coordinate. @param color 16-bit pixel color.
// TRANSACTION API / CORE DRAW API
// These MAY be overridden by the subclass to provide device-specific
@ -146,6 +147,8 @@ class Adafruit_GFX : public Print {
*gfxFont; ///< Pointer to special font
};
/// A simple drawn button UI element
class Adafruit_GFX_Button {
public:
@ -177,6 +180,8 @@ class Adafruit_GFX_Button {
boolean currstate, laststate;
};
/// A GFX 1-bit canvas context for graphics
class GFXcanvas1 : public Adafruit_GFX {
public:
GFXcanvas1(uint16_t w, uint16_t h);
@ -188,6 +193,8 @@ class GFXcanvas1 : public Adafruit_GFX {
uint8_t *buffer;
};
/// A GFX 8-bit canvas context for graphics
class GFXcanvas8 : public Adafruit_GFX {
public:
GFXcanvas8(uint16_t w, uint16_t h);
@ -201,6 +208,8 @@ class GFXcanvas8 : public Adafruit_GFX {
uint8_t *buffer;
};
/// A GFX 16-bit canvas context for graphics
class GFXcanvas16 : public Adafruit_GFX {
public:
GFXcanvas16(uint16_t w, uint16_t h);

View File

@ -65,6 +65,8 @@ uint16_t Adafruit_SPITFT::color565(uint8_t red, uint8_t green, uint8_t blue) {
/**************************************************************************/
/*!
@brief Instantiate Adafruit SPI display driver with software SPI
@param w Display width in pixels
@param h Display height in pixels
@param cs Chip select pin #
@param dc Data/Command pin #
@param mosi SPI MOSI pin #
@ -103,6 +105,16 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
#endif
}
/**************************************************************************/
/*!
@brief Instantiate Adafruit SPI display driver with hardware SPI
@param w Display width in pixels
@param h Display height in pixels
@param cs Chip select pin #
@param dc Data/Command pin #
@param rst Reset pin # (optional, pass -1 if unused)
*/
/**************************************************************************/
Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
int8_t cs, int8_t dc, int8_t rst)
: Adafruit_GFX(w, h) {
@ -127,7 +139,12 @@ Adafruit_SPITFT::Adafruit_SPITFT(uint16_t w, uint16_t h,
#endif
}
/**************************************************************************/
/*!
@brief Initialiaze the SPI interface (hardware or software)
@param freq The desired maximum SPI hardware clock frequency
*/
/**************************************************************************/
void Adafruit_SPITFT::initSPI(uint32_t freq)
{
_freq = freq;
@ -164,6 +181,12 @@ void Adafruit_SPITFT::initSPI(uint32_t freq)
}
}
/**************************************************************************/
/*!
@brief Read one byte from SPI interface (hardware or software
@returns One byte, MSB order
*/
/**************************************************************************/
uint8_t Adafruit_SPITFT::spiRead() {
if(_sclk < 0){
return HSPI_READ();
@ -183,6 +206,12 @@ uint8_t Adafruit_SPITFT::spiRead() {
return r;
}
/**************************************************************************/
/*!
@brief Write one byte to SPI interface (hardware or software
@param b One byte to send, MSB order
*/
/**************************************************************************/
void Adafruit_SPITFT::spiWrite(uint8_t b) {
if(_sclk < 0){
HSPI_WRITE(b);
@ -204,6 +233,15 @@ void Adafruit_SPITFT::spiWrite(uint8_t b) {
* Transaction API
* */
/**************************************************************************/
/*!
@brief SPI displays set an address window rectangle for blitting pixels
@param x Top left corner x coordinate
@param y Top left corner x coordinate
@param w Width of window
@param h Height of window
*/
/**************************************************************************/
void Adafruit_SPITFT::setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
x += _xstart;
y += _ystart;
@ -222,37 +260,78 @@ void Adafruit_SPITFT::setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t
writeCommand(RAMwriteCommand); // write to RAM
}
/**************************************************************************/
/*!
@brief Begin an SPI transaction & set CS low.
*/
/**************************************************************************/
void inline Adafruit_SPITFT::startWrite(void){
SPI_BEGIN_TRANSACTION();
SPI_CS_LOW();
}
/**************************************************************************/
/*!
@brief Begin an SPI transaction & set CS high.
*/
/**************************************************************************/
void inline Adafruit_SPITFT::endWrite(void){
SPI_CS_HIGH();
SPI_END_TRANSACTION();
}
/**************************************************************************/
/*!
@brief Write a command byte (must have a transaction in progress)
@param cmd The 8-bit command to send
*/
/**************************************************************************/
void Adafruit_SPITFT::writeCommand(uint8_t cmd){
SPI_DC_LOW();
spiWrite(cmd);
SPI_DC_HIGH();
}
/**************************************************************************/
/*!
@brief Push a 2-byte color to the framebuffer RAM, will start transaction
@param color 16-bit 5-6-5 Color to draw
*/
/**************************************************************************/
void Adafruit_SPITFT::pushColor(uint16_t color) {
startWrite();
SPI_WRITE16(color);
endWrite();
}
/**************************************************************************/
/*!
@brief Write a 2-byte color (must have a transaction in progress)
@param color 16-bit 5-6-5 Color to draw
*/
/**************************************************************************/
void inline Adafruit_SPITFT::writePixel(uint16_t color){
SPI_WRITE16(color);
}
/**************************************************************************/
/*!
@brief Blit multiple 2-byte colors (must have a transaction in progress)
@param colors Array of 16-bit 5-6-5 Colors to draw
@param len How many pixels to draw - 2 bytes per pixel!
*/
/**************************************************************************/
void inline Adafruit_SPITFT::writePixels(uint16_t * colors, uint32_t len){
SPI_WRITE_PIXELS((uint8_t*)colors , len * 2);
}
/**************************************************************************/
/*!
@brief Blit a 2-byte color many times (must have a transaction in progress)
@param color The 16-bit 5-6-5 Color to draw
@param len How many pixels to draw
*/
/**************************************************************************/
void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len){
#ifdef SPI_HAS_WRITE_PIXELS
if(_sclk >= 0){
@ -290,12 +369,30 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len){
#endif
}
/**************************************************************************/
/*!
@brief Write a pixel (must have a transaction in progress)
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to draw with
*/
/**************************************************************************/
void Adafruit_SPITFT::writePixel(int16_t x, int16_t y, uint16_t color) {
if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return;
setAddrWindow(x,y,1,1);
writePixel(color);
}
/**************************************************************************/
/*!
@brief Write a filled rectangle (must have a transaction in progress)
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param w Width in pixels
@param h Height in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_SPITFT::writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color){
if((x >= _width) || (y >= _height)) return;
int16_t x2 = x + w - 1, y2 = y + h - 1;
@ -320,20 +417,55 @@ void Adafruit_SPITFT::writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h,
writeColor(color, len);
}
/**************************************************************************/
/*!
@brief Write a perfectly vertical line (must have a transaction in progress)
@param x Top-most x coordinate
@param y Top-most y coordinate
@param h Height in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void inline Adafruit_SPITFT::writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color){
writeFillRect(x, y, 1, h, color);
}
/**************************************************************************/
/*!
@brief Write a perfectly horizontal line (must have a transaction in progress)
@param x Left-most x coordinate
@param y Left-most y coordinate
@param w Width in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void inline Adafruit_SPITFT::writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color){
writeFillRect(x, y, w, 1, color);
}
/**************************************************************************/
/*!
@brief Draw a pixel - sets up transaction
@param x x coordinate
@param y y coordinate
@param color 16-bit 5-6-5 Color to draw with
*/
/**************************************************************************/
void Adafruit_SPITFT::drawPixel(int16_t x, int16_t y, uint16_t color){
startWrite();
writePixel(x, y, color);
endWrite();
}
/**************************************************************************/
/*!
@brief Write a perfectly vertical line - sets up transaction
@param x Top-most x coordinate
@param y Top-most y coordinate
@param h Height in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_SPITFT::drawFastVLine(int16_t x, int16_t y,
int16_t h, uint16_t color) {
startWrite();
@ -341,6 +473,15 @@ void Adafruit_SPITFT::drawFastVLine(int16_t x, int16_t y,
endWrite();
}
/**************************************************************************/
/*!
@brief Write a perfectly horizontal line - sets up transaction
@param x Left-most x coordinate
@param y Left-most y coordinate
@param w Width in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_SPITFT::drawFastHLine(int16_t x, int16_t y,
int16_t w, uint16_t color) {
startWrite();
@ -348,6 +489,16 @@ void Adafruit_SPITFT::drawFastHLine(int16_t x, int16_t y,
endWrite();
}
/**************************************************************************/
/*!
@brief Fill a rectangle completely with one color.
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param w Width in pixels
@param h Height in pixels
@param color 16-bit 5-6-5 Color to fill with
*/
/**************************************************************************/
void Adafruit_SPITFT::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color) {
startWrite();
@ -356,17 +507,36 @@ void Adafruit_SPITFT::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
}
/**************************************************************************/
/*!
@brief Invert the display using built-in hardware command
@param i True if you want to invert, false to make 'normal'
*/
/**************************************************************************/
void Adafruit_SPITFT::invertDisplay(boolean i) {
startWrite();
writeCommand(i ? invertOnCommand : invertOffCommand);
endWrite();
}
// Adapted from https://github.com/PaulStoffregen/ILI9341_t3
// by Marc MERLIN. See examples/pictureEmbed to use this.
// 5/6/2017: function name and arguments have changed for compatibility
// with current GFX library and to avoid naming problems in prior
// implementation. Formerly drawBitmap() with arguments in different order.
/**************************************************************************/
/*!
@brief Draw a 16-bit image (RGB 5/6/5) at the specified (x,y) position.
For 16-bit display devices; no color reduction performed.
Adapted from https://github.com/PaulStoffregen/ILI9341_t3
by Marc MERLIN. See examples/pictureEmbed to use this.
5/6/2017: function name and arguments have changed for compatibility
with current GFX library and to avoid naming problems in prior
implementation. Formerly drawBitmap() with arguments in different order.
@param x Top left corner x coordinate
@param y Top left corner y coordinate
@param pcolors 16-bit array with 16-bit color bitmap
@param w Width of bitmap in pixels
@param h Height of bitmap in pixels
*/
/**************************************************************************/
void Adafruit_SPITFT::drawRGBBitmap(int16_t x, int16_t y,
uint16_t *pcolors, int16_t w, int16_t h) {

View File

@ -20,6 +20,7 @@ typedef volatile uint32_t RwReg;
#define USE_FAST_PINIO
/// A heavily optimized SPI display subclass of GFX. Manages SPI bitbanging, transactions, DMA, etc! Despite being called SPITFT, the classic SPI data/command interface is also used by OLEDs.
class Adafruit_SPITFT : public Adafruit_GFX {
protected:
@ -27,7 +28,7 @@ class Adafruit_SPITFT : public Adafruit_GFX {
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST = -1, int8_t _MISO = -1);
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _RST = -1);
virtual void begin(uint32_t freq) = 0;
virtual void begin(uint32_t freq) = 0; ///< Virtual begin() function to set SPI frequency, must be overridden in subclass. @param freq Maximum SPI hardware clock speed
void initSPI(uint32_t freq);
// Required Non-Transaction
@ -61,25 +62,42 @@ class Adafruit_SPITFT : public Adafruit_GFX {
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
protected:
uint32_t _freq;
uint32_t _freq; ///< SPI clock frequency (for hardware SPI)
#if defined (__AVR__) || defined(TEENSYDUINO) || defined (ESP8266) || defined (ESP32)
int8_t _cs, _dc, _rst, _sclk, _mosi, _miso;
#else
int32_t _cs, _dc, _rst, _sclk, _mosi, _miso;
int32_t _cs, ///< Arduino pin # for chip-select pin
_dc, ///< Arduino pin # for data-command pin
_rst, ///< Arduino pin # for reset pin
_sclk, ///< Arduino pin # for SPI clock pin
_mosi, ///< Arduino pin # for SPI MOSI pin
_miso; ///< Arduino pin # for SPI MISO pin
#endif
#ifdef USE_FAST_PINIO
volatile RwReg *mosiport, *misoport, *clkport, *dcport, *csport;
RwReg mosipinmask, misopinmask, clkpinmask, cspinmask, dcpinmask;
volatile RwReg *mosiport, ///< Direct chip register for toggling MOSI with fast bitbang IO
*misoport, ///< Direct chip register for toggling MISO with fast bitbang IO
*clkport, ///< Direct chip register for toggling CLK with fast bitbang IO
*dcport, ///< Direct chip register for toggling DC with fast bitbang IO
*csport; ///< Direct chip register for toggling CS with fast bitbang IO
RwReg mosipinmask, ///< bitmask for turning on/off MOSI with fast register bitbang IO
misopinmask, ///< bitmask for turning on/off MISO with fast register bitbang IO
clkpinmask, ///< bitmask for turning on/off CLK with fast register bitbang IO
cspinmask, ///< bitmask for turning on/off CS with fast register bitbang IO
dcpinmask; ///< bitmask for turning on/off DC with fast register bitbang IO
#endif
void writeCommand(uint8_t cmd);
void spiWrite(uint8_t v);
uint8_t spiRead(void);
uint8_t invertOnCommand = 0, invertOffCommand = 0;
uint8_t ySetCommand, xSetCommand, RAMwriteCommand;
int16_t _xstart = 0, _ystart = 0;
uint8_t invertOnCommand = 0, ///< SPI command byte to turn on invert
invertOffCommand = 0; ///< SPI command byte to turn off invert
uint8_t ySetCommand, ///< SPI command byte to set the Y address window
xSetCommand, ///< SPI command byte to set the X address window
RAMwriteCommand; ///< SPI command byte to start blitting data to framebuffer RAM
int16_t _xstart = 0; ///< Many displays don't have pixels starting at (0,0) of the internal framebuffer, this is the x offset from 0 to align
int16_t _ystart = 0; ///< Many displays don't have pixels starting at (0,0) of the internal framebuffer, this is the y offset from 0 to align
};
#endif

View File

@ -8,7 +8,7 @@ Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information.
All text above must be included in any redistribution.
Recent Arduino IDE releases include the Library Manager for easy installation. Otherwise, to download, click the DOWNLOAD ZIP button, uncompress and rename the uncompressed folder Adafruit_GFX. Confirm that the Adafruit_GFX folder contains Adafruit_GFX.cpp and Adafruit_GFX.h. Place the Adafruit_GFX library folder your <arduinosketchfolder>/Libraries/ folder. You may need to create the Libraries subfolder if its your first library. Restart the IDE.
Recent Arduino IDE releases include the Library Manager for easy installation. Otherwise, to download, click the DOWNLOAD ZIP button, uncompress and rename the uncompressed folder Adafruit_GFX. Confirm that the Adafruit_GFX folder contains Adafruit_GFX.cpp and Adafruit_GFX.h. Place the Adafruit_GFX library folder your ArduinoSketchFolder/Libraries/ folder. You may need to create the Libraries subfolder if its your first library. Restart the IDE.
# Useful Resources
@ -16,9 +16,9 @@ Recent Arduino IDE releases include the Library Manager for easy installation. O
- drawXBitmap function: You can use the GIMP photo editor to save a .xbm file and use the array saved in the file to draw a bitmap with the drawXBitmap function. See the pull request here for more details: https://github.com/adafruit/Adafruit-GFX-Library/pull/31
- 'Fonts' folder contains bitmap fonts for use with recent (1.1 and later) Adafruit_GFX. To use a font in your Arduino sketch, #include the corresponding .h file and pass address of GFXfont struct to setFont(). Pass NULL to revert to 'classic' fixed-space bitmap font.
- 'Fonts' folder contains bitmap fonts for use with recent (1.1 and later) Adafruit_GFX. To use a font in your Arduino sketch, \#include the corresponding .h file and pass address of GFXfont struct to setFont(). Pass NULL to revert to 'classic' fixed-space bitmap font.
- 'fontconvert' folder contains a command-line tool for converting TTF fonts to Adafruit_GFX .h format.
- 'fontconvert' folder contains a command-line tool for converting TTF fonts to Adafruit_GFX header format.
---

View File

@ -7,7 +7,8 @@
#ifndef _GFXFONT_H_
#define _GFXFONT_H_
typedef struct { // Data stored PER GLYPH
/// Font data stored PER GLYPH
typedef struct {
uint16_t bitmapOffset; ///< Pointer into GFXfont->bitmap
uint8_t width; ///< Bitmap dimensions in pixels
uint8_t height; ///< Bitmap dimensions in pixels
@ -16,7 +17,8 @@ typedef struct { // Data stored PER GLYPH
int8_t yOffset; ///< Y dist from cursor pos to UL corner
} GFXglyph;
typedef struct { // Data stored for FONT AS A WHOLE:
/// Data stored for FONT AS A WHOLE
typedef struct {
uint8_t *bitmap; ///< Glyph bitmaps, concatenated
GFXglyph *glyph; ///< Glyph array
uint8_t first; ///< ASCII extents (first char)