X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Flcd_ili9225.c;h=e3112df2a7bf3ded3358e9ff93e8d646eb935a05;hb=ce0a95c32a39e3eed1d3f2aa5ff4395bebdb99ed;hp=51428db6e595552a5411d2261e91762550a9eb74;hpb=e0a81da777b4dd0dd962e366c61de763ccea510c;p=bertos.git diff --git a/bertos/drv/lcd_ili9225.c b/bertos/drv/lcd_ili9225.c index 51428db6..e3112df2 100644 --- a/bertos/drv/lcd_ili9225.c +++ b/bertos/drv/lcd_ili9225.c @@ -30,7 +30,7 @@ * * --> * - * \brief ILI9225B 176x220 graphic driver + * \brief ILI9225B 4 wire interface graphic driver * * \author Stefano Fedrigo * @@ -72,11 +72,18 @@ #include "hw/hw_ili9225.h" #include -#include #include +#include -static struct Serial *spi; +static struct KFile *spi; + +/* + * Display row buffer. When refreshing display one full row of + * graphics data is transferred with DMA, to speed up transfer and + * reduce CPU usage. + */ +static uint16_t lcd_row[LCD_WIDTH]; struct lcd_ili9225_reg @@ -134,26 +141,24 @@ static void lcd_cmd(uint8_t cmd) { LCD_CS_LOW(); LCD_RS_LOW(); - kfile_write(&spi->fd, &cmd, sizeof(cmd)); + kfile_write(spi, &cmd, sizeof(cmd)); } -static void lcd_data(uint16_t data) +static void lcd_data(uint16_t *data, size_t count) { - char bytes[2]; - bytes[0] = data >> 8; - bytes[1] = data & 0xFF; - - kfile_flush(&spi->fd); + kfile_flush(spi); LCD_RS_HIGH(); - kfile_write(&spi->fd, bytes, 2); - kfile_flush(&spi->fd); + kfile_write(spi, data, count*2); + kfile_flush(spi); LCD_CS_HIGH(); } static void lcd_regWrite(uint8_t reg, uint16_t data) { + uint16_t word = cpu_to_be16(data); + lcd_cmd(reg); - lcd_data(data); + lcd_data(&word, 1); } static void lcd_startBlit(uint8_t x, uint8_t y, uint8_t width, uint8_t height) @@ -185,7 +190,6 @@ void lcd_ili9225_blitRaw(UNUSED_ARG(const uint8_t *, data), */ void lcd_ili9225_blitBitmap(const Bitmap *bm) { - //uint16_t lcd_row[bm->width]; uint8_t mask; int i, l, r; @@ -198,10 +202,12 @@ void lcd_ili9225_blitBitmap(const Bitmap *bm) for (i = 0; i < bm->width; i++) { if (bm->raster[l * bm->width + i] & mask) - lcd_regWrite(0x22, 0xffff); + lcd_row[i] = 0x0000; else - lcd_regWrite(0x22, 0x0000); + lcd_row[i] = 0xFFFF; } + lcd_cmd(0x22); + lcd_data(lcd_row, bm->width); } } @@ -210,10 +216,38 @@ void lcd_ili9225_blitBitmap(const Bitmap *bm) for (i = 0; i < bm->width; i++) { if (bm->raster[l * bm->width + i] & mask) - lcd_regWrite(0x22, 0xffff); + lcd_row[i] = 0x0000; else - lcd_regWrite(0x22, 0x0000); + lcd_row[i] = 0xFFFF; } + lcd_cmd(0x22); + lcd_data(lcd_row, bm->width); + } +} + +/* + * Blit a 24 bit color raw raster directly on screen + */ +void lcd_ili9225_blitBitmap24(int x, int y, int width, int height, const char *bmp) +{ + int l, r; + + lcd_startBlit(x, y, width, height); + + for (l = 0; l < height; l++) + { + for (r = 0; r < width; r++) + { + lcd_row[r] = + (((uint16_t)bmp[1] << 11) & 0xE000) | + (((uint16_t)bmp[2] << 5) & 0x1F00) | + (((uint16_t)bmp[0] << 0) & 0x00F8) | + (((uint16_t)bmp[1] >> 5) & 0x0007); + bmp += 3; + } + + lcd_cmd(0x22); + lcd_data(lcd_row, width); } } @@ -244,37 +278,10 @@ static void lcd_reset(void) timer_delay(50); } -/** - * Set display backlight intensity. - */ -void lcd_ili9225_backlight(unsigned level) -{ - unsigned i; - - if (level > LCD_BACKLIGHT_MAX) - level = LCD_BACKLIGHT_MAX; - - // Switch off backlight - LCD_BACKLIGHT_LOW(); - timer_delay(1); - - // Set new level - for (i = 0; i <= level; i++) - { - LCD_BACKLIGHT_LOW(); - LCD_BACKLIGHT_LOW(); - LCD_BACKLIGHT_LOW(); - - LCD_BACKLIGHT_HIGH(); - LCD_BACKLIGHT_HIGH(); - LCD_BACKLIGHT_HIGH(); - } -} - /** * Display initialization. */ -void lcd_ili9225_init(struct Serial *_spi) +void lcd_ili9225_init(struct KFile *_spi) { unsigned i;