main.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.c
  5. * @brief : Main program body
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "main.h"
  22. /* Private includes ----------------------------------------------------------*/
  23. /* USER CODE BEGIN Includes */
  24. /* USER CODE END Includes */
  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN PTD */
  27. typedef enum {
  28. Tube_A = 0,
  29. Tube_B = 1,
  30. Tube_D = 2,
  31. Tube_E = 3
  32. } tube_pos_t;
  33. /* USER CODE END PTD */
  34. /* Private define ------------------------------------------------------------*/
  35. /* USER CODE BEGIN PD */
  36. /* USER CODE END PD */
  37. /* Private macro -------------------------------------------------------------*/
  38. /* USER CODE BEGIN PM */
  39. #define SPI_BUFFER_SIZE 5
  40. /* USER CODE END PM */
  41. /* Private variables ---------------------------------------------------------*/
  42. /* USER CODE BEGIN PV */
  43. static LL_RCC_ClocksTypeDef rcc_clocks;
  44. /**
  45. * Nixi Tube cathodes map:
  46. * {A1 A2 A3 A4 A5 A6 A7 A8}
  47. * {A9 A0 B1 B2 B3 B4 B5 B6}
  48. * {B7 B8 B9 B0 D1 D2 D3 D4}
  49. * {D5 D6 D7 D8 D9 D0 E1 E2}
  50. * {E3 E4 E5 E6 E7 E8 E9 E0}
  51. */
  52. static const uint16_t nixieCathodeMap[4][10] = {
  53. {0x0200, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100},
  54. {0x0800, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400},
  55. {0x2000, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000},
  56. {0x8000, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000}
  57. };
  58. static const uint8_t nixieCathodeMask[4][2] = {{0xff, 0x03}, {0xfc, 0x0f}, {0xf0, 0x3f}, {0xc0, 0xff}};
  59. static uint8_t nixieTubes[SPI_BUFFER_SIZE];
  60. /* USER CODE END PV */
  61. /* Private function prototypes -----------------------------------------------*/
  62. void SystemClock_Config(void);
  63. static void MX_GPIO_Init(void);
  64. static void MX_DMA_Init(void);
  65. static void MX_I2C1_Init(void);
  66. static void MX_SPI1_Init(void);
  67. static void MX_TIM3_Init(void);
  68. static void MX_TIM14_Init(void);
  69. static void MX_TIM16_Init(void);
  70. static void MX_TIM17_Init(void);
  71. /* USER CODE BEGIN PFP */
  72. static void showDigit(tube_pos_t pos, uint8_t dig);
  73. /* USER CODE END PFP */
  74. /* Private user code ---------------------------------------------------------*/
  75. /* USER CODE BEGIN 0 */
  76. /* USER CODE END 0 */
  77. /**
  78. * @brief The application entry point.
  79. * @retval int
  80. */
  81. int main(void)
  82. {
  83. /* USER CODE BEGIN 1 */
  84. /* USER CODE END 1 */
  85. /* MCU Configuration--------------------------------------------------------*/
  86. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  87. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
  88. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
  89. /* System interrupt init*/
  90. /* Peripheral interrupt init*/
  91. /* RCC_IRQn interrupt configuration */
  92. NVIC_SetPriority(RCC_IRQn, 0);
  93. NVIC_EnableIRQ(RCC_IRQn);
  94. /* USER CODE BEGIN Init */
  95. /* USER CODE END Init */
  96. /* Configure the system clock */
  97. SystemClock_Config();
  98. /* USER CODE BEGIN SysInit */
  99. LL_LPM_EnableSleep();
  100. LL_LPM_DisableSleepOnExit();
  101. LL_RCC_GetSystemClocksFreq(&rcc_clocks);
  102. /* USER CODE END SysInit */
  103. /* Initialize all configured peripherals */
  104. MX_GPIO_Init();
  105. MX_DMA_Init();
  106. MX_I2C1_Init();
  107. MX_SPI1_Init();
  108. MX_TIM3_Init();
  109. MX_TIM14_Init();
  110. MX_TIM16_Init();
  111. MX_TIM17_Init();
  112. /* USER CODE BEGIN 2 */
  113. //LL_Init1msTick(rcc_clocks.HCLK_Frequency);
  114. //LL_mDelay(1);
  115. /* Start RGB PWM */
  116. LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH1);
  117. LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH2);
  118. LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH3);
  119. LL_TIM_EnableCounter(TIM3);
  120. /* Start Tube PWR PWM */
  121. LL_TIM_CC_EnableChannel(TIM14, LL_TIM_CHANNEL_CH1);
  122. LL_TIM_EnableCounter(TIM14);
  123. /* Enable tube power */
  124. TUBE_PWR_ON;
  125. // manual dma start sample
  126. /* Set DMA transfer addresses of source and destination */
  127. //LL_DMA_ConfigAddresses(DMA1,
  128. // LL_DMA_CHANNEL_1,
  129. // (uint32_t)&nixieTubes,
  130. // (uint32_t)&(SPI1->DR),
  131. // LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
  132. /* Set DMA transfer size */
  133. //LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, SPI_BUFFER_SIZE);
  134. /* Enable DMA transfer complete/error interrupts */
  135. //LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
  136. //LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
  137. showDigit(Tube_A, 1);
  138. showDigit(Tube_B, 2);
  139. showDigit(Tube_D, 3);
  140. showDigit(Tube_E, 4);
  141. /* Start the DMA transfer from Memory to SPI1 */
  142. //LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
  143. /* Start SPI */
  144. //LL_SPI_EnableIT_ERR(SPI1);
  145. //LL_SPI_EnableIT_RXNE(SPI1);
  146. //LL_SPI_EnableDMAReq_TX(SPI1);
  147. LL_SPI_Enable(SPI1);
  148. LATCH_DOWN;
  149. while ((SPI1->SR & SPI_SR_TXE) == 0);
  150. SPI1->DR = nixieTubes[0];
  151. while ((SPI1->SR & SPI_SR_TXE) == 0);
  152. SPI1->DR = nixieTubes[1];
  153. while ((SPI1->SR & SPI_SR_TXE) == 0);
  154. SPI1->DR = nixieTubes[2];
  155. while ((SPI1->SR & SPI_SR_TXE) == 0);
  156. SPI1->DR = nixieTubes[3];
  157. while ((SPI1->SR & SPI_SR_TXE) == 0);
  158. SPI1->DR = nixieTubes[4];
  159. while ((SPI1->SR & SPI_SR_FTLVL) != 0);
  160. while ((SPI1->SR & SPI_SR_BSY) != 0);
  161. LATCH_UP;
  162. // COLOR_R(0);
  163. // COLOR_G(0);
  164. // COLOR_B(0);
  165. /* USER CODE END 2 */
  166. /* Infinite loop */
  167. /* USER CODE BEGIN WHILE */
  168. while (1)
  169. {
  170. IN15_OFF;
  171. IN15_Plus;
  172. COLOR_RGB(20, 20, 20);
  173. LL_mDelay(500);
  174. IN15_OFF;
  175. IN15_Minus;
  176. COLOR_RGB(40, 40, 40);
  177. LL_mDelay(500);
  178. IN15_OFF;
  179. IN15_Percent;
  180. COLOR_RGB(60, 60, 60);
  181. LL_mDelay(500);
  182. IN15_OFF;
  183. IN15_P;
  184. COLOR_RGB(80, 80, 80);
  185. LL_mDelay(500);
  186. /* USER CODE END WHILE */
  187. /* USER CODE BEGIN 3 */
  188. LATCH_DOWN;
  189. while ((SPI1->SR & SPI_SR_TXE) == 0);
  190. SPI1->DR = nixieTubes[0];
  191. while ((SPI1->SR & SPI_SR_TXE) == 0);
  192. SPI1->DR = nixieTubes[1];
  193. while ((SPI1->SR & SPI_SR_TXE) == 0);
  194. SPI1->DR = nixieTubes[2];
  195. while ((SPI1->SR & SPI_SR_TXE) == 0);
  196. SPI1->DR = nixieTubes[3];
  197. while ((SPI1->SR & SPI_SR_TXE) == 0);
  198. SPI1->DR = nixieTubes[4];
  199. while ((SPI1->SR & SPI_SR_FTLVL) != 0);
  200. while ((SPI1->SR & SPI_SR_BSY) != 0);
  201. LL_mDelay(1);
  202. LATCH_UP;
  203. //__WFI();
  204. }
  205. /* USER CODE END 3 */
  206. }
  207. /**
  208. * @brief System Clock Configuration
  209. * @retval None
  210. */
  211. void SystemClock_Config(void)
  212. {
  213. /* HSI configuration and activation */
  214. LL_RCC_HSI_Enable();
  215. while(LL_RCC_HSI_IsReady() != 1)
  216. {
  217. }
  218. /* Main PLL configuration and activation */
  219. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_2, 9, LL_RCC_PLLR_DIV_3);
  220. LL_RCC_PLL_Enable();
  221. LL_RCC_PLL_EnableDomain_SYS();
  222. while(LL_RCC_PLL_IsReady() != 1)
  223. {
  224. }
  225. /* Set AHB prescaler*/
  226. LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  227. /* Sysclk activation on the main PLL */
  228. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  229. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  230. {
  231. }
  232. /* Set APB1 prescaler*/
  233. LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  234. LL_Init1msTick(24000000);
  235. /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
  236. LL_SetSystemCoreClock(24000000);
  237. LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_HSI);
  238. }
  239. /**
  240. * @brief I2C1 Initialization Function
  241. * @param None
  242. * @retval None
  243. */
  244. static void MX_I2C1_Init(void)
  245. {
  246. /* USER CODE BEGIN I2C1_Init 0 */
  247. /* USER CODE END I2C1_Init 0 */
  248. LL_I2C_InitTypeDef I2C_InitStruct = {0};
  249. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  250. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  251. /**I2C1 GPIO Configuration
  252. PB6 ------> I2C1_SCL
  253. PB7 ------> I2C1_SDA
  254. */
  255. GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
  256. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  257. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  258. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  259. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  260. GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
  261. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  262. GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
  263. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  264. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  265. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  266. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  267. GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
  268. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  269. /* Peripheral clock enable */
  270. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
  271. /* I2C1 DMA Init */
  272. /* I2C1_RX Init */
  273. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_2, LL_DMAMUX_REQ_I2C1_RX);
  274. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_2, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
  275. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PRIORITY_MEDIUM);
  276. LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MODE_CIRCULAR);
  277. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PERIPH_NOINCREMENT);
  278. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MEMORY_INCREMENT);
  279. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PDATAALIGN_BYTE);
  280. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MDATAALIGN_BYTE);
  281. /* I2C1_TX Init */
  282. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_3, LL_DMAMUX_REQ_I2C1_TX);
  283. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_3, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
  284. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PRIORITY_MEDIUM);
  285. LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MODE_CIRCULAR);
  286. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PERIPH_NOINCREMENT);
  287. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MEMORY_INCREMENT);
  288. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PDATAALIGN_BYTE);
  289. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MDATAALIGN_BYTE);
  290. /* USER CODE BEGIN I2C1_Init 1 */
  291. /* USER CODE END I2C1_Init 1 */
  292. /** I2C Initialization
  293. */
  294. I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
  295. I2C_InitStruct.Timing = 0x0010061A;
  296. I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE;
  297. I2C_InitStruct.DigitalFilter = 0;
  298. I2C_InitStruct.OwnAddress1 = 0;
  299. I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
  300. I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
  301. LL_I2C_Init(I2C1, &I2C_InitStruct);
  302. LL_I2C_EnableAutoEndMode(I2C1);
  303. LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK);
  304. LL_I2C_DisableOwnAddress2(I2C1);
  305. LL_I2C_DisableGeneralCall(I2C1);
  306. LL_I2C_EnableClockStretching(I2C1);
  307. /* USER CODE BEGIN I2C1_Init 2 */
  308. /* USER CODE END I2C1_Init 2 */
  309. }
  310. /**
  311. * @brief SPI1 Initialization Function
  312. * @param None
  313. * @retval None
  314. */
  315. static void MX_SPI1_Init(void)
  316. {
  317. /* USER CODE BEGIN SPI1_Init 0 */
  318. /* USER CODE END SPI1_Init 0 */
  319. LL_SPI_InitTypeDef SPI_InitStruct = {0};
  320. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  321. /* Peripheral clock enable */
  322. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
  323. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  324. /**SPI1 GPIO Configuration
  325. PB3 ------> SPI1_SCK
  326. PB5 ------> SPI1_MOSI
  327. */
  328. GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
  329. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  330. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  331. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  332. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  333. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  334. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  335. GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
  336. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  337. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  338. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  339. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  340. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  341. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  342. /* SPI1 DMA Init */
  343. /* SPI1_TX Init */
  344. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_SPI1_TX);
  345. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
  346. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_HIGH);
  347. LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR);
  348. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT);
  349. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT);
  350. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_BYTE);
  351. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_BYTE);
  352. /* SPI1 interrupt Init */
  353. NVIC_SetPriority(SPI1_IRQn, 0);
  354. NVIC_EnableIRQ(SPI1_IRQn);
  355. /* USER CODE BEGIN SPI1_Init 1 */
  356. /* USER CODE END SPI1_Init 1 */
  357. /* SPI1 parameter configuration*/
  358. SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
  359. SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
  360. SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
  361. SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
  362. SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
  363. SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
  364. SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
  365. SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
  366. SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
  367. SPI_InitStruct.CRCPoly = 7;
  368. LL_SPI_Init(SPI1, &SPI_InitStruct);
  369. LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
  370. LL_SPI_DisableNSSPulseMgt(SPI1);
  371. /* USER CODE BEGIN SPI1_Init 2 */
  372. /* USER CODE END SPI1_Init 2 */
  373. }
  374. /**
  375. * @brief TIM3 Initialization Function
  376. * @param None
  377. * @retval None
  378. */
  379. static void MX_TIM3_Init(void)
  380. {
  381. /* USER CODE BEGIN TIM3_Init 0 */
  382. /* USER CODE END TIM3_Init 0 */
  383. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  384. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  385. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  386. /* Peripheral clock enable */
  387. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
  388. /* USER CODE BEGIN TIM3_Init 1 */
  389. /* USER CODE END TIM3_Init 1 */
  390. TIM_InitStruct.Prescaler = 24;
  391. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  392. TIM_InitStruct.Autoreload = 1000;
  393. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  394. LL_TIM_Init(TIM3, &TIM_InitStruct);
  395. LL_TIM_EnableARRPreload(TIM3);
  396. LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH1);
  397. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  398. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  399. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  400. TIM_OC_InitStruct.CompareValue = 100;
  401. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  402. LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  403. LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH1);
  404. LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH2);
  405. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  406. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  407. LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
  408. LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH2);
  409. LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH3);
  410. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  411. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  412. LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
  413. LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH3);
  414. LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
  415. LL_TIM_DisableMasterSlaveMode(TIM3);
  416. /* USER CODE BEGIN TIM3_Init 2 */
  417. /* USER CODE END TIM3_Init 2 */
  418. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
  419. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  420. /**TIM3 GPIO Configuration
  421. PA6 ------> TIM3_CH1
  422. PA7 ------> TIM3_CH2
  423. PB0 ------> TIM3_CH3
  424. */
  425. GPIO_InitStruct.Pin = PWM_R_Pin;
  426. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  427. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  428. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  429. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  430. GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  431. LL_GPIO_Init(PWM_R_GPIO_Port, &GPIO_InitStruct);
  432. GPIO_InitStruct.Pin = PWM_G_Pin;
  433. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  434. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  435. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  436. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  437. GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  438. LL_GPIO_Init(PWM_G_GPIO_Port, &GPIO_InitStruct);
  439. GPIO_InitStruct.Pin = PWM_B_Pin;
  440. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  441. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  442. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  443. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  444. GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  445. LL_GPIO_Init(PWM_B_GPIO_Port, &GPIO_InitStruct);
  446. }
  447. /**
  448. * @brief TIM14 Initialization Function
  449. * @param None
  450. * @retval None
  451. */
  452. static void MX_TIM14_Init(void)
  453. {
  454. /* USER CODE BEGIN TIM14_Init 0 */
  455. /* USER CODE END TIM14_Init 0 */
  456. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  457. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  458. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  459. /* Peripheral clock enable */
  460. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM14);
  461. /* TIM14 interrupt Init */
  462. NVIC_SetPriority(TIM14_IRQn, 0);
  463. NVIC_EnableIRQ(TIM14_IRQn);
  464. /* USER CODE BEGIN TIM14_Init 1 */
  465. /* USER CODE END TIM14_Init 1 */
  466. TIM_InitStruct.Prescaler = 240;
  467. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  468. TIM_InitStruct.Autoreload = 1000;
  469. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  470. LL_TIM_Init(TIM14, &TIM_InitStruct);
  471. LL_TIM_EnableARRPreload(TIM14);
  472. LL_TIM_OC_EnablePreload(TIM14, LL_TIM_CHANNEL_CH1);
  473. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  474. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  475. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  476. TIM_OC_InitStruct.CompareValue = 750;
  477. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  478. LL_TIM_OC_Init(TIM14, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  479. LL_TIM_OC_DisableFast(TIM14, LL_TIM_CHANNEL_CH1);
  480. /* USER CODE BEGIN TIM14_Init 2 */
  481. /* USER CODE END TIM14_Init 2 */
  482. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  483. /**TIM14 GPIO Configuration
  484. PB1 ------> TIM14_CH1
  485. */
  486. GPIO_InitStruct.Pin = PWM_T_Pin;
  487. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  488. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  489. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  490. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  491. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  492. LL_GPIO_Init(PWM_T_GPIO_Port, &GPIO_InitStruct);
  493. }
  494. /**
  495. * @brief TIM16 Initialization Function
  496. * @param None
  497. * @retval None
  498. */
  499. static void MX_TIM16_Init(void)
  500. {
  501. /* USER CODE BEGIN TIM16_Init 0 */
  502. /* USER CODE END TIM16_Init 0 */
  503. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  504. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  505. LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0};
  506. /* Peripheral clock enable */
  507. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM16);
  508. /* TIM16 interrupt Init */
  509. NVIC_SetPriority(TIM16_IRQn, 0);
  510. NVIC_EnableIRQ(TIM16_IRQn);
  511. /* USER CODE BEGIN TIM16_Init 1 */
  512. /* USER CODE END TIM16_Init 1 */
  513. TIM_InitStruct.Prescaler = 24;
  514. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  515. TIM_InitStruct.Autoreload = 1000;
  516. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  517. TIM_InitStruct.RepetitionCounter = 0;
  518. LL_TIM_Init(TIM16, &TIM_InitStruct);
  519. LL_TIM_EnableARRPreload(TIM16);
  520. LL_TIM_OC_EnablePreload(TIM16, LL_TIM_CHANNEL_CH1);
  521. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  522. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  523. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  524. TIM_OC_InitStruct.CompareValue = 0;
  525. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  526. TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
  527. TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
  528. TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
  529. LL_TIM_OC_Init(TIM16, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  530. LL_TIM_OC_DisableFast(TIM16, LL_TIM_CHANNEL_CH1);
  531. TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE;
  532. TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE;
  533. TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF;
  534. TIM_BDTRInitStruct.DeadTime = 0;
  535. TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE;
  536. TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH;
  537. TIM_BDTRInitStruct.BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
  538. TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
  539. LL_TIM_BDTR_Init(TIM16, &TIM_BDTRInitStruct);
  540. /* USER CODE BEGIN TIM16_Init 2 */
  541. /* USER CODE END TIM16_Init 2 */
  542. }
  543. /**
  544. * @brief TIM17 Initialization Function
  545. * @param None
  546. * @retval None
  547. */
  548. static void MX_TIM17_Init(void)
  549. {
  550. /* USER CODE BEGIN TIM17_Init 0 */
  551. /* USER CODE END TIM17_Init 0 */
  552. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  553. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  554. LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0};
  555. /* Peripheral clock enable */
  556. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM17);
  557. /* TIM17 interrupt Init */
  558. NVIC_SetPriority(TIM17_IRQn, 0);
  559. NVIC_EnableIRQ(TIM17_IRQn);
  560. /* USER CODE BEGIN TIM17_Init 1 */
  561. /* USER CODE END TIM17_Init 1 */
  562. TIM_InitStruct.Prescaler = 240;
  563. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  564. TIM_InitStruct.Autoreload = 1000;
  565. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  566. TIM_InitStruct.RepetitionCounter = 100;
  567. LL_TIM_Init(TIM17, &TIM_InitStruct);
  568. LL_TIM_EnableARRPreload(TIM17);
  569. LL_TIM_OC_EnablePreload(TIM17, LL_TIM_CHANNEL_CH1);
  570. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  571. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  572. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  573. TIM_OC_InitStruct.CompareValue = 0;
  574. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  575. TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
  576. TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
  577. TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
  578. LL_TIM_OC_Init(TIM17, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  579. LL_TIM_OC_DisableFast(TIM17, LL_TIM_CHANNEL_CH1);
  580. TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE;
  581. TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE;
  582. TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF;
  583. TIM_BDTRInitStruct.DeadTime = 0;
  584. TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE;
  585. TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH;
  586. TIM_BDTRInitStruct.BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
  587. TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
  588. LL_TIM_BDTR_Init(TIM17, &TIM_BDTRInitStruct);
  589. /* USER CODE BEGIN TIM17_Init 2 */
  590. /* USER CODE END TIM17_Init 2 */
  591. }
  592. /**
  593. * Enable DMA controller clock
  594. */
  595. static void MX_DMA_Init(void)
  596. {
  597. /* Init with LL driver */
  598. /* DMA controller clock enable */
  599. LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
  600. /* DMA interrupt init */
  601. /* DMA1_Channel1_IRQn interrupt configuration */
  602. NVIC_SetPriority(DMA1_Channel1_IRQn, 0);
  603. NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  604. /* DMA1_Channel2_3_IRQn interrupt configuration */
  605. NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0);
  606. NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
  607. }
  608. /**
  609. * @brief GPIO Initialization Function
  610. * @param None
  611. * @retval None
  612. */
  613. static void MX_GPIO_Init(void)
  614. {
  615. LL_EXTI_InitTypeDef EXTI_InitStruct = {0};
  616. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  617. /* GPIO Ports Clock Enable */
  618. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  619. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
  620. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
  621. /**/
  622. LL_GPIO_ResetOutputPin(LC0_GPIO_Port, LC0_Pin);
  623. /**/
  624. LL_GPIO_ResetOutputPin(LC1_GPIO_Port, LC1_Pin);
  625. /**/
  626. LL_GPIO_ResetOutputPin(LC2_GPIO_Port, LC2_Pin);
  627. /**/
  628. LL_GPIO_ResetOutputPin(LC3_GPIO_Port, LC3_Pin);
  629. /**/
  630. LL_GPIO_ResetOutputPin(SHDN_GPIO_Port, SHDN_Pin);
  631. /**/
  632. LL_GPIO_ResetOutputPin(Latch_GPIO_Port, Latch_Pin);
  633. /**/
  634. GPIO_InitStruct.Pin = LL_GPIO_PIN_9;
  635. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  636. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  637. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  638. /**/
  639. GPIO_InitStruct.Pin = LL_GPIO_PIN_14;
  640. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  641. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  642. LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  643. /**/
  644. GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
  645. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  646. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  647. LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  648. /**/
  649. GPIO_InitStruct.Pin = LC0_Pin;
  650. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  651. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  652. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  653. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  654. LL_GPIO_Init(LC0_GPIO_Port, &GPIO_InitStruct);
  655. /**/
  656. GPIO_InitStruct.Pin = LC1_Pin;
  657. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  658. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  659. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  660. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  661. LL_GPIO_Init(LC1_GPIO_Port, &GPIO_InitStruct);
  662. /**/
  663. GPIO_InitStruct.Pin = LC2_Pin;
  664. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  665. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  666. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  667. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  668. LL_GPIO_Init(LC2_GPIO_Port, &GPIO_InitStruct);
  669. /**/
  670. GPIO_InitStruct.Pin = LC3_Pin;
  671. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  672. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  673. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  674. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  675. LL_GPIO_Init(LC3_GPIO_Port, &GPIO_InitStruct);
  676. /**/
  677. GPIO_InitStruct.Pin = SHDN_Pin;
  678. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  679. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  680. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  681. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  682. LL_GPIO_Init(SHDN_GPIO_Port, &GPIO_InitStruct);
  683. /**/
  684. GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
  685. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  686. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  687. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  688. /**/
  689. GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
  690. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  691. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  692. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  693. /**/
  694. GPIO_InitStruct.Pin = BTN1_Pin;
  695. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  696. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  697. LL_GPIO_Init(BTN1_GPIO_Port, &GPIO_InitStruct);
  698. /**/
  699. GPIO_InitStruct.Pin = BTN2_Pin;
  700. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  701. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  702. LL_GPIO_Init(BTN2_GPIO_Port, &GPIO_InitStruct);
  703. /**/
  704. GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
  705. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  706. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  707. LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  708. /**/
  709. GPIO_InitStruct.Pin = BTN3_Pin;
  710. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  711. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  712. LL_GPIO_Init(BTN3_GPIO_Port, &GPIO_InitStruct);
  713. /**/
  714. GPIO_InitStruct.Pin = BTN4_Pin;
  715. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  716. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  717. LL_GPIO_Init(BTN4_GPIO_Port, &GPIO_InitStruct);
  718. /**/
  719. GPIO_InitStruct.Pin = LL_GPIO_PIN_12;
  720. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  721. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  722. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  723. /**/
  724. GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
  725. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  726. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  727. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  728. /**/
  729. GPIO_InitStruct.Pin = Latch_Pin;
  730. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  731. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  732. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  733. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  734. LL_GPIO_Init(Latch_GPIO_Port, &GPIO_InitStruct);
  735. /**/
  736. LL_EXTI_SetEXTISource(LL_EXTI_CONFIG_PORTB, LL_EXTI_CONFIG_LINE8);
  737. /**/
  738. EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_8;
  739. EXTI_InitStruct.LineCommand = ENABLE;
  740. EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
  741. EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING;
  742. LL_EXTI_Init(&EXTI_InitStruct);
  743. /**/
  744. LL_GPIO_SetPinPull(IRQ_GPIO_Port, IRQ_Pin, LL_GPIO_PULL_UP);
  745. /**/
  746. LL_GPIO_SetPinMode(IRQ_GPIO_Port, IRQ_Pin, LL_GPIO_MODE_INPUT);
  747. /* EXTI interrupt init*/
  748. NVIC_SetPriority(EXTI4_15_IRQn, 0);
  749. NVIC_EnableIRQ(EXTI4_15_IRQn);
  750. }
  751. /* USER CODE BEGIN 4 */
  752. /**
  753. * S U B R O U T I N E S
  754. */
  755. static void showDigit(tube_pos_t pos, uint8_t dig)
  756. {
  757. if (dig > 9) {
  758. dig = 0;
  759. }
  760. switch (pos) {
  761. case Tube_A:
  762. nixieTubes[0] = (uint8_t)nixieCathodeMap[Tube_A][dig];
  763. nixieTubes[1] &= ~nixieCathodeMask[Tube_A][1];
  764. nixieTubes[1] |= (uint8_t)(nixieCathodeMap[Tube_A][dig] >> 8);
  765. break;
  766. case Tube_B:
  767. nixieTubes[1] &= ~nixieCathodeMask[Tube_B][0];
  768. nixieTubes[1] |= (uint8_t)nixieCathodeMap[Tube_B][dig];
  769. nixieTubes[2] &= ~nixieCathodeMask[Tube_B][1];
  770. nixieTubes[2] |= (uint8_t)(nixieCathodeMap[Tube_B][dig] >> 8);
  771. break;
  772. case Tube_D:
  773. nixieTubes[2] &= ~nixieCathodeMask[Tube_D][0];
  774. nixieTubes[2] |= (uint8_t)nixieCathodeMap[Tube_D][dig];
  775. nixieTubes[3] &= ~nixieCathodeMask[Tube_D][1];
  776. nixieTubes[3] |= (uint8_t)(nixieCathodeMap[Tube_D][dig] >> 8);
  777. break;
  778. case Tube_E:
  779. nixieTubes[3] &= ~nixieCathodeMask[Tube_E][0];
  780. nixieTubes[3] |= (uint8_t)nixieCathodeMap[Tube_E][dig];
  781. nixieTubes[4] = (uint8_t)(nixieCathodeMap[Tube_E][dig] >> 8);
  782. break;
  783. default:
  784. break;
  785. }
  786. }
  787. /* USER CODE END 4 */
  788. /**
  789. * @brief This function is executed in case of error occurrence.
  790. * @retval None
  791. */
  792. void Error_Handler(void)
  793. {
  794. /* USER CODE BEGIN Error_Handler_Debug */
  795. /* User can add his own implementation to report the HAL error return state */
  796. __disable_irq();
  797. while (1)
  798. {
  799. }
  800. /* USER CODE END Error_Handler_Debug */
  801. }
  802. #ifdef USE_FULL_ASSERT
  803. /**
  804. * @brief Reports the name of the source file and the source line number
  805. * where the assert_param error has occurred.
  806. * @param file: pointer to the source file name
  807. * @param line: assert_param error line source number
  808. * @retval None
  809. */
  810. void assert_failed(uint8_t *file, uint32_t line)
  811. {
  812. /* USER CODE BEGIN 6 */
  813. /* User can add his own implementation to report the file name and line number,
  814. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  815. /* USER CODE END 6 */
  816. }
  817. #endif /* USE_FULL_ASSERT */
  818. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/