www.pudn.com > bu1566.rar > BUxx_DRV.c


/* ************************************************************************ */ 
/*                                                                          */ 
/* ROHM BU15xx demo firmware on MD2306                                      */ 
/*     Client   : ROHM Co., Ltd.                                       */ 
/*     End User :                                                           */ 
/*                                                                          */ 
/*     Processor: ARM-7TDMI(THUMB Mode)                                     */ 
/*     Dev.Env. : ARM-SDTv2.51                                              */ 
/*                                                                          */ 
/*     DRIVER:BU15xx control Routines                                       */ 
/*                                                                          */ 
/*     file     : BUxx_DRV.c                                                */ 
/*     Auther   : J.SATO(NTC)                                              */ 
/*     Date     : 2004/Jul./1 	                                            */ 
/*                                                                          */ 
/*     Copyright (c) 2002-04 Naritagiken Co., Ltd. All rights reserved.     */ 
/* ************************************************************************ */ 
 
/* ************************************************** */ 
/*		     INCLUDE FILES		      */ 
/* ************************************************** */ 
#include "BUxx_setuptable.h" 
 
/* ************************************************** */ 
/*		        TYPEDEF		    	      */ 
/* ************************************************** */ 
 
/* ************************************************** */ 
/*		     LOCAL DEFINES		      */ 
/* ************************************************** */ 
 
/* ************************************************** */ 
/*		    GLOBAL VARIABLE		      */ 
/* ************************************************** */ 
 
/* ************************************************** */ 
/*		         CONST			      */ 
/* ************************************************** */ 
 
/* ************************************************** */ 
/*		    GLOBAL FUNCTIONS		      */ 
/* ************************************************** */ 
 
/* ************************************************** */ 
/*		     LOCAL FUNCTIONS		      */ 
/* ************************************************** */ 
 
 
 
//----------------------------------------------------------------------------- 
//                            register write(8bit access) 
//----------------------------------------------------------------------------- 
void reg_write8(const UINT16 reg, const UINT16 para) 
{ 
 
    if (BUSACCESS_BIT == 16 || reg == INDEX) 
    { 
        //16bit write 
        *(LCD_CMD_WRITE + reg) = para; 
    } 
    else 
    { 
        //8bit write 
        *(LCD_CMD_WRITE + reg) = (para & 0xff00) >> 8; 
        *(LCD_CMD_WRITE + reg) = (para & 0x00ff); 
    } 
 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                            register read(8bit access) 
//----------------------------------------------------------------------------- 
UINT16 reg_read8(const UINT16 reg) 
{ 
    UINT16 reg_data; 
 
    if (BUSACCESS_BIT == 16 || reg == INDEX) 
    { 
        //16bit write 
        reg_data = *(LCD_CMD_WRITE + reg) & 0x00ff; 
    } 
    else 
    { 
        //8bit write 
        reg_data = (*(LCD_CMD_WRITE + reg) & 0x00ff) << 8; 
        reg_data |= (*(LCD_CMD_WRITE + reg) & 0x00ff); 
    } 
    return (reg_data); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                index register write + register write(8bit/16bit) 
//----------------------------------------------------------------------------- 
UINT16 data_write(const UINT16 idx, const UINT16 para) 
{ 
    UINT16 reg_temp; 
 
    reg_write(INDEX, idx); 
    reg_temp = reg_read(REG); 
    reg_write(REG, para); 
 
    return (reg_temp); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                           bit write(8bit/16bit) 
//----------------------------------------------------------------------------- 
void bit_write(const UINT16 idx, const UINT16 bit, const UINT16 value) 
{ 
    UINT16 reg_data; 
 
    reg_data = data_read(idx); 
 
    if (value == LOW) 
    { 
        reg_data &= ~bit; 
        reg_write(REG, reg_data); 
    } 
    else if (value == HIGH) 
    { 
        reg_data |= bit; 
        reg_write(REG, reg_data); 
    } 
    else 
    { 
 
 
    } 
} 
 
 
 
//----------------------------------------------------------------------------- 
//               index register write + register read(8bit/16bit) 
//----------------------------------------------------------------------------- 
UINT16 data_read(const UINT16 idx) 
{ 
 
    reg_write(INDEX, idx); 
    return (reg_read(REG)); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                           bit read(8bit/16bit) 
//----------------------------------------------------------------------------- 
UINT16 bit_read(const UINT16 idx, const UINT16 bit) 
{ 
    UINT16 reg_data; 
 
    reg_write(INDEX, idx); 
    reg_data = reg_read(REG) & bit; 
 
    return (reg_data); 
} 
 
 
//----------------------------------------------------------------------------- 
//                             CLOCK CNT setup 
//----------------------------------------------------------------------------- 
void clk_cnt_set(const UINT16 data) 
{ 
 
    data_write(CLKCNT, LCDFRSRC | data); 
 
} 
 
 
//----------------------------------------------------------------------------- 
//                             CLOCK DIV1 setup 
//----------------------------------------------------------------------------- 
int clk_div1_set(const UINT16 sckdv) 
{ 
    int err_code = 0; 
 
    if (sckdv > maxSCKDV) 
        err_code = 0x0001; 
 
    data_write(CLKDIV1, sckdv); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                             CLOCK DIV2 setup 
//----------------------------------------------------------------------------- 
int clk_div2_set(const UINT16 lcdfrdv, const UINT16 lcdbsytmg) 
{ 
    int err_code = 0; 
 
    if (lcdfrdv > maxLCDFRDV) 
        err_code = 0x0001; 
    if (lcdbsytmg > maxLCDBSYTMG) 
        err_code = 0x0002; 
 
    data_write(CLKDIV2, (lcdbsytmg << 8) | lcdfrdv); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                             CLOCK DIV3 setup 
//----------------------------------------------------------------------------- 
int clk_div3_set(const UINT16 cmckdv) 
{ 
    int err_code = 0; 
 
    if (cmckdv > maxCMCKDV) 
        err_code = 0x0001; 
 
    data_write(CLKDIV3, cmckdv); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                                HWmode write 
//----------------------------------------------------------------------------- 
void hwmode_write(const UINT16 mode) 
{ 
 
    data_write(HWMODE, sCAM_ON | sCLK_XTL | mode); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                                HWmode read 
//----------------------------------------------------------------------------- 
UINT16 hwmode_read(void) 
{ 
 
    return (bit_read(HWMODE, bHWMODE | bSUSP)); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                                HOSTcnt write 
//----------------------------------------------------------------------------- 
void hostcnt_write(const UINT16 write_data) 
{ 
 
    data_write(HOSTCNT, write_data); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                                HOSTcnt write 
//----------------------------------------------------------------------------- 
void hostcnt_bitwrite(const UINT16 write_data, const UINT16 bit) 
{ 
 
    bit_write(HOSTCNT, write_data, bit); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                                HOSTcnt read 
//----------------------------------------------------------------------------- 
UINT16 hostcnt_bitread(const UINT16 read_data) 
{ 
 
    return (bit_read(HOSTCNT, read_data)); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                          operation mode change 
//----------------------------------------------------------------------------- 
void mode_change(const int mode) 
{ 
    bit_write(CLKCNT, bLCDFREN | bSCKEN, LOW);  //LCDFR,SCLK disable 
 
    hwmode_write(sREADY);     //sSUSPEND 
 
    gl_dsc_status = mode; 
    switch (mode) 
    { 
    case sNVIEWER: 
    case sLCDMANUAL: 
        hostcnt_bitwrite(bLCDOFF, HIGH); 
        hostcnt_bitwrite(bLCD_DACS, LOW); 
        break; 
    case sSUSPEND: 
    case sREADY: 
        hostcnt_bitwrite(bLCDOFF, LOW); 
        hostcnt_bitwrite(bLCD_DACS, HIGH); 
        break; 
    } 
    hwmode_write(mode);         //mode set 
 
    bit_write(CLKCNT, bLCDFREN | bSCKEN, HIGH); //LCDFR,SCLK Enable 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                              Interrupt wait 
//----------------------------------------------------------------------------- 
void wait_int0(const UINT16 para) 
{ 
 
    gl_check_int = 0; 
    data_write(INTST, 0x0000);  //Interrupt status clear 
    data_write(INTMSK, (~para) & 0x007f);       //lcded_int enable 
 
#if defined BUXX_POLLING 
    wait(1); 
    reg_write(INDEX, INTST); 
    while (reg_read(REG) == 0); 
    mode_change(sREADY); 
#else 
    while (gl_check_int == 0); 
#endif 
 
    data_write(INTMSK, 0xffff); //all mask cleared 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                             JPEG Interrupt wait 
//----------------------------------------------------------------------------- 
void wait_int0_jpeg(const UINT16 para) 
{ 
    gl_check_int = 0; 
    data_write(JPG_INTST, 0x0000);      //Interrupt status clear 
    data_write(JPG_INTMSK, (~para) & 0x0007);   //lcded_int enable 
 
#if defined BUXX_POLLING 
{ 
    UINT16 idx_push; 
    wait(1); 
    reg_write(INDEX, JPG_INTST); 
    while (reg_read(REG) == 0); 
    switch (gl_dsc_status) //William add for BU1563 fm-encode failed 20050508 
    { 
    case sJPEGDECODE: 
    case sLEDMODE: 
        break; 
    default: 
        idx_push = reg_read(INDEX); 
        mode_change(sREADY); 
        reg_write(INDEX, idx_push); 
	break; 
    } 
} 
#else 
    while (gl_check_int == 0); 
#endif 
 
    data_write(JPG_INTMSK, 0xffff);     //all mask cleared 
} 
 
//----------------------------------------------------------------------------- 
//                              Camera I/F setup 
//----------------------------------------------------------------------------- 
void cam_if_set(const UINT16 data) 
{ 
 
    data_write(CAMIF, SUB_OFFSET | data); 
 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                   Camera signal frame start position setup 
//----------------------------------------------------------------------------- 
int cam_tim_set(const UINT16 cxs, const UINT16 cys) 
{ 
    int err_code = 0; 
 
    if (cxs > maxCXS) 
        err_code = 0x0001; 
    if (cys > maxCYS) 
        err_code = 0x0002; 
 
    data_write(CAMTIM, (cys << 8) | cxs); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                        Camera image size setup 
//----------------------------------------------------------------------------- 
int cam_size_set(const UINT16 xsize, const UINT16 ysize) 
{ 
    int err_code = 0; 
 
    if (xsize > maxCXSIZE) 
        err_code = 0x0001; 
    if (ysize > maxCYSIZE) 
        err_code = 0x0002; 
 
    data_write(CXSIZE, xsize); 
    data_write(CYSIZE, ysize); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                        image shrink rate setup 
//----------------------------------------------------------------------------- 
int cam_shrink_set(const UINT16 cxsrk, const UINT16 cysrk) 
{ 
    int err_code = 0; 
    UINT16 rot_state = 0; 
    UINT16 hwmode_state = 0; 
 
    rot_state = bit_read(MEMCNT, bROT); 
    hwmode_state = hwmode_read(); 
 
    if (cxsrk > maxCXSRK) 
        err_code = 0x0001; 
    if (cysrk > maxCYSRK) 
        err_code = 0x0002; 
 
    if (rot_state != bROT || hwmode_state == sRINGBUFFER) 
    {                           // ROT90 OFF 
        data_write(CXSRK, cxsrk); 
        data_write(CYSRK, cysrk); 
    } 
    else 
    { 
        data_write(CXSRK, cysrk); 
        data_write(CYSRK, cxsrk); 
    } 
    return err_code; 
 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                   The position to cut off an image setup 
//----------------------------------------------------------------------------- 
int cam_cut_set(const UINT16 st_x, const UINT16 st_y, const UINT16 ed_x, 
                const UINT16 ed_y) 
{ 
    int err_code = 0; 
    UINT16 rot_state = 0; 
    UINT16 hwmode_state = 0; 
 
    if (st_x > maxCAMRSX) 
        err_code = 0x0001; 
    if (st_y > maxCAMRSY) 
        err_code = 0x0002; 
    if (ed_x > maxCAMREX) 
        err_code = 0x0003; 
    if (ed_y > maxCAMREY) 
        err_code = 0x0004; 
 
    rot_state = bit_read(MEMCNT, bROT); 
    hwmode_state = hwmode_read(); 
 
    if (rot_state != bROT || hwmode_state == sRINGBUFFER) 
    {                           // ROT90 OFF 
        if (st_x % 2) 
            err_code = 0x0005; 
        if ((ed_x + 1) % 2) 
            err_code = 0x0006; 
 
        data_write(CAMRSX, st_x); 
        data_write(CAMREX, ed_x); 
        data_write(CAMRSY, st_y); 
        data_write(CAMREY, ed_y); 
    } 
    else 
    {                           // ROT90 ON 
        if (st_y % 2) 
            err_code = 0x0007; 
        if ((ed_y + 1) % 2) 
            err_code = 0x0008; 
 
        data_write(CAMRSX, st_y); 
        data_write(CAMREX, ed_y); 
        data_write(CAMRSY, st_x); 
        data_write(CAMREY, ed_x); 
    } 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                          cam capture point setup 
//----------------------------------------------------------------------------- 
int cam_capture_set(const CAMSET * const cam) 
{ 
    int err_code = 0; 
    int ret_code = 0; 
    UINT16 rot_state = 0; 
    UINT16 hwmode_state = 0; 
 
    bit_write(MEMCNT, bROT | bVFLIP | bHFLIP, LOW); 
    bit_write(MEMCNT, cam->rot_h_vflip, HIGH); 
 
    rot_state = bit_read(MEMCNT, bROT); 
    hwmode_state = hwmode_read(); 
 
    if (hwmode_state != sJPEGDECODE) 
    { 
        if (rot_state != bROT || hwmode_state == sRINGBUFFER) 
        {                       // ROT90 OFF 
            if (cam->cst_x + cam->xsize > cam->srkx) 
                err_code = 0x0010; 
            if (cam->cst_y + cam->ysize > cam->srky) 
                err_code = 0x0011; 
        } 
        else 
        { 
            if (cam->cst_x + cam->xsize > cam->srkx) 
                err_code = 0x0012; 
            if (cam->cst_y + cam->ysize > cam->srky) 
                err_code = 0x0013; 
        } 
    } 
 
    ret_code = mem_point_set(cam->mst_x, cam->mst_y);   //cam image storage position set 
    if (ret_code) 
        err_code = ret_code | 0x0020; 
 
    ret_code = cam_shrink_set(cam->srkx, cam->srky); 
    if (ret_code) 
        err_code = ret_code | 0x0030; 
 
    ret_code = cam_cut_set(cam->cst_x, cam->cst_y, cam->cst_x + cam->xsize - 1, cam->cst_y + cam->ysize - 1);   //The position to cut off an image is set up 
    if (ret_code) 
        err_code = ret_code | 0x0040; 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                          low path filter setup 
//----------------------------------------------------------------------------- 
void cam_lowpathfilter_set(void) 
{ 
    data_write(SRKTYPE, YOFFSET | CYTYPE | CXTYPE); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//              The storage position of the image is set up 
//----------------------------------------------------------------------------- 
int mem_point_set(const UINT16 st_x, const UINT16 st_y) 
{ 
    int err_code = 0; 
 
    if (st_x > data_read(MLCDHSIZE)) 
        err_code = 0x0001; 
    if (st_y > data_read(MLCDVSIZE)) 
        err_code = 0x0002; 
    if (st_x % 2) 
        err_code = 0x0003; 
 
    data_write(MEMCSTAX, st_x); 
    data_write(MEMCSTAY, st_y); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                        mem_adr_st/mem_adr_ed setup 
//----------------------------------------------------------------------------- 
int mem_adrst_ed_set(const UINT16 st_x, const UINT16 st_y, 
                     const UINT16 ed_x, const UINT16 ed_y) 
{ 
    int err_code = 0; 
 
    if (st_x > maxMEM_ADR_STX) 
        err_code = 0x0001; 
    if (st_y > maxMEM_ADR_STY) 
        err_code = 0x0002; 
    if (ed_x > maxMEM_ADR_EDX) 
        err_code = 0x0003; 
    if (ed_y > maxMEM_ADR_EDY) 
        err_code = 0x0004; 
    if (st_x % 2) 
        err_code = 0x0005; 
    if ((ed_x + 1) % 2) 
        err_code = 0x0006; 
    if (ed_x >= data_read(MLCDHSIZE)) 
        err_code = 0x0007; //William 20050524 
    if (ed_y >= data_read(MLCDVSIZE)) 
        err_code = 0x0008; //William 20050524 
 
    data_write(MEM_ADR_STX, st_x); 
    data_write(MEM_ADR_STY, st_y); 
    data_write(MEM_ADR_EDX, ed_x); 
    data_write(MEM_ADR_EDY, ed_y); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                  FrameMemory access register setup(for READ) 
//----------------------------------------------------------------------------- 
void mem_acs_read_st(const UINT16 idx) 
{ 
    UINT16 reg_data; 
    UINT16 data_format; 
 
    bit_write(MEMCNT, bRGB_FRAME, HIGH); 
    data_format = bit_read(MEMCNT, bRGB_FRAME); 
 
    reg_data = reg_read(INDEX); 
    reg_write(INDEX, idx); 
 
    if (idx == MEMACS_RGB  && data_format == sYUV422FORMAT) 
    { 
        reg_data = reg_read(REG); 
    } 
 
    reg_data = reg_read(REG); 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                  FrameMemory access register setup(for WRITE) 
//----------------------------------------------------------------------------- 
void mem_acs_write_st(const UINT16 idx) 
{ 
    UINT16 reg_data; 
 
    bit_write(MEMCNT, bRGB_FRAME, HIGH); 
    reg_data = reg_read(INDEX); 
    reg_write(INDEX, idx); 
 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                  FrameMemory absolute address setup 
//----------------------------------------------------------------------------- 
void mem_adr_abs_set(const UINT32 address) 
{ 
 
    data_write(MEM_ADR_ABS1, (UINT16) (address & 0x0000ffff)); 
    data_write(MEM_ADR_ABS2, (UINT16) ((address & 0xffff0000) >> 16)); 
 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                            MaskMemory setup 
//----------------------------------------------------------------------------- 
/* 
int mem_maskmemory_set(const UINT16 xsize, const UINT16 ysize) 
{ 
    UINT16 frame_data; 
    UINT16 mask_temp; 
    int i = 0, cnt, width, height; 
    UINT16 mask_data[12]; 
    int err_code = 0; 
 
 
    if (xsize > data_read(MLCDHSIZE)) 
        err_code = 0x01; 
    if (ysize > data_read(MLCDVSIZE)) 
        err_code = 0x02; 
 
    bit_write(MEMCNT, bINCMTH | bADRINC, HIGH); //auto increment on 
 
    for (height = 0; height < ysize; height++) 
    { 
#if 0 
        mask_temp = 0x0000; 
        mem_adrst_ed_set(0, height, xsize - 1, height); 
        mem_acs_read_st(MEMACS_RGB); 
        i = 0; 
        for (width = 0; width < xsize; width++) 
        { 
            frame_data = reg_read(REG); 
            if (frame_data != TRAN_KEY_COLOR) 
            { 
                mask_temp = mask_temp | (0x8000 >> (width % 16)); 
            } 
            if (((width + 1) % 16 == 0) || (width == xsize - 1)) 
            { 
                mask_data[i] = mask_temp; 
                mask_temp = 0x0000; 
                i++; 
            } 
        } 
#else 
        mask_temp = 0xffff; 
        mem_adrst_ed_set(0, height, xsize - 1, height); 
        mem_acs_read_st(MEMACS_RGB); 
        i = 0; 
        for (width = 0; width < xsize; width++) 
        { 
            frame_data = reg_read(REG); 
#if 0 
            if (frame_data == TRAN_KEY_COLOR) 
            { 
                mask_temp = mask_temp &(~ (0x8000 >> (width % 16))); 
            } 
#else 
            if (frame_data != TRAN_KEY_COLOR) 
            { 
                mask_temp = mask_temp &(~ (0x8000 >> (width % 16))); 
            } 
#endif 
            if (((width + 1) % 16 == 0) || (width == xsize - 1)) 
            { 
                mask_data[i] = mask_temp; 
                mask_temp = 0xffff; 
                i++; 
            } 
        } 
#endif 
        if (xsize % 16) 
        { 
            mem_adrst_ed_set(0, height, xsize / 16, height); 
        } 
        else 
        { 
            mem_adrst_ed_set(0, height, xsize / 16 - 1, height); 
        } 
        mem_acs_write_st(MEMACS_MSK); 
        for (cnt = 0; cnt < i; cnt++) 
        { 
            reg_write(REG, mask_data[cnt]);     //MASK Data are written 
        } 
    } 
    bit_write(MEMCNT, bINCMTH | bADRINC, LOW);  //auto increment on 
 
    return (err_code); 
} 
 
*/ 
int mem_maskmemory_set(const UINT16 xstart, const UINT16 ystart, const UINT16 xsize, const UINT16 ysize, const UINT16 alpha_color) 
{ 
    UINT16 frame_data; 
    UINT16 mask_temp; 
    int i = 0, cnt, width, height; 
    UINT16 mask_data[12]; 
    int err_code = 0; 
 
 
    if (xsize > data_read(MLCDHSIZE)) 
        err_code = 0x01; 
    if (ysize > data_read(MLCDVSIZE)) 
        err_code = 0x02; 
 
    bit_write(MEMCNT, bINCMTH | bADRINC, HIGH);  
     
    for (height = ystart; height < (ystart + ysize); height++) 
     { 
        mask_temp = 0xffff; 
        mem_adrst_ed_set(xstart, height, (xstart + xsize) - 1, height); 
        mem_acs_read_st(MEMACS_RGB); 
        i = 0; 
        for (width = xstart; width < (xstart + xsize); width++) 
        { 
            frame_data = reg_read(REG); 
 
            if (frame_data== alpha_color) 
            { 
                mask_temp = mask_temp &(~ (0x8000 >> (width % 16))); 
            } 
 
            if (((width + 1) % 16 == 0) || (width == xsize - 1)) 
            { 
                mask_data[i] = mask_temp; 
                mask_temp = 0xffff; 
                i++; 
            } 
        }  
        if ((xstart+xsize) % 16) 
        { 
    
            mem_adrst_ed_set(xstart/16, height, (xstart+xsize) / 16, height); 
  
        } 
        else 
        {  
            mem_adrst_ed_set(xstart/16, height, (xstart+xsize) / 16 -1, height); 
 
         } 
 
        mem_acs_write_st(MEMACS_MSK); 
        for (cnt = 0; cnt < i; cnt++) 
        { 
            reg_write(REG, mask_data[cnt]);     
        } 
    } 
    bit_write(MEMCNT, bINCMTH | bADRINC, LOW);   
     
    return (err_code); 
} 
 
//----------------------------------------------------------------------------- 
//                              LCD size setup 
//----------------------------------------------------------------------------- 
int lcd_size_set(const UINT16 xsize, const UINT16 ysize) 
{ 
    int err_code = 0; 
 
    if (xsize > maxMLCDHSIZE) 
        err_code = 0x0001; 
    if (ysize > maxMLCDVSIZE) 
        err_code = 0x0002; 
 
    data_write(MLCDHSIZE, xsize); 
    data_write(MLCDVSIZE, ysize); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                         LCD transfer position setup 
//----------------------------------------------------------------------------- 
int lcd_point_set(const UINT16 st_x, const UINT16 st_y, const UINT16 ed_x, 
                  const UINT16 ed_y) 
{ 
    int err_code = 0; 
 
    if (st_x > maxMLCDSTX) 
        err_code = 0x0001; 
    if (st_y > maxMLCDSTY) 
        err_code = 0x0002; 
    if (st_x % 2) 
        err_code = 0x0003; 
    if ((ed_x + 1) % 2) 
        err_code = 0x0004; 
    if ((st_x + ed_x + 1) > data_read(MLCDHSIZE)) 
        err_code = 0x0005; 
    if ((st_y + ed_y + 1) > data_read(MLCDVSIZE)) 
        err_code = 0x0006; 
 
    data_write(MLCDSTX, st_x); 
    data_write(MLCDSTY, st_y); 
    data_write(MLCDEDX, ed_x); 
    data_write(MLCDEDY, ed_y); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                           MLCDWAV register setup 
//----------------------------------------------------------------------------- 
int lcd_wav_set(const UINT16 lcdwl, const UINT16 lcdwh) 
{ 
    int err_code = 0; 
 
    if (lcdwl > maxLCDWL) 
        err_code = 0x0001; 
    if (lcdwh > maxLCDWH) 
        err_code = 0x0002; 
 
    data_write(MLCDWAV, LCD_DELAY | (lcdwl << 4) | lcdwh); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                         LCD transfer command setup 
//----------------------------------------------------------------------------- 
int lcd_cmd_set(const int access) 
{ 
    int i; 
    UINT8 cmd[] = 
        { MLCDCMD1, MLCDCMD2, MLCDCMD3, MLCDCMD4, MLCDCMD5, MLCDCMD6, 
  MLCDCMD7 }; 
//modified by william 
    UINT16 /*UINT8 */ mcdata[] = 
    { 
    M_CMD_DATA1, M_CMD_DATA2, M_CMD_DATA3, M_CMD_DATA4, M_CMD_DATA5, 
            M_CMD_DATA6, M_CMD_DATA7}; 
    UINT16 /*UINT8 */ scdata[] = 
    { 
    S_CMD_DATA1, S_CMD_DATA2, S_CMD_DATA3, S_CMD_DATA4, S_CMD_DATA5, 
            S_CMD_DATA6, S_CMD_DATA7}; 
 
 
    if (access == sMAIN_ACS) 
    {                           //Main Lcd 
        if (M_EXCMD > maxEXCMD) 
            return 0x0001; 
        for (i = 0; i < M_EXCMD; i++) 
        { 
            data_write(cmd[i], mcdata[i]); 
        } 
 
        bit_write(MLCDCNT, bEXCMD, LOW); 
        bit_write(MLCDCNT, M_EXCMD << 4, HIGH); 
    } 
    else 
    {                           //Sub Lcd 
        if (S_EXCMD > maxEXCMD) 
            return 0x0001; 
        for (i = 0; i < S_EXCMD; i++) 
        { 
            data_write(cmd[i], scdata[i]);      // 
        } 
        bit_write(MLCDCNT, bEXCMD, LOW); 
        bit_write(MLCDCNT, S_EXCMD << 4, HIGH); 
    } 
 
    return 0; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                          lcd transfer point setup 
//----------------------------------------------------------------------------- 
int lcd_trans_set(const UINT16 st_x, const UINT16 st_y, const UINT16 xsize, 
                  const UINT16 ysize) 
{ 
    int err_code = 0; 
    err_code = 
        lcd_point_set(st_x, st_y, st_x + xsize - 1, st_y + ysize - 1); 
    column_page_set(st_x, st_x + xsize - 1, st_y, st_y + ysize - 1); 
 
    return err_code; 
} 
 
 
 
//----------------------------------------------------------------------------- 
//                          jpeg code size read 
//----------------------------------------------------------------------------- 
UINT32 read_je_size(void) 
{ 
    UINT32 je_size; 
 
    je_size = data_read(JE_CSIZE1); 
 
    return je_size; 
}