GT20L16S1Y font library IC driver

GT20L16S1Y font library IC driver

/**
 *  @file GT20L16S1Y.c
 *
 *  @date 2020-7-7
 *
 *  @author aron566
 *
 *  @copyright None
 *
 *  @brief GD20L16S1Y字库驱动
 *
 *  @details --
 *
 *  @version V1.0
 */
#ifdef __cplusplus ///<use C compiler
extern "C" {
    
    
#endif
/** Includes -----------------------------------------------------------------*/
/* Private includes ----------------------------------------------------------*/
#include "GT20L16S1Y.h"
/** Private typedef ----------------------------------------------------------*/

/** Private macros -----------------------------------------------------------*/

/** Private constants --------------------------------------------------------*/
/** Public variables ---------------------------------------------------------*/
/** Private variables --------------------------------------------------------*/

/** Private function prototypes ----------------------------------------------*/

/** Private user code --------------------------------------------------------*/
static void S1Y_SendByte(uint32_t cmd);
static uint8_t S1Y_ReadByte(void);
static uint8_t S1Y_ReadDataToBuf(uint32_t address ,uint8_t byte_long ,uint8_t *p_arr);
/** Private application code -------------------------------------------------*/
/*******************************************************************************
*
*       Static code
*
********************************************************************************
*/
/**
  ******************************************************************
	* @brief   从GT20字库中读数据
  * @param   [in]address字符点阵在芯片中的字节地址
  * @param   [in]byte_long读点阵数据字节数
  * @param   [in]p_arr保存读出的点阵数据的数组
  * @retval  None
  * @author  aron566
  * @version V1.0
  * @date    2020-7-7
  ******************************************************************
  */
static uint8_t S1Y_ReadDataToBuf(uint32_t address ,uint8_t byte_long ,uint8_t *p_arr)
{
    
    
    unsigned int j=0;
    S1Y_CS_L;
    S1Y_SendByte(address);
    for(j=0;j<byte_long;j++)
    {
    
    
      p_arr[j]=S1Y_ReadByte();
    }
    S1Y_CS_H;
    return p_arr[0];	
}

/**
  ******************************************************************
	* @brief   GT20 SPI发送一个字节
  * @param   [in]None
  * @retval  None
  * @author  aron566
  * @version V1.0
  * @date    2020-7-7
  ******************************************************************
  */
static void S1Y_SendByte(uint32_t cmd)
{
    
    
	uint8_t i;
	cmd=cmd|0x03000000;
	for(i=0;i<32;i++)
	{
    
    
		S1Y_CLK_L;
		if(cmd&0x80000000)
		{
    
    
			S1Y_SI_H;
		}
		else 
		{
    
    
			S1Y_SI_L;
		}
		S1Y_CLK_H;
		cmd=cmd<<1;
	}					
}

/**
  ******************************************************************
	* @brief   GT20 SPI读取一个字节
  * @param   [in]None
  * @retval  None
  * @author  aron566
  * @version V1.0
  * @date    2020-7-7
  ******************************************************************
  */
static uint8_t S1Y_ReadByte(void)
{
    
    
      uint8_t i;
      uint8_t dat=0;
      S1Y_CLK_H;
      for(i=0;i<8;i++)
      {
    
    
        S1Y_CLK_L;
        dat=dat<<1;
        if(S1Y_SO)
				{
    
    
          dat=dat|0x01;
				}
        else
				{
    
    
          dat&=0xFE;
				}
        S1Y_CLK_H	;		
      }	
      return dat;
}
/** Public application code --------------------------------------------------*/
/*******************************************************************************
*
*       Public code
*
********************************************************************************
*/
/**
  ******************************************************************
  * @brief   GT20初始化
  * @param   [in]None
  * @retval  None
  * @author  aron566
  * @version V1.0
  * @date    2020-7-7
  ******************************************************************
  */
void GT20_init(void)
{
    
    
	GPIO_InitTypeDef  GPIO_InitStructure = {
    
    0};

	/* enable the GPIOE clock */
    rcu_periph_clock_enable(RCU_GPIOE);

	/*配置 cs clk mosi为输出模式*/
	GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT;
	GPIO_InitStructure.Pin = GT20_MOSI_Pin|GT20_CS_Pin|GT20_CLK_Pin;
	GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
	GPIO_InitStructure.Pull = GPIO_NOPULL;
    GPIO_InitStructure.OutMode = GPIO_MODE_OUTPUT_PP;/*推挽输出模式*/
	HAL_GPIO_Init(GPIOE ,&GPIO_InitStructure);
	
	HAL_GPIO_WritePin(GT20_MOSI_Port ,GT20_MOSI_Pin, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GT20_CS_Port ,GT20_CS_Pin, GPIO_PIN_SET);
	HAL_GPIO_WritePin(GT20_CLK_Port ,GT20_CLK_Pin, GPIO_PIN_SET);

	/*配置 miso为输入模式*/
	GPIO_InitStructure.Pin = GT20_MISO_Pin;
	GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
	HAL_GPIO_Init(GPIOE ,&GPIO_InitStructure);
}

/**
  ******************************************************************
  * @brief   ASCII 调用
  * @param   [in]ASCIICode:ASCII 码(8bits)
  * @param   [in]BaseAdd:说明该套字库在芯片中的起始地址
  * @param   [in]DZ_Data是保存读出的点阵数据的数组
  * @retval  None
  * @author  aron566
  * @version V1.0
  * @date    2020-7-7
  ******************************************************************
  */
uint8_t S1Y_ASCII_GetData(uint8_t ASCIICode ,uint32_t BaseAdd ,uint8_t *S1YDZ_Data)
{
    
    
	if((ASCIICode >= 0x20)&&(ASCIICode<=0x7E))
	{
    
    	
		switch(BaseAdd)
		{
    
    
			case 0x3bfc0:
				/*读点阵数据*/
				S1Y_ReadDataToBuf((ASCIICode-0x20)*8+BaseAdd,8,S1YDZ_Data); //5X7
				break;
			case 0x66c0:
				/*读点阵数据*/
				S1Y_ReadDataToBuf((ASCIICode-0x20)*8+BaseAdd,8,S1YDZ_Data); //7X8
				break;
			case 0x3b7c0:
				/*读点阵数据*/
				S1Y_ReadDataToBuf((ASCIICode-0x20)*16+BaseAdd,16,S1YDZ_Data); //8X16 A
				break;
			case 0x3cf80:
				/*读点阵数据*/
				S1Y_ReadDataToBuf((ASCIICode-0x20)*26+BaseAdd,16,S1YDZ_Data); //8X16 F
				break;
			case 0x3c2c0:
				/*读点阵数据*/
				S1Y_ReadDataToBuf((ASCIICode-0x20)*34+BaseAdd+2,32,S1YDZ_Data); //16X16 Arial
				break;
			case 0x3d580:
				/*读点阵数据*/
				S1Y_ReadDataToBuf((ASCIICode-0x20)*34+BaseAdd+2,32,S1YDZ_Data);//16X16 T
				break;
			default:
				break;
		}
		return 1;
	}
	else  
	{
    
    
		return 0;
	}
}

/**
  ******************************************************************
  * @brief   16 点GB2312 标准点阵字库
  * @param   [in]MSB 表示汉字内码GBCode 的高8bits
  * @param   [in]LSB 表示汉字内码GBCode 的低8bits
  * @param   [in]DZ_Data是保存读出的点阵数据的数组
  * @retval  None
  * @author  aron566
  * @version V1.0
  * @date    2020-7-7
  ******************************************************************
  */
void S1Y_gt16_GetData (uint8_t MSB ,uint8_t LSB ,uint8_t *S1YDZ_Data)
{
    
    
  	uint32_t temp=(MSB-0xB0)*94+LSB-0xA1;
	/*BaseAdd点阵数据在字库芯片中的起始地址*/
  	uint32_t BaseAdd=0,Address;
	
  	if(MSB == 0xA9 && LSB >=0xA1)
	{
    
    
		/*Address 表示汉字或ASCII字符点阵在芯片中的字节地址*/
		Address = (282 + (LSB - 0xA1))*32+BaseAdd;
	}
  	else if(MSB >=0xA1 && MSB <= 0xA3 && LSB >=0xA1)
	{
    
    
		Address =( (MSB - 0xA1) * 94 + (LSB - 0xA1))*32+ BaseAdd;
	}		
  	else if(MSB >=0xB0 && MSB <= 0xF7 && LSB >=0xA1)
	{
    
    
		Address = (846+temp)*32+ BaseAdd;
	}
	
	/*读点阵数据*/
  	S1Y_ReadDataToBuf(Address,32,S1YDZ_Data);
}
//Address=((MSB-0xB0)*94+(LSB-0xA1)+846)*32+BaseAdd;

/**
  ******************************************************************
  * @brief   8X16 点国标扩展字符
  * @param   [in]FontCode:表示字符内码(16bits)
  * @param   [in]DZ_Data是保存读出的点阵数据的数组
  * @retval  None
  * @author  aron566
  * @version V1.0
  * @date    2020-7-7
  ******************************************************************
  */
void S1Y_GB_EXT_816(uint16_t FontCode ,uint8_t *S1YDZ_Data)
{
    
    
	/*BaseAdd字库在字库芯片中的起始字节地址*/
    uint32_t BaseAdd=0x3b7d0,Address;
    uint32_t temp1=(FontCode-0xAAA1 );
    uint32_t temp2=(FontCode-0xABA1+95);
	
    if (FontCode>= 0xAAA1 && FontCode<=0xAAFE)
	{
    
    
		/*Address字符点阵在芯片中的字节地址*/
		Address = temp1*16+BaseAdd;
	}
    else if(FontCode>= 0xABA1&&FontCode<=0xABC0)
	{
    
    
		/*Address字符点阵在芯片中的字节地址*/
		Address = temp2*16+BaseAdd;
	}
		
	/*读点阵数据*/
    S1Y_ReadDataToBuf(Address ,16 ,S1YDZ_Data);
}
#ifdef __cplusplus ///<end extern c
}
#endif

  • API interface file
    GT20L16S1Y.h
/**
 *  @file GT20L16S1Y.h
 *
 *  @date 2020-7-7
 *
 *  @author aron566
 *
 *  @brief GD20L16S1Y字库驱动
 *  
 *  @version V1.0
 */
#ifndef _GT20L16S1Y_H_
#define _GT20L16S1Y_H_
#ifdef __cplusplus ///<use C compiler
extern "C" {
    
    
#endif
/** Includes -----------------------------------------------------------------*/
#include <stdint.h> /**< need definition of uint8_t */
#include <stddef.h> /**< need definition of NULL    */
//#include <stdbool.h>/**< need definition of BOOL    */
#include <stdio.h>  /**< if need printf             */
#include <stdlib.h>
#include <string.h>
/** Private includes ---------------------------------------------------------*/
#include "main.h"
/** Private defines ----------------------------------------------------------*/
#define S1Y_CLK_L   HAL_GPIO_WritePin(GT20_CLK_Port, GT20_CLK_Pin ,GPIO_PIN_RESET)   /**< SCLK LOW*/
#define S1Y_CLK_H   HAL_GPIO_WritePin(GT20_CLK_Port, GT20_CLK_Pin ,GPIO_PIN_SET)     /**< SCLK HI*/

#define S1Y_CS_L    HAL_GPIO_WritePin(GT20_CS_Port, GT20_CS_Pin ,GPIO_PIN_RESET)   /**< CS LOW*/
#define S1Y_CS_H    HAL_GPIO_WritePin(GT20_CS_Port, GT20_CS_Pin ,GPIO_PIN_SET)     /**< CS HI*/

#define S1Y_SI_L    HAL_GPIO_WritePin(GT20_MOSI_Port, GT20_MOSI_Pin ,GPIO_PIN_RESET)   /**< SI LOW*/
#define S1Y_SI_H    HAL_GPIO_WritePin(GT20_MOSI_Port, GT20_MOSI_Pin ,GPIO_PIN_SET)     /**< SI HI*/

#define S1Y_SO      HAL_GPIO_ReadPin(GT20_MISO_Port, GT20_MISO_Pin)  /**< MO READ*/
/** Exported typedefines -----------------------------------------------------*/

/** Exported constants -------------------------------------------------------*/

/** Exported macros-----------------------------------------------------------*/
/** Exported variables -------------------------------------------------------*/
/** Exported functions prototypes --------------------------------------------*/
void GT20_init(void); 
uint8_t  S1Y_ASCII_GetData(uint8_t ASCIICode,uint32_t BaseAdd,uint8_t *S1YDZ_Data);
void S1Y_gt16_GetData (uint8_t MSB,uint8_t LSB,uint8_t *S1YDZ_Data);
void S1Y_GB_EXT_816(uint16_t FontCode,uint8_t *S1YDZ_Data);
#ifdef __cplusplus ///<end extern c
}
#endif
#endif
/******************************** End of file *********************************/


GB2312 character set and its encoding

When the computer is transferred to China, all the codes of one byte (one byte is 8 bits, 2^8 = 256 characters can be expressed in total) have been used up, there is no code that can be used to represent Chinese characters, and one byte Can't represent more than 6000 commonly used Chinese characters, so Chinese characters need 2 bytes to represent.

The first byte does not change from the characters numbered 0 to 127, which still represents ASCII, and the following 0xA1 to 0xFE are used for Chinese character encoding. This byte is called the area code or high byte of Chinese characters, and 0xA1 to 0xFE are converted into The area code is from 01 to 94 (the conversion relationship is to subtract 0xA0 from the coded value).

The second byte 0xA1 to 0xFE is used for Chinese character encoding. This byte is called the bit number or low byte of the Chinese character. The conversion of 0xA1 to 0xFE to bit number is from bit number 01 to bit number 94 (the conversion relationship is to encode Value minus 0xA0). According to the area code and tag number, there are 94*94 = 8836 codes available. In these codes, we have also coded mathematical symbols, Roman Greek letters, and Japanese kana. Even the numbers, punctuation, and letters that exist in ASCII have all been recoded into two-byte long codes, namely Full-width characters, and those characters before 127 are called half-width characters.

For the characters composed of these codes, we named them GB2312. GB2312 is a simplified Chinese extension of the ASCII character set. This is the origin of GB2312. The full name of GB2312 code is "Chinese Character Coded Character Set for Information Exchange-Basic Set", which was issued by the State Administration of Standards of China in 1980 and implemented on May 1, 1981. The standard number is GB 2312-1980.

GB2312 code is suitable for the information exchange between Chinese character processing, Chinese character communication and other systems. It is used in mainland China and Singapore and other places also use this code. Almost all Chinese systems and international software in Mainland China support GB2312. The basic set includes 6763 Chinese characters and 682 non-Chinese graphic characters. The entire character set is divided into 94 areas, each with 94 bits. There is only one character on each location, so the location and location can be used to encode Chinese characters, which is called location code. Among them, the distribution of these 94 districts is as follows:

Area 01-09 is a total of 682 special full-width symbols

Areas 16-55 are 3755 first-level Chinese characters, arranged in phonetic order

Areas 56-87 have 3008 second-level Chinese characters, sorted by radicals/strokes

There are 13 areas in areas 10-15 and 88-94 that have not been coded yet

Location code and Chinese character code:

In order to encode compatible ASCII codes and the internal storage does not conflict with ASCII codes, GB2312 does not directly use 0x0101-0x5E5E (zone code) to represent and store characters, but uses the actual encoding range 0XA1A1 to 0XFEFE. For example, the word "Ah" is stored in two bytes 0xB0A1 in most programs. The location code is 0x1001, and the relationship between them is that the high byte and the low byte are both 0xA0. 0xB0-0x10 = 0xA0, 0xA1-0x01 = 0xA0.

Guess you like

Origin blog.csdn.net/weixin_42892101/article/details/107459547