subsys/cfb: move MSB_FIRST down to font capabilities
Font capabilities currently indicate whether font data is packed horizontally or vertically, and this is used to control frame buffer updates. The font bit ordering should likewise be recorded in the font description, and any reversal to match the display applied when text is being set in the frame buffer. Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
parent
4c4f07e0dc
commit
e3d613e1f4
2 changed files with 19 additions and 25 deletions
|
@ -44,6 +44,7 @@ enum cfb_display_param {
|
|||
enum cfb_font_caps {
|
||||
CFB_FONT_MONO_VPACKED = BIT(0),
|
||||
CFB_FONT_MONO_HPACKED = BIT(1),
|
||||
CFB_FONT_MSB_FIRST = BIT(2),
|
||||
};
|
||||
|
||||
struct cfb_font {
|
||||
|
|
|
@ -15,6 +15,14 @@ LOG_MODULE_REGISTER(cfb);
|
|||
extern const struct cfb_font __font_entry_start[];
|
||||
extern const struct cfb_font __font_entry_end[];
|
||||
|
||||
static inline u8_t byte_reverse(u8_t b)
|
||||
{
|
||||
b = (b & 0xf0) >> 4 | (b & 0x0f) << 4;
|
||||
b = (b & 0xcc) >> 2 | (b & 0x33) << 2;
|
||||
b = (b & 0xaa) >> 1 | (b & 0x55) << 1;
|
||||
return b;
|
||||
}
|
||||
|
||||
struct char_framebuffer {
|
||||
/** Pointer to a buffer in RAM */
|
||||
u8_t *buf;
|
||||
|
@ -75,6 +83,8 @@ static u8_t draw_char_vtmono(const struct char_framebuffer *fb,
|
|||
{
|
||||
const struct cfb_font *fptr = &(fb->fonts[fb->font_idx]);
|
||||
u8_t *glyph_ptr;
|
||||
bool need_reverse = (((fb->screen_info & SCREEN_INFO_MONO_MSB_FIRST) != 0)
|
||||
!= ((fptr->caps & CFB_FONT_MSB_FIRST) != 0));
|
||||
|
||||
if (c < fptr->first_char || c > fptr->last_char) {
|
||||
c = ' ';
|
||||
|
@ -90,12 +100,18 @@ static u8_t draw_char_vtmono(const struct char_framebuffer *fb,
|
|||
|
||||
for (size_t g_y = 0; g_y < fptr->height / 8U; g_y++) {
|
||||
u32_t fb_y = (y_segment + g_y) * fb->x_res;
|
||||
u8_t byte;
|
||||
|
||||
if ((fb_y + x + g_x) >= fb->size) {
|
||||
return 0;
|
||||
}
|
||||
fb->buf[fb_y + x + g_x] =
|
||||
glyph_ptr[g_x * (fptr->height / 8U) + g_y];
|
||||
|
||||
byte = glyph_ptr[g_x * (fptr->height / 8U) + g_y];
|
||||
if (need_reverse) {
|
||||
byte = byte_reverse(byte);
|
||||
}
|
||||
|
||||
fb->buf[fb_y + x + g_x] = byte;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -134,25 +150,6 @@ int cfb_print(struct device *dev, char *str, u16_t x, u16_t y)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int cfb_reverse_bytes(const struct char_framebuffer *fb)
|
||||
{
|
||||
if (!(fb->screen_info & SCREEN_INFO_MONO_VTILED)) {
|
||||
LOG_ERR("Unsupported framebuffer configuration");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < fb->x_res * fb->y_res / 8U; i++) {
|
||||
fb->buf[i] = (fb->buf[i] & 0xf0) >> 4 |
|
||||
(fb->buf[i] & 0x0f) << 4;
|
||||
fb->buf[i] = (fb->buf[i] & 0xcc) >> 2 |
|
||||
(fb->buf[i] & 0x33) << 2;
|
||||
fb->buf[i] = (fb->buf[i] & 0xaa) >> 1 |
|
||||
(fb->buf[i] & 0x55) << 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cfb_invert(const struct char_framebuffer *fb)
|
||||
{
|
||||
for (size_t i = 0; i < fb->x_res * fb->y_res / 8U; i++) {
|
||||
|
@ -213,10 +210,6 @@ int cfb_framebuffer_finalize(struct device *dev)
|
|||
cfb_invert(fb);
|
||||
}
|
||||
|
||||
if (fb->screen_info & SCREEN_INFO_MONO_MSB_FIRST) {
|
||||
cfb_reverse_bytes(fb);
|
||||
}
|
||||
|
||||
return api->write(dev, 0, 0, &desc, fb->buf);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue