Add support JIS X 0201.
Fork of GT20L16J1Y_font by
Embed:
(wiki syntax)
Show/hide line numbers
GT20L16Y1J_font.cpp
00001 #include "mbed.h" 00002 #include "GT20L16J1Y_font.h" 00003 00004 #define GT20L16J1Y_REMAP_ASCIIFONT 1 00005 #define GT20L16J1Y_ENABLE_JISX0201 1 00006 00007 #if GT20L16J1Y_REMAP_ASCIIFONT 00008 const uint16_t ascii_fontmap[] = { 00009 0x0000, 0x015E, 0x0002, 0x007E, 0x0004, 0x0005, 0x0162, 0x0007, 00010 0x006E, 0x006F, 0x007D, 0x000B, 0x000C, 0x000D, 0x000E, 0x007F, 00011 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 00012 0x0068, 0x0069, 0x006C, 0x006D, 0x001C, 0x001D, 0x001E, 0x015F, 00013 0x015D, 0x0121, 0x0122, 0x0123, 0x0124, 0x0125, 0x0126, 0x0127, 00014 0x0128, 0x0129, 0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F, 00015 0x0130, 0x0131, 0x0132, 0x0133, 0x0134, 0x0135, 0x0136, 0x0137, 00016 0x0138, 0x0139, 0x013A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 00017 0x0040, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0147, 00018 0x0148, 0x0149, 0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x014F, 00019 0x0150, 0x0151, 0x0152, 0x0153, 0x0154, 0x0155, 0x0156, 0x0157, 00020 0x0158, 0x0159, 0x015A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F, 00021 }; 00022 #endif 00023 00024 #if GT20L16J1Y_ENABLE_JISX0201 00025 const uint8_t jisx0201_fontmap[] = { 00026 0x0B, 0x1B, 0x1C, 0x0A, 0x50, 0x7E, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x13, 0x14, 0x15, 0x60, 00027 0x90, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 00028 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 00029 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7F, 0xFB, 0xFC, 00030 }; 00031 00032 const uint8_t font_glyph_00A5[] = { 00033 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 00034 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 00035 }; 00036 #endif 00037 00038 #if defined(TARGET_LPC1768) 00039 GT20L16J1Y_FONT::GT20L16J1Y_FONT() : _spi(p11, p12, p13), _CS(p10) { 00040 } 00041 #endif 00042 00043 GT20L16J1Y_FONT::GT20L16J1Y_FONT(PinName mosi, PinName miso, PinName sclk, PinName cs) : _spi(mosi, miso, sclk, NC), _CS(cs) 00044 { 00045 // Deselect the device 00046 _CS = 1; 00047 00048 // Setup the spi for 8 bit data, high steady state clock 00049 _spi.format(8,3); 00050 _spi.frequency(10000000); 00051 } 00052 00053 int GT20L16J1Y_FONT::read_kuten(unsigned short code) { 00054 unsigned char MSB, LSB; 00055 uint32_t address; 00056 int ret; 00057 00058 MSB = (code & 0xFF00) >> 8; 00059 LSB = code & 0x00FF; 00060 address = 0; 00061 00062 if( MSB >= 1 && MSB <= 15 && LSB >= 1 && LSB <= 94) 00063 address =( (MSB - 1) * 94 + (LSB - 1))*32; 00064 else if(MSB >= 16 && MSB <= 47 && LSB >= 1 && LSB <= 94) 00065 address =( (MSB - 16) * 94 + (LSB - 1))*32 + 0x0AA40L; 00066 else if(MSB >= 48 && MSB <= 84 && LSB >= 1 && LSB <= 94) 00067 address = ((MSB - 48) * 94 + (LSB - 1))*32 + 0x21CDFL; 00068 else if(MSB == 85 && LSB >= 1 && LSB <= 94) 00069 address = ((MSB - 85) * 94 + (LSB - 1))*32 + 0x3C4A0L; 00070 else if(MSB >= 88 && MSB <= 89 && LSB >= 1 && LSB <= 94) 00071 address = ((MSB - 88) * 94 + (LSB - 1))*32 + 0x3D060L; 00072 else if(MSB == 0 && LSB >= 0x20 && LSB <= 0x7F) 00073 #if GT20L16J1Y_REMAP_ASCIIFONT 00074 address = ascii_fontmap[LSB - 0x20]*16 + 255968; // 0x3E7E0 00075 #else 00076 address = (LSB - 0x20)*16 + 255968; 00077 #endif 00078 #if GT20L16J1Y_ENABLE_JISX0201 00079 else if(MSB == 0 && LSB == 0xA5) { // Font patch (0x00A5) 00080 memcpy(bitmap, font_glyph_00A5, 16); 00081 return 8; 00082 } 00083 else if(MSB == 0 && LSB >= 0xA1 && LSB <= 0xDF) // JIS X 0201 00084 address = jisx0201_fontmap[LSB - 0xA1]*16 + 257504; // 0x3EDE0 00085 #endif 00086 00087 // Deselect the device 00088 _CS = 1; 00089 00090 //_spi.begin(); 00091 _spi.write(0); // Dummy (mbed: change SPI owner and SPI format.) 00092 00093 // Select the device by seting chip select low 00094 _CS = 0; 00095 _spi.write(0x03); // Read data byte 00096 _spi.write(address>>16 & 0xff); 00097 _spi.write(address>>8 & 0xff); 00098 _spi.write(address & 0xff); 00099 00100 #if GT20L16J1Y_ENABLE_JISX0201 00101 if(MSB == 0 && (LSB >= 0x20 && LSB <= 0x7F) || (LSB >= 0xA1 && LSB <= 0xDF)) { 00102 #else 00103 if(MSB == 0 && LSB >= 0x20 && LSB <= 0x7F) { 00104 #endif 00105 for(int i=0; i<16; i++) 00106 { 00107 bitmap[i] = _spi.write(0x00); 00108 } 00109 ret = 8; 00110 } 00111 else { 00112 for(int i=0; i<32; i++) 00113 { 00114 bitmap[i] = _spi.write(0x00); 00115 } 00116 ret = 16; 00117 } 00118 00119 // Deselect the device 00120 _CS = 1; 00121 00122 return ret; 00123 } 00124 00125 int GT20L16J1Y_FONT::read(unsigned short code) { 00126 unsigned char c1, c2, MSB, LSB; 00127 uint32_t seq; 00128 uint16_t address; 00129 00130 // SJIS to kuten code conversion 00131 c1 = (code>>8); 00132 c2 = (code & 0xFF); 00133 seq = (c1<=159 ? c1-129 : c1-193)*188 + (c2<=126 ? c2-64 : c2-65); 00134 MSB = seq / 94 + 1; 00135 LSB = seq % 94 + 1; 00136 00137 address = ((MSB << 8) | LSB); 00138 return read_kuten(address); 00139 } 00140 00141 void GT20L16J1Y_FONT::read_direct(unsigned long address) { 00142 // Deselect the device 00143 _CS = 1; 00144 00145 //_spi.begin(); 00146 _spi.write(0); // Dummy (mbed: change SPI owner and SPI format.) 00147 00148 // Select the device by seting chip select low 00149 _CS = 0; 00150 _spi.write(0x03); // Read data byte 00151 _spi.write(address>>16 & 0xff); 00152 _spi.write(address>>8 & 0xff); 00153 _spi.write(address & 0xff); 00154 00155 for(int i=0; i<32; i++) 00156 { 00157 bitmap[i] = _spi.write(0x00); 00158 } 00159 00160 // Deselect the device 00161 _CS = 1; 00162 }
Generated on Tue Jul 12 2022 21:49:14 by
1.7.2
ban4jp -
