main.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2025 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. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. /* Private includes ----------------------------------------------------------*/
  22. /* USER CODE BEGIN Includes */
  23. #include "ST7735.h"
  24. #include "GFX_FUNCTIONS.h"
  25. #include "stm32f4xx_hal.h"
  26. #include "string.h"
  27. #include <stdbool.h>
  28. #include <stdio.h>
  29. #include <math.h> // Не забудьте подключить библиотеку math.h
  30. extern unsigned short testImage[];
  31. /* USER CODE END Includes */
  32. /* Private typedef -----------------------------------------------------------*/
  33. /* USER CODE BEGIN PTD */
  34. #define LED_SCREEN1 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
  35. #define LED_SCREEN0 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
  36. #define RELAY_PIN1 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
  37. #define RELAY_PIN0 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
  38. #define MAX6675_CS1 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
  39. #define MAX6675_CS0 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
  40. #define Speak_CS1 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);
  41. #define Speak_CS0 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
  42. float Kp = 3.0;
  43. float Ki = 0.0;
  44. float Kd = 2.9;
  45. volatile uint16_t data3;
  46. volatile uint16_t data2 = 0;
  47. volatile uint16_t data4 = 100;
  48. volatile uint16_t data5;
  49. uint8_t data8[2];
  50. volatile bool encFlag = 1;
  51. float integral = 0;
  52. float last_error = 0;
  53. volatile int counter = 0;
  54. float last_output = 0.0;
  55. float second_last_output = 0.0;
  56. volatile bool oscillating = false;
  57. char buffer[100] = {0};
  58. char buffer1[100] = {0};
  59. char buffer3[10] = {0};
  60. volatile bool err1 = 0;
  61. uint8_t hours = 0;
  62. uint8_t minutes = 30;
  63. uint8_t seconds = 0;
  64. volatile bool speak_flag = 0;
  65. volatile bool speak_flag1 = 0;
  66. volatile bool timer_running = 0;
  67. float current_temperature;
  68. /* USER CODE END PTD */
  69. /* Private define ------------------------------------------------------------*/
  70. /* USER CODE BEGIN PD */
  71. /* USER CODE END PD */
  72. /* Private macro -------------------------------------------------------------*/
  73. /* USER CODE BEGIN PM */
  74. /* USER CODE END PM */
  75. /* Private variables ---------------------------------------------------------*/
  76. SPI_HandleTypeDef hspi1;
  77. SPI_HandleTypeDef hspi2;
  78. /* USER CODE BEGIN PV */
  79. /* USER CODE END PV */
  80. /* Private function prototypes -----------------------------------------------*/
  81. void SystemClock_Config(void);
  82. static void MX_GPIO_Init(void);
  83. static void MX_SPI1_Init(void);
  84. static void MX_SPI2_Init(void);
  85. /* USER CODE BEGIN PFP */
  86. /* USER CODE END PFP */
  87. /* Private user code ---------------------------------------------------------*/
  88. /* USER CODE BEGIN 0 */
  89. uint16_t ReadTemperature(void){
  90. MAX6675_CS0;
  91. HAL_SPI_Receive(&hspi2, data8, 2, 100);
  92. int16_t temp = ((data8[1] << 8) | data8[0]) >> 3;
  93. MAX6675_CS1;
  94. float temperature = (float)temp * 0.25;
  95. static float temp_filtered = 0;
  96. float alpha = 0.1;
  97. temp_filtered = (1 - alpha) * temp_filtered + alpha * temperature;
  98. return temp_filtered;
  99. }
  100. char buffer2[8] = {0};
  101. void IndicationERR1(){
  102. ST7735_SetRotation(1);
  103. fillRect(5, 93, 100, 19, WHITE);
  104. ST7735_SetRotation(1);
  105. ST7735_WriteString(50, 93, "ERR1", Font_11x18, RED, WHITE);
  106. err1 = 1;
  107. HAL_Delay(500);
  108. }
  109. void IndicationERR2(){
  110. ST7735_SetRotation(1);
  111. fillRect(5, 93, 100, 19, WHITE);
  112. ST7735_SetRotation(1);
  113. ST7735_WriteString(50, 93, "ERR2", Font_11x18, RED, WHITE);
  114. err1 = 1;
  115. HAL_Delay(500);
  116. //Buzzer_Peak();
  117. }
  118. void beep(void) {
  119. Speak_CS1;
  120. HAL_Delay(10);
  121. Speak_CS0;
  122. }
  123. void Speak_Stop(void) {
  124. Speak_CS1;
  125. HAL_Delay(700);
  126. Speak_CS0;
  127. HAL_Delay(300);
  128. Speak_CS1;
  129. HAL_Delay(700);
  130. Speak_CS0;
  131. HAL_Delay(300);
  132. Speak_CS1;
  133. HAL_Delay(700);
  134. Speak_CS0;
  135. }
  136. /* USER CODE END 0 */
  137. /**
  138. * @brief The application entry point.
  139. * @retval int
  140. */
  141. int main(void)
  142. {
  143. /* USER CODE BEGIN 1 */
  144. /* USER CODE END 1 */
  145. /* MCU Configuration--------------------------------------------------------*/
  146. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  147. HAL_Init();
  148. /* USER CODE BEGIN Init */
  149. /* USER CODE END Init */
  150. /* Configure the system clock */
  151. SystemClock_Config();
  152. /* USER CODE BEGIN SysInit */
  153. /* USER CODE END SysInit */
  154. /* Initialize all configured peripherals */
  155. MX_GPIO_Init();
  156. MX_SPI1_Init();
  157. MX_SPI2_Init();
  158. /* USER CODE BEGIN 2 */
  159. LED_SCREEN0;
  160. ST7735_Init(0);
  161. RELAY_PIN0;
  162. fillScreen(BLACK);
  163. HAL_Delay(200);
  164. LED_SCREEN1;
  165. ST7735_SetRotation(1);
  166. ST7735_SetBackgroundImage(0, 0, 160, 128, testImage);
  167. HAL_Delay(10000);
  168. ST7735_SetRotation(2);
  169. fillScreen(WHITE);
  170. ST7735_SetRotation(1);
  171. ST7735_FillRectangle(0, 0, 160, 24, RED);
  172. //HAL_Delay(300);
  173. ST7735_SetRotation(3);
  174. ST7735_FillRectangle(0, 0, 160, 15, WHITE);
  175. // HAL_Delay(300);
  176. ST7735_SetRotation(1);
  177. sprintf(buffer2, "TEK");
  178. ST7735_WriteString(20, 5, buffer2, Font_11x18, WHITE, RED);
  179. ST7735_SetRotation(1);
  180. ST7735_WriteString(110, 5, "YCT", Font_11x18, WHITE, RED);
  181. // HAL_Delay(100);
  182. //ST7735_SetRotation(1);
  183. //ST7735_WriteString(5, 117, "bitcom63.ru v1.2", Font_6x8, BLACK, WHITE);
  184. /* USER CODE END 2 */
  185. /* Infinite loop */
  186. /* USER CODE BEGIN WHILE */
  187. while (1)
  188. {
  189. /* USER CODE END WHILE */
  190. float current_temperature = ReadTemperature();
  191. data3 = ReadTemperature();
  192. sprintf(buffer, "%d ", data3);
  193. ST7735_SetRotation(1);
  194. ST7735_WriteString(10, 40, buffer, Font_16x26, RED, WHITE);
  195. HAL_Delay(100);
  196. if (encFlag) {
  197. data2 = counter;
  198. sprintf(buffer1, "%d ", data2);
  199. ST7735_SetRotation(1);
  200. ST7735_WriteString(100, 40, buffer1, Font_16x26, BLACK, WHITE);
  201. encFlag = 0;
  202. HAL_Delay(10);
  203. }
  204. sprintf(buffer3, "%02d:%02d:%02d ", hours, minutes, seconds);
  205. ST7735_SetRotation(1);
  206. ST7735_WriteString(10, 70, buffer3, Font_11x18, RED, WHITE);
  207. static uint32_t last_time4 = 0;
  208. //if (data3 < 2){
  209. // IndicationERR2();
  210. // timer_running = false;
  211. //hours=0;
  212. // minutes=0;
  213. //seconds =0;
  214. //RELAY_PIN0;
  215. // }else{timer_running=true;
  216. // err1 = 0;}
  217. if (timer_running == true && err1 == 0) {
  218. /* USER CODE END WHILE */
  219. if (counter > 0){
  220. if (data3 > counter + 100){
  221. IndicationERR1();
  222. err1= 1;
  223. timer_running = false;
  224. RELAY_PIN0;
  225. hours=0;
  226. minutes=0;
  227. seconds =0;
  228. }else{timer_running=true;
  229. err1 = 0;}
  230. }
  231. float error = counter - current_temperature;
  232. float P = Kp * error;
  233. integral += error;
  234. float I = Ki * integral;
  235. float D = Kd * (error - last_error);
  236. last_error = error;
  237. float output = P + I + D;
  238. if (output > 0) {
  239. // if (err1 = 0){
  240. RELAY_PIN1;
  241. err1 = 0;
  242. ST7735_SetRotation(1);
  243. ST7735_WriteString(5, 93, "HAGPEB", Font_11x18, RED, WHITE);
  244. // }
  245. } else {
  246. RELAY_PIN0;
  247. //err1 = 1;
  248. ST7735_SetRotation(1);
  249. fillRect(5, 93, 100, 19, WHITE);
  250. }
  251. if (hours == 0 && minutes == 0 && seconds == 0) {
  252. timer_running = false; // Остановить таймер
  253. fillRect(5, 93, 100, 19, WHITE);
  254. Speak_Stop();
  255. } else {
  256. if (HAL_GetTick() - last_time4 >= 900) { // Каждые 100 мс
  257. last_time4 = HAL_GetTick();
  258. if (seconds == 0 && err1 ==0) {
  259. if (minutes == 0) {
  260. if (hours > 0) {
  261. hours--;
  262. minutes = 59; // Сбрасываем минуты на 59
  263. seconds = 59; // Сбрасываем секунды на 59
  264. }
  265. } else {
  266. minutes--;
  267. seconds = 59; // Сбрасываем секунды на 59
  268. }
  269. } else {
  270. seconds--; // Уменьшаем секунды
  271. }
  272. }
  273. }
  274. }else {
  275. RELAY_PIN0;
  276. ST7735_SetRotation(1);
  277. fillRect(5, 93, 100, 19, WHITE);
  278. }
  279. if(counter<=5 && timer_running==true){
  280. timer_running=false;
  281. hours=0;
  282. minutes=0;
  283. seconds =0;
  284. Speak_Stop();
  285. }
  286. if (hours == 0 && minutes == 10 && seconds == 0) {
  287. Speak_CS1;
  288. HAL_Delay(500);
  289. Speak_CS0;
  290. }
  291. if (hours == 0 && minutes == 5 && seconds == 0) {
  292. Speak_CS1;
  293. HAL_Delay(500);
  294. Speak_CS0;
  295. Speak_CS1;
  296. HAL_Delay(500);
  297. Speak_CS0;
  298. }
  299. if (speak_flag) {
  300. HAL_Delay(100);
  301. Speak_CS1;
  302. HAL_Delay(700); // Здесь можно использовать задержку, так как это не блокирует прерывание
  303. Speak_CS0;
  304. speak_flag = 0; // Сбросить флаг
  305. }
  306. if (speak_flag1) {
  307. Speak_CS1;
  308. HAL_Delay(100);
  309. Speak_CS0;
  310. speak_flag1 = 0;
  311. }
  312. HAL_Delay(100);
  313. /* USER CODE BEGIN 3 */
  314. // testAll();
  315. }
  316. //HAL_Delay(100);
  317. /* USER CODE END 3 */
  318. }
  319. void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
  320. static uint32_t last_interrupt_time = 0;
  321. uint32_t current_time = HAL_GetTick();
  322. static uint32_t last_interrupt_time1 = 0;
  323. uint32_t current_time1 = HAL_GetTick();
  324. if (GPIO_Pin == BTN__Pin) {
  325. if (timer_running == 0){
  326. if (current_time - last_interrupt_time > 250) {
  327. if (counter - 5 >= 0) {
  328. //Buzzer_Peak();
  329. counter -= 5;
  330. encFlag = 1;
  331. speak_flag1 = 1;
  332. }
  333. }
  334. }
  335. }
  336. else if (GPIO_Pin == BTN_A11_Pin) {
  337. if (timer_running == 0){
  338. if (current_time - last_interrupt_time > 250) {
  339. if (counter + 5 <= 200) {
  340. counter += 5;
  341. encFlag = 1;
  342. speak_flag1 = 1;
  343. // Buzzer_Peak();
  344. }
  345. }
  346. }
  347. }
  348. else if (GPIO_Pin == BTN_S_S_Pin) {
  349. if (timer_running == 0){
  350. if (current_time1 - last_interrupt_time1 > 250) {
  351. if (minutes < 1440) {
  352. speak_flag1 = 1;// Максимальное время 30 минут
  353. if (minutes > 29) {
  354. hours++;
  355. minutes = 0;
  356. seconds = 0;
  357. } else {
  358. minutes +=30;
  359. }
  360. }
  361. if (hours==24 && minutes>0){
  362. hours=0;
  363. minutes = 0;
  364. seconds = 0;
  365. }
  366. }
  367. }
  368. }
  369. else if (GPIO_Pin == BTN_T_Pin && counter>5) { // Замените на ваш пин
  370. if (current_time - last_interrupt_time > 250) {
  371. timer_running = !timer_running; // Переключить состояние таймера
  372. speak_flag = 1;
  373. }
  374. }
  375. last_interrupt_time = current_time;
  376. last_interrupt_time1 = current_time1;
  377. }
  378. void EXTI9_5_IRQHandler(void)
  379. {
  380. /* USER CODE BEGIN EXTI9_5_IRQn 0 */
  381. /* USER CODE END EXTI9_5_IRQn 0 */
  382. HAL_GPIO_EXTI_IRQHandler(BTN_T_Pin);
  383. /* USER CODE BEGIN EXTI9_5_IRQn 1 */
  384. /* USER CODE END EXTI9_5_IRQn 1 */
  385. }
  386. /**
  387. * @brief This function handles EXTI line[15:10] interrupts.
  388. */
  389. void EXTI15_10_IRQHandler(void)
  390. {
  391. /* USER CODE BEGIN EXTI15_10_IRQn 0 */
  392. /* USER CODE END EXTI15_10_IRQn 0 */
  393. HAL_GPIO_EXTI_IRQHandler(BTN__Pin);
  394. HAL_GPIO_EXTI_IRQHandler(BTN_A11_Pin);
  395. HAL_GPIO_EXTI_IRQHandler(BTN_S_S_Pin);
  396. /* USER CODE BEGIN EXTI15_10_IRQn 1 */
  397. /* USER CODE END EXTI15_10_IRQn 1 */
  398. }
  399. /**
  400. * @brief System Clock Configuration
  401. * @retval None
  402. */
  403. void SystemClock_Config(void)
  404. {
  405. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  406. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  407. /** Configure the main internal regulator output voltage
  408. */
  409. __HAL_RCC_PWR_CLK_ENABLE();
  410. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
  411. /** Initializes the RCC Oscillators according to the specified parameters
  412. * in the RCC_OscInitTypeDef structure.
  413. */
  414. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  415. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  416. RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  417. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  418. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  419. RCC_OscInitStruct.PLL.PLLM = 8;
  420. RCC_OscInitStruct.PLL.PLLN = 84;
  421. RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  422. RCC_OscInitStruct.PLL.PLLQ = 4;
  423. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  424. {
  425. Error_Handler();
  426. }
  427. /** Initializes the CPU, AHB and APB buses clocks
  428. */
  429. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  430. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  431. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  432. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  433. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  434. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  435. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  436. {
  437. Error_Handler();
  438. }
  439. }
  440. /**
  441. * @brief SPI1 Initialization Function
  442. * @param None
  443. * @retval None
  444. */
  445. static void MX_SPI1_Init(void)
  446. {
  447. /* USER CODE BEGIN SPI1_Init 0 */
  448. /* USER CODE END SPI1_Init 0 */
  449. /* USER CODE BEGIN SPI1_Init 1 */
  450. /* USER CODE END SPI1_Init 1 */
  451. /* SPI1 parameter configuration*/
  452. hspi1.Instance = SPI1;
  453. hspi1.Init.Mode = SPI_MODE_MASTER;
  454. hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  455. hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  456. hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  457. hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  458. hspi1.Init.NSS = SPI_NSS_SOFT;
  459. hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
  460. hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  461. hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  462. hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  463. hspi1.Init.CRCPolynomial = 10;
  464. if (HAL_SPI_Init(&hspi1) != HAL_OK)
  465. {
  466. Error_Handler();
  467. }
  468. /* USER CODE BEGIN SPI1_Init 2 */
  469. /* USER CODE END SPI1_Init 2 */
  470. }
  471. /**
  472. * @brief SPI2 Initialization Function
  473. * @param None
  474. * @retval None
  475. */
  476. static void MX_SPI2_Init(void)
  477. {
  478. /* USER CODE BEGIN SPI2_Init 0 */
  479. /* USER CODE END SPI2_Init 0 */
  480. /* USER CODE BEGIN SPI2_Init 1 */
  481. /* USER CODE END SPI2_Init 1 */
  482. /* SPI2 parameter configuration*/
  483. hspi2.Instance = SPI2;
  484. hspi2.Init.Mode = SPI_MODE_MASTER;
  485. hspi2.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;
  486. hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  487. hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  488. hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  489. hspi2.Init.NSS = SPI_NSS_SOFT;
  490. hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
  491. hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  492. hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  493. hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  494. hspi2.Init.CRCPolynomial = 10;
  495. if (HAL_SPI_Init(&hspi2) != HAL_OK)
  496. {
  497. Error_Handler();
  498. }
  499. /* USER CODE BEGIN SPI2_Init 2 */
  500. /* USER CODE END SPI2_Init 2 */
  501. }
  502. /* USER CODE BEGIN SPI2_Init 2 */
  503. /* USER CODE END SPI2_Init 2 */
  504. /**
  505. * @brief GPIO Initialization Function
  506. * @param None
  507. * @retval None
  508. */
  509. static void MX_GPIO_Init(void)
  510. {
  511. GPIO_InitTypeDef GPIO_InitStruct = {0};
  512. /* USER CODE BEGIN MX_GPIO_Init_1 */
  513. /* USER CODE END MX_GPIO_Init_1 */
  514. /* GPIO Ports Clock Enable */
  515. __HAL_RCC_GPIOC_CLK_ENABLE();
  516. __HAL_RCC_GPIOH_CLK_ENABLE();
  517. __HAL_RCC_GPIOA_CLK_ENABLE();
  518. __HAL_RCC_GPIOB_CLK_ENABLE();
  519. /*Configure GPIO pin Output Level */
  520. HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET);
  521. /*Configure GPIO pin Output Level */
  522. HAL_GPIO_WritePin(SPI1_LED_GPIO_Port, SPI1_LED_Pin, GPIO_PIN_RESET);
  523. /*Configure GPIO pin Output Level */
  524. HAL_GPIO_WritePin(GPIOB, SPI1_DC_Pin|SPI1_CS_Pin|SP1_RESET_Pin|SPI2_CS_Pin
  525. |SPEAK_Pin|GPIO_PIN_14, GPIO_PIN_RESET);
  526. /*Configure GPIO pin : PC15 */
  527. GPIO_InitStruct.Pin = GPIO_PIN_15;
  528. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  529. GPIO_InitStruct.Pull = GPIO_PULLUP;
  530. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  531. HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  532. /*Configure GPIO pin : SPI1_LED_Pin */
  533. GPIO_InitStruct.Pin = SPI1_LED_Pin;
  534. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  535. GPIO_InitStruct.Pull = GPIO_PULLUP;
  536. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  537. HAL_GPIO_Init(SPI1_LED_GPIO_Port, &GPIO_InitStruct);
  538. /*Configure GPIO pins : SPI1_DC_Pin SPI1_CS_Pin SP1_RESET_Pin SPI2_CS_Pin */
  539. GPIO_InitStruct.Pin = SPI1_DC_Pin|SPI1_CS_Pin|SP1_RESET_Pin|SPI2_CS_Pin;
  540. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  541. GPIO_InitStruct.Pull = GPIO_NOPULL;
  542. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  543. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  544. /*Configure GPIO pins : SPEAK_Pin PB14 */
  545. GPIO_InitStruct.Pin = SPEAK_Pin|GPIO_PIN_14;
  546. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  547. GPIO_InitStruct.Pull = GPIO_PULLUP;
  548. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  549. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  550. /*Configure GPIO pins : BTN_T_Pin BTN__Pin BTN_A11_Pin BTN_S_S_Pin */
  551. GPIO_InitStruct.Pin = BTN_T_Pin|BTN__Pin|BTN_A11_Pin|BTN_S_S_Pin;
  552. GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  553. GPIO_InitStruct.Pull = GPIO_PULLUP;
  554. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  555. /* EXTI interrupt init*/
  556. HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
  557. HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
  558. HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
  559. HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
  560. /* USER CODE BEGIN MX_GPIO_Init_2 */
  561. /* USER CODE END MX_GPIO_Init_2 */
  562. }
  563. /* USER CODE BEGIN 4 */
  564. /* USER CODE END 4 */
  565. /**
  566. * @brief This function is executed in case of error occurrence.
  567. * @retval None
  568. */
  569. void Error_Handler(void)
  570. {
  571. /* USER CODE BEGIN Error_Handler_Debug */
  572. /* User can add his own implementation to report the HAL error return state */
  573. __disable_irq();
  574. while (1)
  575. {
  576. }
  577. /* USER CODE END Error_Handler_Debug */
  578. }
  579. #ifdef USE_FULL_ASSERT
  580. /**
  581. * @brief Reports the name of the source file and the source line number
  582. * where the assert_param error has occurred.
  583. * @param file: pointer to the source file name
  584. * @param line: assert_param error line source number
  585. * @retval None
  586. */
  587. void assert_failed(uint8_t *file, uint32_t line)
  588. {
  589. /* USER CODE BEGIN 6 */
  590. /* User can add his own implementation to report the file name and line number,
  591. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  592. /* USER CODE END 6 */
  593. }
  594. #endif /* USE_FULL_ASSERT */