Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * (C) Copyright 2015 |
| 5 | * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com |
| 6 | * (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com> |
| 7 | */ |
| 8 | |
Janne Grunau | 5548c36 | 2024-03-16 22:50:19 +0100 | [diff] [blame] | 9 | #include <charset.h> |
| 10 | #include <config.h> |
| 11 | |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 12 | #define FLIPPED_DIRECTION 1 |
| 13 | #define NORMAL_DIRECTION 0 |
| 14 | |
| 15 | /** |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 16 | * struct console_simple_priv - Private data for this driver |
| 17 | * |
| 18 | * @video_fontdata font graphical representation data |
| 19 | */ |
| 20 | struct console_simple_priv { |
| 21 | struct video_fontdata *fontdata; |
| 22 | }; |
| 23 | |
| 24 | /** |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 25 | * Checks if bits per pixel supported. |
| 26 | * |
| 27 | * @param bpix framebuffer bits per pixel. |
| 28 | * |
| 29 | * @returns 0, if supported, or else -ENOSYS. |
| 30 | */ |
| 31 | int check_bpix_support(int bpix); |
| 32 | |
| 33 | /** |
| 34 | * Fill 1 pixel in framebuffer, and go to next one. |
| 35 | * |
| 36 | * @param dstp a pointer to pointer to framebuffer. |
| 37 | * @param value value to write to framebuffer. |
| 38 | * @param pbytes framebuffer bytes per pixel. |
| 39 | * @param step framebuffer pointer increment. Usually is equal to pbytes, |
| 40 | * and may be negative to control filling direction. |
| 41 | */ |
| 42 | void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int step); |
| 43 | |
| 44 | /** |
| 45 | * Fills 1 character in framebuffer vertically. Vertically means we're filling char font data rows |
| 46 | * across the lines. |
| 47 | * |
| 48 | * @param pfont a pointer to character font data. |
| 49 | * @param line a pointer to pointer to framebuffer. It's a point for upper left char corner |
| 50 | * @param vid_priv driver private data. |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 51 | * @fontdata font graphical representation data |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 52 | * @param direction controls character orientation. Can be normal or flipped. |
| 53 | * When normal: When flipped: |
| 54 | *|-----------------------------------------------| |
| 55 | *| line stepping | | |
| 56 | *| | | stepping -> | |
| 57 | *| * | | * * * | |
| 58 | *| * * v | * | |
| 59 | *| * | * | |
| 60 | *| * | * * ^ | |
| 61 | *| * * * | * | | |
| 62 | *| | | | |
| 63 | *| stepping -> | line stepping | |
| 64 | *|---!!we're starting from upper left char corner| |
| 65 | *|-----------------------------------------------| |
| 66 | * |
| 67 | * @returns 0, if success, or else error code. |
| 68 | */ |
| 69 | int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv, |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 70 | struct video_fontdata *fontdata, bool direction); |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Fills 1 character in framebuffer horizontally. |
| 74 | * Horizontally means we're filling char font data columns across the lines. |
| 75 | * |
| 76 | * @param pfont a pointer to character font data. |
| 77 | * @param line a pointer to pointer to framebuffer. It's a point for upper left char corner |
| 78 | * @param vid_priv driver private data. |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 79 | * @fontdata font graphical representation data |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 80 | * @param direction controls character orientation. Can be normal or flipped. |
| 81 | * When normal: When flipped: |
| 82 | *|-----------------------------------------------| |
| 83 | *| * | line stepping | |
| 84 | *| ^ * * * * * | | | |
| 85 | *| | * * | v * * | |
| 86 | *| | | * * * * * | |
| 87 | *| line stepping | * | |
| 88 | *| | | |
| 89 | *| stepping -> | <- stepping | |
| 90 | *|---!!we're starting from upper left char corner| |
| 91 | *|-----------------------------------------------| |
| 92 | * |
| 93 | * @returns 0, if success, or else error code. |
| 94 | */ |
| 95 | int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_priv, |
Dzmitry Sankouski | 7fa964a | 2023-03-07 13:21:14 +0300 | [diff] [blame] | 96 | struct video_fontdata *fontdata, bool direction); |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 97 | |
| 98 | /** |
Simon Glass | 377f79aa | 2023-10-01 19:13:21 -0600 | [diff] [blame] | 99 | * draw_cursor_vertically() - Draw a simple vertical cursor |
| 100 | * |
| 101 | * @line: pointer to framebuffer buffer: upper left cursor corner |
| 102 | * @vid_priv: driver private data |
| 103 | * @height: height of the cursor in pixels |
| 104 | * @param direction controls cursor orientation. Can be normal or flipped. |
| 105 | * When normal: When flipped: |
| 106 | *|-----------------------------------------------| |
| 107 | *| * | line stepping | |
| 108 | *| ^ * * * * * | | | |
| 109 | *| | * * | v * * | |
| 110 | *| | | * * * * * | |
| 111 | *| line stepping | * | |
| 112 | *| | | |
| 113 | *| stepping -> | <<- stepping | |
| 114 | *|---!!we're starting from upper left char corner| |
| 115 | *|-----------------------------------------------| |
| 116 | * |
| 117 | * Return: 0, if success, or else error code. |
| 118 | */ |
| 119 | int draw_cursor_vertically(void **line, struct video_priv *vid_priv, |
| 120 | uint height, bool direction); |
| 121 | |
| 122 | /** |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame] | 123 | * console probe function. |
| 124 | * |
| 125 | * @param dev a pointer to device. |
| 126 | * |
| 127 | * @returns 0, if success, or else error code. |
| 128 | */ |
| 129 | int console_probe(struct udevice *dev); |
Dzmitry Sankouski | bb165e4 | 2023-03-07 13:21:16 +0300 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * Internal function to be used in as ops. |
| 133 | * See details in video_console.h get_font_size function |
| 134 | **/ |
| 135 | const char *console_simple_get_font_size(struct udevice *dev, uint *sizep); |
| 136 | |
| 137 | /** |
| 138 | * Internal function to be used in as ops. |
| 139 | * See details in video_console.h get_font function |
| 140 | **/ |
| 141 | int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *info); |
| 142 | |
| 143 | /** |
| 144 | * Internal function to be used in as ops. |
| 145 | * See details in video_console.h select_font function |
| 146 | **/ |
| 147 | int console_simple_select_font(struct udevice *dev, const char *name, uint size); |
Janne Grunau | 5548c36 | 2024-03-16 22:50:19 +0100 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * Internal function to convert Unicode code points to code page 437. |
| 151 | * Used by video consoles using bitmap fonts. |
| 152 | * |
| 153 | * @param codepoint Unicode code point |
| 154 | * @returns code page 437 character. |
| 155 | */ |
| 156 | static inline u8 console_utf_to_cp437(int codepoint) |
| 157 | { |
| 158 | if (CONFIG_IS_ENABLED(CHARSET)) { |
| 159 | utf_to_cp(&codepoint, codepage_437); |
| 160 | return codepoint; |
| 161 | } |
| 162 | return codepoint; |
| 163 | } |