From e2c946536e2b23fa91b4a33fd793890411f06f92 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sat, 14 Jan 2023 16:07:05 +0900 Subject: [PATCH] fb: cfb_shell: Add `draw text` command Add the `draw text` command to execute the `cfb_draw_text()` API. The command is similar to the `print` command. The difference is `draw text` can render to coordinate that is not on tile boundaries. The command is not run `cfb_framebuffer_clear()`, So it allows rendering appendiceal with keeping already drawn image. Signed-off-by: TOKITA Hiroshi --- subsys/fb/cfb_shell.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/subsys/fb/cfb_shell.c b/subsys/fb/cfb_shell.c index 103cc1e2ed2..407721be201 100644 --- a/subsys/fb/cfb_shell.c +++ b/subsys/fb/cfb_shell.c @@ -119,6 +119,29 @@ static int cmd_print(const struct shell *shell, size_t argc, char *argv[]) return err; } +static int cmd_draw_text(const struct shell *sh, size_t argc, char *argv[]) +{ + int err; + int x, y; + + if (!dev) { + shell_error(sh, HELP_INIT); + return -ENODEV; + } + + x = strtol(argv[1], NULL, 10); + y = strtol(argv[2], NULL, 10); + err = cfb_draw_text(dev, argv[3], x, y); + if (err) { + shell_error(sh, "Failed text drawing to Framebuffer error=%d", err); + return err; + } + + err = cfb_framebuffer_finalize(dev); + + return err; +} + static int cmd_scroll_vert(const struct shell *shell, size_t argc, char *argv[]) { int err = 0; @@ -488,6 +511,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(sub_cmd_scroll, SHELL_SUBCMD_SET_END ); +SHELL_STATIC_SUBCMD_SET_CREATE(sub_cmd_draw, + SHELL_CMD_ARG(text, NULL, HELP_PRINT, cmd_draw_text, 4, 0), + SHELL_SUBCMD_SET_END +); + SHELL_STATIC_SUBCMD_SET_CREATE(cfb_cmds, SHELL_CMD_ARG(init, NULL, HELP_NONE, cmd_init, 1, 0), SHELL_CMD_ARG(get_device, NULL, HELP_NONE, cmd_get_device, 1, 0), @@ -500,6 +528,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(cfb_cmds, SHELL_CMD_ARG(print, NULL, HELP_PRINT, cmd_print, 4, 0), SHELL_CMD(scroll, &sub_cmd_scroll, "scroll a text in vertical or " "horizontal direction", NULL), + SHELL_CMD(draw, &sub_cmd_draw, "drawing text", NULL), SHELL_CMD_ARG(clear, NULL, HELP_NONE, cmd_clear, 1, 0), SHELL_SUBCMD_SET_END );