Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LEDMatrix_Master by
15x16fontsLib.cpp@7:a0cf625479c9, 2013-11-30 (annotated)
- Committer:
- MACRUM
- Date:
- Sat Nov 30 14:40:18 2013 +0000
- Revision:
- 7:a0cf625479c9
- Parent:
- 6:bfd5c9d80f48
Fixed text length issue.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nameless129 | 4:70a1803901d1 | 1 | #include "mbed.h" |
| nameless129 | 4:70a1803901d1 | 2 | #include "displayCom.h" |
| nameless129 | 4:70a1803901d1 | 3 | #include "15x16fontsLib.h" |
| nameless129 | 4:70a1803901d1 | 4 | |
| nameless129 | 4:70a1803901d1 | 5 | SPI FontROM(p11, p12, p13); // mosi, miso, sclk |
| nameless129 | 4:70a1803901d1 | 6 | DigitalOut FontROM_CS(p14); |
| nameless129 | 4:70a1803901d1 | 7 | |
| nameless129 | 4:70a1803901d1 | 8 | |
| nameless129 | 4:70a1803901d1 | 9 | unsigned char matrixdata[32]; |
| nameless129 | 4:70a1803901d1 | 10 | |
| nameless129 | 4:70a1803901d1 | 11 | void read_font(unsigned short code) { |
| nameless129 | 4:70a1803901d1 | 12 | unsigned char c1, c2, MSB,LSB; |
| nameless129 | 4:70a1803901d1 | 13 | uint32_t Address, seq; |
| nameless129 | 4:70a1803901d1 | 14 | |
| nameless129 | 4:70a1803901d1 | 15 | // SJIS to kuten code conversion |
| nameless129 | 4:70a1803901d1 | 16 | c1 = (code>>8); |
| nameless129 | 4:70a1803901d1 | 17 | c2 = (code & 0xFF); |
| nameless129 | 4:70a1803901d1 | 18 | seq = (c1<=159 ? c1-129 : c1-193)*188 + (c2<=126 ? c2-64 : c2-65); |
| nameless129 | 4:70a1803901d1 | 19 | MSB = seq / 94 + 1; |
| nameless129 | 4:70a1803901d1 | 20 | LSB = seq % 94 + 1; |
| nameless129 | 4:70a1803901d1 | 21 | Address = 0; |
| MACRUM | 6:bfd5c9d80f48 | 22 | |
| nameless129 | 4:70a1803901d1 | 23 | if( MSB >= 1 && MSB <= 15 && LSB >= 1 && LSB <= 94) |
| nameless129 | 4:70a1803901d1 | 24 | Address =( (MSB - 1) * 94 + (LSB - 1))*32; |
| nameless129 | 4:70a1803901d1 | 25 | else if(MSB >= 16 && MSB <= 47 && LSB >= 1 && LSB <= 94) |
| nameless129 | 4:70a1803901d1 | 26 | Address =( (MSB - 16) * 94 + (LSB - 1))*32 + 0x0AA40L; |
| nameless129 | 4:70a1803901d1 | 27 | else if(MSB >= 48 && MSB <= 84 && LSB >= 1 && LSB <= 94) |
| nameless129 | 4:70a1803901d1 | 28 | Address = ((MSB - 48) * 94 + (LSB - 1))*32 + 0x21CDFL; |
| nameless129 | 4:70a1803901d1 | 29 | else if(MSB == 85 && LSB >= 1 && LSB <= 94) |
| nameless129 | 4:70a1803901d1 | 30 | Address = ((MSB - 85) * 94 + (LSB - 1))*32 + 0x3C4A0L; |
| nameless129 | 4:70a1803901d1 | 31 | else if(MSB >= 88 && MSB <= 89 && LSB >= 1 && LSB <= 94) |
| nameless129 | 4:70a1803901d1 | 32 | Address = ((MSB - 88) * 94 + (LSB - 1))*32 + 0x3D060L; |
| nameless129 | 4:70a1803901d1 | 33 | |
| MACRUM | 6:bfd5c9d80f48 | 34 | // if ASCII code |
| MACRUM | 6:bfd5c9d80f48 | 35 | int font_width; |
| MACRUM | 6:bfd5c9d80f48 | 36 | if(code >= 0x20 && code <= 0x7F) { |
| MACRUM | 6:bfd5c9d80f48 | 37 | Address = (code - 0x20)*16 + 255968; |
| MACRUM | 6:bfd5c9d80f48 | 38 | font_width = 8; |
| MACRUM | 6:bfd5c9d80f48 | 39 | } |
| MACRUM | 6:bfd5c9d80f48 | 40 | else { |
| MACRUM | 6:bfd5c9d80f48 | 41 | font_width = 16; |
| MACRUM | 6:bfd5c9d80f48 | 42 | } |
| MACRUM | 6:bfd5c9d80f48 | 43 | |
| nameless129 | 4:70a1803901d1 | 44 | // Deselect the device |
| nameless129 | 4:70a1803901d1 | 45 | FontROM_CS = 1; |
| nameless129 | 4:70a1803901d1 | 46 | |
| nameless129 | 4:70a1803901d1 | 47 | // Setup the spi for 8 bit data, high steady state clock |
| nameless129 | 4:70a1803901d1 | 48 | FontROM.format(8,3); |
| nameless129 | 4:70a1803901d1 | 49 | FontROM.frequency(1000000); |
| nameless129 | 4:70a1803901d1 | 50 | |
| nameless129 | 4:70a1803901d1 | 51 | // Select the device by seting chip select low |
| nameless129 | 4:70a1803901d1 | 52 | FontROM_CS = 0; |
| nameless129 | 4:70a1803901d1 | 53 | FontROM.write(0x03); // Read data byte |
| nameless129 | 4:70a1803901d1 | 54 | FontROM.write(Address>>16 & 0xff); |
| nameless129 | 4:70a1803901d1 | 55 | FontROM.write(Address>>8 & 0xff); |
| nameless129 | 4:70a1803901d1 | 56 | FontROM.write(Address & 0xff); |
| nameless129 | 4:70a1803901d1 | 57 | |
| nameless129 | 4:70a1803901d1 | 58 | // Send a dummy byte to receive the contents of the WHOAMI register |
| MACRUM | 6:bfd5c9d80f48 | 59 | for(int i=0; i<(font_width*2); i++) |
| nameless129 | 4:70a1803901d1 | 60 | { |
| MACRUM | 6:bfd5c9d80f48 | 61 | matrixdata[i]=FontROM.write(0x00); |
| nameless129 | 4:70a1803901d1 | 62 | } |
| nameless129 | 4:70a1803901d1 | 63 | |
| nameless129 | 4:70a1803901d1 | 64 | // Deselect the device |
| nameless129 | 4:70a1803901d1 | 65 | FontROM_CS = 1; |
| nameless129 | 4:70a1803901d1 | 66 | } |
| nameless129 | 4:70a1803901d1 | 67 | |
| MACRUM | 6:bfd5c9d80f48 | 68 | void draw_kanji_15x16(int pos_x,unsigned char color, int font_width) |
| nameless129 | 4:70a1803901d1 | 69 | { |
| MACRUM | 6:bfd5c9d80f48 | 70 | for(int i=0; i<font_width; i++) |
| nameless129 | 4:70a1803901d1 | 71 | { |
| nameless129 | 4:70a1803901d1 | 72 | if( ((signed int)(15-i+pos_x) >= 0) && ((15-i+pos_x) <= (DISPLAY_XSIZE-1)) ) |
| nameless129 | 4:70a1803901d1 | 73 | { |
| nameless129 | 4:70a1803901d1 | 74 | if(color == COLOR_G || color == COLOR_C || color == COLOR_Y || color == COLOR_W) |
| nameless129 | 4:70a1803901d1 | 75 | { |
| nameless129 | 4:70a1803901d1 | 76 | ImageBuf[0][15-i+pos_x] = matrixdata[i]; |
| MACRUM | 6:bfd5c9d80f48 | 77 | ImageBuf[0][15-i+pos_x] |= matrixdata[i+font_width]<<8; |
| nameless129 | 4:70a1803901d1 | 78 | } |
| nameless129 | 4:70a1803901d1 | 79 | if(color == COLOR_R || color == COLOR_Y || color == COLOR_M || color == COLOR_W) |
| nameless129 | 4:70a1803901d1 | 80 | { |
| nameless129 | 4:70a1803901d1 | 81 | ImageBuf[1][15-i+pos_x] = matrixdata[i]; |
| MACRUM | 6:bfd5c9d80f48 | 82 | ImageBuf[1][15-i+pos_x] |= matrixdata[i+font_width]<<8; |
| nameless129 | 4:70a1803901d1 | 83 | } |
| nameless129 | 4:70a1803901d1 | 84 | if(color == COLOR_B || color == COLOR_C || color == COLOR_M || color == COLOR_W) |
| nameless129 | 4:70a1803901d1 | 85 | { |
| nameless129 | 4:70a1803901d1 | 86 | ImageBuf[2][15-i+pos_x] = matrixdata[i]; |
| MACRUM | 6:bfd5c9d80f48 | 87 | ImageBuf[2][15-i+pos_x] |= matrixdata[i+font_width]<<8; |
| nameless129 | 4:70a1803901d1 | 88 | } |
| nameless129 | 4:70a1803901d1 | 89 | } |
| nameless129 | 4:70a1803901d1 | 90 | } |
| nameless129 | 4:70a1803901d1 | 91 | } |
| nameless129 | 4:70a1803901d1 | 92 | |
| nameless129 | 4:70a1803901d1 | 93 | void drawStr15x16(char *str ,int pos_x,unsigned char color) |
| nameless129 | 4:70a1803901d1 | 94 | { |
| nameless129 | 4:70a1803901d1 | 95 | unsigned char f_SJISChar = 0; |
| nameless129 | 4:70a1803901d1 | 96 | unsigned char c = 0; |
| nameless129 | 4:70a1803901d1 | 97 | unsigned int SJISChar = 0; |
| nameless129 | 4:70a1803901d1 | 98 | unsigned int CountChar = 0; |
| nameless129 | 4:70a1803901d1 | 99 | |
| nameless129 | 4:70a1803901d1 | 100 | c = *str; |
| nameless129 | 4:70a1803901d1 | 101 | while(c != '\0') |
| nameless129 | 4:70a1803901d1 | 102 | { |
| nameless129 | 4:70a1803901d1 | 103 | //2バイト文字の判定 |
| nameless129 | 4:70a1803901d1 | 104 | if( ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)) && f_SJISChar != 1 ) |
| nameless129 | 4:70a1803901d1 | 105 | { |
| nameless129 | 4:70a1803901d1 | 106 | SJISChar = c; |
| nameless129 | 4:70a1803901d1 | 107 | f_SJISChar = 1; |
| nameless129 | 4:70a1803901d1 | 108 | } |
| nameless129 | 4:70a1803901d1 | 109 | else if(f_SJISChar == 1) |
| nameless129 | 4:70a1803901d1 | 110 | { |
| nameless129 | 4:70a1803901d1 | 111 | SJISChar = (SJISChar<<8) | c; |
| nameless129 | 4:70a1803901d1 | 112 | f_SJISChar = 0; |
| nameless129 | 4:70a1803901d1 | 113 | read_font(SJISChar); |
| MACRUM | 6:bfd5c9d80f48 | 114 | draw_kanji_15x16(pos_x-CountChar*8, color, 16); |
| MACRUM | 6:bfd5c9d80f48 | 115 | CountChar+=2; |
| nameless129 | 4:70a1803901d1 | 116 | } |
| nameless129 | 4:70a1803901d1 | 117 | else //ASCII文字 |
| nameless129 | 4:70a1803901d1 | 118 | { |
| nameless129 | 4:70a1803901d1 | 119 | SJISChar = c; |
| nameless129 | 4:70a1803901d1 | 120 | f_SJISChar = 0; |
| nameless129 | 4:70a1803901d1 | 121 | read_font(SJISChar); |
| MACRUM | 6:bfd5c9d80f48 | 122 | draw_kanji_15x16(pos_x-CountChar*8, color, 8); |
| nameless129 | 4:70a1803901d1 | 123 | CountChar++; |
| nameless129 | 4:70a1803901d1 | 124 | } |
| nameless129 | 4:70a1803901d1 | 125 | str++; |
| nameless129 | 4:70a1803901d1 | 126 | c = *str; |
| nameless129 | 4:70a1803901d1 | 127 | } |
| MACRUM | 6:bfd5c9d80f48 | 128 | } |
