⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buxx_drv.c

📁 bu1566dsp芯片用来处理ov7660或其他30万摄像模组的图像预览.图像拍照(jpeg压缩)
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ************************************************************************ */
/*                                                                          */
/* 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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -