stm32f429 SRAM + ext SRAM + TFT 16bit with DMA

What are you developing?
User avatar
diger67
Posts: 24
Joined: Thu Sep 10, 2015 12:13 am
Location: Russia, Sankt- Piterburg

Re: stm32f429 SRAM + ext SRAM + TFT 16bit with DMA

Postby diger67 » Sun Mar 12, 2017 10:25 am

The problem with the stabilization of the read readings when touching the touchscreen was decided. Below, you can see how this is done.

Code: Select all

void Sort (uint16_t *mas)
{
uint8_t i,j;
uint16_t k;
   for(i=1;i<10;i++)
      for(j=0;j<9;j++)
      if(mas[i]>mas[j])
      {
         k=mas[i];
         mas[i]=mas[j];
         mas[j]=k;
      }
}

//-------------------------------------------------------------------------------
bool IsTouch(void)
{
   if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_8) == RESET)
            return true;
   return false;
}

//-------------------------------------------------------------------------------
bool Get_Touch_xy(__IO uint16_t *x_kor, __IO uint16_t *y_kor) 
{
   __IO uint16_t touch_x = 0;
   __IO uint16_t touch_y = 0;
   uint16_t touch_X[10]={0}, touch_Y[10]={0}, touch_avg;
   uint8_t i, flag;
   
   flag = IsTouch();
   //press = IsTouch_XY();
   if(flag)   //Есть касание   //There is a touch
   {
         for(i=0;i<10;i++)   //Считываем десять измерений x и y в точке касания   //Read ten dimensions x and y at the point of tangency
         {
            touch_X[i] = Get_Touch(chx);
            touch_Y[i] = Get_Touch(chy);
         }
         
         Sort(touch_X);   //Сортируем измерения по нарастающей   //We sort the measurements by increasing
         Sort(touch_Y);
            
         touch_avg=0;      //Расчитываем среднее арифметическое измерений отбросив два наименьших и два наибольших   
         for(i=2;i<6;i++)    //We calculate the average of the arithmetic measurements by discarding the two smallest and two largest
         touch_avg+=touch_X[i];
         touch_x=touch_avg/4;
            
         touch_avg=0;
         for(i=2;i<6;i++)
         touch_avg+=touch_Y[i];
         touch_y=touch_avg/4;
         
         touch_x -= Xmin;
         touch_x = 240 - touch_x/((Xmax-Xmin)/240);
         touch_y -= Ymin;
         touch_y = 320 - touch_y/((Ymax-Ymin)/320);
         
         if(touch_x > 240)
            touch_x = 240;
         if(touch_y > 320)
            touch_y = 320;
         
         init_XPT2046();   
         
//         *x_kor = touch_x;
//         *y_kor = touch_y;
         *y_kor = touch_x;
         *x_kor = touch_y;
   }
   return flag;
}


User avatar
diger67
Posts: 24
Joined: Thu Sep 10, 2015 12:13 am
Location: Russia, Sankt- Piterburg

Re: stm32f429 SRAM + ext SRAM + TFT 16bit with DMA

Postby diger67 » Tue Mar 14, 2017 2:40 pm

In this video, we'll look at creating a slider element and its work in practice. Also consider the changes made to the function of reading the coordinates that increase the stability of the read value. Well and on a small bonus, we will consider functions for work with a hardware image shift using the capabilities of the ili9341 controller.

https://youtu.be/CGoGelFqEys

User avatar
diger67
Posts: 24
Joined: Thu Sep 10, 2015 12:13 am
Location: Russia, Sankt- Piterburg

Re: stm32f429 SRAM + ext SRAM + TFT 16bit with DMA

Postby diger67 » Sun Mar 19, 2017 6:45 am

Connected the energy independent memory 24c16, now you can save the calibration values and variables without fear of power failure. Well, here's a simple calibration of the touchscreen. The accuracy is 2-4 pixels. I had enough.

Code: Select all

void touchSetCoef(int16_t _ax, int16_t _bx, int16_t _ay, int16_t _by, bool colibrate)
{
   I2CBuff[0] = _ax>>8;    //hight byte
   I2CBuff[1] = _ax;         //low byte
   I2CBuff[2] = _bx>>8;
   I2CBuff[3] = _bx;
   I2CBuff[4] = _ay>>8;
   I2CBuff[5] = _ay;   
   I2CBuff[6] = _by>>8;
   I2CBuff[7] = _by;
   I2CBuff[8] = colibrate;
   I2cWriteBuffer(hi2c1, EEPROM_HW_ADDRESS, 0, 8);
}

//------------------------------------------------------------------------------
void touchGetCoef(int16_t *_ax, int16_t *_bx, int16_t *_ay, int16_t *_by)
{
   I2cReadBuffer(hi2c1, EEPROM_HW_ADDRESS, 0, 8);
   *_ax = I2CBuff[0]<<8;   //hight byte
   *_ax |= I2CBuff[1];      //low byte
   *_bx = I2CBuff[2]<<8;   
   *_bx |= I2CBuff[3];
   *_ay = I2CBuff[4]<<8;   
   *_ay |= I2CBuff[5];
   *_by = I2CBuff[6]<<8;   
   *_by |= I2CBuff[7];
}

//------------------------------------------------------------------------------
void TouchColibrate(void)
{
   uint16_t x, y;
      
   static Text_TypeDef text0;
   static Text_TypeDef text1;
   
//   if(!ReadStatusCalibrate())
//      return;
      init_text(&text0, 50, 100, BLACK, CYAN, 2, 2, MANUAL);
      init_text(&text1, 50, 120, BLACK, CYAN, 2, 2, MANUAL);
      sprintf(text0.text1, "%s", "Калибровка");
      
      ram_bg_to_screen(SCREEN_BASE_ADDR_1);
      tft_text(&text0, &text0.textvar);
      drawLine (10, 10+25, 10+50, 10+25, BLACK);
      drawLine (10+25, 10, 10+25, 10+50, BLACK);
      DrawCircle(35, 35, 4, BLACK);
      SetCursor(50, 120);
      sprintf(text1.text1, "%s", "Нажимайте ");
      tft_text(&text1, &text1.textvar);
      tft();
   
      while (1)
      {
         // ждать нажатия
         while (!IsTouch());
         Get_Touch_xy (&x, &y, false);
         if (x < 4090 && y < 4090)
         {
            xPos[0] = x;
            yPos[0] = y;
            break;
         } // if
      } // while
      sprintf(text1.text1, "%s", "Отпускайте");
      tft_text(&text1, &text1.textvar);
      tft();
      
      while (IsTouch());
      ram_bg_to_screen(SCREEN_BASE_ADDR_1);
      tft_text(&text0, &text0.textvar);
      drawLine (LCD_PIXEL_WIDTH-10-50, 10+25, LCD_PIXEL_WIDTH-10-50+50, 10+25, BLACK);
      drawLine (LCD_PIXEL_WIDTH-10-25, 10, LCD_PIXEL_WIDTH-10-25, 10+50, BLACK);
      DrawCircle(285, 35, 4, BLACK);
      sprintf(text1.text1, "%s", "Нажимайте ");
      tft_text(&text1, &text1.textvar);
      tft();
      while (1)
      {
         // ждать нажатия
         while (!IsTouch());
         Get_Touch_xy (&x, &y, false);
         if (x < 4090 && y < 4090)
         {
            xPos[1] = x;
            yPos[1] = y;
            break;
         } // if
      } // while
      sprintf(text1.text1, "%s", "Отпускайте");
      tft_text(&text1, &text1.textvar);
      tft();      
      
      while (IsTouch());
      ram_bg_to_screen(SCREEN_BASE_ADDR_1);
      tft_text(&text0, &text0.textvar);
      drawLine (10, LCD_PIXEL_HEIGHT-10-25, 10+50, LCD_PIXEL_HEIGHT-10-25, BLACK);   // hor
      drawLine (10+25, LCD_PIXEL_HEIGHT-10-50, 10+25, LCD_PIXEL_HEIGHT-10-50+50, BLACK);   // vert
      DrawCircle(35, 205, 4, BLACK);
      sprintf(text1.text1, "%s", "Нажимайте ");
      tft_text(&text1, &text1.textvar);
      tft();
      while (1)
      {
         // ждать нажатия
         while (!IsTouch());
         Get_Touch_xy (&x, &y, false);
         if (x < 4090 && y < 4090)
         {
            xPos[2] = x;
            yPos[2] = y;
            break;
         } // if
      } // while
      sprintf(text1.text1, "%s", "Отпускайте");
      tft_text(&text1, &text1.textvar);
      tft();
      
      while (IsTouch());
      ram_bg_to_screen(SCREEN_BASE_ADDR_1);
      tft_text(&text0, &text0.textvar);
      drawLine (LCD_PIXEL_WIDTH-10-50, LCD_PIXEL_HEIGHT-10-25, LCD_PIXEL_WIDTH-10-50+50, LCD_PIXEL_HEIGHT-10-25, BLACK);   // hor
      drawLine (LCD_PIXEL_WIDTH-10-25, LCD_PIXEL_HEIGHT-10-50, LCD_PIXEL_WIDTH-10-25, LCD_PIXEL_HEIGHT-10-50+50, BLACK);   // vert
      DrawCircle(285, 205, 4, BLACK);
      sprintf(text1.text1, "%s", "Нажимайте ");
      tft_text(&text1, &text1.textvar);
      tft();
      while (1)
      {
         // ждать нажатия
         while (!IsTouch());
         Get_Touch_xy (&x, &y, false);
         if (x < 4090 && y < 4090)
         {
            xPos[3] = x;
            yPos[3] = y;
            break;
         } // if
      } // while
      sprintf(text1.text1, "%s", "Отпускайте");
      tft_text(&text1, &text1.textvar);
      tft();
      
      while (IsTouch());
      sprintf(text1.text1, "%s", "          ");
      tft_text(&text1, &text1.textvar);
      tft();
      
      // Расчёт коэффициентов
      if(xPos[0]>xPos[3])
      {
         swap(xPos[0],xPos[3]);
      }
      axc[0] = (xPos[3] - xPos[0])/(xCenter[3] - xCenter[0]);
      bxc[0] = xCenter[0] - xPos[0]/axc[0];
      if(yPos[0]>yPos[3])
      {
         swap(yPos[0],yPos[3]);
      }
      ayc[0] = (yPos[3] - yPos[0])/(yCenter[3] - yCenter[0]);
      byc[0] = yCenter[0] - yPos[0]/ayc[0];

      touchSetCoef (axc[0], bxc[0], ayc[0], byc[0], true);
      
      ram_bg_to_screen(SCREEN_BASE_ADDR_1);
      text0.y0 = 110;
      text0.text_poz = CENTER;
      touchGetCoef(&ax, &bx, &ay, &by);
      sprintf(text0.text1, "%s", "Калибровка завершена");
      tft_text(&text0, &text0.textvar);
      tft();
      HAL_Delay(2000);
}

User avatar
diger67
Posts: 24
Joined: Thu Sep 10, 2015 12:13 am
Location: Russia, Sankt- Piterburg

Re: stm32f429 SRAM + ext SRAM + TFT 16bit with DMA

Postby diger67 » Sun Mar 19, 2017 5:05 pm

Work with the touchscreen can be considered complete, there may be an optimization. Now when you first turn on after downloading the firmware, the system immediately enters the calibration mode. Then records all the data and flag "calibration, is made in its eeprom. It remains to provide a forced transition to this mode in the settings options. And this variant of the section code work was did.

User avatar
diger67
Posts: 24
Joined: Thu Sep 10, 2015 12:13 am
Location: Russia, Sankt- Piterburg

Re: stm32f429 SRAM + ext SRAM + TFT 16bit with DMA

Postby diger67 » Sun Mar 26, 2017 4:18 pm

Calibrating the touchscreen and saving data in its eeprom 24L16

https://youtu.be/5Kthe-pgFUQ


Return to “Projects”

Who is online

Users browsing this forum: No registered users and 1 guest