📄 hw_tw2834_api.c
字号:
/* set tabstop=4 *//******************************************************************************** * * * Copyright(C) 2004 Penta-Micro * * * * ALL RIGHT RESERVED * * * * This software is the property of Penta-Micro and is furnished under * * license by Penta-Micro. This software may be used only in accordance * * with the terms of said license. This copyright notice may not be * * removed, modified or obliterated without the prior written permission * * of Penta-Micro. * * * * This software may not be copyed, transmitted, provided to or otherwise * * made available to any other person, company, corporation or other entity * * except as specified in the terms of said license. * * * * No right, title, ownership or other interest in the software is hereby * * granted or transferred. * * * * The information contained herein is subject to change without notice and * * should not be construed as a commitment by Penta-Micro. * * * ******************************************************************************** MODULE NAME: HW_TW2834_API.C REVISION HISTORY: Date Ver Name Description ---------- --- --------------------- ----------------------------------------- 06/16/2005 1.0 JiGwanKang(xchannel) Created ............................................................................... DESCRIPTION: This Module contains functions for TW2834. ...............................................................................*/ /** ************************************************************************* ** ** includes ** ************************************************************************* **/#include <fcntl.h>#include <stdio.h>#include <stdlib.h>#include <asm/ioctl.h>#include <asm/errno.h>#include <linux/i2c.h>#include <linux/i2c-dev.h>#include <semaphore.h> #include "hw_tw2834_api.h"#include "tbl_init_font.h"#include "tbl_init_page0.h"#include "tbl_init_page1.h"#include "tbl_init_page2.h"/** ************************************************************************* ** ** defines ** ************************************************************************* **///#define m_DEBUG(format, args...) printf(format, ## args) #define m_DEBUG(format, args...) #define m_MSG(format, args...) printf(format, ## args) #define m_ERROR(format, args...) printf(format, ## args);fflush(stdout); /** ************************************************************************* ** ** typedefs ** ************************************************************************* **/#ifdef I2C_INTERFACE#else/* TW2834 data structure */typedef struct __IOCTL_TW283X__ { unsigned char addr; unsigned char data[256]; unsigned char bank; unsigned int len;} IOCTL_TW283X;#endif /** ************************************************************************* ** ** globals ** ************************************************************************* **//** ************************************************************************* ** ** locals ** ************************************************************************* **/static S32 fd_tw2834;static sem_t tw2834_sem;/** ************************************************************************* ** ** forward declarations ** ************************************************************************* **///... only one path at oncevoid write_prop(UNS8 path, UNS8 range, UNS8 osd_page, UNS8 osd_size){ UNS8 buf[10]; if(path == Y_PATH) range |= BIT7; buf[0] = range; buf[1] = osd_page; buf[2] = osd_size; tw2834_burst_write_reg(TW2834_PAGE1, 0x9b, buf, 3); /* must be delay */ usleep(10000);}UNS8 GetCodeLength(UNS8 *str){ UNS8 count=0; while((*str++)!='\0')++count; return (count);}void SelFont(UNS8 _path, UNS8 _line, UNS8 _page, UNS8 _field) //... only one _path at once{ UNS8 t_field, t_field_en; UNS8 ii; for(ii=0;ii<TBL_OSD_PAGE_NUM;ii++){ IfBitSet(_field,OSD_EN_ODD) t_field = 0; else IfBitSet(_field,OSD_EN_EVEN) t_field = 1; if((UNS8)(osd_tbl_info_page[ii][t_field]&0x000f) == _page){ if(osd_tbl_info_size[ii][t_field] != 0xff){ IfBitSet(osd_tbl_info_size[ii][t_field],BIT7) t_field_en = OSD_EN_EVEN|OSD_EN_ODD; //... twice resolution else t_field_en = _field; if(_line != OSD_PROP_ALL) _line |= OSD_PROP_ONE; IfBitSet(_path,X_PATH) write_prop(X_PATH,_line,t_field_en|_page,osd_tbl_info_size[ii][t_field]&0x3f); IfBitSet(_path,Y_PATH) write_prop(Y_PATH,_line,t_field_en|_page,osd_tbl_info_size[ii][t_field]&0x3f); } } }}void SetFontSpace(UNS8 path, UNS8 h_space, UNS8 v_space){ UNS8 temp; temp = (h_space<<4)|v_space; IfBitSet(path,X_PATH) tw2834_write_reg(TW2834_PAGE1,0xa1,temp); IfBitSet(path,Y_PATH) tw2834_write_reg(TW2834_PAGE1,0xa3,temp);}void SetFontDelay(UNS8 path, UNS8 h_delay, UNS8 v_delay){ UNS8 temp; temp = (h_delay<<4)|v_delay; IfBitSet(path,X_PATH) tw2834_write_reg(TW2834_PAGE1,0xa2,temp); IfBitSet(path,Y_PATH) tw2834_write_reg(TW2834_PAGE1,0xa4,temp);}UNS8 ExtractFontTableData(UNS16 _tbl_index, UNS8 _page_field){ UNS8 ii; #ifdef TBL_OSD_PG0_ODD if(_page_field == 0x00) ii = tbl_osd_page0_odd[_tbl_index];#endif#ifdef TBL_OSD_PG0_EVEN if(_page_field == 0x01) ii = tbl_osd_page0_even[_tbl_index];#endif#ifdef TBL_OSD_PG1_ODD if(_page_field == 0x10) ii = tbl_osd_page1_odd[_tbl_index];#endif#ifdef TBL_OSD_PG1_EVEN if(_page_field == 0x11) ii = tbl_osd_page1_even[_tbl_index];#endif#ifdef TBL_OSD_PG2_ODD if(_page_field == 0x20) ii = tbl_osd_page2_odd[_tbl_index];#endif#ifdef TBL_OSD_PG2_EVEN if(_page_field == 0x21) ii = tbl_osd_page2_even[_tbl_index];#endif#ifdef TBL_OSD_PG3_ODD if(_page_field == 0x30) ii = tbl_osd_page3_odd[_tbl_index];#endif#ifdef TBL_OSD_PG3_EVEN if(_page_field == 0x31) ii = tbl_osd_page3_even[_tbl_index];#endif#ifdef TBL_OSD_PG4_ODD if(_page_field == 0x40) ii = tbl_osd_page4_odd[_tbl_index];#endif#ifdef TBL_OSD_PG4_EVEN if(_page_field == 0x41) ii = tbl_osd_page4_even[_tbl_index];#endif#ifdef TBL_OSD_PG5_ODD if(_page_field == 0x50) ii = tbl_osd_page5_odd[_tbl_index];#endif#ifdef TBL_OSD_PG5_EVEN if(_page_field == 0x51) ii = tbl_osd_page5_even[_tbl_index];#endif#ifdef TBL_OSD_PG6_ODD if(_page_field == 0x60) ii = tbl_osd_page6_odd[_tbl_index];#endif#ifdef TBL_OSD_PG6_EVEN if(_page_field == 0x61) ii = tbl_osd_page6_even[_tbl_index];#endif#ifdef TBL_OSD_PG7_ODD if(_page_field == 0x70) ii = tbl_osd_page7_odd[_tbl_index];#endif#ifdef TBL_OSD_PG7_EVEN if(_page_field == 0x71) ii = tbl_osd_page7_even[_tbl_index];#endif#ifdef TBL_OSD_PG8_ODD if(_page_field == 0x80) ii = tbl_osd_page8_odd[_tbl_index];#endif#ifdef TBL_OSD_PG8_EVEN if(_page_field == 0x81) ii = tbl_osd_page8_even[_tbl_index];#endif#ifdef TBL_OSD_PG9_ODD if(_page_field == 0x90) ii = tbl_osd_page9_odd[_tbl_index];#endif#ifdef TBL_OSD_PG9_EVEN if(_page_field == 0x91) ii = tbl_osd_page9_even[_tbl_index];#endif#ifdef TBL_OSD_PG10_ODD if(_page_field == 0xa0) ii = tbl_osd_page10_odd[_tbl_index];#endif#ifdef TBL_OSD_PG10_EVEN if(_page_field == 0xa1) ii = tbl_osd_page10_even[_tbl_index];#endif#ifdef TBL_OSD_PG11_ODD if(_page_field == 0xb0) ii = tbl_osd_page11_odd[_tbl_index];#endif#ifdef TBL_OSD_PG11_EVEN if(_page_field == 0xb1) ii = tbl_osd_page11_even[_tbl_index];#endif#ifdef TBL_OSD_PG12_ODD if(_page_field == 0xc0) ii = tbl_osd_page12_odd[_tbl_index];#endif#ifdef TBL_OSD_PG12_EVEN if(_page_field == 0xc1) ii = tbl_osd_page12_even[_tbl_index];#endif#ifdef TBL_OSD_PG13_ODD if(_page_field == 0xd0) ii = tbl_osd_page13_odd[_tbl_index];#endif#ifdef TBL_OSD_PG13_EVEN if(_page_field == 0xd1) ii = tbl_osd_page13_even[_tbl_index];#endif#ifdef TBL_OSD_PG14_ODD if(_page_field == 0xe0) ii = tbl_osd_page14_odd[_tbl_index];#endif#ifdef TBL_OSD_PG14_EVEN if(_page_field == 0xe1) ii = tbl_osd_page14_even[_tbl_index];#endif#ifdef TBL_OSD_PG15_ODD if(_page_field == 0xf0) ii = tbl_osd_page15_odd[_tbl_index];#endif#ifdef TBL_OSD_PG15_EVEN if(_page_field == 0xf1) ii = tbl_osd_page15_even[_tbl_index];#endif return ii;}void DumpFontSub(UNS16 _info_page, UNS8 _info_size){ UNS16 array_index = 0, array_line; UNS8 t_cnt_index, t_cnt_line, t_cnt_data; UNS8 t_num_index, t_num_index_h; UNS8 t_num_line, t_num_data; UNS8 t_page_field=0; UNS8 ii; ii = (UNS8)((_info_page&0xf800)>>11); //... check OSD_TBL_INDEX_NUM_V t_num_index_h = (UNS8)((_info_page&0x07e0)>>5); //... check OSD_TBL_INDEX_NUM_H t_num_index = t_num_index_h * ii; t_page_field |= (UNS8)((_info_page&0x000f)<<4); t_page_field |= (UNS8)((_info_page&0x0010)>>4); ii = (_info_size&0x30)>>4; t_num_line = 10+(ii<<1); //... check OSD_TBL_SIZE_V; ii = _info_size&0x0f; //... check OSD_TBL_SIZE_H; if(ii > 8) t_num_data = 8; else{ tw2834_write_reg(TW2834_PAGE1,0x97,0x00); //... Font write data [7:0] layer0 if(ii > 7) t_num_data = 7; else{ tw2834_write_reg(TW2834_PAGE1,0x96,0x00); //... Font write data [15:8] layer0 if(ii > 6) t_num_data = 6; else{ tw2834_write_reg(TW2834_PAGE1,0x95,0x00); //... Font write data [23:16] layer0 if(ii > 5) t_num_data = 5; else{ tw2834_write_reg(TW2834_PAGE1,0x94,0x00); //... Font write data [31:24] layer0 if(ii > 2) t_num_data = 4; else{ tw2834_write_reg(TW2834_PAGE1,0x93,0x00); //... Font write data [39:32] layer0 if(ii > 0) t_num_data = 3; else{ tw2834_write_reg(TW2834_PAGE1,0x92,0x00); //... Font write data [47:40] layer0 t_num_data = 2; } } } } } } for(t_cnt_index = 0 ; t_cnt_index < t_num_index ; t_cnt_index++){ /* writing to the fontRAM */ array_index = (t_num_data * t_num_line)*t_num_index_h; /* total byte number of 1 index row */ array_index = array_index * ( t_cnt_index/t_num_index_h); /* multiply array_index by offset for 1 index row */ array_index = array_index + ((t_cnt_index%t_num_index_h)*t_num_data); /* add array_index to offset for 1 index column */ tw2834_write_reg(TW2834_PAGE1,0x98,t_cnt_index); /* index set */ for(t_cnt_line=0 ; t_cnt_line < t_num_line ; t_cnt_line++){ /* one font write to the fontRAM (current font size is 40byte ) */ array_line = t_cnt_line * (t_num_data * t_num_index_h); for(t_cnt_data=0 ; t_cnt_data < t_num_data ; t_cnt_data++){ ii = ExtractFontTableData(array_index + array_line + t_cnt_data,t_page_field); tw2834_write_reg(TW2834_PAGE1,(0x90 + t_cnt_data),ii); } tw2834_write_reg(TW2834_PAGE1,0x99,(t_page_field&0xf0)|t_cnt_line); /* font_page, font_line */ if(t_num_data > 6) ii = 0x04; else if(t_num_data > 4) ii = 0x02; else ii = 0x00; tw2834_write_reg(TW2834_PAGE1,0x9a,0xc0 | ii |(t_page_field & 0x01)); /* request_D/C, font_type=0, font_field=x */ } }}RETURN tw2834_open(void) { sem_init(&tw2834_sem, 0, 1); #ifdef I2C_INTERFACE if ( (fd_tw2834 = open("/dev/i2c-0", O_RDWR)) < 0 ) { m_ERROR("tw2834.c: tw2834 open failed\n"); return FAILURE; }#else if ( (fd_tw2834 = open("/dev/tw2834", O_RDWR)) < 0 ) { m_ERROR("tw2834.c: tw2834 open failed\n"); return FAILURE; }#endif return SUCCESS;}void tw2834_close(void){ close(fd_tw2834); if(sem_destroy(&tw2834_sem)) m_ERROR("\ntw2834: semaphore error");}RETURN tw2834_font_upload(void){ UNS16 ii, page; UNS8 size; /* when the use to user defined font data, Font Data Upload routine */ for(ii=0 ; ii<(TBL_OSD_PAGE_NUM<<1); ii++){ page = *((UNS16 *)osd_tbl_info_page + ii); size = *((UNS8 *)osd_tbl_info_size + ii); if(size != 0xff) DumpFontSub(page, size); } return SUCCESS;}RETURN tw2834_write_reg(UNS8 page, UNS8 sub_addr, UNS8 data){#ifdef I2C_INTERFACE UNS8 buf[4]; #else IOCTL_TW283X ioctl_arg;#endif sem_wait(&tw2834_sem);#ifdef I2C_INTERFACE if (ioctl(fd_tw2834, I2C_SLAVE_FORCE, TW2834_WRITE_CMD) < 0) { m_ERROR("tw2834.c: set slave addr error\n"); sem_post(&tw2834_sem); return FAILURE; }#else ioctl_arg.addr = sub_addr; ioctl_arg.bank = page+1; ioctl_arg.data[0] = data; ioctl_arg.len = 1; if (ioctl(fd_tw2834, REGISTER_WRITE, &ioctl_arg) < 0) { m_ERROR("tw2834.c: local bus write error\n"); sem_post(&tw2834_sem); return FAILURE; }#endif#ifdef I2C_INTERFACE buf[0] = page; buf[1] = sub_addr; buf[2] = data; if (write(fd_tw2834, buf , 3) != 3) { m_ERROR("tw2834.c: write data error %02x\n", sub_addr); sem_post(&tw2834_sem); return FAILURE; }#endif sem_post(&tw2834_sem); return SUCCESS;}RETURN tw2834_burst_write_reg(UNS8 page, UNS8 sub_addr, UNS8 *data, UNS16 length){ UNS16 ii;#ifdef I2C_INTERFACE UNS8 buf[256]; #else IOCTL_TW283X ioctl_arg;#endif sem_wait(&tw2834_sem);#ifdef I2C_INTERFACE if (ioctl(fd_tw2834, I2C_SLAVE_FORCE, TW2834_WRITE_CMD) < 0) { m_ERROR("tw2834.c: set slave addr error\n"); sem_post(&tw2834_sem); return FAILURE; } buf[0] = page; buf[1] = sub_addr; for(ii=0;ii < length;ii++) buf[2+ii] = *(data+ii); if (write(fd_tw2834, buf , length+2 ) != (length+2)) { m_ERROR("tw2834.c: write data error %02x\n", sub_addr); sem_post(&tw2834_sem); return FAILURE; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -