New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ili9341 develop #323

Closed
wants to merge 17 commits into
base: master
from
Commits
Jump to file or symbol
Failed to load files and symbols.
+236 −351
Diff settings

Always

Just for now

@@ -228,6 +228,7 @@ void Adafruit_ILI9341_STM::setAddrWindow(uint16_t x0, uint16_t y0,
spiwrite(y1);
writecommand(ILI9341_RAMWR); // write to RAM
cs_set();
}
@@ -243,22 +244,12 @@ void Adafruit_ILI9341_STM::pushColors(void * colorBuffer, uint16_t nr_pixels, ui
}
}
void Adafruit_ILI9341_STM::pushColor(uint16_t color)
{
cs_clear();
spiwrite(color);
cs_set();
}
void Adafruit_ILI9341_STM::drawPixel(int16_t x, int16_t y, uint16_t color)
{
if ((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) return;
setAddrWindow(x, y, x + 1, y + 1);
spiwrite(color);
cs_set();
pushColor(color);
}
@@ -276,6 +267,7 @@ void Adafruit_ILI9341_STM::drawFastVLine(int16_t x, int16_t y, int16_t h,
setAddrWindow(x, y, x, y + h - 1);
cs_clear();
if (h>DMA_ON_LIMIT) {
lineBuffer[0] = color;
mSPI.dmaSend(lineBuffer, h, 0);
@@ -299,6 +291,7 @@ void Adafruit_ILI9341_STM::drawFastHLine(int16_t x, int16_t y, int16_t w,
setAddrWindow(x, y, x + w - 1, y);
cs_clear();
if (w>DMA_ON_LIMIT) {
lineBuffer[0] = color;
mSPI.dmaSend(lineBuffer, w, 0);
@@ -312,6 +305,7 @@ void Adafruit_ILI9341_STM::fillScreen(uint16_t color)
{
lineBuffer[0] = color;
setAddrWindow(0, 0, _width - 1, _height - 1);
cs_clear();
uint32_t nr_bytes = _width * _height;
while ( nr_bytes>65535 ) {
nr_bytes -= 65535;
@@ -336,6 +330,7 @@ void Adafruit_ILI9341_STM::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
}
setAddrWindow(x, y, x + w - 1, y + h - 1);
cs_clear();
uint32_t nr_bytes = w * h;
if ( nr_bytes>DMA_ON_LIMIT ) {
while ( nr_bytes>65535 ) {
@@ -574,10 +569,8 @@ uint16_t Adafruit_ILI9341_STM::readPixelsRGB24(int16_t x1, int16_t y1, int16_t x
spiwrite16(y2);
writecommand(ILI9341_RAMRD); // read GRAM
(void)spiread(); //dummy read
uint8_t r, g, b;
uint16_t len = (x2-x1+1)*(y2-y1+1);
uint16_t ret = len;
mSPI.dmaTransfer(buf, buf, len*3);
cs_set();
@@ -104,7 +104,6 @@ class Adafruit_ILI9341_STM : public Adafruit_GFX {
void begin(SPIClass & spi, uint32_t freq=48000000);
void begin(void) { begin(SPI); }
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
pushColor(uint16_t color),
pushColors(void * colorBuffer, uint16_t nr_pixels, uint8_t async=0),
fillScreen(uint16_t color),
drawLine(int16_t x0, int16_t y0,int16_t x1, int16_t y1, uint16_t color),
@@ -148,6 +147,8 @@ class Adafruit_ILI9341_STM : public Adafruit_GFX {
inline void writedata(uint8_t c) { mSPI.write(c); }
inline void spiwrite(uint16_t c) { mSPI.write(c); }
inline void spiwrite16(uint16_t c) { mSPI.write16(c); } // 8 bit mode
inline void pushColor(uint16_t color) { cs_clear(); spiwrite(color); cs_set(); }
void writecommand(uint8_t c),
commandList(uint8_t *addr);
@@ -14,25 +14,29 @@
****************************************************/
#include "SPI.h"
#include "Adafruit_GFX_AS.h"
#include "Adafruit_ILI9341_STM.h"
#include <Adafruit_ILI9341_STM.h>
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
// Use hardware SPI
Adafruit_ILI9341_STM tft(PA4, PA3, PA2); // input chip select, DC and reset pins
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
// For using software SPI, define pins as desired, MISO is optional, needed for reading only
//Adafruit_ILI9341_STM tft(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_CLK, [TFT_MISO]);
void setup() {
void setup()
{
Serial.begin(9600);
while ( !Serial );
delay(1000);
Serial.println("ILI9341 Test!");
#if true
// use standard SPI port
tft.begin();
#else
// use alternative SPI port
static SPIClass _spi(2);
tft.begin(_spi);
#endif
// read diagnostics (optional but can help debug problems)
uint8_t x = tft.readcommand8(ILI9341_RDMODE);
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
@@ -43,8 +47,13 @@ void setup() {
x = tft.readcommand8(ILI9341_RDIMGFMT);
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(ILI9341_RDSELFDIAG);
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
tft.fillScreen(ILI9341_BLACK);
}
void do_test(void)
{
Serial.println(F("Benchmark Time (microseconds)"));
Serial.print(F("Screen fill "));
@@ -95,16 +104,17 @@ void setup() {
delay(500);
Serial.println(F("Done!"));
}
void loop(void) {
void loop(void)
{
for(uint8_t rotation=0; rotation<4; rotation++) {
tft.setRotation(rotation);
testText();
delay(1000);
}
do_test();
}
unsigned long testFillScreen() {
@@ -14,25 +14,21 @@
****************************************************/
#include "SPI.h"
#include <Adafruit_GFX_AS.h> // Core graphics library, with extra fonts.
#include <Adafruit_ILI9341_STM.h> // STM32 DMA Hardware-specific library
// For the Adafruit shield, these are the default.
#define TFT_CS 8
#define TFT_DC 10
#define TFT_RST 9
#define TFT_CS PA4
#define TFT_DC PA3
#define TFT_RST PA2
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC, TFT_RST); // Use hardware SPI
Adafruit_ILI9341_STM tft(TFT_CS, TFT_DC, TFT_RST); // Use hardware SPI
void setup() {
Serial.begin(115200);
while(!Serial);
delay(1000);
tft.begin();
}
@@ -370,13 +370,6 @@ extern timer_dev timer14;
#define TIMER_EGR_CC1G (1U << TIMER_EGR_CC1G_BIT)
#define TIMER_EGR_UG (1U << TIMER_EGR_UG_BIT)
/* Capture/compare mode registers, common values */
#define TIMER_CCMR_CCS_OUTPUT 0x0
#define TIMER_CCMR_CCS_INPUT_TI1 0x1
#define TIMER_CCMR_CCS_INPUT_TI2 0x2
#define TIMER_CCMR_CCS_INPUT_TRC 0x3
/* Capture/compare mode register 1 (CCMR1) */
#define TIMER_CCMR1_OC2CE_BIT 15
@@ -393,21 +386,21 @@ extern timer_dev timer14;
#define TIMER_CCMR1_OC2FE (1U << TIMER_CCMR1_OC2FE_BIT)
#define TIMER_CCMR1_IC2PSC (0x3 << 10)
#define TIMER_CCMR1_CC2S (0x3 << 8)
#define TIMER_CCMR1_CC2S_OUTPUT (TIMER_CCMR_CCS_OUTPUT << 8)
#define TIMER_CCMR1_CC2S_INPUT_TI1 (TIMER_CCMR_CCS_INPUT_TI1 << 8)
#define TIMER_CCMR1_CC2S_INPUT_TI2 (TIMER_CCMR_CCS_INPUT_TI2 << 8)
#define TIMER_CCMR1_CC2S_INPUT_TRC (TIMER_CCMR_CCS_INPUT_TRC << 8)
#define TIMER_CCMR1_CC2S_OUTPUT (0x0 << 8)
#define TIMER_CCMR1_CC2S_INPUT_TI2 (0x1 << 8)
#define TIMER_CCMR1_CC2S_INPUT_TI1 (0x2 << 8)
#define TIMER_CCMR1_CC2S_INPUT_TRC (0x3 << 8)
#define TIMER_CCMR1_OC1CE (1U << TIMER_CCMR1_OC1CE_BIT)
#define TIMER_CCMR1_OC1M (0x3 << 4)
#define TIMER_CCMR1_IC1F (0xF << 4)
#define TIMER_CCMR1_OC1PE (1U << TIMER_CCMR1_OC1PE_BIT)
#define TIMER_CCMR1_OC1FE (1U << TIMER_CCMR1_OC1FE_BIT)
#define TIMER_CCMR1_IC1PSC (0x3 << 2)
#define TIMER_CCMR1_CC1S 0x3
#define TIMER_CCMR1_CC1S_OUTPUT TIMER_CCMR_CCS_OUTPUT
#define TIMER_CCMR1_CC1S_INPUT_TI1 TIMER_CCMR_CCS_INPUT_TI1
#define TIMER_CCMR1_CC1S_INPUT_TI2 TIMER_CCMR_CCS_INPUT_TI2
#define TIMER_CCMR1_CC1S_INPUT_TRC TIMER_CCMR_CCS_INPUT_TRC
#define TIMER_CCMR1_CC1S_OUTPUT 0x0
#define TIMER_CCMR1_CC1S_INPUT_TI1 0x1
#define TIMER_CCMR1_CC1S_INPUT_TI2 0x2
#define TIMER_CCMR1_CC1S_INPUT_TRC 0x3
/* Capture/compare mode register 2 (CCMR2) */
@@ -425,21 +418,21 @@ extern timer_dev timer14;
#define TIMER_CCMR2_OC4FE (1U << TIMER_CCMR2_OC4FE_BIT)
#define TIMER_CCMR2_IC4PSC (0x3 << 10)
#define TIMER_CCMR2_CC4S (0x3 << 8)
#define TIMER_CCMR2_CC4S_OUTPUT (TIMER_CCMR_CCS_OUTPUT << 8)
#define TIMER_CCMR2_CC4S_INPUT_TI1 (TIMER_CCMR_CCS_INPUT_TI1 << 8)
#define TIMER_CCMR2_CC4S_INPUT_TI2 (TIMER_CCMR_CCS_INPUT_TI2 << 8)
#define TIMER_CCMR2_CC4S_INPUT_TRC (TIMER_CCMR_CCS_INPUT_TRC << 8)
#define TIMER_CCMR2_CC4S_OUTPUT (0x0 << 8)
#define TIMER_CCMR2_CC4S_INPUT_TI4 (0x1 << 8)
#define TIMER_CCMR2_CC4S_INPUT_TI3 (0x2 << 8)
#define TIMER_CCMR2_CC4S_INPUT_TRC (0x3 << 8)
#define TIMER_CCMR2_OC3CE (1U << TIMER_CCMR2_OC3CE_BIT)
#define TIMER_CCMR2_OC3M (0x3 << 4)
#define TIMER_CCMR2_IC3F (0xF << 4)
#define TIMER_CCMR2_OC3PE (1U << TIMER_CCMR2_OC3PE_BIT)
#define TIMER_CCMR2_OC3FE (1U << TIMER_CCMR2_OC3FE_BIT)
#define TIMER_CCMR2_IC3PSC (0x3 << 2)
#define TIMER_CCMR2_CC3S 0x3
#define TIMER_CCMR2_CC3S_OUTPUT TIMER_CCMR_CCS_OUTPUT
#define TIMER_CCMR2_CC3S_INPUT_TI1 TIMER_CCMR_CCS_INPUT_TI1
#define TIMER_CCMR2_CC3S_INPUT_TI2 TIMER_CCMR_CCS_INPUT_TI2
#define TIMER_CCMR2_CC3S_INPUT_TRC TIMER_CCMR_CCS_INPUT_TRC
#define TIMER_CCMR2_CC3S_OUTPUT 0x0
#define TIMER_CCMR2_CC3S_INPUT_TI3 0x1
#define TIMER_CCMR2_CC3S_INPUT_TI4 0x2
#define TIMER_CCMR2_CC3S_INPUT_TRC 0x3
/* Capture/compare enable register (CCER) */
@@ -1071,76 +1064,10 @@ static inline void timer_oc_set_mode(timer_dev *dev,
uint32 tmp = *ccmr;
tmp &= ~(0xFF << shift);
tmp |= (mode | flags | TIMER_CCMR_CCS_OUTPUT) << shift;
tmp |= (mode | flags) << shift;
*ccmr = tmp;
}
/*
* Old, erroneous bit definitions from previous releases, kept for
* backwards compatibility:
*/
/** Deprecated. Use TIMER_CCMR1_CC4S_OUTPUT instead. */
#define TIMER_CCMR1_CC4S_OUTPUT TIMER_CCMR2_CC4S_OUTPUT
/** Deprecated. Use TIMER_CCMR1_CC4S_INPUT_TI1 instead. */
#define TIMER_CCMR1_CC4S_INPUT_TI1 TIMER_CCMR2_CC4S_INPUT_TI1
/** Deprecated. Use TIMER_CCMR1_CC4S_INPUT_TI2 instead. */
#define TIMER_CCMR1_CC4S_INPUT_TI2 TIMER_CCMR2_CC4S_INPUT_TI2
/** Deprecated. Use TIMER_CCMR1_CC4S_INPUT_TRC instead. */
#define TIMER_CCMR1_CC4S_INPUT_TRC TIMER_CCMR2_CC4S_INPUT_TRC
/** Deprecated. Use TIMER_CCMR2_IC4F instead. */
#define TIMER_CCMR2_IC2F TIMER_CCMR2_IC4F
/** Deprecated. Use TIMER_CCMR2_IC4PSC instead. */
#define TIMER_CCMR2_IC2PSC TIMER_CCMR2_IC4PSC
/** Deprecated. Use TIMER_CCMR2_IC3F instead. */
#define TIMER_CCMR2_IC1F TIMER_CCMR2_IC3F
/** Deprecated. Use TIMER_CCMR2_IC3PSC instead. */
#define TIMER_CCMR2_IC1PSC TIMER_CCMR2_IC3PSC
/** Deprecated. Use TIMER_CCMR1_CC3S_OUTPUT instead. */
#define TIMER_CCMR1_CC3S_OUTPUT TIMER_CCMR2_CC3S_OUTPUT
/** Deprecated. Use TIMER_CCMR1_CC3S_INPUT_TI1 instead. */
#define TIMER_CCMR1_CC3S_INPUT_TI1 TIMER_CCMR2_CC3S_INPUT_TI1
/** Deprecated. Use TIMER_CCMR1_CC3S_INPUT_TI2 instead. */
#define TIMER_CCMR1_CC3S_INPUT_TI2 TIMER_CCMR2_CC3S_INPUT_TI2
/** Deprecated. Use TIMER_CCMR1_CC3S_INPUT_TRC instead. */
#define TIMER_CCMR1_CC3S_INPUT_TRC TIMER_CCMR2_CC3S_INPUT_TRC
/** Deprecated. Use TIMER_DCR_DBL_1_XFER instead. */
#define TIMER_DCR_DBL_1BYTE TIMER_DCR_DBL_1_XFER
/** Deprecated. Use TIMER_DCR_DBL_2_XFER instead. */
#define TIMER_DCR_DBL_2BYTE TIMER_DCR_DBL_2_XFER
/** Deprecated. Use TIMER_DCR_DBL_3_XFER instead. */
#define TIMER_DCR_DBL_3BYTE TIMER_DCR_DBL_3_XFER
/** Deprecated. Use TIMER_DCR_DBL_4_XFER instead. */
#define TIMER_DCR_DBL_4BYTE TIMER_DCR_DBL_4_XFER
/** Deprecated. Use TIMER_DCR_DBL_5_XFER instead. */
#define TIMER_DCR_DBL_5BYTE TIMER_DCR_DBL_5_XFER
/** Deprecated. Use TIMER_DCR_DBL_6_XFER instead. */
#define TIMER_DCR_DBL_6BYTE TIMER_DCR_DBL_6_XFER
/** Deprecated. Use TIMER_DCR_DBL_7_XFER instead. */
#define TIMER_DCR_DBL_7BYTE TIMER_DCR_DBL_7_XFER
/** Deprecated. Use TIMER_DCR_DBL_8_XFER instead. */
#define TIMER_DCR_DBL_8BYTE TIMER_DCR_DBL_8_XFER
/** Deprecated. Use TIMER_DCR_DBL_9_XFER instead. */
#define TIMER_DCR_DBL_9BYTE TIMER_DCR_DBL_9_XFER
/** Deprecated. Use TIMER_DCR_DBL_10_XFER instead. */
#define TIMER_DCR_DBL_10BYTE TIMER_DCR_DBL_10_XFER
/** Deprecated. Use TIMER_DCR_DBL_11_XFER instead. */
#define TIMER_DCR_DBL_11BYTE TIMER_DCR_DBL_11_XFER
/** Deprecated. Use TIMER_DCR_DBL_12_XFER instead. */
#define TIMER_DCR_DBL_12BYTE TIMER_DCR_DBL_12_XFER
/** Deprecated. Use TIMER_DCR_DBL_13_XFER instead. */
#define TIMER_DCR_DBL_13BYTE TIMER_DCR_DBL_13_XFER
/** Deprecated. Use TIMER_DCR_DBL_14_XFER instead. */
#define TIMER_DCR_DBL_14BYTE TIMER_DCR_DBL_14_XFER
/** Deprecated. Use TIMER_DCR_DBL_15_XFER instead. */
#define TIMER_DCR_DBL_15BYTE TIMER_DCR_DBL_15_XFER
/** Deprecated. Use TIMER_DCR_DBL_16_XFER instead. */
#define TIMER_DCR_DBL_16BYTE TIMER_DCR_DBL_16_XFER
/** Deprecated. Use TIMER_DCR_DBL_17_XFER instead. */
#define TIMER_DCR_DBL_17BYTE TIMER_DCR_DBL_17_XFER
/** Deprecated. Use TIMER_DCR_DBL_18_XFER instead. */
#define TIMER_DCR_DBL_18BYTE TIMER_DCR_DBL_18_XFER
#ifdef __cplusplus
} // extern "C"
@@ -61,18 +61,18 @@ static inline afio_exti_port gpio_exti_port(const gpio_dev *dev) {
*/
static inline void gpio_write_pin(uint8_t pin, uint8 val) {
if (val) {
(PIN_MAP[pin].gpio_device)->regs->BSRRL = BIT(pin&0x0F);
(PIN_MAP[pin].gpio_device)->regs->BSRR = (uint32_t)BIT(pin&0x0F);
} else {
(PIN_MAP[pin].gpio_device)->regs->BSRRH = BIT(pin&0x0F);
(PIN_MAP[pin].gpio_device)->regs->BSRR = (uint32_t)BIT(pin&0x0F)<<16;
}
}
static inline void gpio_set_pin(uint8_t pin) {
(PIN_MAP[pin].gpio_device)->regs->BSRRL = BIT(pin&0x0F);
(PIN_MAP[pin].gpio_device)->regs->BSRR = (uint32_t)BIT(pin&0x0F);
}
static inline void gpio_clear_pin(uint8_t pin) {
(PIN_MAP[pin].gpio_device)->regs->BSRRH = BIT(pin&0x0F);
(PIN_MAP[pin].gpio_device)->regs->BSRR = (uint32_t)BIT(pin&0x0F)<<16;
}
/**
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.