银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 0379-69926675-801 | ||
技术支持邮件 | Gingko@vip.163.com | ||
版本 | 日期 | 作者 | 修改内容 |
---|---|---|---|
V1.0 | 2020-11-09 | gingko | 初次建立 |
1.在主界面选择File–>New Project 或者直接点击ACCEE TO MCU SELECTOR 2.出现芯片型号选择,搜索自己芯片的型号,双击型号,或者点击Start Project进入配置 在搜索栏的下面,提供的各种查找方式,可以选择芯片内核、型号等等,可以帮助你查找芯片。本实验选取的芯片型号为:STM32H750IBKx。 3.配置RCC,使用外部时钟源 4.时基源选择SysTick 5.将PA10,PB7,PB8,PI1,PI2,PI3设置为GPIO_Output 6.引脚模式配置 7.配置定时器 定时器分配引脚如下所示 8.配置FMC 9.配置SDMMC 10.配置LTDC 11.配置CRC 12.配置FATFS 13.时钟源设置,选择外部高速时钟源,配置为最大主频。 14.工程文件的设置, 这里就是工程的各种配置 我们只用到有限几个,其他的默认即可 IDE我们使用的是 MDK V5.27 15.点击Code Generator,进行进一步配置
创建成功,打开工程。
int main(void) { FATFS fatfs; HAL_Init(); SystemClock_Config(); i2c.initialize(); axp152.initialize(); axp152.set_dcdc1(3500);//[ARM & FPGA BK1/2/6 &OTHER] axp152.set_dcdc2(1200);//[FPGA INT & PLL D] axp152.set_aldo1(2500);//[FPGA PLL A] axp152.set_dcdc4(3300);//[POWER_OUTPUT] axp152.set_dcdc3(3300);//[FPGA BK4][Adjustable] axp152.set_aldo2(3300);//[FPGA BK3][Adjustable] axp152.set_dldo1(3300);//[FPGA BK7][Adjustable] axp152.set_dldo2(3300);//[FPGA BK5][Adjustable] MX_GPIO_Init(); MX_CRC_Init(); MX_LTDC_Init(); MX_TIM12_Init(); MX_SDMMC1_SD_Init(); MX_FATFS_Init(); MX_FMC_Init(); BSP_SDRAM_Init(); lcd.initialize(); GUI_Init(); GUI_SetBkColor(GUI_BLACK); GUI_Clear(); HAL_TIM_PWM_Start(&htim12,TIM_CHANNEL_1); touch_type = gt911.initialize();//判断是否为电容触摸 if(touch_type != TOUCH_CAP){ touch_type = TOUCH_RES; } res = f_mount(&fatfs,"0:",1); if(res != RES_OK){ GUI_SetColor(GUI_RED); GUI_SetFont(&GUI_FontFixedsys16); GUI_DispStringHCenterAt("f_mount Error!",480/2,272/2); while(1){ } } GUI_SetColor(GUI_BLUE); if(touch_type == TOUCH_RES){ power_on.check_touch(); } GUI_CURSOR_Show(); frame.process(); //界面处理 LCD_ON;
static void frame_process(void) { GUI_CURSOR_Show(); WM_SetCreateFlags(WM_CF_MEMDEV); GUI_CreateDialogBox(_aDialogCreate,GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0); while(1){ if(systick._20ms_flag == 1){ systick._20ms_flag = 0; if(touch_type == TOUCH_RES){ ns2009.convert_pos(); }else if(touch_type == TOUCH_CAP){ gt911.scan(1); } } if(touch_flag == 1){ touch_flag = 0; if(touch_type == TOUCH_RES){ EDIT_SetValue(h_edit_0,pen.x0); EDIT_SetValue(h_edit_1,pen.y0); }else{ EDIT_SetValue(h_edit_0,gt911.x[0]); EDIT_SetValue(h_edit_1,gt911.y[0]); } } GUI_Exec(); } }
static int convert_pos(void) //坐标变换 { int i; i = readxy(&pen.X,&pen.Y); if(i == 2) return 2; else if(i == 1){ pen.x0 = 0; pen.y0 = 0; return 1; } pen.x0 = (int)(rgb_cal.a[0] + ((rgb_cal.a[1] * pen.X + rgb_cal.a[2]*pen.Y)/rgb_cal.a[6])); pen.y0 = (int)(rgb_cal.a[3] + ((rgb_cal.a[4] * pen.X +rgb_cal.a[5]*pen.Y)/rgb_cal.a[6])); if(pen.x0 > 0 && pen.x0 < 100 && pen.y0 > 240 && pen.y0 < 272){ pen.x0 = 479; pen.y0 = 271; }return 0;
static int touch_adjust(void) { int i; char buf[100]; do{ GUI_SetBkColor(GUI_WHITE); GUI_Clear(); get_sample(&rgb_cal,0,40,40); get_sample(&rgb_cal,1,RGB_XSIZE - 40,40); get_sample(&rgb_cal,2,RGB_XSIZE - 40,RGB_YSIZE - 40); get_sample(&rgb_cal,3,40,RGB_YSIZE - 40); get_sample(&rgb_cal,4,RGB_XSIZE / 2,RGB_YSIZE / 2); }while(perform_calibration(&rgb_cal)); for(i = 0; i < 7; i ++){ sprintf(buf,"a[%d] : %d \r\n",i,rgb_cal.a[i]); GUI_DispStringAt(buf,200,70 + 20 * i); } GUI_DispStringAt("calibration success",200,70 + 20 * i); for(i = 0; i < 30000000; i ++); GUI_Clear(); return 0; }
static int readxy(int *x, int *y) //读XY坐标 { int a[MAX_CNT_DATA],b[MAX_CNT_DATA]; int i = 0,j = 0; unsigned short int datx[3]; unsigned short int daty[3]; unsigned short int temp_x,temp_y; unsigned int cnt = 0; *x = 0; *y = 0; memset(a,0,MAX_CNT_DATA); memset(b,0,MAX_CNT_DATA); for(i = 0; i < MAX_CNT_DATA; i ++){ read_ads(&a[cnt],&b[cnt]); cnt ++; for(j = 0; j < 2100; j ++); } if(cnt < MAX_CNT_DATA - 5)return 3; qsort (a,MAX_CNT_DATA,sizeof(a[0]),acmp); //快速排序,就是中值滤波 qsort (b,MAX_CNT_DATA,sizeof(b[0]),acmp); datx[0] = a[MAX_CNT_DATA / 2 - 1]; datx[1] = a[MAX_CNT_DATA / 2]; datx[2] = a[MAX_CNT_DATA / 2 + 1]; daty[0] = b[MAX_CNT_DATA / 2 - 1]; daty[1] = b[MAX_CNT_DATA / 2]; daty[2] = b[MAX_CNT_DATA / 2 + 1]; if( abs(datx[0] - datx[1]) > 20 || abs(datx[1] - datx[2]) > 20 || abs(daty[0] - daty[1]) > 20 || abs(daty[1] - daty[2]) > 20 )return 2; temp_x = (datx[0] + datx[1] + datx[2]) / 3; temp_y = (daty[0] + daty[1] + daty[2]) / 3; *x = temp_x; *y = temp_y; return 0; }
static int perform_calibration(TOUCH_CALIBRATION_T *cal) { int j; double n, x, y, x2, y2, xy, z, zx, zy; double det, a, b, c, e, f, i; float scaling = 32768.0; // Get sums for matrix n = x = y = x2 = y2 = xy = 0; for(j = 0;j < 5;j++) { n += 1.0; x += (float)cal->x[j]; y += (float)cal->y[j]; x2 += (float)(cal->x[j]*cal->x[j]); y2 += (float)(cal->y[j]*cal->y[j]); xy += (float)(cal->x[j]*cal->y[j]); } // Get determinant of matrix -- check if determinant is too small det = n*(x2*y2 - xy*xy) + x*(xy*y - x*y2) + y*(x*xy - y*x2); if(det < 0.1 && det > -0.1) { return 1; } // Get elements of inverse matrix a = (x2*y2 - xy*xy)/det; b = (xy*y - x*y2)/det; c = (x*xy - y*x2)/det; e = (n*y2 - y*y)/det; f = (x*y - n*xy)/det; i = (n*x2 - x*x)/det; // Get sums for x calibration z = zx = zy = 0; for(j=0;j<5;j++) { z += (float)cal->xfb[j]; zx += (float)(cal->xfb[j]*cal->x[j]); zy += (float)(cal->xfb[j]*cal->y[j]); } // Now multiply out to get the calibration for framebuffer x coord cal->a[0] = (int)(a*z + b*zx + c*zy); cal->a[1] = (int)((b*z + e*zx + f*zy)*(scaling)); cal->a[2] = (int)((c*z + f*zx + i*zy)*(scaling)); // Get sums for y calibration z = zx = zy = 0; for(j=0;j<5;j++) { z += (float)cal->yfb[j]; zx += (float)(cal->yfb[j]*cal->x[j]); zy += (float)(cal->yfb[j]*cal->y[j]); } // Now multiply out to get the calibration for framebuffer y coord cal->a[3] = (int)(a*z + b*zx + c*zy); cal->a[4] = (int)((b*z + e*zx + f*zy)*(scaling)); cal->a[5] = (int)((c*z + f*zx + i*zy)*(scaling)); // If we got here, we're OK, so assign scaling to a[6] and return cal->a[6] = (int)scaling; for(j = 0; j < 5; j ++){ x = cal->a[0] + ((cal->a[1]*cal->x[j] + cal->a[2]*cal->y[j] ) / cal->a[6]); y = cal->a[3] + ((cal->a[4]*cal->x[j] + cal->a[5]*cal->y[j] ) / cal->a[6]); if((fabs(x - cal->xfb[j]) > 10) || (fabs(y - cal->yfb[j]) > 10)) return 1; } return 0; }
触摸iCore4T(4.3寸TFT_LCD)电阻屏屏即显示当前触摸位置的坐标值。