[STM32N6] 运行STM32N6 的BSP外设综合测试

[复制链接]
2598|12
 楼主| 一路向北lm 发表于 2025-3-15 19:26 | 显示全部楼层 |阅读模式
本帖最后由 一路向北lm 于 2025-3-15 19:35 编辑

Demo:按键触摸
2535467d564009424e.png
3165567d56407dc4b9.png
5987167d5641ba567a.png

DemoSD卡实验
5798967d5642eded53.png

Demo:摄像头实验
9439967d5643cbfe72.png

视频动图展示
3 00_00_00-00_00_30.gif
4 00_00_00-00_00_30.gif
5 00_00_00-00_00_30.gif
6 00_00_00-00_00_30.gif
7 00_00_00-00_00_30.gif
8 00_00_00-00_00_30.gif

 楼主| 一路向北lm 发表于 2025-3-15 19:29 | 显示全部楼层

摄像头camera代码部分

  1. /**
  2.   ******************************************************************************
  3.   * [url=home.php?mod=space&uid=288409]@file[/url]    camera.c
  4.   * [url=home.php?mod=space&uid=187600]@author[/url]  MCD Application Team
  5.   * [url=home.php?mod=space&uid=247401]@brief[/url]   This example code shows how to use the camera features of the
  6.   *          stm32h7b3i_eval_camera driver
  7.   ******************************************************************************
  8.   * @attention
  9.   *
  10.   * Copyright (c) 2024 STMicroelectronics.
  11.   * All rights reserved.
  12.   *
  13.   * This software is licensed under terms that can be found in the LICENSE file
  14.   * in the root directory of this software component.
  15.   * If no LICENSE file comes with this software, it is provided AS-IS.
  16.   *
  17.   ******************************************************************************
  18.   */

  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. /** @addtogroup STM32N6xx_HAL_Examples
  22.   * @{
  23.   */

  24. /** @addtogroup BSP
  25.   * @{
  26.   */

  27. /* Private typedef -----------------------------------------------------------*/
  28. /* Private define ------------------------------------------------------------*/
  29. #define WVGA_RES_X      800
  30. #define WVGA_RES_Y      480
  31. #define CAMERA_FRAME_BUFFER LCD_LAYER_1_ADDRESS
  32. /* Private macro -------------------------------------------------------------*/
  33. /* Private variables ---------------------------------------------------------*/
  34. static uint8_t MirrorFlipIndex = 0;
  35. /* Camera resolutions */

  36. uint8_t  CameraMirrorFlip[4] =
  37. {
  38.   CAMERA_MIRRORFLIP_NONE,
  39.   CAMERA_MIRRORFLIP_FLIP,
  40.   CAMERA_MIRRORFLIP_MIRROR,
  41.   CAMERA_MIRRORFLIP_FLIP | CAMERA_MIRRORFLIP_MIRROR,
  42. };

  43. CAMERA_Capabilities_t Cap;

  44. /* Private function prototypes -----------------------------------------------*/
  45. static void Camera_SetHint(void);
  46. static uint32_t Camera_ISP_IdleWait(uint32_t delay);

  47. /* Private functions ---------------------------------------------------------*/
  48. /**
  49.   * @brief  Camera demo
  50.   * @param  None
  51.   * @retval None
  52.   */
  53. void Camera_Demo (void)
  54. {
  55.   Camera_SetHint();

  56.   UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);
  57.   /* Display USB initialization message */
  58.   UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
  59.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_DARKBLUE);

  60.   UTIL_LCD_SetFont(&Font24);
  61.   BSP_LCD_LayerConfig_t cam_layer;
  62.   cam_layer.Address = LCD_LAYER_1_ADDRESS;
  63.   cam_layer.PixelFormat = LCD_PIXEL_FORMAT_RGB565;
  64.   cam_layer.X0 = 0;
  65.   cam_layer.X1 = 800;
  66.   cam_layer.Y0 = 0;
  67.   cam_layer.Y1 = 480;
  68.   BSP_LCD_ConfigLayer(0, 1, &cam_layer);
  69.   BSP_LCD_SetColorKeying(0, 1, UTIL_LCD_COLOR_WHITE);
  70.   BSP_LCD_SetActiveLayer(0,1);
  71.   BSP_LCD_SetLayerAddress(0, 0, LCD_LAYER_1_ADDRESS);
  72.   BSP_LCD_SetLayerAddress(0, 1, LCD_LAYER_0_ADDRESS);
  73.   /* Initialize the Camera */
  74.   if(BSP_CAMERA_Init(0, CAMERA_R2592x1944, CAMERA_PF_RAW_RGGB10) != BSP_ERROR_NONE)
  75.   {
  76.     UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
  77.     UTIL_LCD_DisplayStringAt(20, 0, (uint8_t *)" NO CAMERA CONNECTED", CENTER_MODE);
  78.   }
  79.   else
  80.   {
  81.     UTIL_LCD_DisplayStringAt(20, 35, (uint8_t *)"CAMERA CONTINUOUS MODE", CENTER_MODE);
  82.     /* Wait for the camera initialization after HW reset*/
  83.     HAL_Delay(100);

  84.     BSP_CAMERA_GetCapabilities(0, &Cap);

  85.     /* Start the Camera Capture */
  86.     BSP_CAMERA_Start(0, (uint8_t *)CAMERA_FRAME_BUFFER, CAMERA_MODE_CONTINUOUS);

  87.     UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
  88.     Camera_ISP_IdleWait(5000);
  89.     /* Start the Camera Capture */
  90.     UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);
  91.     if(Cap.MirrorFlip != 1)
  92.     {
  93.       UTIL_LCD_DisplayStringAt(0, 35, (uint8_t *)"Camera MirrorFlip feature not supported", CENTER_MODE);
  94.       Camera_ISP_IdleWait(2000);
  95.     }
  96.     else
  97.     {
  98.       UTIL_LCD_DisplayStringAt(0, 35, (uint8_t *)"                                               ", CENTER_MODE);
  99.       UTIL_LCD_DisplayStringAt(0, 70, (uint8_t *)"Camera Mirror/Flip", CENTER_MODE);
  100.       /* Test Camera Mirror/Flip */
  101.       while(MirrorFlipIndex < 4)
  102.       {
  103.         Camera_ISP_IdleWait(2000);
  104.         BSP_CAMERA_SetMirrorFlip(0, CameraMirrorFlip[MirrorFlipIndex]);
  105.         MirrorFlipIndex++;
  106.       }
  107.       Camera_ISP_IdleWait(2000);
  108.       MirrorFlipIndex = 1;
  109.       BSP_CAMERA_SetMirrorFlip(0, CameraMirrorFlip[MirrorFlipIndex]);
  110.     }
  111.     BSP_CAMERA_SetMirrorFlip(0, CAMERA_MIRRORFLIP_NONE);

  112.     Camera_ISP_IdleWait(2000);
  113.   }
  114.   BSP_CAMERA_Stop(0);
  115.   UTIL_LCD_FillRect(0, 0, 800, 480, UTIL_LCD_COLOR_WHITE);
  116.   BSP_LCD_ResetColorKeying(0, 1);
  117.   BSP_LCD_SetLayerAddress(0, 0, LCD_LAYER_0_ADDRESS);
  118.   BSP_LCD_SetLayerAddress(0, 1, LCD_LAYER_1_ADDRESS);
  119.   BSP_LCD_SetLayerVisible(0, 1, DISABLE);
  120.   BSP_LCD_SetActiveLayer(0,0);
  121.   UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
  122.   UTIL_LCD_DisplayStringAt(20, 35, (uint8_t *)"CAMERA Demo done. press USR1 to continue", CENTER_MODE);



  123.   while (1)
  124.   {
  125.     if(CheckForUserInput() > 0)
  126.     {
  127.       ClearUserInput();
  128.       BSP_CAMERA_DeInit(0);
  129.       return;
  130.     }
  131.   }
  132. }

  133. /**
  134.   * @brief  Display Camera demo hint
  135.   * @param  None
  136.   * @retval None
  137.   */
  138. static void Camera_SetHint(void)
  139. {
  140.   uint32_t x_size, y_size;

  141.   BSP_LCD_GetXSize(0, &x_size);
  142.   BSP_LCD_GetYSize(0, &y_size);

  143.   /* Clear the LCD */
  144.   UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);

  145.   /* Set Camera Demo description */
  146.   UTIL_LCD_FillRect(0, 0, x_size, 120, UTIL_LCD_COLOR_BLUE);
  147.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_WHITE);
  148.   UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_BLUE);
  149.   UTIL_LCD_SetFont(&Font24);
  150.   UTIL_LCD_DisplayStringAt(0, 0, (uint8_t *)"CAMERA EXAMPLE", CENTER_MODE);
  151.   UTIL_LCD_SetFont(&Font12);
  152.   UTIL_LCD_DisplayStringAt(0, 30, (uint8_t *)"     Press User button for next menu     ", CENTER_MODE);

  153.   /* Set the LCD Text Color */
  154.   UTIL_LCD_DrawRect(10, 130, x_size - 20, y_size - 130, UTIL_LCD_COLOR_BLUE);
  155.   UTIL_LCD_DrawRect(11, 131, x_size - 22, y_size - 132, UTIL_LCD_COLOR_BLUE);
  156. }

  157. /**
  158.   * @brief  Camera demo idle loop
  159.   * @param  None
  160.   * @retval None
  161.   */
  162. static uint32_t Camera_ISP_IdleWait(uint32_t delay){
  163.   uint32_t initial_tick =  HAL_GetTick();
  164.   while((HAL_GetTick() - initial_tick) < delay){
  165.     int err = BSP_CAMERA_BackgroundProcess();
  166.     if(err != BSP_ERROR_NONE){
  167.       return err;
  168.     }
  169.   }
  170.   return 0;
  171. }
  172. /**
  173.   * @}
  174.   */

  175. /**
  176.   * @}
  177.   */





 楼主| 一路向北lm 发表于 2025-3-15 19:30 | 显示全部楼层
LCD 部分代码:
  1. /**
  2.   ******************************************************************************
  3.   * @file    lcd.c
  4.   * @author  MCD Application Team
  5.   * @brief   This example code shows how to use the LCD display feature in the
  6.   *          STM32H573I-DK driver
  7.   ******************************************************************************
  8.   * @attention
  9.   *
  10.   * Copyright (c) 2024 STMicroelectronics.
  11.   * All rights reserved.
  12.   *
  13.   * This software is licensed under terms that can be found in the LICENSE file
  14.   * in the root directory of this software component.
  15.   * If no LICENSE file comes with this software, it is provided AS-IS.
  16.   *
  17.   ******************************************************************************
  18.   */

  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"

  21. /** @addtogroup STM32H5xx_HAL_Examples
  22.   * @{
  23.   */

  24. /** @addtogroup BSP
  25.   * @{
  26.   */

  27. /* Private typedef -----------------------------------------------------------*/
  28. /* Private define ------------------------------------------------------------*/
  29. /* Private macro -------------------------------------------------------------*/
  30. /* Private variables ---------------------------------------------------------*/
  31. uint32_t  colors[24] = {UTIL_LCD_COLOR_BLUE , UTIL_LCD_COLOR_GREEN, UTIL_LCD_COLOR_RED, UTIL_LCD_COLOR_CYAN,
  32.                         UTIL_LCD_COLOR_MAGENTA, UTIL_LCD_COLOR_YELLOW,UTIL_LCD_COLOR_LIGHTBLUE, UTIL_LCD_COLOR_LIGHTGREEN,
  33.                         UTIL_LCD_COLOR_LIGHTRED, UTIL_LCD_COLOR_WHITE, UTIL_LCD_COLOR_LIGHTMAGENTA, UTIL_LCD_COLOR_LIGHTYELLOW,
  34.                         UTIL_LCD_COLOR_DARKGREEN, UTIL_LCD_COLOR_DARKRED, UTIL_LCD_COLOR_DARKCYAN,UTIL_LCD_COLOR_DARKMAGENTA,
  35.                         UTIL_LCD_COLOR_LIGHTGRAY, UTIL_LCD_COLOR_GRAY, UTIL_LCD_COLOR_DARKGRAY, UTIL_LCD_COLOR_DARKYELLOW,
  36.                         UTIL_LCD_COLOR_BLACK, UTIL_LCD_COLOR_BROWN, UTIL_LCD_COLOR_ORANGE, UTIL_LCD_COLOR_DARKBLUE};
  37. /* Private function prototypes -----------------------------------------------*/
  38. /* Private functions ---------------------------------------------------------*/
  39. /**
  40.   * @brief  LCD demo
  41.   * @param  None
  42.   * @retval None
  43.   */
  44. void Lcd_Demo(void)
  45. {
  46.   Point    triangle[3] = {{0, 0}, {0, 0}, {0, 0}};
  47.   uint32_t colorIndex = 0;
  48.   uint32_t x;
  49.   uint32_t y;
  50.   uint32_t  i, color_index;

  51.   UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);
  52.   UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_ST_BLUE_DARK);
  53.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_WHITE);
  54.   UTIL_LCD_FillRect(0, 0, 800, 40, UTIL_LCD_COLOR_ST_BLUE_DARK);
  55.   UTIL_LCD_DisplayStringAt(0, 15, (uint8_t *)" Test LCD  ", CENTER_MODE);

  56.   /* Display a grid of colored rectangles with each rectangle being 80x80 pixels in size.
  57.      There are 8 rectangles per row and 3 rows, each with a color from the colors array */
  58.   for (color_index = 0; color_index < 24; color_index++)
  59.   {
  60.     int x = 80 * ((color_index % 8) + 1);
  61.     int y = 80 * (color_index / 8 + 2);

  62.     UTIL_LCD_FillRect(x, y, 80, 80, colors[color_index]);
  63.   }

  64.   HAL_Delay(1000);

  65.   UTIL_LCD_FillRect(0, 40, 800, 440, UTIL_LCD_COLOR_WHITE);

  66.   /* Display a grid of circles on an LCD screen */
  67.   for(color_index = 0; color_index < 4; color_index++)
  68.   {
  69.     for(i = 0; i < 6; i++)
  70.     {
  71.       UTIL_LCD_DrawCircle(150 + (100*i), 100*(color_index+1), 40, UTIL_LCD_COLOR_BLACK);
  72.     }
  73.   }

  74.   HAL_Delay(1000);

  75.   /* Display a grid of colored circles */
  76.   for(color_index = 0; color_index < 4; color_index++)
  77.   {
  78.     for(i = 0; i < 6; i++)
  79.     {
  80.       UTIL_LCD_FillCircle(150 + (100*i), 100*(color_index+1), 40, colors[colorIndex]);
  81.       colorIndex++;
  82.       HAL_Delay(50);
  83.     }
  84.   }

  85.   HAL_Delay(1000);
  86.   UTIL_LCD_FillRect(0, 40, 800, 440, UTIL_LCD_COLOR_WHITE);

  87.   colorIndex = 0;
  88.   /* Display a grid of colored triangles */
  89.   for(color_index = 0; color_index < 6; color_index++)
  90.   {
  91.     for(i = 0; i < 4; i++)
  92.     {
  93.       triangle[0].X = 40*color_index;
  94.       triangle[0].Y = 40 + 50*(i);
  95.       triangle[1].X = 40*(color_index+1);
  96.       triangle[1].Y = 65 + 50*(i);
  97.       triangle[2].X = 40*color_index;
  98.       triangle[2].Y = 40 + 50*(1+i);
  99.       UTIL_LCD_FillPolygon(triangle, 3, colors[colorIndex]);
  100.       if(colors[colorIndex] == UTIL_LCD_COLOR_WHITE)
  101.       {
  102.         UTIL_LCD_DrawPolygon(triangle, 3, UTIL_LCD_COLOR_BLACK);
  103.       }
  104.       colorIndex++;
  105.     }
  106.   }
  107.   HAL_Delay(1000);

  108.   UTIL_LCD_FillRect(0, 40, 800, 440, UTIL_LCD_COLOR_WHITE);

  109.   /* Draw bitmap */
  110.   UTIL_LCD_DrawBitmap(80, 130, (uint8_t *)st**);
  111.   HAL_Delay(500);

  112.   UTIL_LCD_DrawBitmap(240, 130, (uint8_t *)st**);

  113.   HAL_Delay(500);

  114.   UTIL_LCD_DrawBitmap(400, 130, (uint8_t *)st**);

  115.   HAL_Delay(500);

  116.   UTIL_LCD_DrawBitmap(560, 130, (uint8_t *)st**);

  117.   HAL_Delay(1000);
  118.   UTIL_LCD_FillRect(0, 40, 800, 440, UTIL_LCD_COLOR_WHITE);

  119.   BSP_LCD_DisplayOff(0);

  120.   if (BSP_LCD_DeInit(0) != BSP_ERROR_NONE)
  121.   {
  122.     Error_Handler();
  123.   }

  124.   BSP_LCD_InitEx(0, LCD_ORIENTATION_LANDSCAPE, LCD_PIXEL_FORMAT_RGB888, LCD_DEFAULT_WIDTH, LCD_DEFAULT_HEIGHT);
  125.   UTIL_LCD_SetFuncDriver(&LCD_Driver);
  126.   BSP_LCD_DisplayOn(0);


  127.   UTIL_LCD_FillRect(0, 40, 800, 440, UTIL_LCD_COLOR_WHITE);
  128.   UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_ST_BLUE_DARK);
  129.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_WHITE);
  130.   UTIL_LCD_FillRect(0, 0, 800, 40, UTIL_LCD_COLOR_ST_BLUE_DARK);
  131.   UTIL_LCD_DisplayStringAt(0, 15, (uint8_t *)" Test LCD  ", CENTER_MODE);
  132.   UTIL_LCD_DisplayStringAt(0, 100, (uint8_t *)"LCD RGB888", CENTER_MODE);

  133.   for (color_index = 0; color_index < 16; color_index++)
  134.   {
  135.      x = 40 * ((color_index % 4) + 8) ;
  136.      y = (40 * (color_index / 4 + 4));

  137.     UTIL_LCD_FillRect(x, y, 40, 40, colors[color_index]);
  138.   }

  139.   HAL_Delay(1000);
  140.   if (BSP_LCD_DeInit(0) != BSP_ERROR_NONE)
  141.   {
  142.     Error_Handler();
  143.   }

  144.   BSP_LCD_DisplayOff(0);

  145.   BSP_LCD_InitEx(0, LCD_ORIENTATION_LANDSCAPE, LCD_PIXEL_FORMAT_ARGB4444, LCD_DEFAULT_WIDTH, LCD_DEFAULT_HEIGHT);
  146.   UTIL_LCD_SetFuncDriver(&LCD_Driver);
  147.   BSP_LCD_DisplayOn(0);

  148.   UTIL_LCD_FillRect(0, 40, 800, 440, UTIL_LCD_COLOR_WHITE);
  149.   UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_ST_BLUE_DARK);
  150.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_WHITE);
  151.   UTIL_LCD_FillRect(0, 0, 800, 40, UTIL_LCD_COLOR_ST_BLUE_DARK);
  152.   UTIL_LCD_DisplayStringAt(0, 15, (uint8_t *)" Test LCD  ", CENTER_MODE);
  153.   UTIL_LCD_DisplayStringAt(0, 100, (uint8_t *)"LCD ARGB4444", CENTER_MODE);

  154.   for (color_index = 8; color_index < 24; color_index++)
  155.   {
  156.      x = 40 * ((color_index % 4) + 8) ;
  157.      y = (40 * (color_index / 4 + 4));

  158.     UTIL_LCD_FillRect(x, y, 40, 40, colors[color_index]);
  159.   }

  160.   HAL_Delay(1000);
  161.   UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);

  162.   if (BSP_LCD_DeInit(0) != BSP_ERROR_NONE)
  163.   {
  164.     Error_Handler();
  165.   }

  166.   if(BSP_LCD_Init(0, LCD_ORIENTATION_LANDSCAPE) != BSP_ERROR_NONE)
  167.   {
  168.     Error_Handler();
  169.   }

  170.   UTIL_LCD_SetFuncDriver(&LCD_Driver);

  171.   UTIL_LCD_FillRect(0, 0, 800, 40, UTIL_LCD_COLOR_ST_BLUE_DARK);
  172.   UTIL_LCD_DisplayStringAt(0, 15, (uint8_t *)" Test LCD  ", CENTER_MODE);
  173. }


  174. /**
  175.   * @}
  176.   */

  177. /**
  178.   * @}
  179.   */



 楼主| 一路向北lm 发表于 2025-3-15 19:31 | 显示全部楼层
触摸演示相关函数

  1. /**
  2.   ******************************************************************************
  3.   * @file    touchscreen.c
  4.   * @author  MCD Application Team
  5.   * @brief   This example code shows how to use the touchscreen driver.
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2024 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */

  18. /* Includes ------------------------------------------------------------------*/
  19. #include "main.h"

  20. /** @addtogroup STM32H7RSxx_HAL_Examples
  21.   * @{
  22.   */

  23. /** @addtogroup BSP
  24.   * @{
  25.   */

  26. /* Private typedef -----------------------------------------------------------*/
  27. /* Private define ------------------------------------------------------------*/
  28. #define  CIRCLE_RADIUS        40
  29. #define  LINE_LENGHT          30
  30. /* Private macro -------------------------------------------------------------*/
  31. #define  CIRCLE_XPOS(i)       ((i * 480) / 5)
  32. #define  CIRCLE_YPOS(i)       (272 - CIRCLE_RADIUS - 60)

  33. /* Private Structures and Enumerations ------------------------------------------------------------*/
  34. /* Possible allowed indexes of touchscreen demo */
  35. typedef enum
  36. {
  37.   TOUCHSCREEN_DEMO_1 = 1,
  38. #if (USE_TS_MULTI_TOUCH == 1)
  39.   TOUCHSCREEN_DEMO_2 = 2,
  40.   TOUCHSCREEN_DEMO_3 = 3,
  41.   TOUCHSCREEN_DEMO_MAX = TOUCHSCREEN_DEMO_3,
  42. #else
  43.   TOUCHSCREEN_DEMO_MAX = TOUCHSCREEN_DEMO_1,
  44. #endif /* USE_TS_MULTI_TOUCH == 1 */
  45. } TouchScreenDemoTypeDef;

  46. /* Table for touchscreen event information display on LCD : table indexed on enum [url=home.php?mod=space&uid=144993]@ref[/url] TS_TouchEventTypeDef information */
  47. char * ts_event_string_tab[4] = { "None",
  48.                                   "Press down",
  49.                                   "Lift up",
  50.                                   "Contact"};

  51. /* Global variables ---------------------------------------------------------*/
  52. uint16_t x_new_pos = 0, x_previous_pos = 0;
  53. uint16_t y_new_pos = 0, y_previous_pos = 0;
  54. TS_State_t  TS_State;
  55. TS_MultiTouch_State_t  TS_MTState = {0};

  56. extern uint32_t colors[];

  57. /* Private variables ---------------------------------------------------------*/
  58. /* Static variable holding the current touch color index : used to change color at each touch */
  59. #if (USE_TS_MULTI_TOUCH == 1)
  60. static uint32_t touchscreen_color_idx = 0;
  61. #endif /* USE_TS_MULTI_TOUCH == 1 */
  62. TS_Init_t hTS;
  63. /* Private function prototypes -----------------------------------------------*/
  64. static void     Touchscreen_SetHint_Demo(TouchScreenDemoTypeDef demoIndex);
  65. #if (USE_TS_MULTI_TOUCH == 1)
  66. static uint32_t Touchscreen_Handle_NewTouch(void);
  67. static void TS_Update(void);
  68. #endif /* USE_TS_MULTI_TOUCH == 1 */

  69. /* Private functions ---------------------------------------------------------*/
  70. /**
  71.   * @brief  Touchscreen Demo1 : test touchscreen calibration and single touch in polling mode
  72.   * @param  None
  73.   * @retval None
  74.   */
  75. void Touchscreen_demo1(void)
  76. {
  77.   uint16_t x1, y1;
  78.   uint8_t state = 0;
  79.   uint32_t ts_status = BSP_ERROR_NONE;
  80.   uint32_t x_size, y_size;

  81.   BSP_LCD_GetXSize(0, &x_size);
  82.   BSP_LCD_GetYSize(0, &y_size);
  83.   UserButtonPressed = 0;

  84.   hTS.Width = x_size;
  85.   hTS.Height = y_size;
  86.   hTS.Orientation = TS_SWAP_NONE;
  87.   hTS.Accuracy = 5;

  88.   /* Touchscreen initialization */
  89.   ts_status = BSP_TS_Init(0, &hTS);

  90.   if(ts_status == BSP_ERROR_NONE)
  91.   {
  92.     /* Display touch screen demo description */
  93.     Touchscreen_SetHint_Demo(TOUCHSCREEN_DEMO_1);
  94.     Touchscreen_DrawBackground_Circles(state);

  95.     while (1)
  96.     {
  97.       /* Check in polling mode in touch screen the touch status and coordinates */
  98.       /* of touches if touch occurred                                           */
  99.       ts_status = BSP_TS_GetState(0, &TS_State);
  100.       if(TS_State.TouchDetected)
  101.       {
  102.         /* One or dual touch have been detected          */
  103.         /* Only take into account the first touch so far */

  104.         /* Get X and Y position of the first touch post calibrated */
  105.         x1 = TS_State.TouchX;
  106.         y1 = TS_State.TouchY;

  107.         if ((y1 > (CIRCLE_YPOS(1) - CIRCLE_RADIUS)) &&
  108.             (y1 < (CIRCLE_YPOS(1) + CIRCLE_RADIUS)))
  109.         {
  110.           if ((x1 > (CIRCLE_XPOS(1) - CIRCLE_RADIUS)) &&
  111.               (x1 < (CIRCLE_XPOS(1) + CIRCLE_RADIUS)))
  112.           {
  113.             if ((state & 1) == 0)
  114.             {
  115.               Touchscreen_DrawBackground_Circles(state);
  116.               UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLUE);
  117.               HAL_Delay(1);
  118.               state = 1;
  119.             }
  120.           }
  121.           if ((x1 > (CIRCLE_XPOS(2) - CIRCLE_RADIUS)) &&
  122.               (x1 < (CIRCLE_XPOS(2) + CIRCLE_RADIUS)))
  123.           {
  124.             if ((state & 2) == 0)
  125.             {
  126.               Touchscreen_DrawBackground_Circles(state);
  127.               UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS, UTIL_LCD_COLOR_RED);
  128.               HAL_Delay(1);
  129.               state = 2;
  130.             }
  131.           }

  132.           if ((x1 > (CIRCLE_XPOS(3) - CIRCLE_RADIUS)) &&
  133.               (x1 < (CIRCLE_XPOS(3) + CIRCLE_RADIUS)))
  134.           {
  135.             if ((state & 4) == 0)
  136.             {
  137.               Touchscreen_DrawBackground_Circles(state);
  138.               UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS, UTIL_LCD_COLOR_YELLOW);
  139.               state = 4;
  140.             }
  141.           }

  142.           if ((x1 > (CIRCLE_XPOS(4) - CIRCLE_RADIUS)) &&
  143.               (x1 < (CIRCLE_XPOS(4) + CIRCLE_RADIUS)))
  144.           {
  145.             if ((state & 8) == 0)
  146.             {
  147.               Touchscreen_DrawBackground_Circles(state);
  148.               UTIL_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS, UTIL_LCD_COLOR_GREEN);
  149.               state = 8;
  150.             }
  151.           }
  152.         }

  153.       } /* of if(TS_State.TouchDetected) */

  154.       if(CheckForUserInput() > 0)
  155.       {
  156.         ClearUserInput();
  157.         BSP_TS_DeInit(0);
  158.         return;
  159.       }

  160.       HAL_Delay(20);
  161.     }
  162.   } /* of if(status == BSP_ERROR_NONE) */
  163. }

  164. #if (USE_TS_MULTI_TOUCH == 1)
  165. /**
  166.   * @brief  Touchscreen Demo2 : test touchscreen single and dual touch in polling mode
  167.   * @param  None
  168.   * @retval None
  169.   */
  170. void Touchscreen_demo2(void)
  171. {
  172.   uint32_t ts_status = BSP_ERROR_NONE;
  173.   uint32_t x_size, y_size;
  174.   UserButtonPressed = 0;
  175.   BSP_LCD_GetXSize(0, &x_size);
  176.   BSP_LCD_GetYSize(0, &y_size);

  177.   hTS.Width = x_size;
  178.   hTS.Height = y_size;
  179.   hTS.Orientation = TS_SWAP_NONE;
  180.   hTS.Accuracy = 0;

  181.   /* Touchscreen initialization */
  182.   ts_status = BSP_TS_Init(0, &hTS);

  183.   if(ts_status == BSP_ERROR_NONE)
  184.   {
  185.     /* Display touch screen demo2 description */
  186.     Touchscreen_SetHint_Demo(TOUCHSCREEN_DEMO_2);
  187.   } /* of if(status == BSP_ERROR_NONE) */

  188.   while (1)
  189.   {
  190.     Touchscreen_Handle_NewTouch();
  191.     if(CheckForUserInput() > 0)
  192.     {
  193.       ClearUserInput();
  194.       BSP_TS_DeInit(0);
  195.       return;
  196.     }
  197.     HAL_Delay(100);
  198.   }
  199. }

  200. /**
  201.   * @brief  Touchscreen Demo3 : test touchscreen single touch in interrupt mode
  202.   * @param  None
  203.   * @retval None
  204.   */
  205. void Touchscreen_demo3(void)
  206. {
  207.   uint16_t k, l;
  208.   uint32_t x_size, y_size;

  209.   BSP_LCD_GetXSize(0, &x_size);
  210.   BSP_LCD_GetYSize(0, &y_size);

  211.   hTS.Width = x_size;
  212.   hTS.Height = y_size;
  213.   hTS.Orientation = TS_SWAP_NONE;
  214.   hTS.Accuracy = 0;

  215.   /* Touchscreen initialization */
  216.   BSP_TS_Init(0, &hTS);

  217.   BSP_TS_EnableIT(0);

  218.   UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);
  219.   for(k = 0; k < hTS.Width/40; k++)
  220.   {
  221.     for(l = 0; l < hTS.Height/40; l++)
  222.     {
  223.       UTIL_LCD_DrawRect(40*k, 40*l,40,40, UTIL_LCD_COLOR_BLACK);
  224.     }
  225.   }

  226.   while (1)
  227.   {
  228.     if(CheckForUserInput() > 0)
  229.     {
  230.       ClearUserInput();
  231.       BSP_TS_DisableIT(0);
  232.       BSP_TS_DeInit(0);
  233.       return;
  234.     }
  235.   }
  236. }

  237. void BSP_TS_Callback(uint32_t Instance)
  238. {
  239.   TS_Update();
  240. }

  241. static void TS_Update(void)
  242. {
  243.   uint16_t i, j;

  244.   BSP_TS_GetState(0, &TS_State);
  245.   if(TS_State.TouchDetected)
  246.   {
  247.     /* One or dual touch have been detected          */
  248.     /* Only take into account the first touch so far */
  249.     /* Get X and Y position of the first touch post calibrated */
  250.     x_new_pos = TS_State.TouchX;
  251.     y_new_pos = TS_State.TouchY;

  252.     for(i = 0; i < hTS.Width/40; i++)
  253.     {
  254.       for(j = 0; j < hTS.Height/40; j++)
  255.       {
  256.         if(((x_new_pos > 40*i) && (x_new_pos < 40*(i+1))) && ((y_new_pos > 40*j) && (y_new_pos < 40*(j+1))))
  257.         {
  258.           UTIL_LCD_FillRect(x_previous_pos, y_previous_pos,40,40, UTIL_LCD_COLOR_WHITE);
  259.           UTIL_LCD_DrawRect(x_previous_pos, y_previous_pos,40,40, UTIL_LCD_COLOR_BLACK);

  260.           UTIL_LCD_FillRect(40*i, 40*j,40,40, colors[(touchscreen_color_idx++ % 24)]);

  261.           x_previous_pos = 40*i;
  262.           y_previous_pos = 40*j;
  263.           break;
  264.         }
  265.       }
  266.     }
  267.     x_new_pos = TS_State.TouchX;
  268.     y_new_pos = TS_State.TouchY;
  269.   }
  270. }

  271. /**
  272.   * @brief  Touchscreen_Handle_NewTouch: factorization of touch management
  273.   * @param  None
  274.   * @retval BSP_ERROR_NONE
  275.   */
  276. static uint32_t Touchscreen_Handle_NewTouch(void)
  277. {
  278. #define TS_MULTITOUCH_FOOTPRINT_CIRCLE_RADIUS 15
  279. #define TOUCH_INFO_STRING_SIZE                70
  280.   uint16_t x1 = 0;
  281.   uint16_t y1 = 0;
  282.   uint16_t x2 = 0;
  283.   uint16_t y2 = 0;
  284.   uint32_t drawTouch1 = 0; /* activate/deactivate draw of footprint of touch 1 */
  285.   uint32_t drawTouch2 = 0; /* activate/deactivate draw of footprint of touch 2 */
  286.   uint32_t colors[24] = {UTIL_LCD_COLOR_BLUE, UTIL_LCD_COLOR_GREEN, UTIL_LCD_COLOR_RED, UTIL_LCD_COLOR_CYAN, UTIL_LCD_COLOR_MAGENTA, UTIL_LCD_COLOR_YELLOW,
  287.                          UTIL_LCD_COLOR_LIGHTBLUE, UTIL_LCD_COLOR_LIGHTGREEN, UTIL_LCD_COLOR_LIGHTRED, UTIL_LCD_COLOR_LIGHTCYAN, UTIL_LCD_COLOR_LIGHTMAGENTA,
  288.                          UTIL_LCD_COLOR_LIGHTYELLOW, UTIL_LCD_COLOR_DARKBLUE, UTIL_LCD_COLOR_DARKGREEN, UTIL_LCD_COLOR_DARKRED, UTIL_LCD_COLOR_DARKCYAN,
  289.                          UTIL_LCD_COLOR_DARKMAGENTA, UTIL_LCD_COLOR_DARKYELLOW, UTIL_LCD_COLOR_LIGHTGRAY, UTIL_LCD_COLOR_GRAY, UTIL_LCD_COLOR_DARKGRAY,
  290.                          UTIL_LCD_COLOR_BLACK, UTIL_LCD_COLOR_BROWN, UTIL_LCD_COLOR_ORANGE };
  291.   uint32_t ts_status = BSP_ERROR_NONE;
  292.   uint8_t lcd_string[TOUCH_INFO_STRING_SIZE] = "";
  293.   uint32_t x_size, y_size;

  294.   BSP_LCD_GetXSize(0, &x_size);
  295.   BSP_LCD_GetYSize(0, &y_size);

  296.   /* Check in polling mode in touch screen the touch status and coordinates */
  297.   /* of touches if touch occurred                                           */
  298.   ts_status = BSP_TS_Get_MultiTouchState(0, &TS_MTState);
  299.   if(TS_MTState.TouchDetected)
  300.   {
  301.     /* One or dual touch have been detected  */
  302.     /* Erase previous information on touchscreen play pad area */
  303.     UTIL_LCD_FillRect(0, 80, x_size, y_size - 160, UTIL_LCD_COLOR_WHITE);

  304.     /* Re-Draw touch screen play area on LCD */
  305.     UTIL_LCD_DrawRect(10, 90, x_size - 20, y_size - 180, UTIL_LCD_COLOR_BLUE);
  306.     UTIL_LCD_DrawRect(11, 91, x_size - 22, y_size - 182, UTIL_LCD_COLOR_BLUE);

  307.     /* Erase previous information on bottom text bar */
  308.     UTIL_LCD_FillRect(0, y_size - 80, x_size, 80, UTIL_LCD_COLOR_BLUE);

  309.     /* Deactivate drawing footprint of touch 1 and touch 2 until validated against boundaries of touch pad values */
  310.     drawTouch1 = drawTouch2 = 0;

  311.     /* Get X and Y position of the first touch post calibrated */
  312.     x1 = TS_MTState.TouchX[0];
  313.     y1 = TS_MTState.TouchY[0];

  314.     if((y1 > (90 + TS_MULTITOUCH_FOOTPRINT_CIRCLE_RADIUS)) &&
  315.        (y1 < (y_size - 90 - TS_MULTITOUCH_FOOTPRINT_CIRCLE_RADIUS)))
  316.     {
  317.       drawTouch1 = 1;
  318.     }

  319.     /* If valid touch 1 position : inside the reserved area for the use case : draw the touch */
  320.     if(drawTouch1 == 1)
  321.     {
  322.       /* Draw circle of first touch : turn on colors[] table */
  323.       UTIL_LCD_FillCircle(x1, y1, TS_MULTITOUCH_FOOTPRINT_CIRCLE_RADIUS, colors[(touchscreen_color_idx++ % 24)]);

  324.       UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_WHITE);
  325.       UTIL_LCD_SetFont(&Font16);
  326.       UTIL_LCD_DisplayStringAt(0, y_size - 70, (uint8_t *)"TOUCH INFO : ", CENTER_MODE);

  327.       UTIL_LCD_SetFont(&Font12);
  328.       sprintf((char*)lcd_string, "x1 = %u, y1 = %u",  x1, y1);
  329.       UTIL_LCD_DisplayStringAt(0, y_size - 45, lcd_string, CENTER_MODE);
  330.     } /* of if(drawTouch1 == 1) */

  331.     if(TS_MTState.TouchDetected > 1)
  332.     {
  333.       /* Get X and Y position of the second touch post calibrated */
  334.       x2 = TS_MTState.TouchX[1];
  335.       y2 = TS_MTState.TouchY[1];

  336.       if((y2 > (90 + TS_MULTITOUCH_FOOTPRINT_CIRCLE_RADIUS)) &&
  337.          (y2 < (y_size - 90 - TS_MULTITOUCH_FOOTPRINT_CIRCLE_RADIUS)))
  338.       {
  339.         drawTouch2 = 1;
  340.       }

  341.       /* If valid touch 2 position : inside the reserved area for the use case : draw the touch */
  342.       if(drawTouch2 == 1)
  343.       {
  344.         sprintf((char*)lcd_string, "x2 = %u, y2 = %u",  x2, y2);
  345.         UTIL_LCD_DisplayStringAt(0, y_size - 35, lcd_string, CENTER_MODE);

  346.         /* Draw circle of second touch : turn on color[] table */
  347.         UTIL_LCD_FillCircle(x2, y2, TS_MULTITOUCH_FOOTPRINT_CIRCLE_RADIUS, colors[(touchscreen_color_idx++ % 24)]);
  348.       } /* of if(drawTouch2 == 1) */
  349.     } /* of if(TS_MTState.TouchDetected > 1) */
  350.   } /* of if(TS_MTState.TouchDetected) */
  351.   return(ts_status);
  352. }
  353. #endif /* USE_TS_MULTI_TOUCH == 1 */

  354. /**
  355.   * @brief  Display TS Demo Hint for all touchscreen demos depending on passed
  356.   *         demoIndex in parameter.
  357.   * @param  demoIndex : parameter of type @ref TouchScreenDemoTypeDef
  358.   * @retval None
  359.   */
  360. static void Touchscreen_SetHint_Demo(TouchScreenDemoTypeDef demoIndex)
  361. {
  362.   uint32_t x_size, y_size;

  363.   BSP_LCD_GetXSize(0, &x_size);
  364.   BSP_LCD_GetYSize(0, &y_size);

  365.   BSP_LCD_SetLayerVisible(0,0, DISABLE);

  366.   if(demoIndex <= TOUCHSCREEN_DEMO_MAX)
  367.   {
  368.     /* Clear the LCD */
  369.     UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);

  370.     /* Set Touchscreen Demo1 description */
  371.     UTIL_LCD_FillRect(0, 0, x_size, 80, UTIL_LCD_COLOR_BLUE);
  372.     UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_WHITE);
  373.     UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_BLUE);
  374.     UTIL_LCD_SetFont(&Font24);

  375.     if(demoIndex == TOUCHSCREEN_DEMO_1)
  376.     {
  377.       UTIL_LCD_DisplayStringAt(0, 0, (uint8_t *)"Touchscreen basic polling", CENTER_MODE);
  378.       UTIL_LCD_SetFont(&Font16);
  379.       UTIL_LCD_DisplayStringAt(0, 45, (uint8_t *)"Please use the Touchscreen to activate the colored circle", CENTER_MODE);
  380.       UTIL_LCD_DisplayStringAt(0, 60, (uint8_t *)"inside the rectangle, then press USER button", CENTER_MODE);
  381.     }
  382. #if (USE_TS_MULTI_TOUCH == 1)
  383.     else if (demoIndex == TOUCHSCREEN_DEMO_2)
  384.     {
  385.       UTIL_LCD_DisplayStringAt(0, 0, (uint8_t *)"Touchscreen dual touch polling", CENTER_MODE);
  386.       UTIL_LCD_SetFont(&Font16);
  387.       UTIL_LCD_DisplayStringAt(0, 45, (uint8_t *)"Please press the Touchscreen to activate", CENTER_MODE);
  388.       UTIL_LCD_DisplayStringAt(0, 60, (uint8_t *)"single and dual touch, then press USER button", CENTER_MODE);

  389.     }
  390.     else /* demoIndex == TOUCHSCREEN_DEMO_3 */
  391.     {
  392.       UTIL_LCD_DisplayStringAt(0, 0, (uint8_t *)"Touchscreen dual touch interrupt", CENTER_MODE);
  393.       UTIL_LCD_SetFont(&Font16);
  394.       UTIL_LCD_DisplayStringAt(0, 45, (uint8_t *)"Please press the Touchscreen to activate", CENTER_MODE);
  395.       UTIL_LCD_DisplayStringAt(0, 60, (uint8_t *)"single and dual touch, then press USER button", CENTER_MODE);
  396.     }
  397. #endif /* USE_TS_MULTI_TOUCH == 1 */

  398.     UTIL_LCD_DrawRect(10, 90, x_size - 20, y_size - 100, UTIL_LCD_COLOR_BLUE);
  399.     UTIL_LCD_DrawRect(11, 91, x_size - 22, y_size - 102, UTIL_LCD_COLOR_BLUE);

  400.   } /* of if(demoIndex <= TOUCHSCREEN_DEMO_MAX) */

  401.   BSP_LCD_SetLayerVisible(0,0, ENABLE);
  402. }

  403. /**
  404.   * @brief  Draw Touchscreen Background
  405.   * @param  state : touch zone state
  406.   * @retval None
  407.   */
  408. void Touchscreen_DrawBackground_Circles(uint8_t state)
  409. {
  410.   uint16_t x, y;
  411.   switch (state)
  412.   {
  413.     case 0:
  414.       UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLUE);

  415.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS, UTIL_LCD_COLOR_RED);

  416.       UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS, UTIL_LCD_COLOR_YELLOW);


  417.       UTIL_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS, UTIL_LCD_COLOR_GREEN);

  418.       UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  419.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  420.       UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  421.       UTIL_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  422.       break;

  423.     case 1:
  424.       UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLUE);
  425.       UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  426.       break;

  427.     case 2:
  428.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS, UTIL_LCD_COLOR_RED);
  429.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  430.       break;

  431.     case 4:
  432.       UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS, UTIL_LCD_COLOR_YELLOW);
  433.       UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  434.       break;

  435.     case 8:
  436.       UTIL_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(4), CIRCLE_RADIUS, UTIL_LCD_COLOR_GREEN);
  437.       UTIL_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(4), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  438.       break;

  439.     case 16:
  440.       UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLUE);
  441.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLUE);
  442.       UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLUE);
  443.       UTIL_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLUE);

  444.       UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  445.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  446.       UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  447.       UTIL_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);

  448.       UTIL_LCD_DrawHLine(CIRCLE_XPOS(1)-LINE_LENGHT, CIRCLE_YPOS(1), 2*LINE_LENGHT, UTIL_LCD_COLOR_BLUE);
  449.       UTIL_LCD_DrawHLine(CIRCLE_XPOS(2)-LINE_LENGHT, CIRCLE_YPOS(2), 2*LINE_LENGHT, UTIL_LCD_COLOR_BLUE);
  450.       UTIL_LCD_DrawVLine(CIRCLE_XPOS(2), CIRCLE_YPOS(2)-LINE_LENGHT, 2*LINE_LENGHT, UTIL_LCD_COLOR_BLUE);
  451.       UTIL_LCD_DrawHLine(CIRCLE_XPOS(3)-LINE_LENGHT, CIRCLE_YPOS(3), 2*LINE_LENGHT, UTIL_LCD_COLOR_BLUE);
  452.       UTIL_LCD_DrawHLine(CIRCLE_XPOS(4)-LINE_LENGHT, CIRCLE_YPOS(4), 2*LINE_LENGHT, UTIL_LCD_COLOR_BLUE);
  453.       UTIL_LCD_DrawVLine(CIRCLE_XPOS(4), CIRCLE_YPOS(4)-LINE_LENGHT, 2*LINE_LENGHT, UTIL_LCD_COLOR_BLUE);

  454.       UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_BLUE);
  455.       UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
  456.       UTIL_LCD_SetFont(&Font24);
  457.       x = CIRCLE_XPOS(1);
  458.       y = CIRCLE_YPOS(1) - CIRCLE_RADIUS - UTIL_LCD_GetFont()->Height;
  459.       UTIL_LCD_DisplayStringAt(x, y, (uint8_t *)"Volume", CENTER_MODE);
  460.       x = CIRCLE_XPOS(4);
  461.       y = CIRCLE_YPOS(4) - CIRCLE_RADIUS - UTIL_LCD_GetFont()->Height;
  462.       UTIL_LCD_DisplayStringAt(x, y, (uint8_t *)"Frequency", CENTER_MODE);

  463.       break;

  464.     case 32:
  465.       UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLACK);
  466.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLACK);

  467.       UTIL_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  468.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);


  469.       UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_BLACK);
  470.       UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
  471.       UTIL_LCD_SetFont(&Font20);
  472.       x = CIRCLE_XPOS(1) - 10;
  473.       y = CIRCLE_YPOS(1) - (UTIL_LCD_GetFont()->Height)/2;
  474.       UTIL_LCD_DisplayStringAt(x, y, (uint8_t *)"Up", LEFT_MODE);
  475.       x = CIRCLE_XPOS(2) - 10;
  476.       y = CIRCLE_YPOS(3)  - (UTIL_LCD_GetFont()->Height)/2;
  477.       UTIL_LCD_DisplayStringAt(x, y, (uint8_t *)"Dw", LEFT_MODE);
  478.       UTIL_LCD_SetFont(&Font12);

  479.       break;

  480.     case 64:
  481.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLUE);
  482.       UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS, UTIL_LCD_COLOR_BLUE);

  483.       UTIL_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);
  484.       UTIL_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS - 2, UTIL_LCD_COLOR_WHITE);

  485.       UTIL_LCD_DrawHLine(CIRCLE_XPOS(2)-LINE_LENGHT, CIRCLE_YPOS(2), 2*LINE_LENGHT, UTIL_LCD_COLOR_BLUE);
  486.       UTIL_LCD_DrawHLine(CIRCLE_XPOS(3)-LINE_LENGHT, CIRCLE_YPOS(3), 2*LINE_LENGHT, UTIL_LCD_COLOR_BLUE);
  487.       UTIL_LCD_DrawVLine(CIRCLE_XPOS(3), CIRCLE_YPOS(3)-LINE_LENGHT, 2*LINE_LENGHT, UTIL_LCD_COLOR_BLUE);

  488.       UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_BLUE);
  489.       UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
  490.       UTIL_LCD_SetFont(&Font24);
  491.       x = CIRCLE_XPOS(2);
  492.       y = CIRCLE_YPOS(1) - CIRCLE_RADIUS - UTIL_LCD_GetFont()->Height;
  493.       UTIL_LCD_DisplayStringAt(x, y, (uint8_t *)"Frequency", LEFT_MODE);
  494.       break;
  495.   }
  496. }

  497. /**
  498.   * @brief  TouchScreen get touch position
  499.   * @param  None
  500.   * @retval None
  501.   */
  502. uint8_t TouchScreen_GetTouchPosition(void)
  503. {
  504.   uint16_t x1, y1;
  505.   uint8_t circleNr = 0;

  506.   /* Check in polling mode in touch screen the touch status and coordinates */
  507.   /* of touches if touch occurred                                           */
  508.   BSP_TS_GetState(0, &TS_State);
  509.   if(TS_State.TouchDetected)
  510.   {
  511.     /* One or dual touch have been detected          */
  512.     /* Only take into account the first touch so far */

  513.     /* Get X and Y position of the first */
  514.     x1 = TS_State.TouchX;
  515.     y1 = TS_State.TouchY;

  516.     if ((y1 > (CIRCLE_YPOS(1) - CIRCLE_RADIUS)) &&
  517.         (y1 < (CIRCLE_YPOS(1) + CIRCLE_RADIUS)))
  518.     {
  519.       if ((x1 > (CIRCLE_XPOS(1) - CIRCLE_RADIUS)) &&
  520.           (x1 < (CIRCLE_XPOS(1) + CIRCLE_RADIUS)))
  521.       {
  522.         circleNr = 1;
  523.       }
  524.       if ((x1 > (CIRCLE_XPOS(2) - CIRCLE_RADIUS)) &&
  525.           (x1 < (CIRCLE_XPOS(2) + CIRCLE_RADIUS)))
  526.       {
  527.         circleNr = 2;
  528.       }

  529.       if ((x1 > (CIRCLE_XPOS(3) - CIRCLE_RADIUS)) &&
  530.           (x1 < (CIRCLE_XPOS(3) + CIRCLE_RADIUS)))
  531.       {
  532.         circleNr = 3;
  533.       }

  534.       if ((x1 > (CIRCLE_XPOS(4) - CIRCLE_RADIUS)) &&
  535.           (x1 < (CIRCLE_XPOS(4) + CIRCLE_RADIUS)))
  536.       {
  537.         circleNr = 4;
  538.       }
  539.     }
  540.     else
  541.     {
  542.       if (((y1 < 220) && (y1 > 140)) &&
  543.           ((x1 < 160) && (x1 > 100)))
  544.       {
  545.         circleNr = 0xFE;   /* top part of the screen */
  546.       }
  547.       else
  548.       {
  549.         circleNr = 0xFF;
  550.       }
  551.     }
  552.   } /* of if(TS_State.TouchDetected) */
  553.   return circleNr;
  554. }

  555. /**
  556.   * @}
  557.   */

  558. /**
  559.   * @}
  560.   */


 楼主| 一路向北lm 发表于 2025-3-15 19:32 | 显示全部楼层
SD卡相关操作:
  1. /**
  2.   ******************************************************************************
  3.   * @file    sd.c
  4.   * @author  MCD Application Team
  5.   * @brief   This example code shows how to use the BSP SD Driver
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2024 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */

  18. /* Includes ------------------------------------------------------------------*/
  19. #include "main.h"

  20. /** @addtogroup STM32N6xx_HAL_Examples
  21.   * @{
  22.   */

  23. /** @addtogroup BSP
  24.   * @{
  25.   */

  26. /* Private typedef -----------------------------------------------------------*/
  27. /* Private define ------------------------------------------------------------*/
  28. #define SD_START_ADDRESS       ((uint32_t)0x00000400U)     /* SD Address to write/read data */
  29. #define NB_BLOCK_BUFFER        (BUFFER_SIZE*4) / BLOCKSIZE /* Number of Block (512b) by Buffer */
  30. #define BUFFER_SIZE            ((uint32_t)1024)            /* 16Ko */

  31. /* Private macro -------------------------------------------------------------*/
  32. /* Private variables ---------------------------------------------------------*/
  33. uint32_t aTxBuffer[BUFFER_SIZE];
  34. uint32_t aRxBuffer[BUFFER_SIZE];
  35. __IO uint32_t SDWriteStatus = 0, SDReadStatus = 0, SDDetectStatus = 0;

  36. /* Private function prototypes -----------------------------------------------*/
  37. static void SD_SetHint(void);
  38. static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset);
  39. static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint32_t BufferLength);
  40. /* Private functions ---------------------------------------------------------*/

  41. /**
  42.   * @brief  SD Demo
  43.   * @param  None
  44.   * @retval None
  45.   */
  46. void SD_Demo (void)
  47. {
  48.   int32_t SD_state;
  49.   uint32_t prev_status = 2;  /* Undefined state */

  50.   SD_SetHint();

  51.   SD_state = BSP_SD_Init(0);
  52.   BSP_SD_DetectITConfig(0);

  53.   UTIL_LCD_SetFont(&Font20);

  54.   if(SD_state != BSP_ERROR_NONE)
  55.   {
  56.     UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
  57.     if (SDDetectStatus == SD_NOT_PRESENT)
  58.     {
  59.       UTIL_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD CARD NOT DETECTED", LEFT_MODE);
  60.       UTIL_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD shall be inserted before running test", LEFT_MODE);
  61.       UTIL_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD Test Aborted", LEFT_MODE);
  62.     }
  63.     else
  64.     {
  65.       UTIL_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD INITIALIZATION : FAIL", LEFT_MODE);
  66.       UTIL_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD Test Aborted", LEFT_MODE);
  67.     }
  68.   }
  69.   else
  70.   {
  71.     UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_GREEN);
  72.     UTIL_LCD_DisplayStringAt(20, 100, (uint8_t *)"SD Initialization : OK", LEFT_MODE);
  73.     UTIL_LCD_DisplayStringAt(20, 300, (uint8_t *)"     SD Connected", RIGHT_MODE);
  74.     SDDetectStatus = SD_PRESENT;
  75.     prev_status = SD_PRESENT;

  76.     SD_state = BSP_SD_Erase(0,SD_START_ADDRESS, (SD_START_ADDRESS+BUFFER_SIZE));
  77.     while(BSP_SD_GetCardState(0) != SD_TRANSFER_OK)
  78.     {
  79.     }

  80.     if(SD_state != BSP_ERROR_NONE)
  81.     {
  82.       UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
  83.       UTIL_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD ERASE : FAILED", LEFT_MODE);
  84.       UTIL_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD Test Aborted", LEFT_MODE);
  85.     }
  86.     else
  87.     {
  88.       UTIL_LCD_DisplayStringAt(20, 115, (uint8_t *)"SD ERASE : OK", LEFT_MODE);

  89.       /* Fill the buffer to write */
  90.       Fill_Buffer(aTxBuffer, BUFFER_SIZE, 0x22FF);
  91.       SD_state = BSP_SD_WriteBlocks(0,(uint32_t *)aTxBuffer, SD_START_ADDRESS, NB_BLOCK_BUFFER);

  92.       if(SD_state != BSP_ERROR_NONE)
  93.       {
  94.         UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
  95.         UTIL_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD WRITE : FAILED", LEFT_MODE);
  96.         UTIL_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD Test Aborted", LEFT_MODE);
  97.       }
  98.       else
  99.       {
  100.         /* Wait until SD cards are ready to use for new operation */
  101.         while(BSP_SD_GetCardState(0) != SD_TRANSFER_OK)
  102.         {
  103.         }
  104.         UTIL_LCD_DisplayStringAt(20, 130, (uint8_t *)"SD WRITE : OK", LEFT_MODE);
  105.         SD_state = BSP_SD_ReadBlocks(0,(uint32_t *)aRxBuffer, SD_START_ADDRESS, NB_BLOCK_BUFFER);

  106.         /* Wait until SD cards are ready to use for new operation */
  107.         while(BSP_SD_GetCardState(0) != SD_TRANSFER_OK)
  108.         {
  109.         }
  110.         if(SD_state != BSP_ERROR_NONE)
  111.         {
  112.           UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
  113.           UTIL_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD READ : FAILED", LEFT_MODE);
  114.           UTIL_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD Test Aborted", LEFT_MODE);
  115.         }
  116.         else
  117.         {
  118.           UTIL_LCD_DisplayStringAt(20, 145, (uint8_t *)"SD READ : OK", LEFT_MODE);
  119.           if(Buffercmp(aTxBuffer, aRxBuffer, BUFFER_SIZE) > 0)
  120.           {
  121.             UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
  122.             UTIL_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD COMPARE : FAILED", LEFT_MODE);
  123.             UTIL_LCD_DisplayStringAt(20, 175, (uint8_t *)"SD Test Aborted", LEFT_MODE);
  124.           }
  125.           else
  126.           {
  127.             UTIL_LCD_DisplayStringAt(20, 160, (uint8_t *)"SD TEST : OK", LEFT_MODE);
  128.           }
  129.         }
  130.       }
  131.     }
  132.   }
  133.   UTIL_LCD_DisplayStringAt(20, 200, (uint8_t *)"SD Demo Done. Press the USR1 button to exit", CENTER_MODE);
  134.   while (1)
  135.   {

  136.     /* Check if the SD card is plugged in the slot */
  137.     if (SDDetectStatus != SD_PRESENT)
  138.     {
  139.       if (prev_status != SD_NOT_PRESENT)
  140.       {
  141.         prev_status = SD_NOT_PRESENT;
  142.         UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
  143.         UTIL_LCD_DisplayStringAt(20, 300, (uint8_t *)"SD NOT Connected", RIGHT_MODE);
  144.       }
  145.     }
  146.     else if (prev_status != SD_PRESENT)
  147.     {
  148.       UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_GREEN);
  149.       UTIL_LCD_DisplayStringAt(20, 300, (uint8_t *)"     SD Connected", RIGHT_MODE);
  150.       prev_status = SD_PRESENT;
  151.     }

  152.     if(CheckForUserInput() > 0)
  153.     {
  154.       ClearUserInput();
  155.       if(SDDetectStatus != SD_NOT_PRESENT)
  156.       {
  157.         BSP_SD_DeInit(0);
  158.       }
  159.       return;
  160.     }
  161.   }
  162. }


  163. /**
  164.   * @brief Tx Transfer completed callback
  165.   * @param  Instance SD Instance
  166.   * @retval None
  167.   */
  168. void BSP_SD_WriteCpltCallback(uint32_t Instance)
  169. {
  170.   SDWriteStatus = 1;

  171. }

  172. /**
  173.   * @brief Rx Transfer completed callback
  174.   * @param  Instance SD Instance
  175.   * @retval None
  176.   */
  177. void BSP_SD_ReadCpltCallback(uint32_t Instance)
  178. {
  179.   SDReadStatus = 1;
  180. }

  181. /**
  182.   * @brief  BSP SD Callback.
  183.   * @param  Instance SD Instance
  184.   * @param  Status   Pin status
  185.   * @retval None
  186.   */
  187. void BSP_SD_DetectCallback(uint32_t Instance, uint32_t Status)
  188. {
  189.   SDDetectStatus = Status;
  190. }

  191. /**
  192.   * @brief  Display SD Demo Hint
  193.   * @param  None
  194.   * @retval None
  195.   */
  196. static void SD_SetHint(void)
  197. {
  198.   uint32_t x_size, y_size;

  199.   BSP_LCD_GetXSize(0, &x_size);
  200.   BSP_LCD_GetYSize(0, &y_size);
  201.   /* Clear the LCD */
  202.   UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);

  203.   /* Set LCD Demo description */
  204.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_BLUE);
  205.   UTIL_LCD_FillRect(0, 0, x_size, 80, UTIL_LCD_COLOR_BLUE);
  206.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_WHITE);
  207.   UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_BLUE);
  208.   UTIL_LCD_SetFont(&Font24);
  209.   UTIL_LCD_DisplayStringAt(0, 0, (uint8_t *)"SD", CENTER_MODE);
  210.   UTIL_LCD_SetFont(&Font16);
  211.   UTIL_LCD_DisplayStringAt(0, 45, (uint8_t *)"This example shows how to detect the presence of the card", CENTER_MODE);
  212.   UTIL_LCD_DisplayStringAt(0, 60, (uint8_t *)"and how to write and read data on the microSD", CENTER_MODE);

  213.   /* Set the LCD Text Color */
  214.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_BLUE);
  215.   UTIL_LCD_DrawRect(10, 90, x_size - 20, y_size - 100, UTIL_LCD_COLOR_BLUE);
  216.   UTIL_LCD_DrawRect(11, 91, x_size - 22, y_size - 102, UTIL_LCD_COLOR_BLUE);

  217.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_BLACK);
  218.   UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
  219. }

  220. /**
  221.   * @brief  Fills buffer with user predefined data.
  222.   * @param  pBuffer: pointer on the buffer to fill
  223.   * @param  uwBufferLenght: size of the buffer to fill
  224.   * @param  uwOffset: first value to fill on the buffer
  225.   * @retval None
  226.   */
  227. static void Fill_Buffer(uint32_t *pBuffer, uint32_t uwBufferLenght, uint32_t uwOffset)
  228. {
  229.   uint32_t tmpIndex = 0;

  230.   /* Put in global buffer different values */
  231.   for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++ )
  232.   {
  233.     pBuffer[tmpIndex] = tmpIndex + uwOffset;
  234.   }
  235. }

  236. /**
  237.   * @brief  Compares two buffers.
  238.   * @param  pBuffer1, pBuffer2: buffers to be compared.
  239.   * @param  BufferLength: buffer's length
  240.   * @retval 1: pBuffer identical to pBuffer1
  241.   *         0: pBuffer differs from pBuffer1
  242.   */
  243. static uint8_t Buffercmp(uint32_t* pBuffer1, uint32_t* pBuffer2, uint32_t BufferLength)
  244. {
  245.   while (BufferLength--)
  246.   {
  247.     if (*pBuffer1 != *pBuffer2)
  248.     {
  249.       return 1;
  250.     }

  251.     pBuffer1++;
  252.     pBuffer2++;
  253.   }

  254.   return 0;
  255. }
  256. /**
  257.   * @}
  258.   */

  259. /**
  260.   * @}
  261.   */



zeshoufx 发表于 2025-4-16 14:32 | 显示全部楼层

这芯片和开发板价格怎么样
地瓜patch 发表于 2025-4-16 17:00 | 显示全部楼层
请教楼主,在板卡的demo程序中,点击下图中的AI命令,会调用摄像头么?摄像头会打开,还是需要刷入其他相关demo程序才能打开摄像头?
3026267ff715c2bae9.png
真的问题不大 发表于 2025-4-22 16:51 | 显示全部楼层
zeshoufx 发表于 2025-4-16 14:32
这芯片和开发板价格怎么样

同问一下
 楼主| 一路向北lm 发表于 2025-4-28 10:15 | 显示全部楼层
地瓜patch 发表于 2025-4-16 17:00
请教楼主,在板卡的demo程序中,点击下图中的AI命令,会调用摄像头么?摄像头会打开,还是需要刷入其他相关 ...

会打开摄像头的
地瓜patch 发表于 2025-4-28 10:53 | 显示全部楼层

我这边打不开摄像头,点AI黑屏,死机。需要拔掉type-c数据线。请问需要拨码么?

评论

请问你解决了吗,我也是这个问题  发表于 2025-7-4 21:57
Chenyudie 发表于 2025-7-4 21:49 | 显示全部楼层
请教楼主,接入摄像头的电源怎么接啊,为什么我摄像头接上后板子就启动不了了,接上前能启动,开始以为另一端接电脑供电不行,结果接手机充电线也不行,也下了STLink v3,但还是不行

评论

已解决  发表于 2025-7-4 21:52
您需要登录后才可以回帖 登录 | 注册

本版积分规则

293

主题

3837

帖子

81

粉丝
快速回复 在线客服 返回列表 返回顶部