LEDMatrixDisplay Program 文字ごとに色を変更できるように修正
Fork of LEDMatrix_Master by
15x16fontsLib.cpp
00001 #include "mbed.h" 00002 #include "displayCom.h" 00003 #include "15x16fontsLib.h" 00004 00005 SPI FontROM(p11, p12, p13); // mosi, miso, sclk 00006 DigitalOut FontROM_CS(p14); 00007 00008 00009 unsigned char matrixdata[32]; 00010 00011 void read_font(unsigned short code) { 00012 unsigned char c1, c2, MSB,LSB; 00013 uint32_t Address, seq; 00014 00015 // SJIS to kuten code conversion 00016 c1 = (code>>8); 00017 c2 = (code & 0xFF); 00018 seq = (c1<=159 ? c1-129 : c1-193)*188 + (c2<=126 ? c2-64 : c2-65); 00019 MSB = seq / 94 + 1; 00020 LSB = seq % 94 + 1; 00021 Address = 0; 00022 00023 if( MSB >= 1 && MSB <= 15 && LSB >= 1 && LSB <= 94) 00024 Address =( (MSB - 1) * 94 + (LSB - 1))*32; 00025 else if(MSB >= 16 && MSB <= 47 && LSB >= 1 && LSB <= 94) 00026 Address =( (MSB - 16) * 94 + (LSB - 1))*32 + 0x0AA40L; 00027 else if(MSB >= 48 && MSB <= 84 && LSB >= 1 && LSB <= 94) 00028 Address = ((MSB - 48) * 94 + (LSB - 1))*32 + 0x21CDFL; 00029 else if(MSB == 85 && LSB >= 1 && LSB <= 94) 00030 Address = ((MSB - 85) * 94 + (LSB - 1))*32 + 0x3C4A0L; 00031 else if(MSB >= 88 && MSB <= 89 && LSB >= 1 && LSB <= 94) 00032 Address = ((MSB - 88) * 94 + (LSB - 1))*32 + 0x3D060L; 00033 00034 // if ASCII code 00035 int font_width; 00036 if(code >= 0x20 && code <= 0x7F) { 00037 Address = (code - 0x20)*16 + 255968; 00038 font_width = 8; 00039 } 00040 else { 00041 font_width = 16; 00042 } 00043 00044 // Deselect the device 00045 FontROM_CS = 1; 00046 00047 // Setup the spi for 8 bit data, high steady state clock 00048 FontROM.format(8,3); 00049 FontROM.frequency(1000000); 00050 00051 // Select the device by seting chip select low 00052 FontROM_CS = 0; 00053 FontROM.write(0x03); // Read data byte 00054 FontROM.write(Address>>16 & 0xff); 00055 FontROM.write(Address>>8 & 0xff); 00056 FontROM.write(Address & 0xff); 00057 00058 // Send a dummy byte to receive the contents of the WHOAMI register 00059 for(int i=0; i<(font_width*2); i++) 00060 { 00061 matrixdata[i]=FontROM.write(0x00); 00062 } 00063 00064 // Deselect the device 00065 FontROM_CS = 1; 00066 } 00067 00068 void draw_kanji_15x16(int pos_x,unsigned char color, int font_width) 00069 { 00070 for(int i=0; i<font_width; i++) 00071 { 00072 if( ((signed int)(15-i+pos_x) >= 0) && ((15-i+pos_x) <= (DISPLAY_XSIZE-1)) ) 00073 { 00074 if(color == COLOR_G || color == COLOR_C || color == COLOR_Y || color == COLOR_W) 00075 { 00076 ImageBuf[0][15-i+pos_x] = matrixdata[i]; 00077 ImageBuf[0][15-i+pos_x] |= matrixdata[i+font_width]<<8; 00078 } 00079 if(color == COLOR_R || color == COLOR_Y || color == COLOR_M || color == COLOR_W) 00080 { 00081 ImageBuf[1][15-i+pos_x] = matrixdata[i]; 00082 ImageBuf[1][15-i+pos_x] |= matrixdata[i+font_width]<<8; 00083 } 00084 if(color == COLOR_B || color == COLOR_C || color == COLOR_M || color == COLOR_W) 00085 { 00086 ImageBuf[2][15-i+pos_x] = matrixdata[i]; 00087 ImageBuf[2][15-i+pos_x] |= matrixdata[i+font_width]<<8; 00088 } 00089 } 00090 } 00091 } 00092 00093 void drawStr15x16(char *str ,int pos_x,unsigned char color) 00094 { 00095 unsigned char f_SJISChar = 0; 00096 unsigned char c = 0; 00097 unsigned int SJISChar = 0; 00098 unsigned int CountChar = 0; 00099 00100 c = *str; 00101 while(c != '\0') 00102 { 00103 //2バイト文字の判定 00104 if( ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)) && f_SJISChar != 1 ) 00105 { 00106 SJISChar = c; 00107 f_SJISChar = 1; 00108 } 00109 else if(f_SJISChar == 1) 00110 { 00111 SJISChar = (SJISChar<<8) | c; 00112 f_SJISChar = 0; 00113 read_font(SJISChar); 00114 draw_kanji_15x16(pos_x-CountChar*8, color, 16); 00115 CountChar+=2; 00116 } 00117 else //ASCII文字 00118 { 00119 SJISChar = c; 00120 f_SJISChar = 0; 00121 read_font(SJISChar); 00122 draw_kanji_15x16(pos_x-CountChar*8, color, 8); 00123 CountChar++; 00124 } 00125 str++; 00126 c = *str; 00127 } 00128 } 00129 00130 void drawStr15x16_AutoColer(char *str ,int pos_x) 00131 { 00132 unsigned char f_SJISChar = 0; 00133 unsigned char c = 0; 00134 unsigned char c_color = 0; 00135 unsigned int SJISChar = 0; 00136 unsigned int CountChar = 0; 00137 const unsigned char color_pattern[6] = {COLOR_R,COLOR_Y,COLOR_G,COLOR_C,COLOR_B,COLOR_M}; 00138 00139 c = *str; 00140 while(c != '\0') 00141 { 00142 //2バイト文字の判定 00143 if( ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc)) && f_SJISChar != 1 ) 00144 { 00145 SJISChar = c; 00146 f_SJISChar = 1; 00147 } 00148 else if(f_SJISChar == 1) 00149 { 00150 SJISChar = (SJISChar<<8) | c; 00151 f_SJISChar = 0; 00152 read_font(SJISChar); 00153 draw_kanji_15x16(pos_x-CountChar*8, color_pattern[c_color], 16); 00154 CountChar+=2; 00155 } 00156 else //ASCII文字 00157 { 00158 SJISChar = c; 00159 f_SJISChar = 0; 00160 read_font(SJISChar); 00161 draw_kanji_15x16(pos_x-CountChar*8, color_pattern[c_color], 8); 00162 CountChar++; 00163 } 00164 str++; 00165 c = *str; 00166 c_color++; 00167 if(c_color>=6) 00168 { 00169 c_color = 0; 00170 } 00171 } 00172 }
Generated on Tue Jul 12 2022 16:59:14 by
1.7.2
