Index: asp3_tinet_ecnl_arm/trunk/ntshell/lcd/draw_font.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/lcd/draw_font.c	(revision 352)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/lcd/draw_font.c	(revision 364)
@@ -1,7 +1,7 @@
 /*
  *  TOPPERS ECHONET Lite Communication Middleware
- * 
+ *
  *  Copyright (C) 2018 Cores Co., Ltd. Japan
- * 
+ *
  *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
  *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
@@ -26,5 +26,5 @@
  *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
  *      免責すること．
- * 
+ *
  *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
  *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
@@ -32,5 +32,5 @@
  *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
  *  の責任を負わない．
- * 
+ *
  *  @(#) $Id$
  */
@@ -41,40 +41,43 @@
 #include <string.h>
 #include <target_syssvc.h>
+#ifndef ADAFRUIT_SSD1306
 #include "adafruit_st7735.h"
+#else
+#include "adafruit_ssd1306.h"
+#endif
 #include "draw_font.h"
-#include "misaki_font.h"
-
-void get_bitmap_font(char *string, unsigned char *bitmap_data, unsigned long *use_chars)
-{
-	unsigned long len, code;
-	unsigned char i,j,k;
-	unsigned long totalj, totalk;
+
+void get_bitmap_font(const uint8_t *string, uint8_t *bitmap_data, uint32_t *use_chars)
+{
+	uint32_t len, code;
+	uint8_t i, j, k;
+	uint32_t totalj, totalk;
 
 	*use_chars = 0;
 	len = 0;
-	if      ((string[0] & 0x80) ==    0) { len = 1; }
+	if ((string[0] & 0x80) == 0) { len = 1; }
 	else if ((string[0] & 0xE0) == 0xC0) { len = 2; }
 	else if ((string[0] & 0xF0) == 0xE0) { len = 3; }
 	else if ((string[0] & 0xF8) == 0xF0) { len = 4; }
-	else { return;	}
+	else { return; }
 
 	j = k = totalj = totalk = 0;
 
-	if( len == 1 ) {
+	if (len == 1) {
 		code = string[0];
-		memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], 8 );
+		memcpy(bitmap_data, &UTF8_1B_CODE_BITMAP[code][0], FONT_WIDTH * FONT_HEIGHT / 8);
 		*use_chars = 1;
 		return;
 	}
 
-	if( len == 2 ) {
+	if (len == 2) {
 		code = string[0];
 		// 1バイト目サーチ
-		for(i = 0; i < UTF8_CODE_2B_1_NUM; i++ ) {
-			if ( Utf8CodeTable_2B_1st[i][0] == code ) {
+		for (i = 0; i < UTF8_CODE_2B_1_NUM; i++) {
+			if (Utf8CodeTable_2B_1st[i][0] == code) {
 				code = string[1];
-				for( j = 0; j < Utf8CodeTable_2B_1st[i][1]; j++ ) {
-					if ( UTF8_2B_CODE_BITMAP[totalk].code == code ) {
-						memcpy(bitmap_data, UTF8_2B_CODE_BITMAP[totalk].bitmap, 8 );
+				for (j = 0; j < Utf8CodeTable_2B_1st[i][1]; j++) {
+					if (UTF8_2B_CODE_BITMAP[totalk].code == code) {
+						memcpy(bitmap_data, UTF8_2B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
 						*use_chars = 2;
 						return;
@@ -90,18 +93,18 @@
 	}
 
-	if( len == 3 ) {
+	if (len == 3) {
 		code = string[0];
 		// 1バイト目サーチ
-		for(i = 0; i < UTF8_CODE_3B_1_NUM; i++ ) {
-			if ( Utf8CodeTable_3B_1st[i][0] == code ) {
+		for (i = 0; i < UTF8_CODE_3B_1_NUM; i++) {
+			if (Utf8CodeTable_3B_1st[i][0] == code) {
 				code = string[1];
 				// 2バイト目サーチ
-				for( j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++ ){
-					if ( Utf8CodeTable_3B_2nd[totalj][0] == code ) {
+				for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
+					if (Utf8CodeTable_3B_2nd[totalj][0] == code) {
 						code = string[2];
 						// 3バイト目サーチ
-						for( k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
+						for (k = 0; k < Utf8CodeTable_3B_2nd[totalj][1]; k++) {
 							if (UTF8_3B_CODE_BITMAP[totalk].code == code) {
-								memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, 8 );
+								memcpy(bitmap_data, UTF8_3B_CODE_BITMAP[totalk].bitmap, FONT_WIDTH * FONT_HEIGHT / 8);
 								*use_chars = 3;
 								return;
@@ -111,5 +114,5 @@
 						return;
 					}
-					else{/*読み飛ばすbitmap個数を蓄積*/
+					else {/*読み飛ばすbitmap個数を蓄積*/
 						totalk += Utf8CodeTable_3B_2nd[totalj][1];
 					}
@@ -118,5 +121,5 @@
 			}
 			else {/*読み飛ばすbitmap個数を蓄積*/
-				for( j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++ ) {
+				for (j = 0; j < Utf8CodeTable_3B_1st[i][1]; j++) {
 					totalk += Utf8CodeTable_3B_2nd[totalj][1];
 					totalj++;
@@ -128,41 +131,56 @@
 }
 
-void lcd_drawFont(LCD_Handler_t *hlcd, unsigned char *bitmap_data, int x, int y, unsigned short color, unsigned short back_color)
-{
-	int i, j;
-
-	for(i = 0; i < 8; i++ ) {
-		for(j = 0; j < 8; j++ ) {
-			if (((bitmap_data[i] >> j) & 0x01) == 1){
-				lcd_drawPixel(hlcd, x - j, y + i, color);
+void lcd_drawFont(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
+{
+	int i, j, b;
+	uint8_t *bitmap = bitmap_data;
+
+	b = 0x80;
+	for (i = 0; i < FONT_HEIGHT; i++) {
+		for (j = 0; j < FONT_WIDTH; j++) {
+			if ((*bitmap & b) != 0) {
+				lcd_drawPixel(hlcd, x + j, y + i, color);
 			}
 			else {
-				lcd_drawPixel(hlcd, x - j, y + i, back_color);
-			}
-		}
-	}
-}
-
-void lcd_drawFontHalf(LCD_Handler_t *hlcd, unsigned char *bitmap_data, int x, int y, unsigned short color, unsigned short back_color)
-{
-	int i, j;
-
-	for(i = 0; i < 8; i++ ) {
-		for(j = 4; j < 8; j++ ) {
-			if (((bitmap_data[i] >> j) & 0x01) == 1){
-				lcd_drawPixel(hlcd, x - j, y + i, color);
+				lcd_drawPixel(hlcd, x + j, y + i, back_color);
+			}
+			b >>= 1;
+			if (b == 0) {
+				b = 0x80;
+				bitmap++;
+			}
+		}
+	}
+}
+
+void lcd_drawFontHalf(LCD_Handler_t *hlcd, uint8_t *bitmap_data, int x, int y, uint16_t color, uint16_t back_color)
+{
+	int i, j, b;
+	uint8_t *bitmap = bitmap_data;
+
+	b = 0x80;
+	for (i = 0; i < FONT_HEIGHT; i++) {
+		for (j = 0; j < FONT_HALF_WIDTH; j++) {
+			if ((*bitmap & b) != 0) {
+				lcd_drawPixel(hlcd, x + j, y + i, color);
 			}
 			else {
-				lcd_drawPixel(hlcd, x - j, y + i, back_color);
-			}
-		}
-	}
-}
-
-void lcd_drawString(LCD_Handler_t *hlcd, char *string, int x, int y, unsigned short color, unsigned short back_color )
-{
-	unsigned long current_top, use_chars, for_3B_hankaku_code;
-	unsigned char bitmap_data[8], ctrl_code;
-	int local_x, local_y;
+				lcd_drawPixel(hlcd, x + j, y + i, back_color);
+			}
+			b >>= 1;
+			if (b == 0) {
+				b = 0x80;
+				bitmap++;
+			}
+		}
+	}
+}
+
+void lcd_drawString(LCD_Handler_t *hlcd, const char *string, int x, int y, uint16_t color, uint16_t back_color)
+{
+	uint32_t current_top, use_chars, for_3B_hankaku_code;
+	uint8_t bitmap_data[FONT_WIDTH * FONT_HEIGHT / 8], ctrl_code;
+	int local_x, local_y, len = strlen(string);
+	const uint8_t *code = (const uint8_t *)string;
 
 	local_x = x;
@@ -170,18 +188,17 @@
 
 	current_top = 0;
-	while( current_top < strlen(string) )
-	{
-		memset(bitmap_data,0x0,8);
-		ctrl_code = string[current_top];
-		get_bitmap_font(&string[current_top], bitmap_data, &use_chars);
-		if(use_chars == 0)
+	while (current_top < len) {
+		memset(bitmap_data, 0x0, FONT_WIDTH * FONT_HEIGHT / 8);
+		ctrl_code = code[current_top];
+		get_bitmap_font(&code[current_top], bitmap_data, &use_chars);
+		if (use_chars == 0)
 			return;
 
 		//3バイトコード半角文字用
-		if(use_chars == 3) {
+		if (use_chars == 3) {
 			for_3B_hankaku_code = 0;
-			for_3B_hankaku_code = ( (string[current_top]   << 16) |
-								    (string[current_top+1] <<  8) |
-								    (string[current_top+2]      )   );
+			for_3B_hankaku_code = ((code[current_top] << 16) |
+				(code[current_top + 1] << 8) |
+				(code[current_top + 2]));
 		}
 
@@ -189,34 +206,34 @@
 
 		//1バイトコード半角文字
-		if ( use_chars == 1 ) {
-			if(ctrl_code == 0x0D) { // CR
+		if (use_chars == 1) {
+			if (ctrl_code == 0x0D) { // CR
 				local_x = X_LINE_TO_PIX(hlcd, 0);
 				continue;
 			}
-			if(ctrl_code == 0x0A) { // LF
-				local_y = local_y + 8;
+			if (ctrl_code == 0x0A) { // LF
+				local_y = local_y + FONT_HEIGHT;
 				continue;
 			}
 
-			if ( local_x >= hlcd->_width + 4 ) {
+			if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
 				local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
-				local_y = local_y + 8;
+				local_y = local_y + FONT_HEIGHT;
 			}
 			lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
-			local_x += 4;
+			local_x += FONT_HALF_WIDTH;
 			continue;
 		}
 
 		//3バイトコード半角文字
-		if( use_chars == 3 ) {
-			if (	( (0xEFBDA1 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBDBF) ) ||
-					( (0xEFBE80 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBE9F) )	) {
+		if (use_chars == 3) {
+			if (((0xEFBDA1 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBDBF)) ||
+				((0xEFBE80 <= for_3B_hankaku_code) && (for_3B_hankaku_code <= 0xEFBE9F))) {
 				//3バイトコード半角文字
-				if ( local_x >= hlcd->_width + 4 ) {
+				if (local_x + FONT_HALF_WIDTH > hlcd->_width) {
 					local_x = X_LINE_HALF_TO_PIX(hlcd, 0);
-					local_y = local_y + 8;
+					local_y = local_y + FONT_HEIGHT;
 				}
 				lcd_drawFontHalf(hlcd, bitmap_data, local_x, local_y, color, back_color);
-				local_x += 4;
+				local_x += FONT_HALF_WIDTH;
 				continue;
 			}
@@ -224,11 +241,11 @@
 
 		//全角文字
-		if ( local_x >= hlcd->_width + 8 ) {
+		if (local_x + FONT_WIDTH > hlcd->_width) {
 			local_x = X_LINE_TO_PIX(hlcd, 0);
-			local_y = local_y + 8;
+			local_y = local_y + FONT_HEIGHT;
 		}
 		lcd_drawFont(hlcd, bitmap_data, local_x, local_y, color, back_color);
-		local_x += 8;
-	}
-}
-
+		local_x += FONT_WIDTH;
+	}
+}
+
