fb: cfb: Add cfb_draw_point() API

Add cfb_draw_point() API for rendering dot.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
This commit is contained in:
TOKITA Hiroshi 2023-05-12 07:46:27 +09:00 committed by Anas Nashif
parent 32668dc7fd
commit 9def1258a0
2 changed files with 45 additions and 0 deletions

View File

@ -57,6 +57,11 @@ struct cfb_font {
uint8_t last_char;
};
struct cfb_position {
uint16_t x;
uint16_t y;
};
/**
* @brief Macro for creating a font entry.
*
@ -104,6 +109,16 @@ int cfb_print(const struct device *dev, const char *const str, uint16_t x, uint1
*/
int cfb_draw_text(const struct device *dev, const char *const str, int16_t x, int16_t y);
/**
* @brief Draw a point.
*
* @param dev Pointer to device structure for driver instance
* @param pos position of the point
*
* @return 0 on success, negative value otherwise
*/
int cfb_draw_point(const struct device *dev, const struct cfb_position *pos);
/**
* @brief Clear framebuffer.
*

View File

@ -183,6 +183,27 @@ static uint8_t draw_char_vtmono(const struct char_framebuffer *fb,
return fptr->width;
}
static inline void draw_point(struct char_framebuffer *fb, int16_t x, int16_t y)
{
const bool need_reverse = ((fb->screen_info & SCREEN_INFO_MONO_MSB_FIRST) != 0);
const size_t index = ((y / 8) * fb->x_res);
uint8_t m = BIT(y % 8);
if (x < 0 || x >= fb->x_res) {
return;
}
if (y < 0 || y >= fb->y_res) {
return;
}
if (need_reverse) {
m = byte_reverse(m);
}
fb->buf[index + x] |= m;
}
static int draw_text(const struct device *dev, const char *const str, int16_t x, int16_t y,
bool wrap)
{
@ -215,6 +236,15 @@ static int draw_text(const struct device *dev, const char *const str, int16_t x,
return -EINVAL;
}
int cfb_draw_point(const struct device *dev, const struct cfb_position *pos)
{
struct char_framebuffer *fb = &char_fb;
draw_point(fb, pos->x, pos->y);
return 0;
}
int cfb_draw_text(const struct device *dev, const char *const str, int16_t x, int16_t y)
{
return draw_text(dev, str, x, y, false);