nrf5/lcd: Correcting indention (tabs with space) in framebuffer module source and header.

This commit is contained in:
Glenn Ruben Bakke 2016-12-29 15:54:47 +01:00
parent c8ff22ced0
commit 82746d4549
2 changed files with 112 additions and 115 deletions

View File

@ -38,14 +38,14 @@
#define LCD_WHITE 1
typedef struct {
mp_obj_base_t base;
fb_byte_t * fb_bytes;
fb_byte_t * fb_dirty;
uint16_t height;
uint16_t width;
mp_uint_t bytes_stride;
mp_uint_t dirty_stride;
mp_obj_t line_update_cb;
mp_obj_base_t base;
fb_byte_t * fb_bytes;
fb_byte_t * fb_dirty;
uint16_t height;
uint16_t width;
mp_uint_t bytes_stride;
mp_uint_t dirty_stride;
mp_obj_t line_update_cb;
} mp_obj_framebuf_t;
static uint8_t m_bg_color;
@ -53,17 +53,17 @@ static uint8_t m_fg_color;
static uint8_t m_font_size;
STATIC void lcd_enable_pixel(mp_obj_framebuf_t * p_framebuffer, uint16_t x, uint16_t y) {
uint16_t column = (x / 8);
uint16_t line = y;
uint8_t bit_pos = x % 8;
uint16_t column = (x / 8);
uint16_t line = y;
uint8_t bit_pos = x % 8;
p_framebuffer->fb_bytes[line * (p_framebuffer->bytes_stride) + column].byte |= (1 << bit_pos);
p_framebuffer->fb_dirty[y / 8].byte |= (uint8_t)(0x1 << y % 8);
p_framebuffer->fb_bytes[line * (p_framebuffer->bytes_stride) + column].byte |= (1 << bit_pos);
p_framebuffer->fb_dirty[y / 8].byte |= (uint8_t)(0x1 << y % 8);
}
STATIC void lcd_disable_pixel(mp_obj_framebuf_t * p_framebuffer, uint16_t x, uint16_t y) {
uint16_t column = (x / 8);
uint16_t line = y;
uint16_t column = (x / 8);
uint16_t line = y;
uint8_t bit_pos = x % 8;
p_framebuffer->fb_bytes[line * (p_framebuffer->bytes_stride) + column].byte &= ~(1 << bit_pos);
@ -71,125 +71,125 @@ STATIC void lcd_disable_pixel(mp_obj_framebuf_t * p_framebuffer, uint16_t x, uin
}
STATIC void lcd_init(mp_obj_framebuf_t * p_framebuffer) {
m_fg_color = LCD_BLACK;
m_bg_color = LCD_WHITE;
m_fg_color = LCD_BLACK;
m_bg_color = LCD_WHITE;
memset(p_framebuffer->fb_bytes, 0x00, p_framebuffer->bytes_stride * p_framebuffer->height);
memset(p_framebuffer->fb_dirty, 0x00, p_framebuffer->dirty_stride);
memset(p_framebuffer->fb_bytes, 0x00, p_framebuffer->bytes_stride * p_framebuffer->height);
memset(p_framebuffer->fb_dirty, 0x00, p_framebuffer->dirty_stride);
}
STATIC void lcd_fg_color_set(mp_obj_framebuf_t * p_framebuffer, uint16_t color) {
m_fg_color = (color == 0) ? LCD_BLACK : LCD_WHITE;
m_fg_color = (color == 0) ? LCD_BLACK : LCD_WHITE;
}
#if 0
STATIC uint16_t lcd_fg_color_get(mp_obj_framebuf_t * p_framebuffer) {
return m_fg_color;
return m_fg_color;
}
#endif
STATIC void lcd_bg_color_set(mp_obj_framebuf_t * p_framebuffer, uint16_t color) {
m_bg_color = (color == 0) ? LCD_BLACK : LCD_WHITE;
m_bg_color = (color == 0) ? LCD_BLACK : LCD_WHITE;
}
#if 0
STATIC uint16_t lcd_bg_color_get(mp_obj_framebuf_t * p_framebuffer) {
return m_bg_color;
return m_bg_color;
}
#endif
STATIC void lcd_clear_screen(mp_obj_framebuf_t * p_framebuffer) {
if (m_bg_color == LCD_BLACK) {
memset(p_framebuffer->fb_bytes, 0x00, p_framebuffer->bytes_stride * p_framebuffer->height);
} else {
memset(p_framebuffer->fb_bytes, 0xFF, p_framebuffer->bytes_stride * p_framebuffer->height);
}
memset(p_framebuffer->fb_dirty, 0xFF, p_framebuffer->dirty_stride);
if (m_bg_color == LCD_BLACK) {
memset(p_framebuffer->fb_bytes, 0x00, p_framebuffer->bytes_stride * p_framebuffer->height);
} else {
memset(p_framebuffer->fb_bytes, 0xFF, p_framebuffer->bytes_stride * p_framebuffer->height);
}
memset(p_framebuffer->fb_dirty, 0xFF, p_framebuffer->dirty_stride);
}
STATIC void lcd_print_char(mp_obj_framebuf_t * p_framebuffer, uint16_t x, uint16_t y, char ch) {
uint16_t col = x;
for (uint8_t i = 0; i < 8; i++) {
uint16_t col = x;
for (uint8_t i = 0; i < 8; i++) {
uint16_t current_col = col + (i * m_font_size);
uint16_t current_col = col + (i * m_font_size);
for (uint8_t y_pos = 0; y_pos < 8; y_pos++) {
if ((((uint8_t)font_petme128_8x8[((ch - 32) * 8) + i]) >> y_pos) & 0x01) {
for (uint8_t s_w = 0; s_w < m_font_size; s_w++) {
for (uint8_t s_h = 0; s_h < m_font_size; s_h++) {
if (m_fg_color < LCD_WHITE) {
lcd_disable_pixel(p_framebuffer,
current_col + s_w,
y + (y_pos * m_font_size) + s_h);
} else {
lcd_enable_pixel(p_framebuffer,
current_col + s_w,
y + (y_pos * m_font_size) + s_h);
}
}
}
} else {
for (uint8_t s_w = 0; s_w < m_font_size; s_w++) {
for (uint8_t s_h = 0; s_h < m_font_size; s_h++) {
if (m_bg_color < LCD_WHITE) {
lcd_disable_pixel(p_framebuffer,
current_col + s_w,
y + (y_pos * m_font_size) + s_h);
} else {
lcd_enable_pixel(p_framebuffer,
current_col + s_w,
y + (y_pos * m_font_size) + s_h);
}
}
}
}
}
}
for (uint8_t y_pos = 0; y_pos < 8; y_pos++) {
if ((((uint8_t)font_petme128_8x8[((ch - 32) * 8) + i]) >> y_pos) & 0x01) {
for (uint8_t s_w = 0; s_w < m_font_size; s_w++) {
for (uint8_t s_h = 0; s_h < m_font_size; s_h++) {
if (m_fg_color < LCD_WHITE) {
lcd_disable_pixel(p_framebuffer,
current_col + s_w,
y + (y_pos * m_font_size) + s_h);
} else {
lcd_enable_pixel(p_framebuffer,
current_col + s_w,
y + (y_pos * m_font_size) + s_h);
}
}
}
} else {
for (uint8_t s_w = 0; s_w < m_font_size; s_w++) {
for (uint8_t s_h = 0; s_h < m_font_size; s_h++) {
if (m_bg_color < LCD_WHITE) {
lcd_disable_pixel(p_framebuffer,
current_col + s_w,
y + (y_pos * m_font_size) + s_h);
} else {
lcd_enable_pixel(p_framebuffer,
current_col + s_w,
y + (y_pos * m_font_size) + s_h);
}
}
}
}
}
}
}
#if 0
STATIC void lcd_font_size_set(mp_obj_framebuf_t * p_framebuffer, uint8_t size) {
m_font_size = size;
m_font_size = size;
}
STATIC uint8_t lcd_font_size_get(mp_obj_framebuf_t * p_framebuffer) {
return m_font_size;
return m_font_size;
}
#endif
STATIC void lcd_print_string(mp_obj_framebuf_t * p_framebuffer, uint16_t x, uint16_t y, const char * p_str) {
uint16_t str_len = strlen(p_str);
for (uint16_t i = 0; i < str_len; i++) {
lcd_print_char(p_framebuffer, x + (i * 8 * m_font_size), y, p_str[i]);
}
uint16_t str_len = strlen(p_str);
for (uint16_t i = 0; i < str_len; i++) {
lcd_print_char(p_framebuffer, x + (i * 8 * m_font_size), y, p_str[i]);
}
}
STATIC void lcd_pixel_draw(mp_obj_framebuf_t * p_framebuffer, uint16_t x, uint16_t y, uint16_t color) {
if (color < LCD_WHITE) {
lcd_disable_pixel(p_framebuffer, x, y);
} else {
lcd_enable_pixel(p_framebuffer, x, y);
}
if (color < LCD_WHITE) {
lcd_disable_pixel(p_framebuffer, x, y);
} else {
lcd_enable_pixel(p_framebuffer, x, y);
}
}
STATIC void lcd_update(mp_obj_framebuf_t * p_framebuffer) {
for (uint16_t i = 0; i < p_framebuffer->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;
mp_obj_t args[3];
args[0] = p_framebuffer;
args[1] = MP_OBJ_NEW_SMALL_INT(line_num);
args[2] = mp_obj_new_bytearray_by_ref(p_framebuffer->bytes_stride,
&p_framebuffer->fb_bytes[line_num * p_framebuffer->bytes_stride]);
mp_call_function_n_kw(p_framebuffer->line_update_cb, 3, 0, args);
}
}
for (uint16_t i = 0; i < p_framebuffer->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;
mp_obj_t args[3];
args[0] = p_framebuffer;
args[1] = MP_OBJ_NEW_SMALL_INT(line_num);
args[2] = mp_obj_new_bytearray_by_ref(p_framebuffer->bytes_stride,
&p_framebuffer->fb_bytes[line_num * p_framebuffer->bytes_stride]);
mp_call_function_n_kw(p_framebuffer->line_update_cb, 3, 0, args);
}
}
p_framebuffer->fb_dirty[i].byte = 0x00;
}
}
p_framebuffer->fb_dirty[i].byte = 0x00;
}
}
}
STATIC mp_obj_t lcd_mono_fb_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
@ -217,10 +217,9 @@ STATIC mp_obj_t lcd_mono_fb_make_new(const mp_obj_type_t *type, size_t n_args, s
}
STATIC mp_obj_t lcd_mono_fb_fill(mp_obj_t self_in, mp_obj_t col_in) {
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t col = mp_obj_get_int(col_in);
lcd_bg_color_set(self, col);
lcd_fg_color_set(self, !col);
@ -231,7 +230,7 @@ STATIC mp_obj_t lcd_mono_fb_fill(mp_obj_t self_in, mp_obj_t col_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_2(lcd_mono_fb_fill_obj, lcd_mono_fb_fill);
STATIC mp_obj_t lcd_mono_fb_pixel(size_t n_args, const mp_obj_t *args) {
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_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 = mp_obj_get_int(args[3]);
@ -244,7 +243,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_mono_fb_pixel_obj, 3, 4, lcd_mono
STATIC mp_obj_t lcd_mono_fb_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t ystep_in) {
#if 0
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t xstep = mp_obj_get_int(xstep_in);
mp_int_t ystep = mp_obj_get_int(ystep_in);
#endif
@ -254,7 +253,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(lcd_mono_fb_scroll_obj, lcd_mono_fb_scroll);
STATIC mp_obj_t lcd_mono_fb_text(size_t n_args, const mp_obj_t *args) {
// extract arguments
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(args[0]);
const char *str = mp_obj_str_get_str(args[1]);
mp_int_t x0 = mp_obj_get_int(args[2]);
mp_int_t y0 = mp_obj_get_int(args[3]);
@ -267,16 +266,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_mono_fb_text_obj, 4, 5, lcd_mono_
STATIC mp_obj_t lcd_mono_fb_show(mp_obj_t self_in) {
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
lcd_update(self);
lcd_update(self);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(lcd_mono_fb_show_obj, lcd_mono_fb_show);
STATIC mp_obj_t lcd_mono_fb_del(mp_obj_t self_in) {
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_framebuf_t *self = MP_OBJ_TO_PTR(self_in);
m_free(self->fb_bytes);
m_free(self->fb_dirty);
@ -291,7 +290,7 @@ STATIC const mp_rom_map_elem_t lcd_mono_fb_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&lcd_mono_fb_pixel_obj) },
{ MP_ROM_QSTR(MP_QSTR_scroll), MP_ROM_PTR(&lcd_mono_fb_scroll_obj) },
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&lcd_mono_fb_text_obj) },
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&lcd_mono_fb_show_obj) },
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&lcd_mono_fb_show_obj) },
};
STATIC MP_DEFINE_CONST_DICT(lcd_mono_fb_locals_dict, lcd_mono_fb_locals_dict_table);

View File

@ -31,24 +31,22 @@ extern const mp_obj_module_t mp_module_lcd_mono_fb;
#include <stdint.h>
typedef struct
{
uint8_t bit0 : 1;
uint8_t bit1 : 1;
uint8_t bit2 : 1;
uint8_t bit3 : 1;
uint8_t bit4 : 1;
uint8_t bit5 : 1;
uint8_t bit6 : 1;
uint8_t bit7 : 1;
typedef struct {
uint8_t bit0 : 1;
uint8_t bit1 : 1;
uint8_t bit2 : 1;
uint8_t bit3 : 1;
uint8_t bit4 : 1;
uint8_t bit5 : 1;
uint8_t bit6 : 1;
uint8_t bit7 : 1;
} bits_t;
typedef struct {
union {
uint8_t byte;
bits_t bits;
};
union {
uint8_t byte;
bits_t bits;
};
} fb_byte_t;
#endif