Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | /* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (c) 2015 Google, Inc * (C) Copyright 2015 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com * (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com> */ #include <charset.h> #include <config.h> #include <video_console.h> struct udevice; struct vidconsole_cursor; struct video_priv; #define FLIPPED_DIRECTION 1 #define NORMAL_DIRECTION 0 /** * struct console_simple_priv - Private data for this driver * * @video_fontdata font graphical representation data */ struct console_simple_priv { struct video_fontdata *fontdata; }; /** * struct console_ctx - context for the normal console * * @com: Common fields from the vidconsole uclass */ struct console_ctx { struct vidconsole_ctx com; }; /** * Checks if bits per pixel supported. * * @param bpix framebuffer bits per pixel. * * @returns 0, if supported, or else -ENOSYS. */ int check_bpix_support(int bpix); /** * Fill 1 pixel in framebuffer, and go to next one. * * @param dstp a pointer to pointer to framebuffer. * @param value value to write to framebuffer. * @param pbytes framebuffer bytes per pixel. * @param step framebuffer pointer increment. Usually is equal to pbytes, * and may be negative to control filling direction. */ void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int step); /** * swap_pixel_and_goto_next() - Swap 1 pixel in framebuffer, and go to next one * * @param dstp a pointer to pointer to framebuffer. * @param value value to write to framebuffer. * @param pbytes framebuffer bytes per pixel. * @param step framebuffer pointer increment. Usually is equal to pbytes, * and may be negative to control filling direction. * Return: old value of the pixel */ u32 swap_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int step); /** * Fills 1 character in framebuffer vertically. Vertically means we're filling char font data rows * across the lines. * * @param pfont a pointer to character font data. * @param line a pointer to pointer to framebuffer. It's a point for upper left char corner * @param vid_priv driver private data. * @fontdata font graphical representation data * @param direction controls character orientation. Can be normal or flipped. * When normal: When flipped: *|-----------------------------------------------| *| line stepping | | *| | | stepping -> | *| * | | * * * | *| * * v | * | *| * | * | *| * | * * ^ | *| * * * | * | | *| | | | *| stepping -> | line stepping | *|---!!we're starting from upper left char corner| *|-----------------------------------------------| * * @returns 0, if success, or else error code. */ int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv, struct video_fontdata *fontdata, bool direction); /** * Fills 1 character in framebuffer horizontally. * Horizontally means we're filling char font data columns across the lines. * * @param pfont a pointer to character font data. * @param line a pointer to pointer to framebuffer. It's a point for upper left char corner * @param vid_priv driver private data. * @fontdata font graphical representation data * @param direction controls character orientation. Can be normal or flipped. * When normal: When flipped: *|-----------------------------------------------| *| * | line stepping | *| ^ * * * * * | | | *| | * * | v * * | *| | | * * * * * | *| line stepping | * | *| | | *| stepping -> | <- stepping | *|---!!we're starting from upper left char corner| *|-----------------------------------------------| * * @returns 0, if success, or else error code. */ int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_priv, struct video_fontdata *fontdata, bool direction); /** * cursor_show() - Show cursor by saving and drawing pixels * * @curs: cursor information * @vid_priv: video-device info * @direction: controls cursor orientation (normal or flipped) * * When normal: When flipped: *|-----------------------------------------------| *| * | line stepping | *| ^ * * * * * | | | *| | * * | v * * | *| | | * * * * * | *| line stepping | * | *| | | *| stepping -> | <<- stepping | *|---!!we're starting from upper left char corner| *|-----------------------------------------------| * * Return: 0 on success, -EINVAL if cursor data already saved */ int cursor_show(struct vidconsole_cursor *curs, struct video_priv *vid_priv, bool direction); /** * cursor_hide() - Hide cursor by restoring saved pixels * * @curs: cursor information * @vid_priv: video-device info * @direction: controls cursor orientation (normal or flipped) * Return: 0 if success, -EINVAL if no cursor data was saved */ int cursor_hide(struct vidconsole_cursor *curs, struct video_priv *vid_priv, bool direction); /** * console_alloc_cursor() - Allocate cursor save buffer * * Allocates memory for saving pixels under the cursor * * @dev: vidconsole device * @curs: cursor to set up * Return: 0 if success, -ENOMEM if allocation fails */ int console_alloc_cursor(struct udevice *dev, struct vidconsole_cursor *curs); /** * console_free_cursor() - Free cursor memory * * Free the memory used by a cursor * * @curs: cursor to set up */ void console_free_cursor(struct vidconsole_cursor *curs); /** * console probe function. * * @param dev a pointer to device. * * @returns 0, if success, or else error code. */ int console_probe(struct udevice *dev); /** * Internal function to be used in as ops. * See details in video_console.h get_font_size function **/ const char *console_simple_get_font_size(struct udevice *dev, void *ctx, uint *sizep); /** * Internal function to be used in as ops. * See details in video_console.h get_font function **/ int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *info); /** * Internal function to be used in as ops. * See details in video_console.h select_font function **/ int console_simple_select_font(struct udevice *dev, void *ctx, const char *name, uint size); /** * Normal console putc_xy function that can be called by other console drivers * * @param dev console device * @param ctx vidconsole context to use, or NULL for default * @param x_frac fractional X position * @param y Y position in pixels * @param cp Unicode code point * @returns width in fractional pixels, or -ve on error */ int console_normal_putc_xy(struct udevice *dev, void *ctx, uint x_frac, uint y, int cp); /** * Fixed font putc_xy function that can be called with explicit font data * * @param dev console device * @param vctx vidconsole context to use (cannot be NULL) * @param x_frac fractional X position * @param y Y position in pixels * @param cp Unicode code point * @param fontdata font data to use for rendering * @returns width in fractional pixels, or -ve on error */ int console_fixed_putc_xy(struct udevice *dev, void *vctx, uint x_frac, uint y, int cp, struct video_fontdata *fontdata); /** * Internal function to convert Unicode code points to code page 437. * Used by video consoles using bitmap fonts. * * @param codepoint Unicode code point * @returns code page 437 character. */ static inline u8 console_utf_to_cp437(int codepoint) { if (CONFIG_IS_ENABLED(CHARSET)) { utf_to_cp(&codepoint, codepage_437); return codepoint; } return codepoint; } /** * console_simple_ctx_new() - Set up a new context for bitmap-font consoles * * Initialises the context with the default bitmap font. This is the ctx_new() * method for bitmap-font console drivers. * * @dev: Vidconsole device * @ctx: Context to initialise (allocated by the uclass) * Return: 0 on success, -ve on error */ int console_simple_ctx_new(struct udevice *dev, void *ctx); |