zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 1 | #include "glcd.h" |
| 2 | //#include "timer.h" |
| 3 | #include "../nec_hardware.h" |
| 4 | #include "gb2312_16.h" |
| 5 | #include "string.h" |
| 6 | #include "stdio.h" |
| 7 | |
| 8 | uint8_t gb2312_16x16_draw_char(uint8_t x, uint8_t y, uint8_t buf[32]) |
| 9 | { |
| 10 | uint8_t i,j; |
| 11 | |
| 12 | for(i=0;i<16;i++) |
| 13 | { |
| 14 | for(j=0;j<2;j++) |
| 15 | { |
| 16 | uint8_t dat,bit; |
| 17 | |
| 18 | dat = buf[2*i+j]; |
| 19 | |
| 20 | if(glcd_get_reverse_sta()) |
| 21 | dat = ~dat; |
| 22 | |
| 23 | for(bit=0;bit<8;bit++) |
| 24 | { |
| 25 | if (dat & (0x80>>bit)) |
| 26 | { |
| 27 | glcd_set_pixel(x+j*8+bit, y+i, BLACK); |
| 28 | } |
| 29 | else |
| 30 | { |
| 31 | glcd_set_pixel(x+j*8+bit, y+i,WHITE); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return 16; |
| 38 | } |
| 39 | |
| 40 | void gb2312_16x16_get_data(uint8_t xy[2], uint8_t buf[32]) |
| 41 | { |
| 42 | uint32_t offset; |
| 43 | |
| 44 | if((xy[0]<0xa1) || (xy[1])<0xa1) |
| 45 | return; |
| 46 | |
| 47 | offset = (94*(xy[0] - 0xa1) + (xy[1] - 0xa1))*32ul; |
| 48 | |
| 49 | HW_Flash_Read(offset+256, 32, buf); |
| 50 | } |
| 51 | |
| 52 | uint8_t gb2312_16x8_draw_char(uint8_t x, uint8_t y, uint8_t buf[16]) |
| 53 | { |
| 54 | uint8_t i; |
| 55 | |
| 56 | for(i=0;i<16;i++) |
| 57 | { |
| 58 | uint8_t dat,bit; |
| 59 | |
| 60 | dat = buf[i]; |
| 61 | |
| 62 | if(glcd_get_reverse_sta()) |
| 63 | dat = ~dat; |
| 64 | for(bit=0;bit<8;bit++) |
| 65 | { |
| 66 | if (dat & (0x80>>bit)) |
| 67 | { |
| 68 | glcd_set_pixel(x+bit, y+i, BLACK); |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | glcd_set_pixel(x+bit, y+i,WHITE); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return 8; |
| 78 | } |
| 79 | |
| 80 | void gb2312_16x8_get_data(uint8_t c, uint8_t buf[16]) |
| 81 | { |
| 82 | uint32_t offset; |
| 83 | |
| 84 | offset = c*16ul + 0x43000; |
| 85 | |
| 86 | HW_Flash_Read(offset, 16, buf); |
| 87 | } |
| 88 | |
| 89 | void gb2312_16x16_test(void) |
| 90 | { |
| 91 | uint32_t i,j; |
| 92 | |
| 93 | HW_Flash_Init(); |
| 94 | glcd_init(); |
| 95 | glcd_clear(); |
| 96 | |
| 97 | for(i=0xa1;i<0xfe;i++) |
| 98 | { |
| 99 | uint8_t xy[2]; |
| 100 | |
| 101 | xy[0] = i; |
| 102 | for(j=0xa1;j<0xfe;j++) |
| 103 | { |
| 104 | uint8_t buf[32]; |
| 105 | |
| 106 | xy[1] = j; |
| 107 | |
| 108 | gb2312_16x16_get_data(xy, buf); |
| 109 | gb2312_16x16_draw_char(0, 0, buf); |
| 110 | glcd_write(); |
| 111 | delay_ms(100); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | |
| 117 | void gb2312_16x8_test(void) |
| 118 | { |
| 119 | uint32_t i; |
| 120 | |
| 121 | HW_Flash_Init(); |
| 122 | glcd_init(); |
| 123 | glcd_clear(); |
| 124 | |
| 125 | for(i=0;i<256;i++) |
| 126 | { |
| 127 | uint8_t buf[32]; |
| 128 | |
| 129 | gb2312_16x8_get_data(i, buf); |
| 130 | gb2312_16x8_draw_char(0, 0, buf); |
| 131 | glcd_write(); |
| 132 | delay_ms(50); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | uint8_t gb2312_16_get_ver(uint8_t ver[3]) |
| 137 | { |
| 138 | uint8_t temp_buff[20]; |
| 139 | |
| 140 | if(HW_Flash_Read(0, sizeof(temp_buff), temp_buff)) |
| 141 | return 1; |
| 142 | |
| 143 | if(memcmp(temp_buff, sk_font_id, 9)) |
| 144 | return 2; |
| 145 | |
| 146 | memcpy(ver, temp_buff+9, 3); |
| 147 | ver[0] -= '0'; |
| 148 | ver[1] -= '0'; |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | void gb2312_16_draw_str(uint8_t x, uint8_t y, char* s) |
| 154 | { |
| 155 | uint8_t i=0,j=0; |
| 156 | |
| 157 | while(*s) |
| 158 | { |
| 159 | uint8_t buf[32]; |
| 160 | |
| 161 | #if 1 |
| 162 | if(x>=GLCD_LCD_WIDTH || y>=GLCD_LCD_HEIGHT) |
| 163 | return ; |
| 164 | #else |
| 165 | if(x+i >= GLCD_LCD_WIDTH) |
| 166 | { |
| 167 | j += 16; //»»ÐÐ |
| 168 | i = 0; //»Ø³µ |
| 169 | } |
| 170 | if(y+j >= GLCD_LCD_HEIGHT) |
| 171 | { |
| 172 | j = 0; |
| 173 | i = 0; |
| 174 | } |
| 175 | #endif |
| 176 | if((uint8_t)(*s)<128) |
| 177 | { |
| 178 | gb2312_16x8_get_data((uint8_t)*s, buf); |
| 179 | i += gb2312_16x8_draw_char(x+i, y+j, buf); |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | gb2312_16x16_get_data((uint8_t *)s, buf); |
| 184 | i += gb2312_16x16_draw_char(x+i, y+j, buf); |
| 185 | s ++; |
| 186 | } |
| 187 | s ++; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | uint8_t gb2312_16_verify(void) |
| 192 | { |
| 193 | const uint8_t font_01[32] = |
| 194 | { |
| 195 | 0x01, 0x00, 0x01, 0x00, 0x01, 0x08, 0x01, 0x10, 0x7D, 0x20, 0x05, 0xC0, 0x05, 0x40, 0x09, 0x20, |
| 196 | 0x09, 0x20, 0x11, 0x10, 0x11, 0x18, 0x21, 0x0E, 0xC1, 0x04, 0x01, 0x00, 0x05, 0x00, 0x02, 0x00 |
| 197 | }; |
| 198 | const uint8_t font_02[32] = |
| 199 | { |
| 200 | 0x10, 0x00, 0x10, 0x20, 0x10, 0x10, 0xFD, 0xFE, 0x11, 0x04, 0x10, 0x50, 0x14, 0x8C, 0x19, 0x04, |
| 201 | 0x30, 0x00, 0xD1, 0xFC, 0x10, 0x20, 0x10, 0x20, 0x10, 0x20, 0x10, 0x20, 0x53, 0xFE, 0x20, 0x00 |
| 202 | }; |
| 203 | const uint8_t font_03[16] = |
| 204 | { |
| 205 | 0x00, 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xC6, 0xC6, 0x00, 0x00, 0x00, 0x00 |
| 206 | }; |
| 207 | const uint8_t font_04[16] = |
| 208 | { |
| 209 | 0x00, 0x00, 0xFC, 0x66, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x66, 0x66, 0xFC, 0x00, 0x00, 0x00, 0x00 |
| 210 | }; |
| 211 | uint8_t buf[32]; |
| 212 | |
| 213 | gb2312_16x16_get_data("Ë®", buf); |
| 214 | if(memcmp(buf, font_01, sizeof(font_01))) |
| 215 | return 1; |
| 216 | gb2312_16x16_get_data("¿Ø", buf); |
| 217 | if(memcmp(buf, font_02, sizeof(font_02))) |
| 218 | return 2; |
| 219 | gb2312_16x8_get_data('A', buf); |
| 220 | if(memcmp(buf, font_03, sizeof(font_03))) |
| 221 | return 3; |
| 222 | gb2312_16x8_get_data('B', buf); |
| 223 | if(memcmp(buf, font_04, sizeof(font_04))) |
| 224 | return 4; |
| 225 | |
| 226 | return 0; |
| 227 | } |