Adapted from Peter Dresche's original for Waveshare 2.8inch TFT Touch Shield Board and Mbed 6. RGB order reversed by changing reg 16 commands, spi write code adjusted as there is no reset pin but there is data command pin. Wait commands changed for new thread_sleep style, Stream class explicitly included. Library to control a QVGA TFT connected to SPI. You can use printf to print text The lib can handle different fonts, draw lines, circles, rect and bmp
Revision 23:469bf5f3c8ac, committed 2020-06-28
- Comitter:
- jhd25
- Date:
- Sun Jun 28 15:52:02 2020 +0100
- Parent:
- 22:4a0f306be8ef
- Child:
- 24:b986bedb0a73
- Commit message:
- Fixed color handling color order and SPI communication (superflous start bits removed
Changed in this revision
SPI_TFT.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/SPI_TFT.cpp Wed Jun 17 22:01:37 2020 +0100 +++ b/SPI_TFT.cpp Sun Jun 28 15:52:02 2020 +0100 @@ -28,6 +28,7 @@ #include "SPI_TFT.h" #include "mbed.h" +#include "stdint.h" #define BPP 16 // Bits per pixel @@ -49,14 +50,6 @@ { orientation = 0; char_x = 0; - #if defined TARGET_LPC1768 - if (mosi == p11 || mosi == P0_18){ - spi_port = 0; // we must know the used SPI port to setup the DMA - } - else { - spi_port = 1; - } - #endif tft_reset(); } @@ -79,16 +72,16 @@ orientation = o; switch (orientation) { case 0: - wr_reg(0x16, 0x00); + wr_reg(0x16, 0x08); break; case 1: - wr_reg(0x16, 0x60); + wr_reg(0x16, 0x68); break; case 2: - wr_reg(0x16, 0xC0); + wr_reg(0x16, 0xC8); break; case 3: - wr_reg(0x16, 0xA0); + wr_reg(0x16, 0xA8); break; } WindowMax(); @@ -99,73 +92,23 @@ void SPI_TFT::wr_cmd(unsigned char cmd) { - _spi.lock(); - _cs = 0; - #if defined NO_MBED_LIB - unsigned short spi_d; - spi_d = 0x7000 | cmd ; - if (spi_port == 0) { // TFT on SSP0 - LPC_SSP0->DR = spi_d; - // we have to wait for SPI IDLE to set CS back to high - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI0 not idle - } else { - LPC_SSP1->DR = spi_d; - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle - } - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - - _spi.write(0x70); - _spi.write(cmd); - - #else - _reset=0; // 16 Bit SPI - unsigned short spi_d; - spi_d = 0x7000 | cmd ; - - _spi.write(spi_d); // mbed lib - - _reset=1; - #endif - #endif - _cs = 1; - _spi.unlock(); + + uint16_t spi_d; + spi_d = 0x7000 | cmd ; + + _spi.write(spi_d); // mbed lib + } // write data to tft register void SPI_TFT::wr_dat(unsigned char dat) { - _spi.lock(); - _cs = 0; - _reset=1; - #if defined NO_MBED_LIB - unsigned short spi_d; - spi_d = 0x7200 | dat; - if (spi_port == 0) { // TFT on SSP0 - LPC_SSP0->DR = spi_d; - // we have to wait for SPI IDLE to set CS back to high - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI0 not idle - } else { - LPC_SSP1->DR = spi_d; - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle - } - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(0x72); - _spi.write(dat); - #else // 16 Bit SPI - unsigned short spi_d; - spi_d = 0x7200 | dat; - _spi.write(spi_d); - #endif - #endif - _cs = 1; - _spi.unlock(); + + unsigned short spi_d; + spi_d = 0x7200 | dat; + _spi.write(spi_d); + } @@ -186,8 +129,12 @@ // write to a TFT register void SPI_TFT::wr_reg (unsigned char reg, unsigned char val) { + _cs=0; + _reset=0; wr_cmd(reg); + _reset=1; wr_dat(val); + _cs=1; } // read from a TFT register @@ -200,11 +147,9 @@ // setup TFT controller - this is called by constructor void SPI_TFT::tft_reset() { -#if defined TARGET_KL25Z // 8 Bit SPI - _spi.format(8,3); -#else // 16 Bit SPI + // 16 Bit SPI _spi.format(16,3); // 16 bit spi mode 3 -#endif + _spi.frequency(48000000); // 48 Mhz SPI clock _cs = 1; // cs high // end reset @@ -278,27 +223,21 @@ wr_reg(0x28, 0x3C); /* Display Control 3 */ switch (orientation) { case 0: - wr_reg(0x16, 0x00); + wr_reg(0x16, 0x08); break; case 2: - wr_reg(0x16, 0xC0); + wr_reg(0x16, 0xC8); break; case 3: - wr_reg(0x16, 0xA0); + wr_reg(0x16, 0xA8); break; case 1: default: - wr_reg(0x16, 0x60); + wr_reg(0x16, 0x68); break; } -#if defined USE_DMA // setup DMA channel 0 - LPC_SC->PCONP |= (1UL << 29); // Power up the GPDMA. - LPC_GPDMA->DMACConfig = 1; // enable DMA controller - LPC_GPDMA->DMACIntTCClear = 0x1; // Reset the Interrupt status - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCLLI = 0; -#endif + WindowMax (); } @@ -309,41 +248,15 @@ wr_reg(0x02, (x >> 8)); wr_reg(0x07, (y >> 0)); wr_reg(0x06, (y >> 8)); - wr_cmd(0x22); _spi.lock(); _cs = 0; - - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set back to 16 bit - LPC_SSP0->DR = color; // Pixel - // we have to wait for SPI IDLE to set CS back to high - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI0 not idle - } else { // TFT on SSP1 - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set back to 16 bit - LPC_SSP1->DR = color; - // we have to wait for SPI IDLE to set CS back to high - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle - } - #else // use mbed lib - - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.write(color >> 8); - _spi.write(color & 0xff); - #else - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch to 16 bit Mode 3 - _spi.write(color); // Write D0..D15 - #endif - #endif + _reset=0; + wr_cmd(0x22); + _reset=1; + // _spi.format(8,3); // 8 bit Mode 3 + // _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 + // _spi.format(16,3); // switch to 16 bit Mode 3 + _spi.write(color); // Write D0..D15 _cs = 1; _spi.unlock(); } @@ -373,94 +286,18 @@ { fprintf(stderr, "CLS \n\r"); int pixel = ( width() * height()); - #if defined USE_DMA - int dma_count; - int color = _background; - #endif WindowMax(); + _spi.lock(); + _cs = 0; + _reset=0; wr_cmd(0x22); - - #if defined NO_MBED_LIB - #if defined USE_DMA - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; - #endif - _spi.lock(); - _cs = 0; - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start byte - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - - #if defined USE_DMA - // start DMA - do { - if (pixel > 4095) { - dma_count = 4095; - pixel = pixel - 4095; - } else { - dma_count = pixel; - pixel = 0; - } - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) ; // 16 bit transfer , no address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; // DMA request - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - } while (pixel > 0); - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((0x0010 & LPC_SSP0->SR) == 0x10); // SPI FIFO not empty - /* disable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x0; - } else { // TFT on SSP1 - do { - } while ((0x0010 & LPC_SSP1->SR) == 0x10); // SPI FIFO not empty - /* disable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x0; - } - - #else // no DMA - unsigned int i; - for (i = 0; i < ( width() * height()); i++) - _spi.write(_background); - #endif - - #else // use mbed lib - _spi.lock(); - _cs = 0; - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - unsigned int i; - for (i = 0; i < ( width() * height()); i++) { - _spi.write(_background >> 8); - _spi.write(_background & 0xff); - } - #else // 16 bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch back to 16 bit Mode 3 - unsigned int i; - for (i = 0; i < ( width() * height()); i++) - _spi.write(_background); - #endif - #endif + _reset=1; // 16 bit SPI +// _spi.format(8,3); // 8 bit Mode 3 +// _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 +// _spi.format(16,3); // switch back to 16 bit Mode 3 + unsigned int i; + for (i = 0; i < ( width() * height()); i++) + _spi.write(_background); _cs = 1; _spi.unlock(); } @@ -505,67 +342,19 @@ int w; w = x1 - x0 + 1; window(x0,y,w,1); + _spi.lock(); + _cs = 0; + _reset=0; wr_cmd(0x22); - _spi.lock(); - _cs = 0; - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - #if defined USE_DMA - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; - LPC_GPDMACH0->DMACCControl = w | (1UL << 18) | (1UL << 21) | (1UL << 31) ; // 16 bit transfer , no address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; // start DMA - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI FIFO not empty - } else { // TFT on SSP1 - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty - } - #else // no DMA - int i; - for (i=0; i<w; i++) { - _spi.write(color); - } - #endif - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - for (int j=0; j<w; j++) { - _spi.write(color >> 8); - _spi.write(color & 0xff); - } - #else // 16 Bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch back to 16 bit Mode 3 + _reset=1; + // 16 Bit SPI + // _spi.format(8,3); // 8 bit Mode 3 + // _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 + // _spi.format(16,3); // switch back to 16 bit Mode 3 for (int j=0; j<w; j++) { _spi.write(color); } - #endif - #endif + _cs = 1; _spi.unlock(); WindowMax(); @@ -578,67 +367,20 @@ int h; h = y1 - y0 + 1; window(x,y0,1,h); + _spi.lock(); + _cs = 0; + _reset=0; wr_cmd(0x22); - _spi.lock(); - _cs = 0; - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - #if defined USE_DMA - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; - LPC_GPDMACH0->DMACCControl = h | (1UL << 18) | (1UL << 21) | (1UL << 31) ; // 16 bit transfer , no address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI FIFO not empty - } else { // TFT on SSP1 - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty - } - #else // no DMA + _reset=1; + + // 16 bit SPI + // _spi.format(8,3); // 8 bit Mode 3 + // _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 + // _spi.format(16,3); // switch to 16 bit Mode 3 for (int y=0; y<h; y++) { _spi.write(color); } - #endif - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - for (int y=0; y<h; y++) { - _spi.write(color >> 8); - _spi.write(color & 0xff); - } - #else // 16 bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch to 16 bit Mode 3 - for (int y=0; y<h; y++) { - _spi.write(color); - } - #endif - #endif + _cs = 1; _spi.unlock(); WindowMax(); @@ -749,80 +491,20 @@ int dma_count; #endif window(x0,y0,w,h); + _spi.lock(); + _cs = 0; + _reset=0; wr_cmd(0x22); - _spi.lock(); - _cs = 0; - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - #if defined USE_DMA - do { - if (pixel > 4095) { - dma_count = 4095; - pixel = pixel - 4095; - } else { - dma_count = pixel; - pixel = 0; - } - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; - LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) ; // 16 bit transfer , no address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - - } while (pixel > 0); - - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI FIFO not empty - } else { // TFT on SSP1 - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty - } - - #else // no DMA - for (int p=0; p<pixel; p++) { - _spi.write(color); - } - #endif - - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - for (int p=0; p<pixel; p++) { - _spi.write(color >> 8); - _spi.write(color & 0xff); - } - - #else // 16 bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch to 16 bit Mode 3 + _reset=1; + + // 16 bit SPI +// _spi.format(8,3); // 8 bit Mode 3 +// _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 +// _spi.format(16,3); // switch to 16 bit Mode 3 for (int p=0; p<pixel; p++) { _spi.write(color); } - #endif - #endif + _cs = 1; _spi.unlock(); WindowMax(); @@ -870,12 +552,6 @@ unsigned int hor,vert,offset,bpl,j,i,b; unsigned char* zeichen; unsigned char z,w; - #if defined USE_DMA - unsigned int pixel; - unsigned int p; - unsigned int dma_count,dma_off; - uint16_t *buffer; - #endif if ((c < 31) || (c > 127)) return; // test char range @@ -893,111 +569,16 @@ } } window(char_x, char_y,hor,vert); // char box + _spi.lock(); + _cs = 0; + _reset=0; wr_cmd(0x22); - - #if defined USE_DMA - pixel = hor * vert; // calculate buffer size - - buffer = (uint16_t *) malloc (2*pixel); // we need a buffer for the 16 bit - if (buffer == NULL) { - //led = 1; - //pc.printf("Malloc error !\n\r"); - return; // error no memory - } - - zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap - w = zeichen[0]; // width of actual char - p = 0; - // construct the char into the buffer - for (j=0; j<vert; j++) { // vert line - for (i=0; i<hor; i++) { // horz line - z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; - b = 1 << (j & 0x07); - if (( z & b ) == 0x00) { - buffer[p] = _background; - } else { - buffer[p] = _foreground; - } - p++; - } - } - - // copy the buffer with DMA SPI to display - dma_off = 0; // offset for DMA transfer - _spi.lock(); - _cs = 0; - if (spi_port == 0) { // TFT on SSP0 - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - - // start DMA - do { - if (pixel > 4095) { // this is a giant font ! - dma_count = 4095; - pixel = pixel - 4095; - } else { - dma_count = pixel; - pixel = 0; - } - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + dma_off); - LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 16 bit transfer , address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - dma_off = dma_off + dma_count; - } while (pixel > 0); - - free ((uint16_t *) buffer); - - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI0 not idle - /* disable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x0; - } else { // TFT on SSP1 - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle - /* disable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x0; - } - - #else // no dma - _spi.lock(); - _cs = 0; - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - #else // mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - #else // 16 bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch back to 16 bit Mode 3 - #endif - #endif + _reset=1; + // 16 bit SPI +// _spi.format(8,3); // 8 bit Mode 3 +// _spi.write(SPI_START ); // Write : RS = 1, RW = 0 +// _spi.format(16,3); // switch back to 16 bit Mode 3 + zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap w = zeichen[0]; // width of actual char @@ -1006,23 +587,17 @@ z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; b = 1 << (j & 0x07); if (( z & b ) == 0x00) { - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(_background >> 8); - _spi.write(_background & 0xff); - #else + _spi.write(_background); - #endif + } else { - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(_foreground >> 8); - _spi.write(_foreground & 0xff); - #else + _spi.write(_foreground); - #endif + } } } - #endif // no DMA + _cs = 1; _spi.unlock(); WindowMax(); @@ -1054,90 +629,30 @@ padd ++; } while (2*(w + padd)%4 != 0); window(x, y, w, h); + _spi.lock(); + _cs = 0; + _reset=0; wr_cmd(0x22); - _spi.lock(); - _cs = 0; -#if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - - } else { - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data command - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } + _reset=1; - bitmap_ptr += ((h - 1)* (w + padd)); - #if defined USE_DMA - for (j = 0; j < h; j++) { //Lines - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)bitmap_ptr; - LPC_GPDMACH0->DMACCControl = w | (1UL << 18) | (1UL << 21) | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 16 bit transfer , address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - bitmap_ptr -= w; - bitmap_ptr -= padd; - } - #else - unsigned int i; - for (j = 0; j < h; j++) { //Lines - for (i = 0; i < w; i++) { // copy pixel data to TFT - _spi.write(*bitmap_ptr); // one line - bitmap_ptr++; - } - bitmap_ptr -= 2*w; - bitmap_ptr -= padd; - } - #endif - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI FIFO not empty - } else { - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty - } -#else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - #else - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch to 16 bit Mode 3 - #endif +// _spi.format(8,3); // 8 bit Mode 3 + // _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 + // _spi.format(16,3); // switch to 16 bit Mode 3 + bitmap_ptr += ((h - 1)* (w + padd)); unsigned int i; for (j = 0; j < h; j++) { //Lines for (i = 0; i < w; i++) { // copy pixel data to TFT - #if defined TARGET_KL25Z // 8 Bit SPI - pix_temp = *bitmap_ptr; - _spi.write(pix_temp >> 8); - _spi.write(pix_temp); - bitmap_ptr++; - #else + _spi.write(*bitmap_ptr); // one line bitmap_ptr++; - #endif + } bitmap_ptr -= 2*w; bitmap_ptr -= padd; } -#endif // USE MBED LIB + _cs = 1; _spi.unlock(); WindowMax(); @@ -1216,9 +731,11 @@ //fseek(Image, 70 ,SEEK_SET); window(x, y,PixelWidth ,PixelHeigh); + _spi.lock(); + _cs = 0; + _reset=0; wr_cmd(0x22); - _spi.lock(); - _cs = 0; + _reset=1; #if defined NO_MBED_LIB if (spi_port == 0) { // TFT on SSP0 #if defined USE_DMA