Add support JIS X 0201.
Fork of GT20L16J1Y_font by
GT20L16Y1J_font.cpp@3:48c4a173bdab, 2014-09-21 (annotated)
- Committer:
- ban4jp
- Date:
- Sun Sep 21 08:04:40 2014 +0000
- Revision:
- 3:48c4a173bdab
- Parent:
- 2:aed20a7685b9
Add support JIS X 0201.; Remap rom-address about ascii fonts.; Fix multi connection spi device issue.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:61b32e34bcbf | 1 | #include "mbed.h" |
MACRUM | 0:61b32e34bcbf | 2 | #include "GT20L16J1Y_font.h" |
MACRUM | 0:61b32e34bcbf | 3 | |
ban4jp | 3:48c4a173bdab | 4 | #define GT20L16J1Y_REMAP_ASCIIFONT 1 |
ban4jp | 3:48c4a173bdab | 5 | #define GT20L16J1Y_ENABLE_JISX0201 1 |
ban4jp | 3:48c4a173bdab | 6 | |
ban4jp | 3:48c4a173bdab | 7 | #if GT20L16J1Y_REMAP_ASCIIFONT |
ban4jp | 3:48c4a173bdab | 8 | const uint16_t ascii_fontmap[] = { |
ban4jp | 3:48c4a173bdab | 9 | 0x0000, 0x015E, 0x0002, 0x007E, 0x0004, 0x0005, 0x0162, 0x0007, |
ban4jp | 3:48c4a173bdab | 10 | 0x006E, 0x006F, 0x007D, 0x000B, 0x000C, 0x000D, 0x000E, 0x007F, |
ban4jp | 3:48c4a173bdab | 11 | 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, |
ban4jp | 3:48c4a173bdab | 12 | 0x0068, 0x0069, 0x006C, 0x006D, 0x001C, 0x001D, 0x001E, 0x015F, |
ban4jp | 3:48c4a173bdab | 13 | 0x015D, 0x0121, 0x0122, 0x0123, 0x0124, 0x0125, 0x0126, 0x0127, |
ban4jp | 3:48c4a173bdab | 14 | 0x0128, 0x0129, 0x012A, 0x012B, 0x012C, 0x012D, 0x012E, 0x012F, |
ban4jp | 3:48c4a173bdab | 15 | 0x0130, 0x0131, 0x0132, 0x0133, 0x0134, 0x0135, 0x0136, 0x0137, |
ban4jp | 3:48c4a173bdab | 16 | 0x0138, 0x0139, 0x013A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, |
ban4jp | 3:48c4a173bdab | 17 | 0x0040, 0x0141, 0x0142, 0x0143, 0x0144, 0x0145, 0x0146, 0x0147, |
ban4jp | 3:48c4a173bdab | 18 | 0x0148, 0x0149, 0x014A, 0x014B, 0x014C, 0x014D, 0x014E, 0x014F, |
ban4jp | 3:48c4a173bdab | 19 | 0x0150, 0x0151, 0x0152, 0x0153, 0x0154, 0x0155, 0x0156, 0x0157, |
ban4jp | 3:48c4a173bdab | 20 | 0x0158, 0x0159, 0x015A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F, |
ban4jp | 3:48c4a173bdab | 21 | }; |
ban4jp | 3:48c4a173bdab | 22 | #endif |
ban4jp | 3:48c4a173bdab | 23 | |
ban4jp | 3:48c4a173bdab | 24 | #if GT20L16J1Y_ENABLE_JISX0201 |
ban4jp | 3:48c4a173bdab | 25 | const uint8_t jisx0201_fontmap[] = { |
ban4jp | 3:48c4a173bdab | 26 | 0x0B, 0x1B, 0x1C, 0x0A, 0x50, 0x7E, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x13, 0x14, 0x15, 0x60, |
ban4jp | 3:48c4a173bdab | 27 | 0x90, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, |
ban4jp | 3:48c4a173bdab | 28 | 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, |
ban4jp | 3:48c4a173bdab | 29 | 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7F, 0xFB, 0xFC, |
ban4jp | 3:48c4a173bdab | 30 | }; |
ban4jp | 3:48c4a173bdab | 31 | |
ban4jp | 3:48c4a173bdab | 32 | const uint8_t font_glyph_00A5[] = { |
ban4jp | 3:48c4a173bdab | 33 | 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, |
ban4jp | 3:48c4a173bdab | 34 | 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, |
ban4jp | 3:48c4a173bdab | 35 | }; |
ban4jp | 3:48c4a173bdab | 36 | #endif |
ban4jp | 3:48c4a173bdab | 37 | |
MACRUM | 2:aed20a7685b9 | 38 | #if defined(TARGET_LPC1768) |
MACRUM | 0:61b32e34bcbf | 39 | GT20L16J1Y_FONT::GT20L16J1Y_FONT() : _spi(p11, p12, p13), _CS(p10) { |
MACRUM | 0:61b32e34bcbf | 40 | } |
MACRUM | 2:aed20a7685b9 | 41 | #endif |
MACRUM | 0:61b32e34bcbf | 42 | |
MACRUM | 2:aed20a7685b9 | 43 | GT20L16J1Y_FONT::GT20L16J1Y_FONT(PinName mosi, PinName miso, PinName sclk, PinName cs) : _spi(mosi, miso, sclk, NC), _CS(cs) |
MACRUM | 2:aed20a7685b9 | 44 | { |
ban4jp | 3:48c4a173bdab | 45 | // Deselect the device |
ban4jp | 3:48c4a173bdab | 46 | _CS = 1; |
ban4jp | 3:48c4a173bdab | 47 | |
MACRUM | 2:aed20a7685b9 | 48 | // Setup the spi for 8 bit data, high steady state clock |
MACRUM | 2:aed20a7685b9 | 49 | _spi.format(8,3); |
MACRUM | 2:aed20a7685b9 | 50 | _spi.frequency(10000000); |
MACRUM | 2:aed20a7685b9 | 51 | } |
MACRUM | 2:aed20a7685b9 | 52 | |
MACRUM | 2:aed20a7685b9 | 53 | int GT20L16J1Y_FONT::read_kuten(unsigned short code) { |
MACRUM | 2:aed20a7685b9 | 54 | unsigned char MSB, LSB; |
MACRUM | 2:aed20a7685b9 | 55 | uint32_t address; |
MACRUM | 2:aed20a7685b9 | 56 | int ret; |
MACRUM | 0:61b32e34bcbf | 57 | |
MACRUM | 2:aed20a7685b9 | 58 | MSB = (code & 0xFF00) >> 8; |
MACRUM | 2:aed20a7685b9 | 59 | LSB = code & 0x00FF; |
MACRUM | 0:61b32e34bcbf | 60 | address = 0; |
MACRUM | 0:61b32e34bcbf | 61 | |
MACRUM | 0:61b32e34bcbf | 62 | if( MSB >= 1 && MSB <= 15 && LSB >= 1 && LSB <= 94) |
MACRUM | 0:61b32e34bcbf | 63 | address =( (MSB - 1) * 94 + (LSB - 1))*32; |
MACRUM | 0:61b32e34bcbf | 64 | else if(MSB >= 16 && MSB <= 47 && LSB >= 1 && LSB <= 94) |
MACRUM | 0:61b32e34bcbf | 65 | address =( (MSB - 16) * 94 + (LSB - 1))*32 + 0x0AA40L; |
MACRUM | 0:61b32e34bcbf | 66 | else if(MSB >= 48 && MSB <= 84 && LSB >= 1 && LSB <= 94) |
MACRUM | 0:61b32e34bcbf | 67 | address = ((MSB - 48) * 94 + (LSB - 1))*32 + 0x21CDFL; |
MACRUM | 0:61b32e34bcbf | 68 | else if(MSB == 85 && LSB >= 1 && LSB <= 94) |
MACRUM | 0:61b32e34bcbf | 69 | address = ((MSB - 85) * 94 + (LSB - 1))*32 + 0x3C4A0L; |
MACRUM | 0:61b32e34bcbf | 70 | else if(MSB >= 88 && MSB <= 89 && LSB >= 1 && LSB <= 94) |
MACRUM | 0:61b32e34bcbf | 71 | address = ((MSB - 88) * 94 + (LSB - 1))*32 + 0x3D060L; |
MACRUM | 2:aed20a7685b9 | 72 | else if(MSB == 0 && LSB >= 0x20 && LSB <= 0x7F) |
ban4jp | 3:48c4a173bdab | 73 | #if GT20L16J1Y_REMAP_ASCIIFONT |
ban4jp | 3:48c4a173bdab | 74 | address = ascii_fontmap[LSB - 0x20]*16 + 255968; // 0x3E7E0 |
ban4jp | 3:48c4a173bdab | 75 | #else |
MACRUM | 2:aed20a7685b9 | 76 | address = (LSB - 0x20)*16 + 255968; |
ban4jp | 3:48c4a173bdab | 77 | #endif |
ban4jp | 3:48c4a173bdab | 78 | #if GT20L16J1Y_ENABLE_JISX0201 |
ban4jp | 3:48c4a173bdab | 79 | else if(MSB == 0 && LSB == 0xA5) { // Font patch (0x00A5) |
ban4jp | 3:48c4a173bdab | 80 | memcpy(bitmap, font_glyph_00A5, 16); |
ban4jp | 3:48c4a173bdab | 81 | return 8; |
ban4jp | 3:48c4a173bdab | 82 | } |
ban4jp | 3:48c4a173bdab | 83 | else if(MSB == 0 && LSB >= 0xA1 && LSB <= 0xDF) // JIS X 0201 |
ban4jp | 3:48c4a173bdab | 84 | address = jisx0201_fontmap[LSB - 0xA1]*16 + 257504; // 0x3EDE0 |
ban4jp | 3:48c4a173bdab | 85 | #endif |
MACRUM | 0:61b32e34bcbf | 86 | |
MACRUM | 0:61b32e34bcbf | 87 | // Deselect the device |
MACRUM | 0:61b32e34bcbf | 88 | _CS = 1; |
MACRUM | 0:61b32e34bcbf | 89 | |
ban4jp | 3:48c4a173bdab | 90 | //_spi.begin(); |
ban4jp | 3:48c4a173bdab | 91 | _spi.write(0); // Dummy (mbed: change SPI owner and SPI format.) |
ban4jp | 3:48c4a173bdab | 92 | |
MACRUM | 0:61b32e34bcbf | 93 | // Select the device by seting chip select low |
MACRUM | 0:61b32e34bcbf | 94 | _CS = 0; |
MACRUM | 0:61b32e34bcbf | 95 | _spi.write(0x03); // Read data byte |
MACRUM | 0:61b32e34bcbf | 96 | _spi.write(address>>16 & 0xff); |
MACRUM | 0:61b32e34bcbf | 97 | _spi.write(address>>8 & 0xff); |
MACRUM | 0:61b32e34bcbf | 98 | _spi.write(address & 0xff); |
MACRUM | 0:61b32e34bcbf | 99 | |
ban4jp | 3:48c4a173bdab | 100 | #if GT20L16J1Y_ENABLE_JISX0201 |
ban4jp | 3:48c4a173bdab | 101 | if(MSB == 0 && (LSB >= 0x20 && LSB <= 0x7F) || (LSB >= 0xA1 && LSB <= 0xDF)) { |
ban4jp | 3:48c4a173bdab | 102 | #else |
MACRUM | 2:aed20a7685b9 | 103 | if(MSB == 0 && LSB >= 0x20 && LSB <= 0x7F) { |
ban4jp | 3:48c4a173bdab | 104 | #endif |
MACRUM | 2:aed20a7685b9 | 105 | for(int i=0; i<16; i++) |
MACRUM | 2:aed20a7685b9 | 106 | { |
MACRUM | 2:aed20a7685b9 | 107 | bitmap[i] = _spi.write(0x00); |
MACRUM | 2:aed20a7685b9 | 108 | } |
MACRUM | 2:aed20a7685b9 | 109 | ret = 8; |
MACRUM | 2:aed20a7685b9 | 110 | } |
MACRUM | 2:aed20a7685b9 | 111 | else { |
MACRUM | 2:aed20a7685b9 | 112 | for(int i=0; i<32; i++) |
MACRUM | 2:aed20a7685b9 | 113 | { |
MACRUM | 2:aed20a7685b9 | 114 | bitmap[i] = _spi.write(0x00); |
MACRUM | 2:aed20a7685b9 | 115 | } |
MACRUM | 2:aed20a7685b9 | 116 | ret = 16; |
MACRUM | 0:61b32e34bcbf | 117 | } |
MACRUM | 0:61b32e34bcbf | 118 | |
MACRUM | 0:61b32e34bcbf | 119 | // Deselect the device |
MACRUM | 0:61b32e34bcbf | 120 | _CS = 1; |
MACRUM | 2:aed20a7685b9 | 121 | |
MACRUM | 2:aed20a7685b9 | 122 | return ret; |
MACRUM | 0:61b32e34bcbf | 123 | } |
MACRUM | 2:aed20a7685b9 | 124 | |
ban4jp | 3:48c4a173bdab | 125 | int GT20L16J1Y_FONT::read(unsigned short code) { |
MACRUM | 2:aed20a7685b9 | 126 | unsigned char c1, c2, MSB, LSB; |
MACRUM | 2:aed20a7685b9 | 127 | uint32_t seq; |
MACRUM | 2:aed20a7685b9 | 128 | uint16_t address; |
MACRUM | 2:aed20a7685b9 | 129 | |
MACRUM | 2:aed20a7685b9 | 130 | // SJIS to kuten code conversion |
MACRUM | 2:aed20a7685b9 | 131 | c1 = (code>>8); |
MACRUM | 2:aed20a7685b9 | 132 | c2 = (code & 0xFF); |
MACRUM | 2:aed20a7685b9 | 133 | seq = (c1<=159 ? c1-129 : c1-193)*188 + (c2<=126 ? c2-64 : c2-65); |
MACRUM | 2:aed20a7685b9 | 134 | MSB = seq / 94 + 1; |
MACRUM | 2:aed20a7685b9 | 135 | LSB = seq % 94 + 1; |
MACRUM | 2:aed20a7685b9 | 136 | |
MACRUM | 2:aed20a7685b9 | 137 | address = ((MSB << 8) | LSB); |
ban4jp | 3:48c4a173bdab | 138 | return read_kuten(address); |
MACRUM | 2:aed20a7685b9 | 139 | } |
ban4jp | 3:48c4a173bdab | 140 | |
ban4jp | 3:48c4a173bdab | 141 | void GT20L16J1Y_FONT::read_direct(unsigned long address) { |
ban4jp | 3:48c4a173bdab | 142 | // Deselect the device |
ban4jp | 3:48c4a173bdab | 143 | _CS = 1; |
ban4jp | 3:48c4a173bdab | 144 | |
ban4jp | 3:48c4a173bdab | 145 | //_spi.begin(); |
ban4jp | 3:48c4a173bdab | 146 | _spi.write(0); // Dummy (mbed: change SPI owner and SPI format.) |
ban4jp | 3:48c4a173bdab | 147 | |
ban4jp | 3:48c4a173bdab | 148 | // Select the device by seting chip select low |
ban4jp | 3:48c4a173bdab | 149 | _CS = 0; |
ban4jp | 3:48c4a173bdab | 150 | _spi.write(0x03); // Read data byte |
ban4jp | 3:48c4a173bdab | 151 | _spi.write(address>>16 & 0xff); |
ban4jp | 3:48c4a173bdab | 152 | _spi.write(address>>8 & 0xff); |
ban4jp | 3:48c4a173bdab | 153 | _spi.write(address & 0xff); |
ban4jp | 3:48c4a173bdab | 154 | |
ban4jp | 3:48c4a173bdab | 155 | for(int i=0; i<32; i++) |
ban4jp | 3:48c4a173bdab | 156 | { |
ban4jp | 3:48c4a173bdab | 157 | bitmap[i] = _spi.write(0x00); |
ban4jp | 3:48c4a173bdab | 158 | } |
ban4jp | 3:48c4a173bdab | 159 | |
ban4jp | 3:48c4a173bdab | 160 | // Deselect the device |
ban4jp | 3:48c4a173bdab | 161 | _CS = 1; |
ban4jp | 3:48c4a173bdab | 162 | } |