comparison FontPack/base_upperRegion.c @ 30:ea1003f63e44

ADD GPL License ...
author jDG
date Tue, 23 Jan 2018 17:29:40 +0100
parents 97eafbcb81a9
children 7801c5d8a562
comparison
equal deleted inserted replaced
29:3a98f9e7ca58 30:ea1003f63e44
1 ///////////////////////////////////////////////////////////////////////////////
2 /// -*- coding: UTF-8 -*-
3 ///
4 /// \file FontPack/./base_upperRegion.c
5 /// \brief The beginning of it all. main() is part of this.
6 /// \author heinrichs/weikamp, Christian Weikamp
7 /// \date 31-August-2015
8 ///
9 /// $Id$
10 ///////////////////////////////////////////////////////////////////////////////
11 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh
12 ///
13 /// This program is free software: you can redistribute it and/or modify
14 /// it under the terms of the GNU General Public License as published by
15 /// the Free Software Foundation, either version 3 of the License, or
16 /// (at your option) any later version.
17 ///
18 /// This program is distributed in the hope that it will be useful,
19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 /// GNU General Public License for more details.
22 ///
23 /// You should have received a copy of the GNU General Public License
24 /// along with this program. If not, see <http://www.gnu.org/licenses/>.
25 //////////////////////////////////////////////////////////////////////////////
1 /** 26 /**
2 ****************************************************************************** 27 @verbatim
3 * @copyright heinrichs weikamp 28 ==============================================================================
4 * @file base_upperRegion.c 29 ##### New characters in fonts #####
5 * @author heinrichs/weikamp, Christian Weikamp 30 ==============================================================================
6 * @date 31-August-2015 31 [..] Use font_tmore.c and add line to corresponding font like font_t54c
7 * @version V0.0.3
8 * @since 03-Dez-2016
9 * @brief The beginning of it all. main() is part of this.
10 * @bug
11 * @warning
12 @verbatim
13 ==============================================================================
14 ##### New characters in fonts #####
15 ==============================================================================
16 [..] Use font_tmore.c and add line to corresponding font like font_t54c
17 Don't forget to adjust the length of the font in the last line starting 32 Don't forget to adjust the length of the font in the last line starting
18 const tFont ..... 33 const tFont .....
19 34
20 [..] last char vor der gro�en L�cke, Stand 160217 35 [..] last char vor der gro�en L�cke, Stand 160217
21 image_data_FontT24_0x002b[364] 36 image_data_FontT24_0x002b[364]
22 __attribute__((at( START_T24_FONT + (1647 * 28) ))), START_T24_FONT (0x08142F00 - MINUS_BANK) 37 __attribute__((at( START_T24_FONT + (1647 * 28) ))), START_T24_FONT (0x08142F00 - MINUS_BANK)
23 38
24 -> frei ab 0x0814E490 39 -> frei ab 0x0814E490
25 geht dann weiter mit image_data_ostc_fuer_Tauchcomputer_240px 40 geht dann weiter mit image_data_ostc_fuer_Tauchcomputer_240px
26 sind ca. 120 kByte frei! 41 sind ca. 120 kByte frei!
27 42
28 @endverbatim 43 @endverbatim
29 ****************************************************************************** 44 ******************************************************************************
30 * @attention 45 */
31 *
32 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
33 *
34 ******************************************************************************
35 */
36 46
37 /* Includes ------------------------------------------------------------------*/ 47 /* Includes ------------------------------------------------------------------*/
38 48
39 // From Common/Inc: 49 // From Common/Inc:
40 #include "FirmwareData.h" 50 #include "FirmwareData.h"
47 57
48 ////////////////////////////////////////////////////////////////////////////// 58 //////////////////////////////////////////////////////////////////////////////
49 59
50 const SFirmwareData font_FirmwareData __attribute__(( section(".font_firmware_data") )) = 60 const SFirmwareData font_FirmwareData __attribute__(( section(".font_firmware_data") )) =
51 { 61 {
52 .versionFirst = 0, 62 .versionFirst = 0,
53 .versionSecond = 9, 63 .versionSecond = 9,
54 .versionThird = 0, 64 .versionThird = 0,
55 .versionBeta = 0, 65 .versionBeta = 0,
56 66
57 /* 4 bytes, including trailing 0 */ 67 /* 4 bytes, including trailing 0 */
58 .signature = "cw", 68 .signature = "cw",
59 69
60 .release_year = 16, 70 .release_year = 16,
61 .release_month = 1, 71 .release_month = 1,
62 .release_day = 13, 72 .release_day = 13,
63 .release_sub = 0, 73 .release_sub = 0,
64 74
65 /* max 48, including trailing 0 */ 75 /* max 48, including trailing 0 */
66 .release_info ="", 76 .release_info ="",
67 77
68 /* for safety reasons and coming functions */ 78 /* for safety reasons and coming functions */
69 .magic[0] = FIRMWARE_MAGIC_FIRST, 79 .magic[0] = FIRMWARE_MAGIC_FIRST,
70 .magic[1] = FIRMWARE_MAGIC_SECOND, 80 .magic[1] = FIRMWARE_MAGIC_SECOND,
71 .magic[2] = FIRMWARE_MAGIC_FONT, /* the magic byte for fonts*/ 81 .magic[2] = FIRMWARE_MAGIC_FONT, /* the magic byte for fonts*/
72 .magic[3] = FIRMWARE_MAGIC_END 82 .magic[3] = FIRMWARE_MAGIC_END
73 }; 83 };
74 84
75 ////////////////////////////////////////////////////////////////////////////// 85 //////////////////////////////////////////////////////////////////////////////
76 86
77 /* Fonts fixed in upper region */ 87 /* Fonts fixed in upper region */
91 101
92 ////////////////////////////////////////////////////////////////////////////// 102 //////////////////////////////////////////////////////////////////////////////
93 103
94 static int errors = 0; 104 static int errors = 0;
95 #define ASSERT(e) \ 105 #define ASSERT(e) \
96 do { if( ! (e) ) {++errors; printf("FAIL at %3d: %s", __LINE__, #e);}} while(0) 106 do { if( ! (e) ) {++errors; printf("FAIL at %3d: %s", __LINE__, #e);}} while(0)
97 107
98 #define ASSERT_RANGE(e, min, max) \ 108 #define ASSERT_RANGE(e, min, max) \
99 ASSERT(min <= e); ASSERT( e <= max) 109 ASSERT(min <= e); ASSERT( e <= max)
100 110
101 int main(void) 111 int main(void)
102 { 112 {
103 //---- Check the linker puts the directory at the requested address ------ 113 //---- Check the linker puts the directory at the requested address ------
104 ASSERT( & Awe48 == (tFont*)0x8100000 ); 114 ASSERT( & Awe48 == (tFont*)0x8100000 );
105 ASSERT( & FontT24 == (tFont*)0x810000c ); 115 ASSERT( & FontT24 == (tFont*)0x810000c );
106 ASSERT( & FontT42 == (tFont*)0x8100018 ); 116 ASSERT( & FontT42 == (tFont*)0x8100018 );
107 ASSERT( & FontT48 == (tFont*)0x8100024 ); 117 ASSERT( & FontT48 == (tFont*)0x8100024 );
108 ASSERT( & FontT54 == (tFont*)0x8100030 ); 118 ASSERT( & FontT54 == (tFont*)0x8100030 );
109 ASSERT( & FontT84 == (tFont*)0x810003c ); 119 ASSERT( & FontT84 == (tFont*)0x810003c );
110 ASSERT( & FontT105 == (tFont*)0x8100048 ); 120 ASSERT( & FontT105 == (tFont*)0x8100048 );
111 ASSERT( & FontT144 == (tFont*)0x8100052 ); 121 ASSERT( & FontT144 == (tFont*)0x8100052 );
112 122
113 //---- Check the linker puts the font data in the requested section ------ 123 //---- Check the linker puts the font data in the requested section ------
114 extern tChar __upper_font_data; 124 extern tChar __upper_font_data;
115 extern tChar __upper_font_data_end; 125 extern tChar __upper_font_data_end;
116 ASSERT( &__upper_font_data == (tChar*)0x08132040 ); 126 ASSERT( &__upper_font_data == (tChar*)0x08132040 );
117 ASSERT_RANGE( (int)&__upper_font_data_end, 0x08132040, 0x081E0000); 127 ASSERT_RANGE( (int)&__upper_font_data_end, 0x08132040, 0x081E0000);
118 128
119 //---- Walk through the directory data ----------------------------------- 129 //---- Walk through the directory data -----------------------------------
120 extern const tFont __font_directory; 130 extern const tFont __font_directory;
121 extern const tFont __font_directory_end; 131 extern const tFont __font_directory_end;
122 for(const tFont* font = & __font_directory; font < &__font_directory_end; ++font) 132 for(const tFont* font = & __font_directory; font < &__font_directory_end; ++font)
123 { 133 {
124 // Check END-OF-DIRECTORY magic marker 134 // Check END-OF-DIRECTORY magic marker
125 if( font->length == (uint32_t)-1 ) 135 if( font->length == (uint32_t)-1 )
126 { 136 {
127 ASSERT( font == &FontT144 + 1 ); 137 ASSERT( font == &FontT144 + 1 );
128 break; 138 break;
129 } 139 }
130 140
131 // Check font descriptors are inside a safe range. 141 // Check font descriptors are inside a safe range.
132 ASSERT_RANGE( font->length, 10, 103 ); 142 ASSERT_RANGE( font->length, 10, 103 );
133 ASSERT_RANGE( font->spacesize, 0, 18 ); 143 ASSERT_RANGE( font->spacesize, 0, 18 );
134 ASSERT_RANGE( font->spacesize2Monospaced, 13, 72 ); 144 ASSERT_RANGE( font->spacesize2Monospaced, 13, 72 );
135 ASSERT_RANGE( font->height, 28, 108 ); 145 ASSERT_RANGE( font->height, 28, 108 );
136 146
137 //---- Walk through each char ---------------------------------------- 147 //---- Walk through each char ----------------------------------------
138 for(int i = 0; i < font->length; ++i) 148 for(int i = 0; i < font->length; ++i)
139 { 149 {
140 const tChar* c = &font->chars[i]; 150 const tChar* c = &font->chars[i];
141 151
142 // Check char data is indeed stored in the actual data section 152 // Check char data is indeed stored in the actual data section
143 ASSERT_RANGE( c, &__upper_font_data, &__upper_font_data_end); 153 ASSERT_RANGE( c, &__upper_font_data, &__upper_font_data_end);
144 154
145 // Check char data sanity 155 // Check char data sanity
146 ASSERT_RANGE( c->code, 0x0000, 0xF143); 156 ASSERT_RANGE( c->code, 0x0000, 0xF143);
147 157
148 // Check image sanity 158 // Check image sanity
149 const tImage* image = c->image; 159 const tImage* image = c->image;
150 ASSERT_RANGE(image, (tImage*)&__upper_font_data, (tImage*)&__upper_font_data_end); 160 ASSERT_RANGE(image, (tImage*)&__upper_font_data, (tImage*)&__upper_font_data_end);
151 ASSERT_RANGE(image->width, font->spacesize, font->spacesize2Monospaced); 161 ASSERT_RANGE(image->width, font->spacesize, font->spacesize2Monospaced);
152 ASSERT(image->height == font->height); 162 ASSERT(image->height == font->height);
153 163
154 // Uncompress image bytes 164 // Uncompress image bytes
155 const uint8_t* byte = image->data; 165 const uint8_t* byte = image->data;
156 ASSERT_RANGE(byte, (uint8_t*)&__upper_font_data, (uint8_t*)&__upper_font_data_end); 166 ASSERT_RANGE(byte, (uint8_t*)&__upper_font_data, (uint8_t*)&__upper_font_data_end);
157 167
158 for(int w=0; w <image->width; ++w) 168 for(int w=0; w <image->width; ++w)
159 { 169 {
160 // Compression: special 0x01 byte at start of column means just skip it. 170 // Compression: special 0x01 byte at start of column means just skip it.
161 if( *byte++ == 0x01 ) 171 if( *byte++ == 0x01 )
162 continue; 172 continue;
163 173
164 int zeros = (byte[-1] == 0x00) ? 1 : 0; 174 int zeros = (byte[-1] == 0x00) ? 1 : 0;
165 for(int h = 1; h < image->height; ++h) 175 for(int h = 1; h < image->height; ++h)
166 { 176 {
167 if( *byte == 0x00 ) 177 if( *byte == 0x00 )
168 ++zeros; 178 ++zeros;
169 179
170 // Other bytes cannot have the 0x01 value... 180 // Other bytes cannot have the 0x01 value...
171 ASSERT( *byte++ != 0x01 ); 181 ASSERT( *byte++ != 0x01 );
172 } 182 }
173 183
174 if( zeros == image->height ) 184 if( zeros == image->height )
175 printf("Font[%d] char[%d]: could skip column %d", 185 printf("Font[%d] char[%d]: could skip column %d",
176 &__font_directory - font, i, w); 186 &__font_directory - font, i, w);
177 } 187 }
178 188
179 // Check the byte stream do not collide with the next char, 189 // Check the byte stream do not collide with the next char,
180 // or with the first tImage struct of the font. 190 // or with the first tImage struct of the font.
181 if( (i+1) < font->length ) 191 if( (i+1) < font->length )
182 ASSERT( byte < font->chars[i+1].image->data ); 192 ASSERT( byte < font->chars[i+1].image->data );
183 else 193 else
184 ASSERT( byte < (uint8_t*)font->chars[0].image ); 194 ASSERT( byte < (uint8_t*)font->chars[0].image );
185 195
186 // TODO: check image bytes are contiguous between chars. 196 // TODO: check image bytes are contiguous between chars.
187 } 197 }
188 } 198 }
189 199
190 if( errors ) 200 if( errors )
191 { 201 {
192 printf("Font Check: %d errors.", errors); 202 printf("Font Check: %d errors.", errors);
193 return -1; 203 return -1;
194 } 204 }
195 205
196 printf("Font Check: no errors."); 206 printf("Font Check: no errors.");
197 return 0; 207 return 0;
198 } 208 }
199 209
200 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ 210 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/