[352] | 1 | /*
|
---|
[400] | 2 | * TOPPERS PROJECT Home Network Working Group Software
|
---|
[364] | 3 | *
|
---|
[400] | 4 | * Copyright (C) 2018-2019 Cores Co., Ltd. Japan
|
---|
[364] | 5 | *
|
---|
[352] | 6 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 7 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 8 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 9 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 10 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 11 | * スコード中に含まれていること.
|
---|
| 12 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 13 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 14 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 15 | * の無保証規定を掲載すること.
|
---|
| 16 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 17 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 18 | * と.
|
---|
| 19 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 20 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 21 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 22 | * 報告すること.
|
---|
| 23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 25 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 26 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 27 | * 免責すること.
|
---|
[364] | 28 | *
|
---|
[352] | 29 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 30 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 31 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 32 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 33 | * の責任を負わない.
|
---|
[364] | 34 | *
|
---|
[352] | 35 | * @(#) $Id$
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <kernel.h>
|
---|
| 39 | #include <t_syslog.h>
|
---|
| 40 | #include <t_stdlib.h>
|
---|
| 41 | #include <string.h>
|
---|
| 42 | #include <target_syssvc.h>
|
---|
[364] | 43 | #ifndef ADAFRUIT_SSD1306
|
---|
[352] | 44 | #include "adafruit_st7735.h"
|
---|
[364] | 45 | #else
|
---|
| 46 | #include "adafruit_ssd1306.h"
|
---|
| 47 | #endif
|
---|
[352] | 48 | #include "draw_font.h"
|
---|
| 49 |
|
---|
[364] | 50 | void get_bitmap_font(const uint8_t *string, uint8_t *bitmap_data, uint32_t *use_chars)
|
---|
[352] | 51 | {
|
---|
[364] | 52 | uint32_t len, code;
|
---|
| 53 | uint8_t i, j, k;
|
---|
| 54 | uint32_t totalj, totalk;
|
---|
[352] | 55 |
|
---|
| 56 | *use_chars = 0;
|
---|
| 57 | len = 0;
|
---|
[364] | 58 | if ((string[0] & 0x80) == 0) { len = 1; }
|
---|
[352] | 59 | else if ((string[0] & 0xE0) == 0xC0) { len = 2; }
|
---|
| 60 | else if ((string[0] & 0xF0) == 0xE0) { len = 3; }
|
---|
| 61 | else if ((string[0] & 0xF8) == 0xF0) { len = 4; }
|
---|
[364] | 62 | else { return; }
|
---|
[352] | 63 |
|
---|
| 64 | j = k = totalj = totalk = 0;
|
---|
| 65 |
|
---|
[364] | 66 | if (len == 1) {
|
---|
[352] | 67 | code = string[0];
|
---|
[364] | 68 | memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
[352] | 69 | *use_chars = 1;
|
---|
| 70 | return;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[364] | 73 | if (len == 2) {
|
---|
[352] | 74 | code = string[0];
|
---|
| 75 | // 1バイト目サーチ
|
---|
[364] | 76 | for (i = 0; i < UTF8_CODE_2B_1_NUM; i++) {
|
---|
| 77 | if (Utf8CodeTable_2B_1st[i][0] == code) {
|
---|
[352] | 78 | code = string[1];
|
---|
[364] | 79 | for (j = 0; j < Utf8CodeTable_2B_1st[i][1]; j++) {
|
---|
| 80 | if (UTF8_2B_CODE_BITMAP[totalk].code == code) {
|
---|
| 81 | memcpy(bitmap_data, UTF8_2B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
[352] | 82 | *use_chars = 2;
|
---|
| 83 | return;
|
---|
| 84 | }
|
---|
| 85 | totalk++;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | else {
|
---|
| 89 | totalk += Utf8CodeTable_2B_1st[i][1];
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | return;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[364] | 95 | if (len == 3) {
|
---|
[352] | 96 | code = string[0];
|
---|
| 97 | // 1バイト目サーチ
|
---|
[364] | 98 | for (i = 0; i < UTF8_CODE_3B_1_NUM; i++) {
|
---|
| 99 | if (Utf8CodeTable_3B_1st[i][0] == code) {
|
---|
[352] | 100 | code = string[1];
|
---|
| 101 | // 2バイト目サーチ
|
---|
[364] | 102 | for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
|
---|
| 103 | if (Utf8CodeTable_3B_2nd[totalj][0] == code) {
|
---|
[352] | 104 | code = string[2];
|
---|
| 105 | // 3バイト目サーチ
|
---|
[364] | 106 | for (k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
|
---|
[352] | 107 | if (UTF8_3B_CODE_BITMAP[totalk].code == code) {
|
---|
[364] | 108 | memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
[352] | 109 | *use_chars = 3;
|
---|
| 110 | return;
|
---|
| 111 | }
|
---|
| 112 | totalk++;
|
---|
| 113 | }
|
---|
| 114 | return;
|
---|
| 115 | }
|
---|
[364] | 116 | else {/*読み飛ばすbitmap個数を蓄積*/
|
---|
[352] | 117 | totalk += Utf8CodeTable_3B_2nd[totalj][1];
|
---|
| 118 | }
|
---|
| 119 | totalj++;
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | else {/*読み飛ばすbitmap個数を蓄積*/
|
---|
[364] | 123 | for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
|
---|
[352] | 124 | totalk += Utf8CodeTable_3B_2nd[totalj][1];
|
---|
| 125 | totalj++;
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | return;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[364] | 133 | void lcd_drawFont(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
|
---|
[352] | 134 | {
|
---|
[364] | 135 | int i, j, b;
|
---|
| 136 | uint8_t *bitmap = bitmap_data;
|
---|
[352] | 137 |
|
---|
[364] | 138 | b = 0x80;
|
---|
| 139 | for (i = 0; i < FONT_HEIGHT; i++) {
|
---|
| 140 | for (j = 0; j < FONT_WIDTH; j++) {
|
---|
| 141 | if ((*bitmap & b) != 0) {
|
---|
| 142 | lcd_drawPixel(hlcd, x + j, y + i, color);
|
---|
[352] | 143 | }
|
---|
| 144 | else {
|
---|
[364] | 145 | lcd_drawPixel(hlcd, x + j, y + i, back_color);
|
---|
[352] | 146 | }
|
---|
[364] | 147 | b >>= 1;
|
---|
| 148 | if (b == 0) {
|
---|
| 149 | b = 0x80;
|
---|
| 150 | bitmap++;
|
---|
| 151 | }
|
---|
[352] | 152 | }
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[364] | 156 | void lcd_drawFontHalf(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
|
---|
[352] | 157 | {
|
---|
[364] | 158 | int i, j, b;
|
---|
| 159 | uint8_t *bitmap = bitmap_data;
|
---|
[352] | 160 |
|
---|
[364] | 161 | b = 0x80;
|
---|
| 162 | for (i = 0; i < FONT_HEIGHT; i++) {
|
---|
| 163 | for (j = 0; j < FONT_HALF_WIDTH; j++) {
|
---|
| 164 | if ((*bitmap & b) != 0) {
|
---|
| 165 | lcd_drawPixel(hlcd, x + j, y + i, color);
|
---|
[352] | 166 | }
|
---|
| 167 | else {
|
---|
[364] | 168 | lcd_drawPixel(hlcd, x + j, y + i, back_color);
|
---|
[352] | 169 | }
|
---|
[364] | 170 | b >>= 1;
|
---|
| 171 | if (b == 0) {
|
---|
| 172 | b = 0x80;
|
---|
| 173 | bitmap++;
|
---|
| 174 | }
|
---|
[352] | 175 | }
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
[364] | 179 | void lcd_drawString(LCD_Handler_t *hlcd, const char *string, int x, int y, uint16_t color, uint16_t back_color)
|
---|
[352] | 180 | {
|
---|
[364] | 181 | uint32_t current_top, use_chars, for_3B_hankaku_code;
|
---|
| 182 | uint8_t bitmap_data[FONT_WIDTH * FONT_HEIGHT / 8], ctrl_code;
|
---|
| 183 | int local_x, local_y, len = strlen(string);
|
---|
| 184 | const uint8_t *code = (const uint8_t *)string;
|
---|
[352] | 185 |
|
---|
| 186 | local_x = x;
|
---|
| 187 | local_y = y;
|
---|
| 188 |
|
---|
| 189 | current_top = 0;
|
---|
[364] | 190 | while (current_top < len) {
|
---|
| 191 | memset(bitmap_data, 0x0, FONT_WIDTH * FONT_HEIGHT / 8);
|
---|
| 192 | ctrl_code = code[current_top];
|
---|
| 193 | get_bitmap_font(&code[current_top], bitmap_data, &use_chars);
|
---|
| 194 | if (use_chars == 0)
|
---|
[352] | 195 | return;
|
---|
| 196 |
|
---|
| 197 | //3バイトコード半角文字用
|
---|
[364] | 198 | if (use_chars == 3) {
|
---|
[352] | 199 | for_3B_hankaku_code = 0;
|
---|
[364] | 200 | for_3B_hankaku_code = ((code[current_top] << 16) |
|
---|
| 201 | (code[current_top + 1] << 8) |
|
---|
| 202 | (code[current_top + 2]));
|
---|
[352] | 203 | }
|
---|
| 204 |
|
---|
| 205 | current_top += use_chars;
|
---|
| 206 |
|
---|
| 207 | //1バイトコード半角文字
|
---|
[364] | 208 | if (use_chars == 1) {
|
---|
| 209 | if (ctrl_code == 0x0D) { // CR
|
---|
[352] | 210 | local_x = X_LINE_TO_PIX(hlcd, 0);
|
---|
| 211 | continue;
|
---|
| 212 | }
|
---|
[364] | 213 | if (ctrl_code == 0x0A) { // LF
|
---|
| 214 | local_y = local_y + FONT_HEIGHT;
|
---|
[352] | 215 | continue;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[364] | 218 | if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
|
---|
[352] | 219 | local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
|
---|
[364] | 220 | local_y = local_y + FONT_HEIGHT;
|
---|
[352] | 221 | }
|
---|
| 222 | lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
[364] | 223 | local_x += FONT_HALF_WIDTH;
|
---|
[352] | 224 | continue;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | //3バイトコード半角文字
|
---|
[364] | 228 | if (use_chars == 3) {
|
---|
| 229 | if (((0xEFBDA1 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBDBF)) ||
|
---|
| 230 | ((0xEFBE80 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBE9F))) {
|
---|
[352] | 231 | //3バイトコード半角文字
|
---|
[364] | 232 | if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
|
---|
[352] | 233 | local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
|
---|
[364] | 234 | local_y = local_y + FONT_HEIGHT;
|
---|
[352] | 235 | }
|
---|
| 236 | lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
[364] | 237 | local_x += FONT_HALF_WIDTH;
|
---|
[352] | 238 | continue;
|
---|
| 239 | }
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | //全角文字
|
---|
[364] | 243 | if (local_x + FONT_WIDTH > hlcd->_width) {
|
---|
[352] | 244 | local_x = X_LINE_TO_PIX(hlcd, 0);
|
---|
[364] | 245 | local_y = local_y + FONT_HEIGHT;
|
---|
[352] | 246 | }
|
---|
| 247 | lcd_drawFont(hlcd, bitmap_data, local_x, local_y, color, back_color);
|
---|
[364] | 248 | local_x += FONT_WIDTH;
|
---|
[352] | 249 | }
|
---|
| 250 | }
|
---|
| 251 |
|
---|