📄 myown_testfacility.c
字号:
#include <services/services.h>
#include <stdio.h>
#include <datatypes.h>
#include "TFTconfig.h"
#ifdef __ADSPBF561__
#include <cdefbf561.h>
#include "../../bf561/gpio_global.h"
#elif defined (__ADSPBF537__)
#include <cdefbf537.h>
#include "../../bf537/gpio_global.h"
#else
#error "processor not yet supported"
#endif
// select target board
//#define DEV_BF5xx
#define EXT_CAMERA_BF5xx
#ifdef DEV_BF5xx
#if defined (__ADSPBF561__)
#define PPI 1
#define LED_PWM_TIMER 7
#define DTMG_SHIFT_TIMER 5
#define CREATE_DOT_CLOCK (true)
#define DCLK_TIMER 4
#define PCI_FLAG _PF28
#define BIT_REVERSE (false)
#elif defined (__ADSPBF537__)
#error "dev-bf5xx does not support a display on cm-bf537"
#endif
#elif defined (EXT_CAMERA_BF5xx)
#if defined (__ADSPBF561__)
#define PPI 0
#define LED_PWM_TIMER 5
#define DTMG_SHIFT_TIMER 6
#define CREATE_DOT_CLOCK (true)
#define DCLK_TIMER 7
#define PCI_FLAG _PF0
#define BIT_REVERSE (true)
#elif defined (__ADSPBF537__)
#define PPI 0
#define LED_PWM_TIMER 6
#define DTMG_SHIFT_TIMER 3
#define CREATE_DOT_CLOCK (true)
#define DCLK_TIMER 5
#define PCI_FLAG _PF14
#define BIT_REVERSE (true)
#endif
#else
#error "target board not supported"
#endif
// clock settings
#define CLKIN 25000000
#define CORE_CLK 600000000
#define SYSTEM_CLK 120000000
#define DEBUG
#ifdef DEBUG
#define DPRINTF printf
#else
#define DPRINTF
#endif
// display resolution
#define XSIZE 240
#define YSIZE 320
#define BYTES_PER_PIXEL 2
// place where the image is stored
//extern unsigned char testPicture; // declared in testPicture.c
extern unsigned char acBall; // declared in testPicture.c
// function for setting the clock divider
void DPMsetDspClocks(unsigned long coreclk, unsigned long systemclk, unsigned long clkin) {
unsigned short msel, ssel, nImask;
msel = (unsigned short)(coreclk / clkin); // msel = VCO / CLKIN
ssel = (unsigned short)((clkin * msel) / systemclk); // ssel = VCO / SCLK
msel = msel << 9;
// csel=0: CCLK = VCO
asm("cli r0; \
%0 = r0;"
:"=d"(nImask)
:
:"r0");
#ifdef __ADSPBF561__
*pSICA_IWR0 |= 0x1; // enable PLL-interrupt to wakeup processor from idle-mode.
#elif defined (__ADSPBF533__)
*pSIC_IWR |= 0x1; // enable PLL-interrupt to wakeup processor from idle-mode.
#elif defined (__ADSPBF537__)
*pSIC_IWR |= 0x1; // enable PLL-interrupt to wakeup processor from idle-mode.
#endif
*pPLL_DIV = ssel;
*pPLL_CTL = msel;
// PLL Programming sequence to lock the pll.
asm ("r0 = %0; \
idle; \
sti r0;"
:
:"d"(nImask)
:"r0");
}
// memory for the adi interrupt manager
#pragma align(4)
static unsigned char intmgr_storage[(ADI_INT_SECONDARY_MEMORY * 8)];
void main (void) {
// set DSP clocks
DPMsetDspClocks(CORE_CLK, SYSTEM_CLK, CLKIN);
// initialize the adi interrupt manager
unsigned long critical_reg;
unsigned long response_count;
if (adi_int_Init (intmgr_storage, sizeof(intmgr_storage), &response_count, &critical_reg) != ADI_INT_RESULT_SUCCESS) {
// error initialising interrupt manager, so stop executing
while (1);
}
// allocate memory for the display frame buffer
unsigned char *pcFrameBuffer = (unsigned char *)malloc (XSIZE * (YSIZE + TFT_Y_BLANKING_LINES) * BYTES_PER_PIXEL);
// setup tft-display
T_ERROR_CODE erResult = TFTsetup ( PPI,
CORE_CLK,
SYSTEM_CLK,
XSIZE,
YSIZE,
BYTES_PER_PIXEL,
LED_PWM_TIMER,
DTMG_SHIFT_TIMER,
CREATE_DOT_CLOCK,
DCLK_TIMER,
PCI_FLAG,
pcFrameBuffer,
BIT_REVERSE,
0);
if (erResult == ERR_NONE) {
DPRINTF ("tft display sucessfully initialized.\n");
} else {
DPRINTF( "error initializing tft display.\n");
}
// convert the image from rgb 24 bit to rgb565
/* signed short cGreen;
signed short cBlue;
signed short cRed;
signed short nX;
unsigned short nY;
unsigned char *pRGBIndex = (unsigned char *)&testPicture;
for (nX=XSIZE-1; nX>=0; nX--) {
for (nY=0; nY<YSIZE; nY++) {
cRed = (signed short)*pRGBIndex;
cGreen = (signed short)(*(pRGBIndex+1));
cBlue = (signed short)(*(pRGBIndex+2));
cGreen = cGreen / 4;
if (cGreen > 63) cGreen = 63;
if (cGreen < 0 ) cGreen = 0;
cRed = cRed / 8;
if (cRed > 31) cRed = 31;
if (cRed < 0 ) cRed = 0;
cBlue = cBlue / 8;
if (cBlue > 31) cBlue = 31;
if (cBlue < 0 ) cBlue = 0;
TFTsetPixel (nX, nY, (unsigned char)cRed, (unsigned char)cGreen, (unsigned char)cBlue);
pRGBIndex+=3;
}
}
*/
// convert the image from rgb 24 bit to rgb565
signed short cGreen;
signed short cBlue;
signed short cRed;
signed short nX;
unsigned short nY;
unsigned char *pRGBIndex = (unsigned char *)&acBall;
/* for (nY=0; nY<XSIZE; nY++) {
for (nX=0; nX<YSIZE; nX++) {
cRed = (signed short)*pRGBIndex;
cGreen = (signed short)(*(pRGBIndex+1));
cBlue = (signed short)(*(pRGBIndex+2));
cGreen = cGreen / 4;
if (cGreen > 63) cGreen = 63;
if (cGreen < 0 ) cGreen = 0;
cRed = cRed / 8;
if (cRed > 31) cRed = 31;
if (cRed < 0 ) cRed = 0;
cBlue = cBlue / 8;
if (cBlue > 31) cBlue = 31;
if (cBlue < 0 ) cBlue = 0;
TFTsetPixel (nX, nY, (unsigned char)cRed, (unsigned char)cGreen, (unsigned char)cBlue);
pRGBIndex+=3;
}
}*/
unsigned char *pa_pcHSIbuffer = (unsigned char *)malloc (320 * 240 * 4);
RGB24BitToHSI24Bit (pRGBIndex, pa_pcHSIbuffer, 320, 240);
unsigned char *pa_pcDestBuffer = (unsigned char *)malloc (320 * 240 * 4);
Copy16BitChannel ((unsigned char *)((unsigned long)pa_pcHSIbuffer + 2), 4, pa_pcDestBuffer, 320, 240);
unsigned char *pResultFrame = (unsigned char *)malloc (320 * 240);
CalcLinearScaling ((unsigned char *)((unsigned long)pa_pcHSIbuffer + 1), 4, pResultFrame, 1.0, 0.0, 320, 240);
unsigned char *pa_pcMarkBuffer = (unsigned char *)malloc (320 * 240);
MarkPixelInHSI (pa_pcHSIbuffer, pa_pcMarkBuffer, 0x10, 0x40, 0x40,0xd0, 320, 240);
unsigned char inbuf[2 * 320 * 2];
unsigned char outbuf[2 * 320 * 4];
*pTCNTL = 5;
*pTPERIOD = 0xffffffff;
*pTSCALE = 0;
*pTCOUNT = 0xffffffff;
*pTCNTL |= 2;
//RGB24BitToHSI24Bit (inbuf, outbuf, 320, 2);
// MarkPixelInHSI (inbuf, outbuf, 0x10, 0x40, 0x40,0xd0, 320, 2);
YUV422ToRGB24Bit (inbuf, outbuf, 320, 2);
*pTCNTL &= ~2;
// uncommenting this you get a white corner on black background
/* for (nY=0; nY<YSIZE; nY++) {
for (nX=0; nX<XSIZE; nX++) {
if ((nX==0) || (nX==XSIZE-1) || (nY==0) || (nY==YSIZE-1)) {
TFTsetPixel (nX, nY, 31, 63, 31);
} else {
TFTsetPixel (nX, nY, 0, 0, 0);
}
}
}
*/
// endless loop
while (1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -