@ -23,8 +23,8 @@
uint16_t spi_buffer [ SPI_BUFFER_SIZE ] ;
// Default foreground & background colors
uint16_t foreground_color = DEFAULT_FG_COLOR ;
uint16_t background_color = DEFAULT_BG_COLOR ;
uint16_t foreground_color = 0 ;
uint16_t background_color = 0 ;
// Display width and height definition
# define ILI9341_WIDTH 320
@ -223,7 +223,7 @@ static void spi_init(void)
SPI1 - > CR1 = SPI_CR1_MSTR // SPI is MASTER
| SPI_CR1_SSM // Software slave management (The external NSS pin is free for other application uses)
| SPI_CR1_SSI ; // Internal slave select (This bit has an effect only when the SSM bit is set. Allow use NSS pin as I/O)
// | SPI_CR1_BR_1; // Baud rate control
// | SPI_CR1_BR_1; // Baud rate control
SPI1 - > CR2 = SPI_CR2_8BIT // SPI data size, set to 8 bit
| SPI_CR2_FRXTH ; // SPI_SR_RXNE generated every 8 bit data
@ -247,7 +247,7 @@ static void spi_init(void)
static void __attribute__ ( ( noinline ) ) send_command ( uint8_t cmd , uint8_t len , const uint8_t * data )
{
CS_LOW ;
// while (SPI_TX_IS_NOT_EMPTY);
// while (SPI_TX_IS_NOT_EMPTY);
DC_CMD ;
SPI_WRITE_8BIT ( cmd ) ;
// Need wait transfer complete and set data bit
@ -301,13 +301,13 @@ static const uint8_t ili9341_init_seq[] = {
// gamma set for curve 01/2/04/08
ILI9341_GAMMA_SET , 1 , 0x01 ,
// positive gamma correction
// ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0x87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00,
// ILI9341_POSITIVE_GAMMA_CORRECTION, 15, 0x1F, 0x1A, 0x18, 0x0A, 0x0F, 0x06, 0x45, 0x87, 0x32, 0x0A, 0x07, 0x02, 0x07, 0x05, 0x00,
// negativ gamma correction
// ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F,
// ILI9341_NEGATIVE_GAMMA_CORRECTION, 15, 0x00, 0x25, 0x27, 0x05, 0x10, 0x09, 0x3A, 0x78, 0x4D, 0x05, 0x18, 0x0D, 0x38, 0x3A, 0x1F,
// Column Address Set
// ILI9341_COLUMN_ADDRESS_SET, 4, 0x00, 0x00, 0x01, 0x3f, // width 320
// ILI9341_COLUMN_ADDRESS_SET, 4, 0x00, 0x00, 0x01, 0x3f, // width 320
// Page Address Set
// ILI9341_PAGE_ADDRESS_SET, 4, 0x00, 0x00, 0x00, 0xef, // height 240
// ILI9341_PAGE_ADDRESS_SET, 4, 0x00, 0x00, 0x00, 0xef, // height 240
// entry mode
ILI9341_ENTRY_MODE_SET , 1 , 0x06 ,
// display function control
@ -343,8 +343,8 @@ void ili9341_init(void)
# ifndef __USE_DISPLAY_DMA__
void ili9341_fill ( int x , int y , int w , int h , int color )
{
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
uint32_t xx = __REV16 ( x | ( ( x + w - 1 ) < < 16 ) ) ;
uint32_t yy = __REV16 ( y | ( ( y + h - 1 ) < < 16 ) ) ;
send_command ( ILI9341_COLUMN_ADDRESS_SET , 4 , ( uint8_t * ) & xx ) ;
@ -359,8 +359,8 @@ void ili9341_fill(int x, int y, int w, int h, int color)
void ili9341_bulk ( int x , int y , int w , int h )
{
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
uint16_t * buf = spi_buffer ;
uint32_t xx = __REV16 ( x | ( ( x + w - 1 ) < < 16 ) ) ;
uint32_t yy = __REV16 ( y | ( ( y + h - 1 ) < < 16 ) ) ;
@ -385,8 +385,8 @@ static uint8_t ssp_sendrecvdata(void)
void ili9341_read_memory ( int x , int y , int w , int h , int len , uint16_t * out )
{
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
uint32_t xx = __REV16 ( x | ( ( x + w - 1 ) < < 16 ) ) ;
uint32_t yy = __REV16 ( y | ( ( y + h - 1 ) < < 16 ) ) ;
send_command ( ILI9341_COLUMN_ADDRESS_SET , 4 , ( uint8_t * ) & xx ) ;
@ -425,6 +425,23 @@ void ili9341_fill(int x, int y, int w, int h, int color)
dmaStreamSetMode ( dmatx , txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD ) ;
dmaStreamFlush ( w * h ) ;
}
void ili9341_bulk_8bit ( int x , int y , int w , int h , uint16_t * palette ) {
uint32_t xx = __REV16 ( x | ( ( x + w - 1 ) < < 16 ) ) ;
uint32_t yy = __REV16 ( y | ( ( y + h - 1 ) < < 16 ) ) ;
send_command ( ILI9341_COLUMN_ADDRESS_SET , 4 , ( uint8_t * ) & xx ) ;
send_command ( ILI9341_PAGE_ADDRESS_SET , 4 , ( uint8_t * ) & yy ) ;
send_command ( ILI9341_MEMORY_WRITE , 0 , NULL ) ;
uint8_t * buf = ( uint8_t * ) spi_buffer ;
int32_t len = w * h ;
while ( len - - > 0 ) {
uint16_t color = palette [ * buf + + ] ;
while ( SPI_TX_IS_NOT_EMPTY ) ;
SPI_WRITE_16BIT ( color ) ;
}
}
// Copy spi_buffer to region
void ili9341_bulk ( int x , int y , int w , int h )
{