nrf5/drivers: Updating ili9341 display object to use new framebuffer.
This commit is contained in:
parent
535f44b8bf
commit
6ab233a5ba
|
@ -38,26 +38,34 @@
|
|||
/// \moduleref display
|
||||
/// \class ILI9341 - ILI9341 TFT LCD display driver.
|
||||
|
||||
#include "moddisplay.h"
|
||||
#include "framebuffer.h"
|
||||
#include "pin.h"
|
||||
#include "spi.h"
|
||||
#include "lcd_mono_fb.h"
|
||||
|
||||
typedef struct _lcd_ili9341_obj_t {
|
||||
mp_obj_base_t base;
|
||||
display_draw_callbacks_t draw_callbacks;
|
||||
framebuffer_t * framebuffer;
|
||||
machine_hard_spi_obj_t *spi;
|
||||
pin_obj_t * pin_cs;
|
||||
pin_obj_t * pin_dc;
|
||||
mp_obj_framebuf_t * framebuffer;
|
||||
} lcd_ili9341_obj_t;
|
||||
|
||||
static void dirty_line_update_cb(mp_obj_framebuf_t * p_framebuffer,
|
||||
uint16_t line,
|
||||
fb_byte_t * p_new,
|
||||
fb_byte_t * p_old) {
|
||||
// the lcd does not have double buffer needs, skip it.
|
||||
(void)p_old;
|
||||
#define LCD_ILI9341_COLOR_BLACK 0
|
||||
#define LCD_ILI9341_COLOR_WHITE 1
|
||||
|
||||
driver_ili9341_update_line(line, p_new, p_framebuffer->bytes_stride, true);
|
||||
static void set_pixel(void * p_display,
|
||||
uint16_t x,
|
||||
uint16_t y,
|
||||
uint16_t color) {
|
||||
lcd_ili9341_obj_t *self = (lcd_ili9341_obj_t *)p_display;
|
||||
|
||||
if (color == LCD_ILI9341_COLOR_BLACK) {
|
||||
framebuffer_pixel_clear(self->framebuffer, x, y);
|
||||
} else {
|
||||
framebuffer_pixel_set(self->framebuffer, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
/// \method __str__()
|
||||
|
@ -80,9 +88,12 @@ STATIC void lcd_ili9341_print(const mp_print_t *print, mp_obj_t o, mp_print_kind
|
|||
self->pin_dc->port,
|
||||
self->pin_dc->pin);
|
||||
|
||||
mp_printf(print, " FB(width=%u, height=%u, dir=%u))\n",
|
||||
self->framebuffer->width,
|
||||
self->framebuffer->height);
|
||||
mp_printf(print, " FB(width=%u, height=%u, dir=%u, fb_stride=%u, fb_dirty_stride=%u))\n",
|
||||
self->framebuffer->screen_width,
|
||||
self->framebuffer->screen_height,
|
||||
self->framebuffer->line_orientation,
|
||||
self->framebuffer->fb_stride,
|
||||
self->framebuffer->fb_dirty_stride);
|
||||
}
|
||||
|
||||
// for make_new
|
||||
|
@ -145,6 +156,7 @@ STATIC mp_obj_t lcd_ili9341_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||
|
||||
lcd_ili9341_obj_t *s = m_new_obj_with_finaliser(lcd_ili9341_obj_t);
|
||||
s->base.type = type;
|
||||
s->draw_callbacks.pixel_set = set_pixel;
|
||||
|
||||
mp_int_t width;
|
||||
mp_int_t height;
|
||||
|
@ -184,15 +196,22 @@ STATIC mp_obj_t lcd_ili9341_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||
"Display DC Pin not set"));
|
||||
}
|
||||
|
||||
// direction arg not yet configurable
|
||||
mp_int_t vertical = true;
|
||||
s->framebuffer = lcd_mono_fb_helper_make_new(width, height, vertical);
|
||||
framebuffer_init_t init_conf = {
|
||||
.width = width,
|
||||
.height = height,
|
||||
.line_orientation = FRAMEBUFFER_LINE_DIR_HORIZONTAL,
|
||||
.double_buffer = false
|
||||
};
|
||||
|
||||
s->framebuffer = m_new(framebuffer_t, sizeof(framebuffer_t));
|
||||
|
||||
framebuffer_init(s->framebuffer, &init_conf);
|
||||
|
||||
driver_ili9341_init(s->spi->pyb->spi->instance, s->pin_cs, s->pin_dc);
|
||||
// Default to white background
|
||||
driver_ili9341_clear(0xFFFF);
|
||||
driver_ili9341_clear(0x0000);
|
||||
|
||||
display_clear_screen(s->framebuffer, 0x1);
|
||||
framebuffer_clear(s->framebuffer);
|
||||
|
||||
return MP_OBJ_FROM_PTR(s);
|
||||
}
|
||||
|
@ -204,18 +223,40 @@ STATIC mp_obj_t lcd_ili9341_make_new(const mp_obj_type_t *type, size_t n_args, s
|
|||
STATIC mp_obj_t lcd_ili9341_fill(mp_obj_t self_in, mp_obj_t color) {
|
||||
lcd_ili9341_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
display_clear_screen(self->framebuffer, (uint8_t)mp_obj_get_int(color));
|
||||
if (color == MP_OBJ_NEW_SMALL_INT(LCD_ILI9341_COLOR_BLACK)) {
|
||||
framebuffer_clear(self->framebuffer);
|
||||
} else {
|
||||
framebuffer_fill(self->framebuffer);
|
||||
}
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(lcd_ili9341_fill_obj, lcd_ili9341_fill);
|
||||
|
||||
static void render(framebuffer_t * p_framebuffer) {
|
||||
for (uint16_t i = 0; i < p_framebuffer->fb_dirty_stride; i++) {
|
||||
if (p_framebuffer->fb_dirty[i].byte != 0) {
|
||||
for (uint16_t b = 0; b < 8; b++) {
|
||||
if ((((p_framebuffer->fb_dirty[i].byte >> b) & 0x01) == 1)) {
|
||||
uint16_t line_num = (i * 8) + b;
|
||||
driver_ili9341_update_line(line_num,
|
||||
&p_framebuffer->fb_new[line_num * p_framebuffer->fb_stride],
|
||||
p_framebuffer->fb_stride);
|
||||
}
|
||||
}
|
||||
|
||||
p_framebuffer->fb_dirty[i].byte = 0x00;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// \method show()
|
||||
/// Display content in framebuffer.
|
||||
STATIC mp_obj_t lcd_ili9341_show(size_t n_args, const mp_obj_t *args) {
|
||||
lcd_ili9341_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
|
||||
display_update(self->framebuffer, false, dirty_line_update_cb);
|
||||
render(self->framebuffer);
|
||||
framebuffer_flip(self->framebuffer);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -245,14 +286,9 @@ STATIC mp_obj_t lcd_ili9341_pixel(size_t n_args, const mp_obj_t *args) {
|
|||
lcd_ili9341_obj_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_int_t x = mp_obj_get_int(args[1]);
|
||||
mp_int_t y = mp_obj_get_int(args[2]);
|
||||
mp_int_t color;
|
||||
if (n_args >= 3) {
|
||||
color = mp_obj_get_int(args[3]);
|
||||
}
|
||||
(void)self;
|
||||
(void)x;
|
||||
(void)y;
|
||||
(void)color;
|
||||
mp_int_t color = mp_obj_get_int(args[3]);
|
||||
|
||||
set_pixel(self, x, y, color);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -273,8 +309,12 @@ STATIC mp_obj_t lcd_ili9341_text(size_t n_args, const mp_obj_t *args) {
|
|||
color = mp_obj_get_int(args[3]);
|
||||
}
|
||||
|
||||
display_print_string(self->framebuffer, x, y, str);
|
||||
// display_print_string(self->framebuffer, x, y, str);
|
||||
|
||||
(void)x;
|
||||
(void)y;
|
||||
(void)self;
|
||||
(void)str;
|
||||
(void)color;
|
||||
|
||||
return mp_const_none;
|
||||
|
@ -299,8 +339,8 @@ STATIC const mp_map_elem_t lcd_ili9341_locals_dict_table[] = {
|
|||
#if 0
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_bitmap), (mp_obj_t)(&lcd_ili9341_bitmap_obj) },
|
||||
#endif
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_BLACK), MP_OBJ_NEW_SMALL_INT(LCD_BLACK) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_WHITE), MP_OBJ_NEW_SMALL_INT(LCD_WHITE) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_BLACK), MP_OBJ_NEW_SMALL_INT(LCD_ILI9341_COLOR_BLACK) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_WHITE), MP_OBJ_NEW_SMALL_INT(LCD_ILI9341_COLOR_WHITE) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_VERTICAL), MP_OBJ_NEW_SMALL_INT(0) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_HORIZONTAL), MP_OBJ_NEW_SMALL_INT(1) },
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue