/********************************************************************* * * 在触摸校正的时候使用这个来读取ADC的值 */ void Touch_MainTask(void) { GUI_CURSOR_Show(); GUI_CURSOR_Select(&GUI_CursorCrossL); GUI_SetBkColor(GUI_WHITE); GUI_SetColor(GUI_BLACK); GUI_Clear(); GUI_DispString("Measurement of\nA/D converter values"); while (1) { GUI_PID_STATE TouchState; int xPhys, yPhys; GUI_TOUCH_GetState(&TouchState); /* Get the touch position in pixel */ xPhys = GUI_TOUCH_GetxPhys(); /* Get the A/D mesurement result in x */ yPhys = GUI_TOUCH_GetyPhys(); /* Get the A/D mesurement result in y */ /* Display the measurement result */ GUI_SetColor(GUI_BLUE); GUI_DispStringAt("Analog input:\n", 0, 20); GUI_GotoY(GUI_GetDispPosY() + 2); GUI_DispString("x:"); GUI_DispDec(xPhys, 4); GUI_DispString(", y:"); GUI_DispDec(yPhys, 4); /* Display the according position */ GUI_SetColor(GUI_RED); GUI_GotoY(GUI_GetDispPosY() + 4); GUI_DispString("\nPosition:\n"); GUI_GotoY(GUI_GetDispPosY() + 2); GUI_DispString("x:"); GUI_DispDec(TouchState.x,4); GUI_DispString(", y:"); GUI_DispDec(TouchState.y,4); /* Wait a while */ GUI_Delay(100); }; }
int main(void) { DelayInit(); GPIO_QuickInit(HW_GPIOE, 6, kGPIO_Mode_OPP); UART_QuickInit(UART0_RX_PD06_TX_PD07, 115200); printf("spi touch screen test\r\n"); /* 初始化SPI2 接口连接触控屏的触控芯片*/ SPI_QuickInit(SPI2_SCK_PD12_SOUT_PD13_SIN_PD14, kSPI_CPOL0_CPHA0, 2*1000*1000); PORT_PinMuxConfig(HW_GPIOD, 11, kPinAlt2); /* SPI2_PCS0 */ /* 初始化触控芯片 使用CS0片选 */ ads7843_init(HW_SPI2, HW_SPI_CS0); GUI_Init();//液晶屏界面初始化 GUI_SetBkColor(GUI_WHITE); //设置背景色 GUI_SetColor(GUI_BLACK); //设置前景色 GUI_Clear(); //清屏 GUI_SetPenSize(3); //设置点的大小 GUI_DispString("Measurement of\nA/D converter values"); while (1) { GUI_PID_STATE TouchState; int xPhys, yPhys; GUI_TOUCH_GetState(&TouchState); /* 获得触控位置 */ xPhys = GUI_TOUCH_GetxPhys(); /* 获得x轴的测量值 */ yPhys = GUI_TOUCH_GetyPhys(); /* 获得y轴的测量值 */ /* 显示测量结果 */ GUI_SetColor(GUI_BLUE); GUI_DispStringAt("Analog input:\n", 0, 20); GUI_GotoY(GUI_GetDispPosY() + 2); GUI_DispString("x:"); GUI_DispDec(xPhys, 4); GUI_DispString(", y:"); GUI_DispDec(yPhys, 4); /* Display the according position */ GUI_SetColor(GUI_RED); GUI_GotoY(GUI_GetDispPosY() + 4); GUI_DispString("\nPosition:\n"); GUI_GotoY(GUI_GetDispPosY() + 2); GUI_DispString("x:"); GUI_DispDec(TouchState.x,4); GUI_DispString(", y:"); GUI_DispDec(TouchState.y,4); GUI_DrawPoint(TouchState.x, TouchState.y); GUI_TOUCH_Exec(); } }
/********************************************************************* * * GUI_EditString */ void GUI_EditString(char * pString, int Len, int xsize) { int Key, x, y, ysize, Id; EDIT_Handle hEdit; EDIT_Obj* pObj; const GUI_FONT GUI_UNI_PTR * pOldFont; WM_LOCK(); pOldFont = GUI_SetFont(EDIT_GetDefaultFont()); x = GUI_GetDispPosX(); y = GUI_GetDispPosY(); if (xsize == 0) { xsize = GUI_GetCharDistX('X') * Len + 6; } ysize = GUI_GetFontSizeY(); Id = 0x1234; hEdit = EDIT_Create(x, y, xsize, ysize, Id, Len, 0); EDIT_SetText(hEdit, pString); pObj = EDIT_H2P(hEdit); WM_SetFocus(hEdit); do { Key = GUI_WaitKey(); } while ((Key != GUI_KEY_ESCAPE) && (Key != GUI_KEY_ENTER) && (Key != 0)); if (Key == GUI_KEY_ENTER) { EDIT_GetText(hEdit, pString, pObj->MaxLen); } GUI_SetFont(pOldFont); EDIT_Delete(hEdit); WM_UNLOCK(); }
/********************************************************************* * * GUI_EditHex */ U32 GUI_EditHex(U32 Value, U32 Min, U32 Max, int Len, int xsize) { U32 Ret = Value; int Key, x, y, ysize, Id; EDIT_Handle hEdit; EDIT_Obj* pObj; const GUI_FONT GUI_UNI_PTR * pOldFont = GUI_SetFont(EDIT_GetDefaultFont()); x = GUI_GetDispPosX(); y = GUI_GetDispPosY(); if (xsize == 0) xsize = GUI_GetCharDistX('X') * Len + 6; ysize = GUI_GetFontSizeY(); Id = 0x1234; hEdit = EDIT_Create(x, y, xsize, ysize, Id, Len, 0); pObj = EDIT_H2P(hEdit); EDIT_SetHexMode(hEdit, Value, Min, Max); WM_SetFocus(hEdit); do { Key = GUI_WaitKey(); } while ((Key != GUI_KEY_ESCAPE) && (Key != GUI_KEY_ENTER) && (Key != 0)); GUI_SetFont(pOldFont); if (Key == GUI_KEY_ENTER) Ret = pObj->CurrentValue; EDIT_Delete(hEdit); return Ret; }
/********************************************************************* * * _ShowEdgeWeights */ static void _ShowEdgeWeights(void) { const char * Weight_name[] = { "\nlight: ", "\nsemi-light: ", "\nregular: ", "\nsemi-bold: ", "\nbold: " }; const char Chinese_string[] = { "\xe5\x9f\xba\xe6\x9c\xac\xe4\xb8\x8a\xe8\xae\xa1\xe7\xae\x97\xe6\x9c\xba\xe5\x8f\xaa\xe6\x98\xaf\xe5\xa4\x84\xe7\x90\x86\xe6\x95\xb0\xe5\xad\x97\xe5\xae\x83\xe4\xbb\xac\xe6\x8c\x87\xe5\xae\x9a\xe4\xb8\x80\xe4\xb8\xaa\n" }; const char Weight_order[] = { 0, 3, 1, 2, 4 }; int i; int j; GUI_Clear(); i = 0; GUI_ITYPE_GetFamilyName(&_aFont[i], _acFamily, sizeof(_acFamily)); GUI_ITYPE_GetStyleName(&_aFont[i], _acStyle, sizeof(_acStyle)); GUI_SetFont(&GUI_Font20_1); GUI_DispString(" Edge font: "); GUI_DispString(_acFamily); GUI_DispString(", "); GUI_DispString(_acStyle); GUI_DispNextLine(); GUI_DrawHLine(GUI_GetDispPosY(), 0, 0xfff); GUI_SetFont(&_aFont[1]); GUI_ITYPE_SetOutputStyle(&_aFont[1], &_aCS[1], (long)ITYPE_NO_EFFECT); // Turn off all effects GUI_ITYPE_SetOutputStyle(&_aFont[1], &_aCS[1], (long)ITYPE_GRAYMAP4); // Edge graymap output GUI_DispString("** iType Edge CSM tuning, 5 weights in the same font **"); for (j = 0; j < 5; j++){ i = Weight_order[j]; GUI_SetFont(&_aFont[i]); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_EFFECT); // Turn off all effects GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_EDGE_GRAYMAP4); // Edge graymap output GUI_DispNextLine(); GUI_DispString(Weight_name[j]); GUI_UC_SetEncodeUTF8(); GUI_DispString(Chinese_string); GUI_UC_SetEncodeNone(); } GUI_Delay(PAGE_DELAY); }
/*This function trait "<<" as a character '<'.*/ BYTE ShowHelp(void) { UBYTE ch; UWORD double_ch; WORD pos_y; while(1) { ch=*(HelpStr++); if(ch=='<') { if(*(HelpStr++)!='<') { HelpStr-=2;/*Got a Tag, roll back. Change to SetHelpTag().*/ return(0); } } else if(ch==0x00) return(-1); pos_y=GUI_GetDispPosY(); if(pos_y>posYMax/*196*/) return(-1); if((DoubleByteFlag==1)&&(ch>0x80)) /*Check for double byte character.*/ { double_ch=((UWORD)ch)<<8; double_ch+=(UBYTE)*(HelpStr++); GUI_DispChar(double_ch); } else GUI_DispChar(ch); } }
/********************************************************************* * * _ShowText */ static void _ShowText(void) { int i; GUI_Clear(); i = 0; GUI_TTF_GetFamilyName(&_aFont[i], _acFamily, sizeof(_acFamily)); GUI_TTF_GetStyleName(&_aFont[i], _acStyle, sizeof(_acStyle)); GUI_SetFont(&GUI_Font20_1); GUI_DispString(_acFamily); GUI_DispString(", "); GUI_DispString(_acStyle); GUI_DispNextLine(); GUI_DrawHLine(GUI_GetDispPosY(), 0, 0xfff); GUI_SetFont(&_aFont[i]); GUI_DispString("abcdefghijklmnopqrstuvwxyz\n"); GUI_DispString("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"); GUI_DispString("123456789.:,;(:*!?')\n"); GUI_DrawHLine(GUI_GetDispPosY(), 0, 0xfff); for (i = 0; i < GUI_COUNTOF(_aHeight); i++) { GUI_SetFont(&_aFont[i]); GUI_DispString("The quick brown fox jumps over the lazy dog. 1234567890\n"); } GUI_Delay(1000); }
/********************************************************************* * * _ShowDynamicCSM * * Function description * Shows 5 different weights of the same font by applying dynamic CSM adjustments. */ static void _ShowDynamicCSM(void) { double Alpha; double S0; double S1; double T0; double T1; double R; int i; int j; int N; N = 5; GUI_Clear(); i = 0; GUI_ITYPE_GetFamilyName(&_aFont[i], _acFamily, sizeof(_acFamily)); GUI_ITYPE_GetStyleName(&_aFont[i], _acStyle, sizeof(_acStyle)); GUI_SetFont(&GUI_Font20_1); GUI_DispString(" Edge font: "); GUI_DispString(_acFamily); GUI_DispString(", "); GUI_DispString(_acStyle); GUI_DispNextLine(); GUI_DrawHLine(GUI_GetDispPosY(), 0, 0xfff); GUI_UC_SetEncodeUTF8(); GUI_SetFont(&_aFont[0]); GUI_ITYPE_SetOutputStyle(&_aFont[0], &_aCS[0], (long)ITYPE_NO_EFFECT); // Turn off all effects GUI_ITYPE_SetOutputStyle(&_aFont[0], &_aCS[0], (long)ITYPE_EDGE_GRAYMAP4); // Edge graymap output GUI_DispString("** iType Dynamic CSM tuning **\n"); GUI_DispNextLine(); // // Parameters for adjustments // R = 1.4; S0 = 0.0; S1 = -0.001; T0 = 0.01; T1 = 0.007; // // Make 5 sets of adjustments which range from -R to R. // for (j = 0; j < N; j++){ Alpha = R * (2 * j / (N - 1) - 1); GUI_ITYPE_SetCSMAdjustments(&_aFont[i], &_aCS[i], (FS_FIXED)(Alpha*S0*65536), (FS_FIXED)(Alpha*S1*65536), (FS_FIXED)(Alpha*T0*65536), (FS_FIXED)(Alpha*T1*65536)); GUI_DispString("\xe5\x9f\xba\xe6\x9c\xac\xe4\xb8\x8a\xe8\xae\xa1\xe7\xae\x97\xe6\x9c\xba\xe5\x8f\xaa\xe6\x98\xaf\xe5\xa4\x84\xe7\x90\x86\xe6\x95\xb0\xe5\xad\x97\xe5\xae\x83\xe4\xbb\xac\xe6\x8c\x87\xe5\xae\x9a\xe4\xb8\x80\xe4\xb8\xaa\n"); } GUI_Delay(PAGE_DELAY); }
/********************************************************************* * * _cbDesktop * * Purpose: * This routine handles the drawing of the desktop window. */ static void _cbDesktop(WM_MESSAGE * pMsg) { int i; switch (pMsg->MsgId) { case WM_PAINT: GUI_SetBkColor(GUI_RED); GUI_Clear(); GUI_SetFont(&GUI_Font24_ASCII); GUI_DispStringHCenterAt(_aTitle, 160, 5); GUI_DispNextLine(); GUI_SetFont(GUI_DEFAULT_FONT); GUI_DispNextLine(); for (i = 0; i < GUI_COUNTOF(_apExplain); i++) { GUI_DispStringHCenterAt(_apExplain[i], 160, GUI_GetDispPosY()); GUI_DispNextLine(); } break; } }
/********************************************************************* * * _ShowLanguages */ static void _ShowLanguages(void) { const char Bopomofo_string[] = { "\nBopomofo: \xe3\x84\x85 \xe3\x84\x86 \xe3\x84\x87 \xe3\x84\x88 \xe3\x84\x89 \xe3\x84\x8a \xe3\x84\x8b \xe3\x84\x8c \xe3\x84\x8d \xe3\x84\x8e \xe3\x84\x8f \xe3\x84\x90 \xe3\x84\x91 \xe3\x84\x92 \xe3\x84\x93\n" }; const char Simplified_Chinese[] = { "\nSimplified: \xe5\x9f\xba\xe6\x9c\xac\xe4\xb8\x8a\xe8\xae\xa1\xe7\xae\x97\xe6\x9c\xba\xe5\x8f\xaa\xe6\x98\xaf\xe5\xa4\x84\xe7\x90\x86\xe6\x95\xb0\xe5\xad\x97\xe5\xae\x83\xe4\xbb\xac\xe6\x8c\x87\xe5\xae\x9a\n" }; const char Traditional_Chinese[] = { "\nTraditional: \xe9\x80\x99\xe4\xba\x9b\xe7\xb7\xa8\xe7\xa2\xbc\xe7\xb3\xbb\xe7\xb5\xb1\xe4\xb9\x9f\xe6\x9c\x83\xe4\xba\x92\xe7\x9b\xb8\xe8\xa1\x9d\xe7\xaa\x81\xe4\xb9\x9f\xe5\xb0\xb1\xe6\x98\xaf\xe8\xaa\xaa\xe5\x85\xa9\xe7\xa8\xae" }; int i; GUI_Clear(); i = 0; GUI_ITYPE_GetFamilyName(&_aFont[i], _acFamily, sizeof(_acFamily)); GUI_ITYPE_GetStyleName(&_aFont[i], _acStyle, sizeof(_acStyle)); GUI_SetFont(&GUI_Font20_1); GUI_DispString(" Linked font: "); GUI_DispString(_acFamily); GUI_DispString(", "); GUI_DispString(_acStyle); GUI_DispNextLine(); GUI_DrawHLine(GUI_GetDispPosY(), 0, 0xfff); // // Show alphabet strings // GUI_SetFont(&_aFont[i]); GUI_DispString("** iType User Defined Linked Font **"); GUI_UC_SetEncodeUTF8(); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_EFFECT); // Turn off all effects GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_GRAYMAP4); // Graymap output GUI_DispString("\nabcdefghijklmnopqrstuvwxyz\n"); GUI_DispString("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"); // // Show language strings // GUI_DispString(Bopomofo_string); GUI_DispString(Simplified_Chinese); GUI_DispString(Traditional_Chinese); GUI_UC_SetEncodeNone(); GUI_Delay(PAGE_DELAY); }
/********************************************************************* * * _ShowFeatures */ static void _ShowFeatures(void) { int i; GUI_Clear(); i = 0; GUI_ITYPE_GetFamilyName(&_aFont[i], _acFamily, sizeof(_acFamily)); GUI_ITYPE_GetStyleName (&_aFont[i], _acStyle, sizeof(_acStyle)); GUI_SetFont(&GUI_Font20_1); GUI_DispString(" Standard font: "); GUI_DispString(_acFamily); GUI_DispString(", "); GUI_DispString(_acStyle); GUI_DispNextLine(); GUI_DrawHLine(GUI_GetDispPosY(), 0, 0xfff); // // Unattributed bitmap / graymap output // GUI_SetFont(&_aFont[i]); GUI_DispString("** iType Text Special Effects **"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_EFFECT); // Turn off all effects GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_BITMAP); // Bitmap output GUI_DispString("\nUnattributed bitmap text\n"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_GRAYMAP4); // Graymap output GUI_DispString("Unattributed 4 bpp graymap text\n"); // // Italic / Bold / Bold-Italic output // GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_ITALIC); // Italic on GUI_DispString("Italic text\n"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_REGULAR_BOLD); // Bold on GUI_DispString("Regular bold italic text\n"); GUI_ITYPE_SetItalicAngle(&_aFont[i], &_aCS[i], 0); // Italic off GUI_DispString("Regular bold text\n"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_BOLD); // Bold off // // Filled / Unfilled outline output // GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_OUTLINED_FILLED); // Filled outline on GUI_DispString("Filled outline\n"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_EFFECT); // Filled outline off GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_OUTLINED_UNFILLED); // Unfilled outline on GUI_DispString("Unfilled outline\n"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_EFFECT); // Unfilled outline off // // Embossed / Engraved output // GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_EMBOSSED); // Embossed on GUI_DispString("Embossed text\n"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_EFFECT); // Embossed off GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_ENGRAVED); // Engraved on GUI_DispString("Engraved text\n"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_EFFECT); // Engraved off // // Shadow / Glow output // GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_SHADOW); // Shadow on GUI_DispString("Shadow text\n"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_EFFECT); // Shadow off GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_GLOW); // Glow on GUI_DispString("Glow text\n"); GUI_ITYPE_SetOutputStyle(&_aFont[i], &_aCS[i], (long)ITYPE_NO_EFFECT); // Glow off GUI_Delay(PAGE_DELAY); }