diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Adafruit_GFX_AS.cpp b/STM32F1/libraries/Adafruit_GFX_Extended/Adafruit_GFX.cpp similarity index 89% rename from STM32F1/libraries/Adafruit_GFX_AS/Adafruit_GFX_AS.cpp rename to STM32F1/libraries/Adafruit_GFX_Extended/Adafruit_GFX.cpp index 2c669e5..93e9090 100644 --- a/STM32F1/libraries/Adafruit_GFX_AS/Adafruit_GFX_AS.cpp +++ b/STM32F1/libraries/Adafruit_GFX_Extended/Adafruit_GFX.cpp @@ -31,7 +31,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "Adafruit_GFX_AS.h" +#include "Adafruit_GFX.h" #ifdef LOAD_GLCD #include "glcdfont.c" @@ -59,7 +59,7 @@ POSSIBILITY OF SUCH DAMAGE. #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #endif -Adafruit_GFX_AS::Adafruit_GFX_AS(int16_t w, int16_t h): +Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h): WIDTH(w), HEIGHT(h) { _width = WIDTH; @@ -72,7 +72,7 @@ Adafruit_GFX_AS::Adafruit_GFX_AS(int16_t w, int16_t h): } // Draw a circle outline -void Adafruit_GFX_AS::drawCircle(int16_t x0, int16_t y0, int16_t r, +void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) { int16_t f = 1 - r; int16_t ddF_x = 1; @@ -106,7 +106,7 @@ void Adafruit_GFX_AS::drawCircle(int16_t x0, int16_t y0, int16_t r, } } -void Adafruit_GFX_AS::drawCircleHelper( int16_t x0, int16_t y0, +void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color) { int16_t f = 1 - r; int16_t ddF_x = 1; @@ -142,14 +142,14 @@ void Adafruit_GFX_AS::drawCircleHelper( int16_t x0, int16_t y0, } } -void Adafruit_GFX_AS::fillCircle(int16_t x0, int16_t y0, int16_t r, +void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color) { drawFastVLine(x0, y0-r, 2*r+1, color); fillCircleHelper(x0, y0, r, 3, 0, color); } // Used to do circles and roundrects -void Adafruit_GFX_AS::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, +void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color) { int16_t f = 1 - r; @@ -180,7 +180,7 @@ void Adafruit_GFX_AS::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, } // Bresenham's algorithm - thx wikpedia -void Adafruit_GFX_AS::drawLine(int16_t x0, int16_t y0, +void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) { int16_t steep = abs(y1 - y0) > abs(x1 - x0); @@ -222,7 +222,7 @@ void Adafruit_GFX_AS::drawLine(int16_t x0, int16_t y0, } // Draw a rectangle -void Adafruit_GFX_AS::drawRect(int16_t x, int16_t y, +void Adafruit_GFX::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { drawFastHLine(x, y, w, color); @@ -231,19 +231,19 @@ void Adafruit_GFX_AS::drawRect(int16_t x, int16_t y, drawFastVLine(x+w-1, y, h, color); } -void Adafruit_GFX_AS::drawFastVLine(int16_t x, int16_t y, +void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { // Update in subclasses if desired! drawLine(x, y, x, y+h-1, color); } -void Adafruit_GFX_AS::drawFastHLine(int16_t x, int16_t y, +void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { // Update in subclasses if desired! drawLine(x, y, x+w-1, y, color); } -void Adafruit_GFX_AS::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, +void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { // Update in subclasses if desired! for (int16_t i=x; i= 100 -size_t Adafruit_GFX_AS::write(uint8_t c) { +size_t Adafruit_GFX::write(uint8_t c) { //#else -//void Adafruit_GFX_AS::write(uint8_t c) { +//void Adafruit_GFX::write(uint8_t c) { //#endif if (c == '\n') { cursor_y += textsize*8; @@ -407,7 +407,7 @@ size_t Adafruit_GFX_AS::write(uint8_t c) { } // Draw a character -void Adafruit_GFX_AS::drawChar(int16_t x, int16_t y, unsigned char c, +void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size) { #ifdef LOAD_GLCD if((x >= _width) || // Clip right @@ -442,35 +442,35 @@ void Adafruit_GFX_AS::drawChar(int16_t x, int16_t y, unsigned char c, #endif } -void Adafruit_GFX_AS::setCursor(int16_t x, int16_t y) { +void Adafruit_GFX::setCursor(int16_t x, int16_t y) { cursor_x = x; cursor_y = y; } -void Adafruit_GFX_AS::setTextSize(uint8_t s) { +void Adafruit_GFX::setTextSize(uint8_t s) { textsize = (s > 0) ? s : 1; } -void Adafruit_GFX_AS::setTextColor(uint16_t c) { +void Adafruit_GFX::setTextColor(uint16_t c) { // For 'transparent' background, we'll set the bg // to the same as fg instead of using a flag textcolor = textbgcolor = c; } -void Adafruit_GFX_AS::setTextColor(uint16_t c, uint16_t b) { +void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; } -void Adafruit_GFX_AS::setTextWrap(boolean w) { +void Adafruit_GFX::setTextWrap(boolean w) { wrap = w; } -uint8_t Adafruit_GFX_AS::getRotation(void) { +uint8_t Adafruit_GFX::getRotation(void) { return rotation; } -void Adafruit_GFX_AS::setRotation(uint8_t x) { +void Adafruit_GFX::setRotation(uint8_t x) { rotation = (x & 3); switch(rotation) { case 0: @@ -487,15 +487,15 @@ void Adafruit_GFX_AS::setRotation(uint8_t x) { } // Return the size of the display (per current rotation) -int16_t Adafruit_GFX_AS::width(void) { +int16_t Adafruit_GFX::width(void) { return _width; } -int16_t Adafruit_GFX_AS::height(void) { +int16_t Adafruit_GFX::height(void) { return _height; } -void Adafruit_GFX_AS::invertDisplay(boolean i) { +void Adafruit_GFX::invertDisplay(boolean i) { // Do nothing, must be subclassed if supported } @@ -503,7 +503,7 @@ void Adafruit_GFX_AS::invertDisplay(boolean i) { ** Function name: drawUnicode ** Descriptions: draw a unicode ***************************************************************************************/ -int16_t Adafruit_GFX_AS::drawUnicode(uint16_t uniCode, int16_t x, int16_t y, int16_t size) +int16_t Adafruit_GFX::drawUnicode(uint16_t uniCode, int16_t x, int16_t y, int16_t size) { if (size) uniCode -= 32; @@ -615,7 +615,7 @@ return (width+gap)*textsize; // x + ** Function name: drawNumber unsigned with size ** Descriptions: drawNumber ***************************************************************************************/ -int16_t Adafruit_GFX_AS::drawNumber(long long_num,int16_t poX, int16_t poY, int16_t size) +int16_t Adafruit_GFX::drawNumber(long long_num,int16_t poX, int16_t poY, int16_t size) { char tmp[10]; if (long_num < 0) sprintf(tmp, "%li", long_num); @@ -627,7 +627,7 @@ int16_t Adafruit_GFX_AS::drawNumber(long long_num,int16_t poX, int16_t poY, int1 ** Function name: drawChar ** Descriptions: draw char ***************************************************************************************/ -int16_t Adafruit_GFX_AS::drawChar(char c, int16_t x, int16_t y, int16_t size) +int16_t Adafruit_GFX::drawChar(char c, int16_t x, int16_t y, int16_t size) { return drawUnicode(c, x, y, size); } @@ -636,7 +636,7 @@ int16_t Adafruit_GFX_AS::drawChar(char c, int16_t x, int16_t y, int16_t size) ** Function name: drawString ** Descriptions: draw string ***************************************************************************************/ -int16_t Adafruit_GFX_AS::drawString(char *string, int16_t poX, int16_t poY, int16_t size) +int16_t Adafruit_GFX::drawString(char *string, int16_t poX, int16_t poY, int16_t size) { int16_t sumX = 0; @@ -654,7 +654,7 @@ int16_t Adafruit_GFX_AS::drawString(char *string, int16_t poX, int16_t poY, int1 ** Function name: drawCentreString ** Descriptions: draw string across centre ***************************************************************************************/ -int16_t Adafruit_GFX_AS::drawCentreString(char *string, int16_t dX, int16_t poY, int16_t size) +int16_t Adafruit_GFX::drawCentreString(char *string, int16_t dX, int16_t poY, int16_t size) { int16_t sumX = 0; int16_t len = 0; @@ -703,7 +703,7 @@ int16_t Adafruit_GFX_AS::drawCentreString(char *string, int16_t dX, int16_t poY, ** Function name: drawRightString ** Descriptions: draw string right justified ***************************************************************************************/ -int16_t Adafruit_GFX_AS::drawRightString(char *string, int16_t dX, int16_t poY, int16_t size) +int16_t Adafruit_GFX::drawRightString(char *string, int16_t dX, int16_t poY, int16_t size) { int16_t sumX = 0; int16_t len = 0; @@ -754,7 +754,7 @@ int16_t Adafruit_GFX_AS::drawRightString(char *string, int16_t dX, int16_t poY, ** Function name: drawFloat ** Descriptions: drawFloat ***************************************************************************************/ -int16_t Adafruit_GFX_AS::drawFloat(float floatNumber, int16_t decimal, int16_t poX, int16_t poY, int16_t size) +int16_t Adafruit_GFX::drawFloat(float floatNumber, int16_t decimal, int16_t poX, int16_t poY, int16_t size) { unsigned long temp=0; float decy=0.0; diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Adafruit_GFX_AS.h b/STM32F1/libraries/Adafruit_GFX_Extended/Adafruit_GFX.h similarity index 92% rename from STM32F1/libraries/Adafruit_GFX_AS/Adafruit_GFX_AS.h rename to STM32F1/libraries/Adafruit_GFX_Extended/Adafruit_GFX.h index 42c9919..974c47c 100644 --- a/STM32F1/libraries/Adafruit_GFX_AS/Adafruit_GFX_AS.h +++ b/STM32F1/libraries/Adafruit_GFX_Extended/Adafruit_GFX.h @@ -1,5 +1,5 @@ -#ifndef _ADAFRUIT_GFX_AS_H -#define _ADAFRUIT_GFX_AS_H +#ifndef _ADAFRUIT_GFX_H +#define _ADAFRUIT_GFX_H #include "Load_fonts.h" @@ -12,11 +12,11 @@ #define swap(a, b) { int16_t t = a; a = b; b = t; } -class Adafruit_GFX_AS : public Print { +class Adafruit_GFX : public Print { public: - Adafruit_GFX_AS(int16_t w, int16_t h); // Constructor + 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; @@ -32,7 +32,7 @@ class Adafruit_GFX_AS : public Print { fillScreen(uint16_t color), invertDisplay(boolean i); - // These exist only with Adafruit_GFX_AS (no subclass overrides) + // These exist only with Adafruit_GFX (no subclass overrides) void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color), drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, @@ -94,4 +94,4 @@ class Adafruit_GFX_AS : public Print { wrap; // If set, 'wrap' text at right edge of display }; -#endif // _ADAFRUIT_GFX_AS_H +#endif // _ADAFRUIT_GFX_H diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Font16.c b/STM32F1/libraries/Adafruit_GFX_Extended/Font16.c similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/Font16.c rename to STM32F1/libraries/Adafruit_GFX_Extended/Font16.c diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Font16.h b/STM32F1/libraries/Adafruit_GFX_Extended/Font16.h similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/Font16.h rename to STM32F1/libraries/Adafruit_GFX_Extended/Font16.h diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Font32.c b/STM32F1/libraries/Adafruit_GFX_Extended/Font32.c similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/Font32.c rename to STM32F1/libraries/Adafruit_GFX_Extended/Font32.c diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Font32.h b/STM32F1/libraries/Adafruit_GFX_Extended/Font32.h similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/Font32.h rename to STM32F1/libraries/Adafruit_GFX_Extended/Font32.h diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Font64.c b/STM32F1/libraries/Adafruit_GFX_Extended/Font64.c similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/Font64.c rename to STM32F1/libraries/Adafruit_GFX_Extended/Font64.c diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Font64.h b/STM32F1/libraries/Adafruit_GFX_Extended/Font64.h similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/Font64.h rename to STM32F1/libraries/Adafruit_GFX_Extended/Font64.h diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Font7s.c b/STM32F1/libraries/Adafruit_GFX_Extended/Font7s.c similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/Font7s.c rename to STM32F1/libraries/Adafruit_GFX_Extended/Font7s.c diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Font7s.h b/STM32F1/libraries/Adafruit_GFX_Extended/Font7s.h similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/Font7s.h rename to STM32F1/libraries/Adafruit_GFX_Extended/Font7s.h diff --git a/STM32F1/libraries/Adafruit_GFX_AS/Load_fonts.h b/STM32F1/libraries/Adafruit_GFX_Extended/Load_fonts.h similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/Load_fonts.h rename to STM32F1/libraries/Adafruit_GFX_Extended/Load_fonts.h diff --git a/STM32F1/libraries/Adafruit_GFX_AS/README.txt b/STM32F1/libraries/Adafruit_GFX_Extended/README.txt similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/README.txt rename to STM32F1/libraries/Adafruit_GFX_Extended/README.txt diff --git a/STM32F1/libraries/Adafruit_GFX_AS/glcdfont.c b/STM32F1/libraries/Adafruit_GFX_Extended/glcdfont.c similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/glcdfont.c rename to STM32F1/libraries/Adafruit_GFX_Extended/glcdfont.c diff --git a/STM32F1/libraries/Adafruit_GFX_AS/license.txt b/STM32F1/libraries/Adafruit_GFX_Extended/license.txt similarity index 100% rename from STM32F1/libraries/Adafruit_GFX_AS/license.txt rename to STM32F1/libraries/Adafruit_GFX_Extended/license.txt diff --git a/STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.cpp b/STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.cpp index 2f6e1c7..261dd20 100644 --- a/STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.cpp +++ b/STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.cpp @@ -1,28 +1,20 @@ -/*************************************************** - This is our library for the Adafruit ILI9341 Breakout and Shield - ----> http://www.adafruit.com/products/1651 - - Check out the links above for our tutorials and wiring diagrams - 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! - - Written by Limor Fried/Ladyada for Adafruit Industries. - MIT license, all text above must be included in any redistribution - ****************************************************/ - +/* +See rights and use declaration in License.h +This library has been modified for the Maple Mini +*/ #include "Adafruit_ILI9341.h" #include #include +#include #include "pins_arduino.h" #include "wiring_private.h" -#include +#include // Using library SPI in folder: D:\Documents\Arduino\hardware\STM32\STM32F1XX\libraries\SPI + +volatile bool dma1_ch3_Active = false; // Constructor when using software SPI. All output pins are configurable. Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t mosi, - int8_t sclk, int8_t rst, int8_t miso) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) { + int8_t sclk, int8_t rst, int8_t miso) : Adafruit_GFX(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT) { _cs = cs; _dc = dc; _mosi = mosi; @@ -43,36 +35,43 @@ Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst) : Adafruit_ _mosi = _sclk = 0; } +inline void DMA1_CH3_Event() { + dma1_ch3_Active = 0; + dma_disable(DMA1, DMA_CH3); +} + void Adafruit_ILI9341::spiwrite(uint8_t c) { //Serial.print("0x"); Serial.print(c, HEX); Serial.print(", "); - if (hwSPI) { + if (hwSPI) + { #if defined (__AVR__) - uint8_t backupSPCR = SPCR; + uint8_t backupSPCR = SPCR; SPCR = mySPCR; SPDR = c; - while(!(SPSR & _BV(SPIF))); + while (!(SPSR & _BV(SPIF))); SPCR = backupSPCR; #elif defined(TEENSYDUINO) SPI.transfer(c); #elif defined (__STM32F1__) - SPI.write(c);// Faster than transfer as we don't need to read + SPI.transfer(c); #elif defined (__arm__) SPI.setClockDivider(11); // 8-ish MHz (full! speed!) SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); SPI.transfer(c); + #endif } else { // Fast SPI bitbang swiped from LPD8806 library - for(uint8_t bit = 0x80; bit; bit >>= 1) { - if(c & bit) { - //digitalWrite(_mosi, HIGH); - *mosiport |= mosipinmask; + for (uint8_t bit = 0x80; bit; bit >>= 1) { + if (c & bit) { + //digitalWrite(_mosi, HIGH); + *mosiport |= mosipinmask; } else { - //digitalWrite(_mosi, LOW); - *mosiport &= ~mosipinmask; + //digitalWrite(_mosi, LOW); + *mosiport &= ~mosipinmask; } //digitalWrite(_sclk, HIGH); *clkport |= clkpinmask; @@ -85,18 +84,32 @@ void Adafruit_ILI9341::spiwrite(uint8_t c) { void Adafruit_ILI9341::writecommand(uint8_t c) { *dcport &= ~dcpinmask; + //digitalWrite(_dc, LOW); + //*clkport &= ~clkpinmask; // clkport is a NULL pointer when hwSPI==true + //digitalWrite(_sclk, LOW); *csport &= ~cspinmask; - SPI.write(c); + //digitalWrite(_cs, LOW); + + spiwrite(c); + *csport |= cspinmask; + //digitalWrite(_cs, HIGH); } void Adafruit_ILI9341::writedata(uint8_t c) { *dcport |= dcpinmask; + //digitalWrite(_dc, HIGH); + //*clkport &= ~clkpinmask; // clkport is a NULL pointer when hwSPI==true + //digitalWrite(_sclk, LOW); *csport &= ~cspinmask; - SPI.write(c); + //digitalWrite(_cs, LOW); + + spiwrite(c); + + //digitalWrite(_cs, HIGH); *csport |= cspinmask; -} +} // If the SPI library has transaction support, these functions // establish settings and protect from interference from other @@ -130,29 +143,22 @@ void Adafruit_ILI9341::commandList(uint8_t *addr) { uint8_t numCommands, numArgs; uint16_t ms; - *dcport |= dcpinmask; - *csport &= ~cspinmask; - - - - numCommands = pgm_read_byte(addr++); // Number of commands to follow - while(numCommands--) { // For each command... + while (numCommands--) { // For each command... writecommand(pgm_read_byte(addr++)); // Read, issue command numArgs = pgm_read_byte(addr++); // Number of args to follow ms = numArgs & DELAY; // If hibit set, delay follows args numArgs &= ~DELAY; // Mask out delay bit - while(numArgs--) { // For each argument... - SPI.write(pgm_read_byte(addr++)); // Read, issue argument + while (numArgs--) { // For each argument... + writedata(pgm_read_byte(addr++)); // Read, issue argument } - if(ms) { + if (ms) { ms = pgm_read_byte(addr++); // Read post-command delay time (ms) - if(ms == 255) ms = 500; // If 255, delay for 500 ms + if (ms == 255) ms = 500; // If 255, delay for 500 ms delay(ms); } } - *csport |= cspinmask; } @@ -169,23 +175,36 @@ void Adafruit_ILI9341::begin(void) { dcport = portOutputRegister(digitalPinToPort(_dc)); dcpinmask = digitalPinToBitMask(_dc); - if(hwSPI) { // Using hardware SPI + if (hwSPI) { // Using hardware SPI #if defined (__AVR__) SPI.begin(); SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!) SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); mySPCR = SPCR; -#elif defined(TEENSYDUINO) || defined (__STM32F1__) +#elif defined(TEENSYDUINO) SPI.begin(); SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (full! speed!) SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); +#elif defined (__STM32F1__) + SPI.begin(); + SPI.setClockDivider(SPI_CLOCK_DIV2); + SPI.setBitOrder(MSBFIRST); + SPI.setDataMode(SPI_MODE0); + // DMA setup stuff. We use a line buffer and usa DMA for filling lines and blocks. + spi_tx_dma_enable(SPI1); + dma_init(DMA1); + dma_attach_interrupt(DMA1, DMA_CH3, DMA1_CH3_Event); + dma_setup_transfer(DMA1, DMA_CH3, &SPI1->regs->DR, DMA_SIZE_8BITS, + lineBuffer, DMA_SIZE_8BITS, (DMA_MINC_MODE | DMA_FROM_MEM | DMA_TRNS_CMPLT)); + + #elif defined (__arm__) - SPI.begin(); - SPI.setClockDivider(11); // 8-ish MHz (full! speed!) - SPI.setBitOrder(MSBFIRST); - SPI.setDataMode(SPI_MODE0); + SPI.begin(); + SPI.setClockDivider(11); // 8-ish MHz (full! speed!) + SPI.setBitOrder(MSBFIRST); + SPI.setDataMode(SPI_MODE0); #endif } else { pinMode(_sclk, OUTPUT); @@ -209,139 +228,148 @@ void Adafruit_ILI9341::begin(void) { delay(150); } - + /* + uint8_t x = readcommand8(ILI9341_RDMODE); + Serial.print("\nDisplay Power Mode: 0x"); Serial.println(x, HEX); + x = readcommand8(ILI9341_RDMADCTL); + Serial.print("\nMADCTL Mode: 0x"); Serial.println(x, HEX); + x = readcommand8(ILI9341_RDPIXFMT); + Serial.print("\nPixel Format: 0x"); Serial.println(x, HEX); + x = readcommand8(ILI9341_RDIMGFMT); + Serial.print("\nImage Format: 0x"); Serial.println(x, HEX); + x = readcommand8(ILI9341_RDSELFDIAG); + Serial.print("\nSelf Diagnostic: 0x"); Serial.println(x, HEX); + */ + //if(cmdList) commandList(cmdList); + if (hwSPI) spi_begin(); writecommand(0xEF); writedata(0x03); writedata(0x80); writedata(0x02); - writecommand(0xCF); - writedata(0x00); - writedata(0XC1); - writedata(0X30); + writecommand(0xCF); + writedata(0x00); + writedata(0XC1); + writedata(0X30); - writecommand(0xED); - writedata(0x64); - writedata(0x03); - writedata(0X12); - writedata(0X81); - - writecommand(0xE8); - writedata(0x85); - writedata(0x00); - writedata(0x78); + writecommand(0xED); + writedata(0x64); + writedata(0x03); + writedata(0X12); + writedata(0X81); - writecommand(0xCB); - writedata(0x39); - writedata(0x2C); - writedata(0x00); - writedata(0x34); - writedata(0x02); - - writecommand(0xF7); - writedata(0x20); + writecommand(0xE8); + writedata(0x85); + writedata(0x00); + writedata(0x78); - writecommand(0xEA); - writedata(0x00); - writedata(0x00); - - writecommand(ILI9341_PWCTR1); //Power control - writedata(0x23); //VRH[5:0] - - writecommand(ILI9341_PWCTR2); //Power control - writedata(0x10); //SAP[2:0];BT[3:0] - - writecommand(ILI9341_VMCTR1); //VCM control - writedata(0x3e); //对比度调节 - writedata(0x28); - - writecommand(ILI9341_VMCTR2); //VCM control2 + writecommand(0xCB); + writedata(0x39); + writedata(0x2C); + writedata(0x00); + writedata(0x34); + writedata(0x02); + + writecommand(0xF7); + writedata(0x20); + + writecommand(0xEA); + writedata(0x00); + writedata(0x00); + + writecommand(ILI9341_PWCTR1); //Power control + writedata(0x23); //VRH[5:0] + + writecommand(ILI9341_PWCTR2); //Power control + writedata(0x10); //SAP[2:0];BT[3:0] + + writecommand(ILI9341_VMCTR1); //VCM control + writedata(0x3e); //锟皆比度碉拷锟斤拷 + writedata(0x28); + + writecommand(ILI9341_VMCTR2); //VCM control2 writedata(0x86); //-- - - writecommand(ILI9341_MADCTL); // Memory Access Control + + writecommand(ILI9341_MADCTL); // Memory Access Control writedata(0x48); - writecommand(ILI9341_PIXFMT); - writedata(0x55); - - writecommand(ILI9341_FRMCTR1); - writedata(0x00); - writedata(0x18); - - writecommand(ILI9341_DFUNCTR); // Display Function Control - writedata(0x08); - writedata(0x82); - writedata(0x27); - - writecommand(0xF2); // 3Gamma Function Disable - writedata(0x00); - - writecommand(ILI9341_GAMMASET); //Gamma curve selected - writedata(0x01); - - writecommand(ILI9341_GMCTRP1); //Set Gamma - writedata(0x0F); - writedata(0x31); - writedata(0x2B); - writedata(0x0C); - writedata(0x0E); - writedata(0x08); - writedata(0x4E); - writedata(0xF1); - writedata(0x37); - writedata(0x07); - writedata(0x10); - writedata(0x03); - writedata(0x0E); - writedata(0x09); - writedata(0x00); - - writecommand(ILI9341_GMCTRN1); //Set Gamma - writedata(0x00); - writedata(0x0E); - writedata(0x14); - writedata(0x03); - writedata(0x11); - writedata(0x07); - writedata(0x31); - writedata(0xC1); - writedata(0x48); - writedata(0x08); - writedata(0x0F); - writedata(0x0C); - writedata(0x31); - writedata(0x36); - writedata(0x0F); + writecommand(ILI9341_PIXFMT); + writedata(0x55); - writecommand(ILI9341_SLPOUT); //Exit Sleep + writecommand(ILI9341_FRMCTR1); + writedata(0x00); + writedata(0x18); + + writecommand(ILI9341_DFUNCTR); // Display Function Control + writedata(0x08); + writedata(0x82); + writedata(0x27); + + writecommand(0xF2); // 3Gamma Function Disable + writedata(0x00); + + writecommand(ILI9341_GAMMASET); //Gamma curve selected + writedata(0x01); + + writecommand(ILI9341_GMCTRP1); //Set Gamma + writedata(0x0F); + writedata(0x31); + writedata(0x2B); + writedata(0x0C); + writedata(0x0E); + writedata(0x08); + writedata(0x4E); + writedata(0xF1); + writedata(0x37); + writedata(0x07); + writedata(0x10); + writedata(0x03); + writedata(0x0E); + writedata(0x09); + writedata(0x00); + + writecommand(ILI9341_GMCTRN1); //Set Gamma + writedata(0x00); + writedata(0x0E); + writedata(0x14); + writedata(0x03); + writedata(0x11); + writedata(0x07); + writedata(0x31); + writedata(0xC1); + writedata(0x48); + writedata(0x08); + writedata(0x0F); + writedata(0x0C); + writedata(0x31); + writedata(0x36); + writedata(0x0F); + + writecommand(ILI9341_SLPOUT); //Exit Sleep if (hwSPI) spi_end(); - delay(120); + delay(120); if (hwSPI) spi_begin(); - writecommand(ILI9341_DISPON); //Display on + writecommand(ILI9341_DISPON); //Display on if (hwSPI) spi_end(); } void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, - uint16_t y1) { + uint16_t y1) { writecommand(ILI9341_CASET); // Column addr set - *dcport |= dcpinmask; - *csport &= ~cspinmask; - SPI.write(x0 >> 8); - SPI.write(x0 & 0xFF); // XSTART - SPI.write(x1 >> 8); - SPI.write(x1 & 0xFF); // XEND + writedata(x0 >> 8); + writedata(x0 & 0xFF); // XSTART + writedata(x1 >> 8); + writedata(x1 & 0xFF); // XEND writecommand(ILI9341_PASET); // Row addr set - *dcport |= dcpinmask; - *csport &= ~cspinmask; - SPI.write(y0>>8); - SPI.write(y0); // YSTART - SPI.write(y1>>8); - SPI.write(y1); // YEND + writedata(y0 >> 8); + writedata(y0); // YSTART + writedata(y1 >> 8); + writedata(y1); // YEND writecommand(ILI9341_RAMWR); // write to RAM } @@ -349,13 +377,13 @@ void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, void Adafruit_ILI9341::pushColor(uint16_t color) { if (hwSPI) spi_begin(); - + //digitalWrite(_dc, HIGH); *dcport |= dcpinmask; - + //digitalWrite(_cs, LOW); *csport &= ~cspinmask; - SPI.write(color >> 8); - SPI.write(color); + spiwrite(color >> 8); + spiwrite(color); *csport |= cspinmask; //digitalWrite(_cs, HIGH); @@ -364,67 +392,102 @@ void Adafruit_ILI9341::pushColor(uint16_t color) { void Adafruit_ILI9341::drawPixel(int16_t x, int16_t y, uint16_t color) { - if((x < 0) ||(x >= _width) || (y < 0) || (y >= _height)) return; + if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) return; if (hwSPI) spi_begin(); - setAddrWindow(x,y,x+1,y+1); + setAddrWindow(x, y, x + 1, y + 1); + //digitalWrite(_dc, HIGH); *dcport |= dcpinmask; + //digitalWrite(_cs, LOW); *csport &= ~cspinmask; - SPI.write(color >> 8); - SPI.write(color); + spiwrite(color >> 8); + spiwrite(color); *csport |= cspinmask; + //digitalWrite(_cs, HIGH); if (hwSPI) spi_end(); } void Adafruit_ILI9341::drawFastVLine(int16_t x, int16_t y, int16_t h, - uint16_t color) { + uint16_t color) { // Rudimentary clipping - if((x >= _width) || (y >= _height)) return; + if ((x >= _width) || (y >= _height || h < 1)) return; + + if ((y + h - 1) >= _height) + h = _height - y; + + // if (hwSPI) spi_begin(); + setAddrWindow(x, y, x, y + h - 1); - if((y+h-1) >= _height) - { - h = _height-y; - } - - if (hwSPI) spi_begin(); - setAddrWindow(x, y, x, y+h-1); uint8_t hi = color >> 8, lo = color; + *dcport |= dcpinmask; + //digitalWrite(_dc, HIGH); *csport &= ~cspinmask; - - while (h--) + //digitalWrite(_cs, LOW); + +#if defined (__STM32F1__) + for (int i = 0; i < (h * 2) - 1 ; i = i + 2) { - SPI.write(hi); - SPI.write(lo); + lineBuffer[i] = hi; + lineBuffer[i + 1] = lo; } - *csport |= cspinmask; + dma_set_num_transfers(DMA1, DMA_CH3, h * 2); // 2 bytes per pixel + dma1_ch3_Active = true; + dma_enable(DMA1, DMA_CH3); + while (dma1_ch3_Active); - if (hwSPI) spi_end(); + #else + while (h--) { + spiwrite(hi); + spiwrite(lo); + } +#endif + *csport |= cspinmask; + //digitalWrite(_cs, HIGH); + // if (hwSPI) spi_end(); } void Adafruit_ILI9341::drawFastHLine(int16_t x, int16_t y, int16_t w, - uint16_t color) { + uint16_t color) { + // Rudimentary clipping - if((x >= _width) || (y >= _height)) return; - if((x+w-1) >= _width) w = _width-x; + if ((x >= _width) || (y >= _height || w < 1)) return; + if ((x + w - 1) >= _width) w = _width - x; if (hwSPI) spi_begin(); - setAddrWindow(x, y, x+w-1, y); + setAddrWindow(x, y, x + w - 1, y); uint8_t hi = color >> 8, lo = color; *dcport |= dcpinmask; *csport &= ~cspinmask; - while (w--) { - SPI.write(hi); - SPI.write(lo); + //digitalWrite(_dc, HIGH); + //digitalWrite(_cs, LOW); +#if defined (__STM32F1__) + + for (int i = 0; i < (w * 2) - 1 ; i = i + 2) + { + lineBuffer[i] = hi; + lineBuffer[i + 1] = lo; } + dma_set_num_transfers(DMA1, DMA_CH3, w * 2); // 2 bytes per pixel + dma1_ch3_Active = true; + dma_enable(DMA1, DMA_CH3); + while (dma1_ch3_Active) delayMicroseconds(1); + +#else + while (w--) { + spiwrite(hi); + spiwrite(lo); + } +#endif *csport |= cspinmask; + //digitalWrite(_cs, HIGH); if (hwSPI) spi_end(); } @@ -434,21 +497,42 @@ void Adafruit_ILI9341::fillScreen(uint16_t color) { // fill a rectangle void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, - uint16_t color) { - int numPixels; + uint16_t color) { + // rudimentary clipping (drawChar w/big text requires this) - if((x >= _width) || (y >= _height)) return; - if((x + w - 1) >= _width) w = _width - x; - if((y + h - 1) >= _height) h = _height - y; + if ((x >= _width) || (y >= _height || h < 1 || w < 1)) return; + if ((x + w - 1) >= _width) w = _width - x; + if ((y + h - 1) >= _height) h = _height - y; if (hwSPI) spi_begin(); - setAddrWindow(x, y, x+w-1, y+h-1); + setAddrWindow(x, y, x + w - 1, y + h - 1); uint8_t hi = color >> 8, lo = color; *dcport |= dcpinmask; + //digitalWrite(_dc, HIGH); *csport &= ~cspinmask; + //digitalWrite(_cs, LOW); +#if defined (__STM32F1__) + //moved this loop outside as we can fill the buffer once and send it multiple times. + for (int i = 0; i < (w * 2) - 1 ; i = i + 2) + { + lineBuffer[i] = hi; + lineBuffer[i + 1] = lo; + } + + for (y = h; y > 0; y--) { + // for(x=w; x>0; x--) { + // spiwrite(hi); + // spiwrite(lo); + // } + dma_set_num_transfers(DMA1, DMA_CH3, w * 2); // 2 bytes per pixel + dma1_ch3_Active = true; + dma_enable(DMA1, DMA_CH3); + while (dma1_ch3_Active) delayMicroseconds(1); + } +#else for(y=h; y>0; y--) { for(x=w; x>0; x--) @@ -457,9 +541,11 @@ void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, SPI.write(lo); } } - - if (hwSPI) spi_end(); +#endif + + //digitalWrite(_cs, HIGH); *csport |= cspinmask; + if (hwSPI) spi_end(); } @@ -483,26 +569,26 @@ void Adafruit_ILI9341::setRotation(uint8_t m) { writecommand(ILI9341_MADCTL); rotation = m % 4; // can't be higher than 3 switch (rotation) { - case 0: - writedata(MADCTL_MX | MADCTL_BGR); - _width = ILI9341_TFTWIDTH; - _height = ILI9341_TFTHEIGHT; - break; - case 1: - writedata(MADCTL_MV | MADCTL_BGR); - _width = ILI9341_TFTHEIGHT; - _height = ILI9341_TFTWIDTH; - break; - case 2: - writedata(MADCTL_MY | MADCTL_BGR); - _width = ILI9341_TFTWIDTH; - _height = ILI9341_TFTHEIGHT; - break; - case 3: - writedata(MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR); - _width = ILI9341_TFTHEIGHT; - _height = ILI9341_TFTWIDTH; - break; + case 0: + writedata(MADCTL_MX | MADCTL_BGR); + _width = ILI9341_TFTWIDTH; + _height = ILI9341_TFTHEIGHT; + break; + case 1: + writedata(MADCTL_MV | MADCTL_BGR); + _width = ILI9341_TFTHEIGHT; + _height = ILI9341_TFTWIDTH; + break; + case 2: + writedata(MADCTL_MY | MADCTL_BGR); + _width = ILI9341_TFTWIDTH; + _height = ILI9341_TFTHEIGHT; + break; + case 3: + writedata(MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR); + _width = ILI9341_TFTHEIGHT; + _height = ILI9341_TFTWIDTH; + break; } if (hwSPI) spi_end(); } @@ -526,10 +612,12 @@ uint8_t Adafruit_ILI9341::spiread(void) { uint8_t backupSPCR = SPCR; SPCR = mySPCR; SPDR = 0x00; - while(!(SPSR & _BV(SPIF))); + while (!(SPSR & _BV(SPIF))); r = SPDR; SPCR = backupSPCR; -#elif defined(TEENSYDUINO) || defined (__STM32F1__) +#elif defined(TEENSYDUINO) + r = SPI.transfer(0x00); +#elif defined (__STM32F1__) r = SPI.transfer(0x00); #elif defined (__arm__) SPI.setClockDivider(11); // 8-ish MHz (full! speed!) @@ -539,59 +627,59 @@ uint8_t Adafruit_ILI9341::spiread(void) { #endif } else { - for (uint8_t i=0; i<8; i++) { + for (uint8_t i = 0; i < 8; i++) { digitalWrite(_sclk, LOW); digitalWrite(_sclk, HIGH); r <<= 1; if (digitalRead(_miso)) - r |= 0x1; + r |= 0x1; } } //Serial.print("read: 0x"); Serial.print(r, HEX); - + return r; } - uint8_t Adafruit_ILI9341::readdata(void) { - digitalWrite(_dc, HIGH); - digitalWrite(_cs, LOW); - uint8_t r = spiread(); - digitalWrite(_cs, HIGH); - - return r; +uint8_t Adafruit_ILI9341::readdata(void) { + digitalWrite(_dc, HIGH); + digitalWrite(_cs, LOW); + uint8_t r = spiread(); + digitalWrite(_cs, HIGH); + + return r; } - + uint8_t Adafruit_ILI9341::readcommand8(uint8_t c, uint8_t index) { - if (hwSPI) spi_begin(); - digitalWrite(_dc, LOW); // command - digitalWrite(_cs, LOW); - SPI.write(0xD9); // woo sekret command? - digitalWrite(_dc, HIGH); // data - SPI.write(0x10 + index); - digitalWrite(_cs, HIGH); + if (hwSPI) spi_begin(); + digitalWrite(_dc, LOW); // command + digitalWrite(_cs, LOW); + spiwrite(0xD9); // woo sekret command? + digitalWrite(_dc, HIGH); // data + spiwrite(0x10 + index); + digitalWrite(_cs, HIGH); - digitalWrite(_dc, LOW); - digitalWrite(_sclk, LOW); - digitalWrite(_cs, LOW); - SPI.write(c); - - digitalWrite(_dc, HIGH); - uint8_t r = spiread(); - digitalWrite(_cs, HIGH); - if (hwSPI) spi_end(); - return r; + digitalWrite(_dc, LOW); + digitalWrite(_sclk, LOW); + digitalWrite(_cs, LOW); + spiwrite(c); + + digitalWrite(_dc, HIGH); + uint8_t r = spiread(); + digitalWrite(_cs, HIGH); + if (hwSPI) spi_end(); + return r; } - + /* uint16_t Adafruit_ILI9341::readcommand16(uint8_t c) { digitalWrite(_dc, LOW); if (_cs) digitalWrite(_cs, LOW); - + spiwrite(c); pinMode(_sid, INPUT); // input! uint16_t r = spiread(); @@ -599,21 +687,21 @@ uint8_t Adafruit_ILI9341::readcommand8(uint8_t c, uint8_t index) { r |= spiread(); if (_cs) digitalWrite(_cs, HIGH); - + pinMode(_sid, OUTPUT); // back to output return r; } - + uint32_t Adafruit_ILI9341::readcommand32(uint8_t c) { digitalWrite(_dc, LOW); if (_cs) digitalWrite(_cs, LOW); spiwrite(c); pinMode(_sid, INPUT); // input! - + dummyclock(); dummyclock(); - + uint32_t r = spiread(); r <<= 8; r |= spiread(); @@ -623,9 +711,9 @@ uint8_t Adafruit_ILI9341::readcommand8(uint8_t c, uint8_t index) { r |= spiread(); if (_cs) digitalWrite(_cs, HIGH); - + pinMode(_sid, OUTPUT); // back to output return r; } - + */ diff --git a/STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.h b/STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.h index 1ce359a..591612b 100644 --- a/STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.h +++ b/STM32F1/libraries/Adafruit_ILI9341/Adafruit_ILI9341.h @@ -1,31 +1,16 @@ -/*************************************************** - This is our library for the Adafruit ILI9341 Breakout and Shield - ----> http://www.adafruit.com/products/1651 - - Check out the links above for our tutorials and wiring diagrams - 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! - - Written by Limor Fried/Ladyada for Adafruit Industries. - MIT license, all text above must be included in any redistribution - ****************************************************/ +/* +See rights and use declaration in License.h +This library has been modified for the Maple Mini +*/ #ifndef _ADAFRUIT_ILI9341H_ #define _ADAFRUIT_ILI9341H_ -#if ARDUINO >= 100 - #include "Arduino.h" - #include "Print.h" -#else - #include "WProgram.h" -#endif -#include +#include "Arduino.h" +#include "Print.h" +#include "Adafruit_GFX.h" #include - #define ILI9341_TFTWIDTH 240 #define ILI9341_TFTHEIGHT 320 @@ -114,7 +99,7 @@ class Adafruit_ILI9341 : public Adafruit_GFX { Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST, int8_t _MISO); Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1); - + void begin(void), setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1), pushColor(uint16_t color), @@ -143,22 +128,23 @@ class Adafruit_ILI9341 : public Adafruit_GFX { commandList(uint8_t *addr); uint8_t spiread(void); + private: uint8_t tabcolor; +volatile byte lineBuffer[640]; boolean hwSPI; -#if defined (__STM32F1__) -#define RwReg uint32 -#endif - - #if defined (__AVR__) || defined(TEENSYDUINO) uint8_t mySPCR; volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport; int8_t _cs, _dc, _rst, _mosi, _miso, _sclk; uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask; +#elif defined (__STM32F1__) + volatile uint32 *mosiport, *clkport, *dcport, *rsport, *csport; + uint32_t _cs, _dc, _rst, _mosi, _miso, _sclk; + uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask; #elif defined (__arm__) volatile RwReg *mosiport, *clkport, *dcport, *rsport, *csport; uint32_t _cs, _dc, _rst, _mosi, _miso, _sclk; diff --git a/STM32F1/libraries/Adafruit_ILI9341/License.h b/STM32F1/libraries/Adafruit_ILI9341/License.h new file mode 100644 index 0000000..b7da6b9 --- /dev/null +++ b/STM32F1/libraries/Adafruit_ILI9341/License.h @@ -0,0 +1,99 @@ +// License.h +// All tab licenses are here +// This library was modified to support DMA in Maple Mini by Victor Perez in 03/17/2015 + +/*************************************************** + This is our GFX example for the Adafruit ILI9341 Breakout and Shield + ----> http://www.adafruit.com/products/1651 + Check out the links above for our tutorials and wiring diagrams + These displays use SPI to communicate, 4 or 5 pins are required to + interface (RST is optional) +/* +This is the core graphics library for all our displays, providing a common +set of graphics primitives (points, lines, circles, etc.). It needs to be +paired with a hardware-specific library for each display device we carry +(to handle the lower-level functions). + +Adafruit invests time and resources providing this open source code, please +support Adafruit & open-source hardware by purchasing products from Adafruit! + +Copyright (c) 2013 Adafruit Industries. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +/*************************************************** + This is our library for the Adafruit ILI9341 Breakout and Shield + ----> http://www.adafruit.com/products/1651 + + Check out the links above for our tutorials and wiring diagrams + 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! + + Written by Limor Fried/Ladyada for Adafruit Industries. + MIT license, all text above must be included in any redistribution + ****************************************************/ + +/* +Roughly based on Adafruit example sketch: "parsing" +Utilizes the (modified) Adafruit_GPS library https://github.com/adafruit/Adafruit-GPS-Library +20131204: GPS TimeDate with Temperature + Heavily mucked by M. Ray Burnette to simply use (most) any dumb serial TTL GPS for time-date + Tested with unit#28146 Parallax module @4800 BAUD http://www.abra-electronics.com/products/28146-Parallax-GPS-Receiver-Module.html + Tested with uBlox and external antenna @9600 BAUD http://www.ebay.com/itm/390647042336 + Tested with uBlox and internal antenna @9600 BAUD http://www.ebay.com/itm/181219728986 + +*/ +/* +SoftwareSerial.h (formerly NewSoftSerial.h) - +Multi-instance software serial library for Arduino/Wiring +-- Interrupt-driven receive and other improvements by ladyada + (http://ladyada.net) +-- Tuning, circular buffer, derivation from class Print/Stream, + multi-instance support, porting to 8MHz processors, + various optimizations, PROGMEM delay tables, inverse logic and + direct port writing by Mikal Hart (http://www.arduiniana.org) +-- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com) +-- 20MHz processor support by Garrett Mace (http://www.macetech.com) +-- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/) + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +The latest version of this library can always be found at +http://arduiniana.org. +*/ + diff --git a/STM32F1/libraries/Adafruit_ILI9341/README.txt b/STM32F1/libraries/Adafruit_ILI9341/README.txt index 58d2b57..6fa8ba8 100644 --- a/STM32F1/libraries/Adafruit_ILI9341/README.txt +++ b/STM32F1/libraries/Adafruit_ILI9341/README.txt @@ -1,19 +1,5 @@ -This library is based on the Adafruit ILI9341 (see original Adafuit text description below) - - -It has minor modifications to support STM32 and also one small change to use spi.write(byte) instead of spi.transfer(byte) as this gave -a useful speed improvement. - -It has been tested with standard ILI9341 from various suppliers e.g on eBay - -This library requires the Adafruit GFC library, https://github.com/adafruit/Adafruit-GFX-Library - -An addition example stm32_graphicstest has been added to show how to configure for stm32 - which uses hardware SPI and hence its not possible to -set the SCK MISO and MOSI pins. - -_________________________ Original text from Adafruit ____________________________________________ - - +It has minor modifications to support STM32. It has been tested with the Maple Mini. +Further modifications to support DMA transfers in the STM32F1xx by Victor Perez 3/17/2015 This is a library for the Adafruit ILI9341 display products diff --git a/STM32F1/libraries/Adafruit_ILI9341_AS/examples/TFT_Clock_Digital_ILI9341/TFT_Clock_Digital_ILI9341.ino b/STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Clock_Digital_ILI9341/TFT_Clock_Digital_ILI9341.ino similarity index 93% rename from STM32F1/libraries/Adafruit_ILI9341_AS/examples/TFT_Clock_Digital_ILI9341/TFT_Clock_Digital_ILI9341.ino rename to STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Clock_Digital_ILI9341/TFT_Clock_Digital_ILI9341.ino index 1be8715..286bd44 100644 --- a/STM32F1/libraries/Adafruit_ILI9341_AS/examples/TFT_Clock_Digital_ILI9341/TFT_Clock_Digital_ILI9341.ino +++ b/STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Clock_Digital_ILI9341/TFT_Clock_Digital_ILI9341.ino @@ -31,19 +31,19 @@ code color */ // These are the connections for the UNO -#define sclk 6 // Don't change -#define mosi 4 // Don't change +//#define sclk 6 // Don't change +//#define mosi 4 // Don't change #define cs 8 #define dc 10 #define rst 9 // you can also connect this to the Arduino reset -#include // Core graphics library -#include // Hardware-specific library +#include // Core graphics library +#include // Hardware-specific library #include #define ILI9341_GREY 0x5AEB -Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(cs, dc, rst); // Invoke custom library +Adafruit_ILI9341 tft = Adafruit_ILI9341(cs, dc, rst); // Invoke custom library uint32_t targetTime = 0; // for next 1 second timeout uint8_t hh=conv2d(__TIME__), mm=conv2d(__TIME__+3), ss=conv2d(__TIME__+6); // Get H, M, S from compile time diff --git a/STM32F1/libraries/Adafruit_ILI9341_AS/examples/TFT_Clock_ILI9341/TFT_Clock_ILI9341.ino b/STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Clock_ILI9341/TFT_Clock_ILI9341.ino similarity index 94% rename from STM32F1/libraries/Adafruit_ILI9341_AS/examples/TFT_Clock_ILI9341/TFT_Clock_ILI9341.ino rename to STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Clock_ILI9341/TFT_Clock_ILI9341.ino index 6dd9e63..ada0fb4 100644 --- a/STM32F1/libraries/Adafruit_ILI9341_AS/examples/TFT_Clock_ILI9341/TFT_Clock_ILI9341.ino +++ b/STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Clock_ILI9341/TFT_Clock_ILI9341.ino @@ -11,19 +11,19 @@ Updated by Alan Senior 18/1/2015 */ -#define sclk 6 // Don't change -#define mosi 4 // Don't change +//#define sclk 6 // Don't change +//#define mosi 4 // Don't change #define cs 8 #define dc 10 #define rst 9 // you can also connect this to the Arduino reset -#include // Core graphics library -#include // Hardware-specific library +#include // Core graphics library +#include // Hardware-specific library #include #define ILI9341_GREY 0x5AEB -Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(cs, dc, rst); // Invoke custom library +Adafruit_ILI9341 tft = Adafruit_ILI9341(cs, dc, rst); // Invoke custom library float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0; // Saved H, M, S x & y multipliers float sdeg=0, mdeg=0, hdeg=0; diff --git a/STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Rainbow_ILI9341/TFT_Rainbow_ILI9341.ino b/STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Rainbow_ILI9341/TFT_Rainbow_ILI9341.ino new file mode 100644 index 0000000..2fd0c4d --- /dev/null +++ b/STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Rainbow_ILI9341/TFT_Rainbow_ILI9341.ino @@ -0,0 +1,124 @@ +/* + An example showing rainbow colours on a 2.2" TFT LCD screen + and to show a basic example of font use. + + The existing Adafruit font is still in the library + Only new font sizes 2,4,6 and 7 are implemented in the Adafruit_GFX library. + + This examples uses the hardware SPI only. Non-hardware SPI + is just too slow (~8 times slower!) + + Alan Senior 18/1/2015 + + */ + +// These are the connections for the UNO +//#define sclk 13 // Don't change +//#define mosi 11 // Don't change +#define cs 8 +#define dc 10 +#define rst 9 // you can also connect this to the Arduino reset +#include // Core graphics library +#include // Hardware-specific library +#include + +Adafruit_ILI9341 tft = Adafruit_ILI9341(cs, dc, rst); // Invoke custom library + +unsigned long targetTime = 0; +byte red = 31; +byte green = 0; +byte blue = 0; +byte state = 0; +unsigned int colour = red << 11; + +void setup(void) { + tft.begin(); + tft.setRotation(2); + tft.fillScreen(ILI9341_BLACK); + + targetTime = millis() + 1000; +} + +void loop() { + + if (targetTime < millis()) { + targetTime = millis()+10000; + for (int i = 0; i<240; i++) { + tft.drawFastVLine(i, 0, tft.height(), colour); + switch (state) { + case 0: + green +=2; + if (green == 64) { + green=63; + state = 1; + } + break; + case 1: + red--; + if (red == 255) { + red = 0; + state = 2; + } + break; + case 2: + blue ++; + if (blue == 32) { + blue=31; + state = 3; + } + break; + case 3: + green -=2; + if (green ==255) { + green=0; + state = 4; + } + break; + case 4: + red ++; + if (red == 32) { + red = 31; + state = 5; + } + break; + case 5: + blue --; + if (blue == 255) { + blue = 0; + state = 0; + } + break; + } + colour = red<<11 | green<<5 | blue; + } + + // The standard ADAFruit font still works as berfore + tft.setTextColor(ILI9341_BLACK, ILI9341_BLACK); // Note these fonts do not plot the background colour + tft.setCursor (68, 5); + tft.print("Original ADAfruit font!"); + + // The new larger fonts do not use the .setCursor call, coords are embedded + tft.setTextColor(ILI9341_BLACK); // Do not plot the background colour + // Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!) + tft.drawCentreString("Font size 2",120,14,2); // Draw text centre at position 120, 14 using font 2 + tft.drawCentreString("Font size 4",120,30,4); // Draw text centre at position 120, 30 using font 4 + tft.drawCentreString("12.34",120,54,6); // Draw text centre at position 120, 54 using font 6 + tft.drawCentreString("12.34 is in font size 6",120,92,2); // Draw text centre at position 120, 92 using font 2 + // Note the x position is the top of the font! + + // draw a floating point number + float pi = 3.14159; // Value to print + int precision = 3; // Number of digits after decimal point + int xpos = 90; // x position + int ypos = 110; // y position + int font = 2; // font number only 2,4,6,7 valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : . a p m + xpos+=tft.drawFloat(pi,precision,xpos,ypos,font); // Draw rounded number and return new xpos delta for next print position + tft.drawString(" is pi",xpos,ypos,font); // Continue printing from new x position + } +} + + + + + + diff --git a/STM32F1/libraries/Adafruit_ILI9341_AS/examples/TFT_Show_Font_ILI9341/TFT_Show_Font_ILI9341.ino b/STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Show_Font_ILI9341/TFT_Show_Font_ILI9341.ino similarity index 94% rename from STM32F1/libraries/Adafruit_ILI9341_AS/examples/TFT_Show_Font_ILI9341/TFT_Show_Font_ILI9341.ino rename to STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Show_Font_ILI9341/TFT_Show_Font_ILI9341.ino index 14d54df..956a69a 100644 --- a/STM32F1/libraries/Adafruit_ILI9341_AS/examples/TFT_Show_Font_ILI9341/TFT_Show_Font_ILI9341.ino +++ b/STM32F1/libraries/Adafruit_ILI9341/examples/TFT_Show_Font_ILI9341/TFT_Show_Font_ILI9341.ino @@ -1,7 +1,7 @@ /* Sow all the fonts. - Only font sizes 2, 4, 6 and 7 are implemented in the Adafruit_GFX_AS library. + Only font sizes 2, 4, 6 and 7 are implemented in the Adafruit_GFX library. This examples uses the hardware SPI only. Non-hardware SPI is just too slow (~8 times slower!) @@ -26,17 +26,17 @@ */ -#define sclk 6 // Don't change -#define mosi 4 // Don't change +//#define sclk 6 // Don't change +//#define mosi 4 // Don't change #define cs 8 #define dc 10 #define rst 9 // you can also connect this to the Arduino reset -#include // Core graphics library -#include // Hardware-specific library +#include // Core graphics library +#include // Hardware-specific library #include -Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(cs, dc, rst); // Invoke custom library +Adafruit_ILI9341 tft = Adafruit_ILI9341(cs, dc, rst); // Invoke custom library unsigned long targetTime = 0; byte red = 31; diff --git a/STM32F1/libraries/Adafruit_ILI9341_AS/README.txt b/STM32F1/libraries/Adafruit_ILI9341_AS/README.txt deleted file mode 100644 index 3443bec..0000000 --- a/STM32F1/libraries/Adafruit_ILI9341_AS/README.txt +++ /dev/null @@ -1,23 +0,0 @@ -It has minor modifications to support STM32. It has been tested with the Maple Mini. - -This is a library for the Adafruit ILI9341 display products - -This library works with the Adafruit 2.8" Touch Shield V2 (SPI) - ----> http://www.adafruit.com/products/1651 - -Check out the links above for our tutorials and wiring diagrams. -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! - -Written by Limor Fried/Ladyada for Adafruit Industries. -MIT license, all text above must be included in any redistribution - -To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_ILI9341. Check that the Adafruit_ILI9341 folder contains Adafruit_ILI9341.cpp and Adafruit_ILI9341. - -Place the Adafruit_ILI9341 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. diff --git a/STM32F1/libraries/deprecatedAdafruit_ILI9341.zip b/STM32F1/libraries/deprecatedAdafruit_ILI9341.zip new file mode 100644 index 0000000..5177fd4 Binary files /dev/null and b/STM32F1/libraries/deprecatedAdafruit_ILI9341.zip differ