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

📄 buxx_drv.c

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

⌨️ 快捷键说明

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