Added first pas at SPI::DMATransfer(byte *buf, int length) - and updated ILI9341 lib to use DMA Transfer for fill rect
This commit is contained in:
parent
a47caee80d
commit
5f9e8a04dd
|
@ -327,9 +327,11 @@ void Adafruit_ILI9341::begin(void) {
|
||||||
void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
|
void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
|
||||||
uint16_t y1) {
|
uint16_t y1) {
|
||||||
|
|
||||||
|
byte buf[4];
|
||||||
writecommand(ILI9341_CASET); // Column addr set
|
writecommand(ILI9341_CASET); // Column addr set
|
||||||
*dcport |= dcpinmask;
|
*dcport |= dcpinmask;
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
|
|
||||||
SPI.write(x0 >> 8);
|
SPI.write(x0 >> 8);
|
||||||
SPI.write(x0 & 0xFF); // XSTART
|
SPI.write(x0 & 0xFF); // XSTART
|
||||||
SPI.write(x1 >> 8);
|
SPI.write(x1 >> 8);
|
||||||
|
@ -338,11 +340,13 @@ void Adafruit_ILI9341::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
|
||||||
writecommand(ILI9341_PASET); // Row addr set
|
writecommand(ILI9341_PASET); // Row addr set
|
||||||
*dcport |= dcpinmask;
|
*dcport |= dcpinmask;
|
||||||
*csport &= ~cspinmask;
|
*csport &= ~cspinmask;
|
||||||
|
|
||||||
SPI.write(y0>>8);
|
SPI.write(y0>>8);
|
||||||
SPI.write(y0); // YSTART
|
SPI.write(y0); // YSTART
|
||||||
SPI.write(y1>>8);
|
SPI.write(y1>>8);
|
||||||
SPI.write(y1); // YEND
|
SPI.write(y1); // YEND
|
||||||
|
|
||||||
|
|
||||||
writecommand(ILI9341_RAMWR); // write to RAM
|
writecommand(ILI9341_RAMWR); // write to RAM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,33 +437,56 @@ void Adafruit_ILI9341::fillScreen(uint16_t color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill a rectangle
|
// fill a rectangle
|
||||||
void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
|
void Adafruit_ILI9341::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
|
||||||
uint16_t color) {
|
|
||||||
int numPixels;
|
int numPixels;
|
||||||
// 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 (hwSPI) spi_begin();
|
unsigned char *buff;
|
||||||
setAddrWindow(x, y, x+w-1, y+h-1);
|
|
||||||
|
|
||||||
uint8_t hi = color >> 8, lo = 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;
|
||||||
|
|
||||||
*dcport |= dcpinmask;
|
if (hwSPI) spi_begin();
|
||||||
*csport &= ~cspinmask;
|
setAddrWindow(x, y, x+w-1, y+h-1);
|
||||||
|
|
||||||
|
uint8_t hi = color >> 8, lo = color;
|
||||||
|
|
||||||
for(y=h; y>0; y--)
|
*dcport |= dcpinmask;
|
||||||
{
|
*csport &= ~cspinmask;
|
||||||
for(x=w; x>0; x--)
|
if (true)
|
||||||
{
|
{
|
||||||
SPI.write(hi);
|
// Use DMA
|
||||||
SPI.write(lo);
|
byte lineBuffer[h*2];// Buffer to be sent via DMA
|
||||||
}
|
|
||||||
}
|
// need to build a buffer of the required height (h)
|
||||||
|
// Note I suspect there is a faster way to do this
|
||||||
if (hwSPI) spi_end();
|
for(int i=0;i<h*2;i++)
|
||||||
*csport |= cspinmask;
|
{
|
||||||
|
lineBuffer[i++] = hi&0xff;
|
||||||
|
lineBuffer[i] = lo&0xff;
|
||||||
|
}
|
||||||
|
// Tansfer each line by DMA
|
||||||
|
for(int i=0;i<w;i++)
|
||||||
|
{
|
||||||
|
SPI.DMATransfer(lineBuffer,h*2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Non DMA method (currently not used)
|
||||||
|
for(y=h; y>0; y--)
|
||||||
|
{
|
||||||
|
for(x=w; x>0; x--)
|
||||||
|
{
|
||||||
|
SPI.write(hi);
|
||||||
|
SPI.write(lo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hwSPI) spi_end();
|
||||||
|
*csport |= cspinmask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -330,6 +330,29 @@ uint8 SPIClass::transfer(uint8 byte) {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8 SPIClass::DMATransfer(uint8 *data, uint32 length) {
|
||||||
|
uint8 b;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dma1_ch3_Active=true;
|
||||||
|
|
||||||
|
spi_tx_dma_enable(SPI1);
|
||||||
|
dma_init(DMA1);
|
||||||
|
|
||||||
|
|
||||||
|
dma_attach_interrupt(DMA1, DMA_CH3, &SPIClass::DMA1_CH3_Event);
|
||||||
|
dma_setup_transfer(DMA1, DMA_CH3, &SPI1->regs->DR, DMA_SIZE_8BITS,
|
||||||
|
data, DMA_SIZE_8BITS, (DMA_MINC_MODE | DMA_FROM_MEM | DMA_TRNS_CMPLT));
|
||||||
|
|
||||||
|
dma_set_num_transfers(DMA1, DMA_CH3, length); // 2 bytes per pixel
|
||||||
|
dma_enable(DMA1, DMA_CH3);
|
||||||
|
while (dma1_ch3_Active);
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SPIClass::attachInterrupt(void) {
|
void SPIClass::attachInterrupt(void) {
|
||||||
// Should be enableInterrupt()
|
// Should be enableInterrupt()
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include <libmaple/libmaple_types.h>
|
#include <libmaple/libmaple_types.h>
|
||||||
#include <libmaple/spi.h>
|
#include <libmaple/spi.h>
|
||||||
|
#include <libmaple/dma.h>
|
||||||
|
|
||||||
#include <boards.h>
|
#include <boards.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -121,6 +122,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
volatile static bool dma1_ch3_Active;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Wirish SPI interface.
|
* @brief Wirish SPI interface.
|
||||||
|
@ -130,6 +132,9 @@ private:
|
||||||
*/
|
*/
|
||||||
class SPIClass {
|
class SPIClass {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param spiPortNumber Number of the SPI port to manage.
|
* @param spiPortNumber Number of the SPI port to manage.
|
||||||
*/
|
*/
|
||||||
|
@ -223,6 +228,8 @@ public:
|
||||||
*/
|
*/
|
||||||
uint8 transfer(uint8 data);
|
uint8 transfer(uint8 data);
|
||||||
|
|
||||||
|
uint8 DMATransfer(uint8 *data, uint32 length);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pin accessors
|
* Pin accessors
|
||||||
*/
|
*/
|
||||||
|
@ -289,7 +296,14 @@ public:
|
||||||
|
|
||||||
spi_dev *dev(){ return spi_d;}
|
spi_dev *dev(){ return spi_d;}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
static inline void DMA1_CH3_Event() {
|
||||||
|
dma1_ch3_Active = 0;
|
||||||
|
dma_disable(DMA1, DMA_CH3);
|
||||||
|
}
|
||||||
spi_dev *spi_d;
|
spi_dev *spi_d;
|
||||||
uint8_t _SSPin;
|
uint8_t _SSPin;
|
||||||
uint32_t clockDivider;
|
uint32_t clockDivider;
|
||||||
|
|
Loading…
Reference in New Issue