Use Tslib to display Chinese characters "turn" on the touch screen

Source: Internet
Author: User
Tags fread

Transferred from: http://www.latelee.org/embedded-linux/use-tslib-to-display-chinese-character.html

Finally, the display of Chinese characters on the touchscreen, the real code, the test time is 1 days, before this all preparation, study spent about 2 weeks to 3 weeks time. And in order to get the image displayed on the touchscreen, it takes about 2 days. Because the network driver is close to the state of abandonment, NFS can not be used, had to use a USB stick to copy back and forth (even without patience must have patience). Obviously in the kernel chose to support the NTFS format read and write, but can not copy the Development Board files to the USB flash drive, and another FAT32 format of the other brand of U disk, the Development Board is not recognized, the online information said to modify the code, I am too lazy to change. Helpless under, had to format the NTFS disk drive, the result, this article dragged until now published.

Solemnly explain:

The author does not mention the author's work, working hours, spare time and amateur life in this article and in the previous articles, because it is unwise to cover the work and life content in these articles. There is no indication that the author is not working, has no amateur life, and does not indicate that the author only lives in writing code.

Disclaimer:

This article is an article of the author in the research process, in the spirit of Internet sharing, freedom (free, should not be "no Charge") published here. This article uses the code in the Tslib, and on this basis to add their own code, about Tslib, the author has written a number of articles related to the article, which is only published by their own added code. The author has no obligation to the code, and the author must use this protocol only because Tslib uses the GPL protocol. Author Caishuxueqian, ignorant, limited ability, the wrong place in the text, welcome to leave a message, while the author also has the passion to study, we have been exploring, common learning, day up.

Again, the author on the s3c2440 Chip Development Board, the use of the latest download tslib, using the Chinese character font HZK16, hzk24*, through their own code, on the Development Board with the touch screen display Chinese characters. However, it has not been tested in other test environments and platforms.

On the Chinese character display algorithm (in fact, no algorithm), the steps have been in the previous article said a lot, here no longer mentioned.

Since the Autotool has not been researched yet, and Tslib uses this tool to manage the code, it does not know how to add new files, and if the new files can be compiled. Had to add the code in the original file. The function of the added code is declared in Fbutils.h, the function is defined in the FBUTILS.C file, and the test code is in ts_test.c.

The code was modified about three times, basically a few structural adjustments, not to mention the decent words. As for the real change, only the code of the lowest display character modifies several places, which is to change the original multiplication to shift, while the multiplication and shift tests in some other places find no difference, so the multiplication is preserved. To cite an example, such as

offset = (*ascii–0x20) * 16;

There was no change to

offset = (*ascii–0x20) << 4;

The former is more likely to make people understand that the ASCII character here occupies 16 bytes in the font array, and left 4 bits, really let people do not know what meaning.

Known Bugs:

1, not within the GB2312 range of Chinese characters can not display properly-this is nonsense, as in the en_US character set is displayed in Chinese.

2, Ucdos the hzk24* series font file does not have Chinese characters, such as "-▲" and so on 16 point array Display Normal, and in 24 point array display failure (garbled or other Chinese characters), online can not find including the complete Chinese characters font, in addition, do not know the use of Ucdos font is not considered infringement ( These things can be downloaded on the Internet).

function declaration:

/* New add by late Lee *//* ASCII code */

void Put_string_ascii (int x, int y, char *s, unsigned colidx);

void Put_string_center_ascii (int x, int y, char *s, unsigned colidx);

/* cineses character */

void Put_string_hz (FILE *fp, int x, int y, unsigned char *s, unsigned colidx);

void Put_string_center_hz (FILE *fp, int x, int y, unsigned char *s, unsigned colidx);

/* chineses Character & ASCII */

void Put_font (FILE *fp, int x, int y, unsigned char *s, unsigned colidx);

void Put_font_center (FILE *fp, int x, int y, unsigned char *s, unsigned colidx);

/* End of new add */

Test code (TS_TEST.C):

Static FILE *FP; /* HZK file pointer by late Lee */#define HZK "hzk/hzk16″/* HZK16 or hzk24k/hzk24s */static void Refresh_screen ()

{

......

/* Just a test */

unsigned char incode[] = "▲! ADC test Rong Sample "; Note: The word "rong" is not within the GB2312 range and is not displayed properly.

int y = yres/4+50;

Put_string_ascii (0, Y, "Powered by late Lee", 9);

Put_string_hz (FP, 0, y+30, "The wave God left me to watch the setting sun listen to the Frogs piece", 2);

Put_font (FP, 0, y+56, Incode, 5);

/* End of the test * *

......

}

Key code (FBUTILS.C):

/* New add by late Lee 2011-05-30*///#define HZK24

#ifdef HZK24/* 24 */

#include "ascii24.h"

#define Ascii_code Ascii24

#define FONT_SIZE/* size:24 */

#else/* 16 */

#include "Ascii16.h"

#define Ascii_code ASCII16

#define FONT_SIZE/* size:16 */

#endif
#define BYTES (FONT_SIZE/8)/* for Hz:3 BYTES 2 bytes*/

#define BUF_SIZE (BYTES * font_size)/* HZ buff 3*24 = the BYTES 2*16 = + BYTES */

#define Ascii_bytes (BYTES-1)/* 2 1*/

#define ASCII_SIZE (Font_size * ascii_bytes)/* ASCII buffer:24*2 = BYTES * 1 = BYTES */

#define ASCII_WIDTH (FONT_SIZE/2)/* ascii:16*8 24*12 */

/* End here late lee*/

/*****************************************************************************

* New add by late Lee 2011-05-30

*****************************************************************************/

/**

* __display_ascii–display an ASCII code in touch screen

* @x:column

* @y:row

* @ascii: Which ASCII code to display

* @colidx: Color index (?)

* This routine display a ASCII code that stored in an array (eg, ascii_code).

* 16x8 ASCII code takes 1 byte, 24*12 ASCII code takes 2 bytes, so we need

*-ascii_bytes-.

*/

static void __display_ascii (int x, int y, char *ascii, unsigned colidx)

{

int I, j, K;

unsigned char *p_ascii;

int offset;

offset = (*ascii–0x20) * ascii_size; /* Find the code in the array */

P_ASCII = Ascii_code + offset;

for (i=0;i<font_size;i++)

for (j=0;j<ascii_bytes;j++)

for (k=0;k<8;k++)

if (P_ascii[i*ascii_bytes+j] & (0X80>>K))

if (* (P_ascii + i*ascii_bytes+j) & (0x80>>k))

Pixel (x + j*8 + k, y + i, colidx);

}

/**

* Put_string_ascii–display an ASCII string in touch screen

* @x:column

* @y:row

* @s:which string to display

* @colidx: Color index

*/

void Put_string_ascii (int x, int y, char *s, unsigned colidx)

{

while (*s! = 0) {

__display_ascii (x, Y, S, colidx);

x + = Ascii_width;

s++;

}

}

/* NOT Test */

void Put_string_center_ascii (int x, int y, char *s, unsigned colidx)

{

size_t SL = strlen (s);

Put_string_ascii (x – (SL/2) * Ascii_width,

Y–FONT_SIZE/2, S, COLIDX);

}

/**

* __display_font_16–display a 16x16 (Chinese) Character on touch screen

* @fp: File pointer points to HZK (ie, HZK16)

* @x:column

* @y:row

* @font: Which (Chinese) character to display

* @colidx: Color index

* This routine only display 16*16 character.

* Every character takes-bytes, we show the first 8 bits, then the second 8 bits,

* Then the whole world would be shown before us.

*/

static void __display_font_16 (FILE *fp, int x, int y, unsigned char *font, unsigned colidx)

{

int I, j, K;

unsigned char mat[buf_size]={0};

int QH,WH;

unsigned long offset;

QH = *font–0xa0;

WH = * (font+1) –0xa0;

offset = (94* (qh-1) + (wh-1)) * buf_size; /* Offset of the character in HZK */

/* Read it */

Fseek (Fp,offset,seek_set);

Fread (MAT,BUF_SIZE,1,FP);

/* Show it */

for (i=0;i<font_size;i++)

for (j=0;j<bytes;j++)

for (k=0;k<8;k++)

if (Mat [I*bytes+j] & (0X80>>K))

Pixel (x + j*8 + k, y + i, colidx);

}

/**

* __display_font_24–display a 24x24 (Chinese) Character on touch screen

* @fp: File pointer points to HZK (ie, HZK24)

* @x:column

* @y:row

* @font: Which (Chinese) character to display

* @colidx: Color index

*/

static void __display_font_24 (FILE *fp, int x, int y, unsigned char *font, unsigned colidx)

{

unsigned int i, J;

unsigned char mat[font_size][bytes]={{0}};

int QH,WH;

unsigned long offset;

QH = *font–0xaf;

WH = * (font+1) –0xa0;

offset = (94* (qh-1) + (wh-1)) * buf_size;

Fseek (Fp,offset,seek_set);

Fread (MAT,BUF_SIZE,1,FP);

for (i=0;i<font_size;i++)

for (j=0;j<font_size;j++)

if (Mat[j][i>>3] & (0x80>> (i&7)))

if (MAT[J][I/8] & (0X80>>I%8))/* Org */

Pixel (x + j, y + i, colidx);

}

/**

* Put_string_hz–display A (Chinese) character string on touch screen

* @fp: File pointer points to HZK (ie, HZK24 or HZK16)

* @x:column

* @y:row

* @s:which string to display (must is ' unsigned char* ')

* @colidx: Color index

*/

void Put_string_hz (FILE *fp, int x, int y, unsigned char *s, unsigned colidx)

{

while (*s! = 0) {

#ifdef HZK24

__DISPLAY_FONT_24 (FP, X, Y, S, colidx); /* for HZK24 */

#else

__display_font_16 (FP, X, Y, S, colidx);

#endif

x + = Font_size;

s + = 2; /* 2 Bytes */

}

}

/* NOT Test */

void Put_string_center_hz (FILE *fp, int x, int y, unsigned char *s, unsigned colidx)

{

size_t SL = strlen ((char *) s);

Put_string_hz (FP, X – (SL/2) * font_size, Y–FONT_SIZE/2, S, COLIDX);

}

/**

* Put_font–display an ASCII or/and (Chinese) character string in touch screen

* @fp: File pointer points to HZK (ie, HZK24 or HZK16)

* @x:column

* @y:row

* @s:which string to display

* @colidx: Color index

*/

void Put_font (FILE *fp, int x, int y, unsigned char *s, unsigned colidx)

{

while (*s! = 0) {

if ((*s>0xa0) && (* (s+1) >0xa0)) {

#ifdef HZK24

__DISPLAY_FONT_24 (FP, X, Y, S, colidx); /* for HZK24 */

#else

__display_font_16 (FP, X, Y, S, colidx); /* for HZK16 */

#endif

x + = Font_size;

s + = 2; /* 2 Bytes */

} else {

__display_ascii (x, y, (char *) s, COLIDX);

x + = Ascii_width;

s++; /* 1 byte */

}

}

}

/* NOT Test */

void Put_font_center (FILE *fp, int x, int y, unsigned char *s, unsigned colidx)

{

size_t SL = strlen ((char *) s);

Put_font (FP, X – (SL/2) *, Y–16/2, S, COLIDX);

}

About:

Using Fb2png (Google search "Fb2png", I was very hard to find), cross-compiling, on the development Board to execute the following command:

Fb2png/dev/fb0 filename.png 5 800 600 24

The commands used in practice are:

FB2PNG/DEV/FB0 filename.png 5 240 320 16

as follows (because the picture has already had my name, therefore does not hit the watermark):

Also refer to:

Http://www.latelee.org/yetanothertest/display-hz-on-touch-screen.html

Temporary finishing of the project directory compression package:

Tslib compression pack that can display Chinese characters

The next plan is ADC and TS driver.

This article fixed link: http://www.latelee.org/embedded-linux/use-tslib-to-display-chinese-character.html

Use Tslib to display Chinese characters "turn" on the touch screen

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.