fb: cfb: Add cfb_draw_rect() API
Add cfb_draw_rect() API for rendering rectangle.
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
diff --git a/include/zephyr/display/cfb.h b/include/zephyr/display/cfb.h
index fde4e16..8516114 100644
--- a/include/zephyr/display/cfb.h
+++ b/include/zephyr/display/cfb.h
@@ -132,6 +132,18 @@
const struct cfb_position *end);
/**
+ * @brief Draw a rectangle.
+ *
+ * @param dev Pointer to device structure for driver instance
+ * @param start Top-Left position of the rectangle
+ * @param end Bottom-Right position of the rectangle
+ *
+ * @return 0 on success, negative value otherwise
+ */
+int cfb_draw_rect(const struct device *dev, const struct cfb_position *start,
+ const struct cfb_position *end);
+
+/**
* @brief Clear framebuffer.
*
* @param dev Pointer to device structure for driver instance
diff --git a/subsys/fb/cfb.c b/subsys/fb/cfb.c
index a4cdddd..4730d63 100644
--- a/subsys/fb/cfb.c
+++ b/subsys/fb/cfb.c
@@ -285,6 +285,19 @@
return 0;
}
+int cfb_draw_rect(const struct device *dev, const struct cfb_position *start,
+ const struct cfb_position *end)
+{
+ struct char_framebuffer *fb = &char_fb;
+
+ draw_line(fb, start->x, start->y, end->x, start->y);
+ draw_line(fb, end->x, start->y, end->x, end->y);
+ draw_line(fb, end->x, end->y, start->x, end->y);
+ draw_line(fb, start->x, end->y, start->x, start->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);