main.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  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 Timers */
  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. LL_TIM_CC_EnableChannel(TIM14, LL_TIM_CHANNEL_CH1);
  121. LL_TIM_EnableCounter(TIM14);
  122. /* Enable tube power */
  123. SHDN_OFF;
  124. // manual dma start sample
  125. /* Set DMA transfer addresses of source and destination */
  126. // LL_DMA_ConfigAddresses(DMA1,
  127. // LL_DMA_CHANNEL_1,
  128. // (uint32_t)&nixieTubes,
  129. // (uint32_t)&aDST_Buffer,
  130. // LL_DMA_DIRECTION_MEMORY_TO_MEMORY);
  131. /* Set DMA transfer size */
  132. LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, SPI_BUFFER_SIZE);
  133. /* Enable DMA transfer complete/error interrupts */
  134. // LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
  135. // LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
  136. showDigit(Tube_A, 1);
  137. showDigit(Tube_B, 2);
  138. showDigit(Tube_D, 3);
  139. showDigit(Tube_E, 4);
  140. /* Start the DMA transfer Flash to Memory */
  141. LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
  142. // COLOR_R(0);
  143. // COLOR_G(0);
  144. // COLOR_B(0);
  145. /* USER CODE END 2 */
  146. /* Infinite loop */
  147. /* USER CODE BEGIN WHILE */
  148. while (1)
  149. {
  150. IN15_OFF;
  151. IN15_Plus;
  152. COLOR_RGB(20, 20, 20);
  153. LL_mDelay(500);
  154. IN15_OFF;
  155. IN15_Minus;
  156. COLOR_RGB(40, 40, 40);
  157. LL_mDelay(500);
  158. IN15_OFF;
  159. IN15_Percent;
  160. COLOR_RGB(60, 60, 60);
  161. LL_mDelay(500);
  162. IN15_OFF;
  163. IN15_P;
  164. COLOR_RGB(80, 80, 80);
  165. LL_mDelay(500);
  166. /* USER CODE END WHILE */
  167. /* USER CODE BEGIN 3 */
  168. // __WFI();
  169. }
  170. /* USER CODE END 3 */
  171. }
  172. /**
  173. * @brief System Clock Configuration
  174. * @retval None
  175. */
  176. void SystemClock_Config(void)
  177. {
  178. /* HSI configuration and activation */
  179. LL_RCC_HSI_Enable();
  180. while(LL_RCC_HSI_IsReady() != 1)
  181. {
  182. }
  183. /* Main PLL configuration and activation */
  184. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_2, 9, LL_RCC_PLLR_DIV_3);
  185. LL_RCC_PLL_Enable();
  186. LL_RCC_PLL_EnableDomain_SYS();
  187. while(LL_RCC_PLL_IsReady() != 1)
  188. {
  189. }
  190. /* Set AHB prescaler*/
  191. LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  192. /* Sysclk activation on the main PLL */
  193. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  194. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  195. {
  196. }
  197. /* Set APB1 prescaler*/
  198. LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  199. LL_Init1msTick(24000000);
  200. /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
  201. LL_SetSystemCoreClock(24000000);
  202. LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_HSI);
  203. }
  204. /**
  205. * @brief I2C1 Initialization Function
  206. * @param None
  207. * @retval None
  208. */
  209. static void MX_I2C1_Init(void)
  210. {
  211. /* USER CODE BEGIN I2C1_Init 0 */
  212. /* USER CODE END I2C1_Init 0 */
  213. LL_I2C_InitTypeDef I2C_InitStruct = {0};
  214. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  215. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  216. /**I2C1 GPIO Configuration
  217. PB6 ------> I2C1_SCL
  218. PB7 ------> I2C1_SDA
  219. */
  220. GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
  221. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  222. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  223. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  224. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  225. GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
  226. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  227. GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
  228. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  229. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  230. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  231. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  232. GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
  233. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  234. /* Peripheral clock enable */
  235. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
  236. /* I2C1 DMA Init */
  237. /* I2C1_RX Init */
  238. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_2, LL_DMAMUX_REQ_I2C1_RX);
  239. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_2, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
  240. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PRIORITY_MEDIUM);
  241. LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MODE_CIRCULAR);
  242. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PERIPH_NOINCREMENT);
  243. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MEMORY_INCREMENT);
  244. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PDATAALIGN_BYTE);
  245. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MDATAALIGN_BYTE);
  246. /* I2C1_TX Init */
  247. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_3, LL_DMAMUX_REQ_I2C1_TX);
  248. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_3, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
  249. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PRIORITY_MEDIUM);
  250. LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MODE_CIRCULAR);
  251. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PERIPH_NOINCREMENT);
  252. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MEMORY_INCREMENT);
  253. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PDATAALIGN_BYTE);
  254. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MDATAALIGN_BYTE);
  255. /* USER CODE BEGIN I2C1_Init 1 */
  256. /* USER CODE END I2C1_Init 1 */
  257. /** I2C Initialization
  258. */
  259. I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
  260. I2C_InitStruct.Timing = 0x0010061A;
  261. I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE;
  262. I2C_InitStruct.DigitalFilter = 0;
  263. I2C_InitStruct.OwnAddress1 = 0;
  264. I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
  265. I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
  266. LL_I2C_Init(I2C1, &I2C_InitStruct);
  267. LL_I2C_EnableAutoEndMode(I2C1);
  268. LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK);
  269. LL_I2C_DisableOwnAddress2(I2C1);
  270. LL_I2C_DisableGeneralCall(I2C1);
  271. LL_I2C_EnableClockStretching(I2C1);
  272. /* USER CODE BEGIN I2C1_Init 2 */
  273. /* USER CODE END I2C1_Init 2 */
  274. }
  275. /**
  276. * @brief SPI1 Initialization Function
  277. * @param None
  278. * @retval None
  279. */
  280. static void MX_SPI1_Init(void)
  281. {
  282. /* USER CODE BEGIN SPI1_Init 0 */
  283. /* USER CODE END SPI1_Init 0 */
  284. LL_SPI_InitTypeDef SPI_InitStruct = {0};
  285. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  286. /* Peripheral clock enable */
  287. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
  288. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  289. /**SPI1 GPIO Configuration
  290. PB3 ------> SPI1_SCK
  291. PB5 ------> SPI1_MOSI
  292. */
  293. GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
  294. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  295. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  296. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  297. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  298. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  299. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  300. GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
  301. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  302. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  303. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  304. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  305. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  306. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  307. /* SPI1 DMA Init */
  308. /* SPI1_TX Init */
  309. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_SPI1_TX);
  310. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
  311. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_HIGH);
  312. LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR);
  313. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT);
  314. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT);
  315. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_BYTE);
  316. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_BYTE);
  317. /* SPI1 interrupt Init */
  318. NVIC_SetPriority(SPI1_IRQn, 0);
  319. NVIC_EnableIRQ(SPI1_IRQn);
  320. /* USER CODE BEGIN SPI1_Init 1 */
  321. LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_1, SPI_BUFFER_SIZE);
  322. /* USER CODE END SPI1_Init 1 */
  323. /* SPI1 parameter configuration*/
  324. SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
  325. SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
  326. SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
  327. SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
  328. SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
  329. SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
  330. SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
  331. SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
  332. SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
  333. SPI_InitStruct.CRCPoly = 7;
  334. LL_SPI_Init(SPI1, &SPI_InitStruct);
  335. LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
  336. LL_SPI_DisableNSSPulseMgt(SPI1);
  337. /* USER CODE BEGIN SPI1_Init 2 */
  338. /* USER CODE END SPI1_Init 2 */
  339. }
  340. /**
  341. * @brief TIM3 Initialization Function
  342. * @param None
  343. * @retval None
  344. */
  345. static void MX_TIM3_Init(void)
  346. {
  347. /* USER CODE BEGIN TIM3_Init 0 */
  348. /* USER CODE END TIM3_Init 0 */
  349. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  350. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  351. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  352. /* Peripheral clock enable */
  353. LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
  354. /* USER CODE BEGIN TIM3_Init 1 */
  355. /* USER CODE END TIM3_Init 1 */
  356. TIM_InitStruct.Prescaler = 24;
  357. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  358. TIM_InitStruct.Autoreload = 1000;
  359. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  360. LL_TIM_Init(TIM3, &TIM_InitStruct);
  361. LL_TIM_EnableARRPreload(TIM3);
  362. LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH1);
  363. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  364. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  365. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  366. TIM_OC_InitStruct.CompareValue = 100;
  367. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  368. LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  369. LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH1);
  370. LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH2);
  371. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  372. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  373. LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
  374. LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH2);
  375. LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH3);
  376. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  377. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  378. LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
  379. LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH3);
  380. LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
  381. LL_TIM_DisableMasterSlaveMode(TIM3);
  382. /* USER CODE BEGIN TIM3_Init 2 */
  383. /* USER CODE END TIM3_Init 2 */
  384. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
  385. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  386. /**TIM3 GPIO Configuration
  387. PA6 ------> TIM3_CH1
  388. PA7 ------> TIM3_CH2
  389. PB0 ------> TIM3_CH3
  390. */
  391. GPIO_InitStruct.Pin = PWM_R_Pin;
  392. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  393. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  394. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  395. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  396. GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  397. LL_GPIO_Init(PWM_R_GPIO_Port, &GPIO_InitStruct);
  398. GPIO_InitStruct.Pin = PWM_G_Pin;
  399. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  400. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  401. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  402. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  403. GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  404. LL_GPIO_Init(PWM_G_GPIO_Port, &GPIO_InitStruct);
  405. GPIO_InitStruct.Pin = PWM_B_Pin;
  406. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  407. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  408. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  409. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  410. GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
  411. LL_GPIO_Init(PWM_B_GPIO_Port, &GPIO_InitStruct);
  412. }
  413. /**
  414. * @brief TIM14 Initialization Function
  415. * @param None
  416. * @retval None
  417. */
  418. static void MX_TIM14_Init(void)
  419. {
  420. /* USER CODE BEGIN TIM14_Init 0 */
  421. /* USER CODE END TIM14_Init 0 */
  422. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  423. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  424. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  425. /* Peripheral clock enable */
  426. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM14);
  427. /* TIM14 interrupt Init */
  428. NVIC_SetPriority(TIM14_IRQn, 0);
  429. NVIC_EnableIRQ(TIM14_IRQn);
  430. /* USER CODE BEGIN TIM14_Init 1 */
  431. /* USER CODE END TIM14_Init 1 */
  432. TIM_InitStruct.Prescaler = 240;
  433. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  434. TIM_InitStruct.Autoreload = 1000;
  435. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  436. LL_TIM_Init(TIM14, &TIM_InitStruct);
  437. LL_TIM_EnableARRPreload(TIM14);
  438. LL_TIM_OC_EnablePreload(TIM14, LL_TIM_CHANNEL_CH1);
  439. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  440. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  441. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  442. TIM_OC_InitStruct.CompareValue = 750;
  443. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  444. LL_TIM_OC_Init(TIM14, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  445. LL_TIM_OC_DisableFast(TIM14, LL_TIM_CHANNEL_CH1);
  446. /* USER CODE BEGIN TIM14_Init 2 */
  447. /* USER CODE END TIM14_Init 2 */
  448. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  449. /**TIM14 GPIO Configuration
  450. PB1 ------> TIM14_CH1
  451. */
  452. GPIO_InitStruct.Pin = PWM_T_Pin;
  453. GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  454. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  455. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  456. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  457. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  458. LL_GPIO_Init(PWM_T_GPIO_Port, &GPIO_InitStruct);
  459. }
  460. /**
  461. * @brief TIM16 Initialization Function
  462. * @param None
  463. * @retval None
  464. */
  465. static void MX_TIM16_Init(void)
  466. {
  467. /* USER CODE BEGIN TIM16_Init 0 */
  468. /* USER CODE END TIM16_Init 0 */
  469. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  470. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  471. LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0};
  472. /* Peripheral clock enable */
  473. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM16);
  474. /* TIM16 interrupt Init */
  475. NVIC_SetPriority(TIM16_IRQn, 0);
  476. NVIC_EnableIRQ(TIM16_IRQn);
  477. /* USER CODE BEGIN TIM16_Init 1 */
  478. /* USER CODE END TIM16_Init 1 */
  479. TIM_InitStruct.Prescaler = 24;
  480. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  481. TIM_InitStruct.Autoreload = 1000;
  482. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  483. TIM_InitStruct.RepetitionCounter = 0;
  484. LL_TIM_Init(TIM16, &TIM_InitStruct);
  485. LL_TIM_EnableARRPreload(TIM16);
  486. LL_TIM_OC_EnablePreload(TIM16, LL_TIM_CHANNEL_CH1);
  487. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  488. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  489. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  490. TIM_OC_InitStruct.CompareValue = 0;
  491. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  492. TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
  493. TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
  494. TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
  495. LL_TIM_OC_Init(TIM16, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  496. LL_TIM_OC_DisableFast(TIM16, LL_TIM_CHANNEL_CH1);
  497. TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE;
  498. TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE;
  499. TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF;
  500. TIM_BDTRInitStruct.DeadTime = 0;
  501. TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE;
  502. TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH;
  503. TIM_BDTRInitStruct.BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
  504. TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
  505. LL_TIM_BDTR_Init(TIM16, &TIM_BDTRInitStruct);
  506. /* USER CODE BEGIN TIM16_Init 2 */
  507. /* USER CODE END TIM16_Init 2 */
  508. }
  509. /**
  510. * @brief TIM17 Initialization Function
  511. * @param None
  512. * @retval None
  513. */
  514. static void MX_TIM17_Init(void)
  515. {
  516. /* USER CODE BEGIN TIM17_Init 0 */
  517. /* USER CODE END TIM17_Init 0 */
  518. LL_TIM_InitTypeDef TIM_InitStruct = {0};
  519. LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
  520. LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0};
  521. /* Peripheral clock enable */
  522. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM17);
  523. /* TIM17 interrupt Init */
  524. NVIC_SetPriority(TIM17_IRQn, 0);
  525. NVIC_EnableIRQ(TIM17_IRQn);
  526. /* USER CODE BEGIN TIM17_Init 1 */
  527. /* USER CODE END TIM17_Init 1 */
  528. TIM_InitStruct.Prescaler = 240;
  529. TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
  530. TIM_InitStruct.Autoreload = 1000;
  531. TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  532. TIM_InitStruct.RepetitionCounter = 100;
  533. LL_TIM_Init(TIM17, &TIM_InitStruct);
  534. LL_TIM_EnableARRPreload(TIM17);
  535. LL_TIM_OC_EnablePreload(TIM17, LL_TIM_CHANNEL_CH1);
  536. TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
  537. TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
  538. TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
  539. TIM_OC_InitStruct.CompareValue = 0;
  540. TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  541. TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
  542. TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
  543. TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
  544. LL_TIM_OC_Init(TIM17, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
  545. LL_TIM_OC_DisableFast(TIM17, LL_TIM_CHANNEL_CH1);
  546. TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE;
  547. TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE;
  548. TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF;
  549. TIM_BDTRInitStruct.DeadTime = 0;
  550. TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE;
  551. TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH;
  552. TIM_BDTRInitStruct.BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
  553. TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
  554. LL_TIM_BDTR_Init(TIM17, &TIM_BDTRInitStruct);
  555. /* USER CODE BEGIN TIM17_Init 2 */
  556. /* USER CODE END TIM17_Init 2 */
  557. }
  558. /**
  559. * Enable DMA controller clock
  560. */
  561. static void MX_DMA_Init(void)
  562. {
  563. /* Init with LL driver */
  564. /* DMA controller clock enable */
  565. LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
  566. /* DMA interrupt init */
  567. /* DMA1_Channel1_IRQn interrupt configuration */
  568. NVIC_SetPriority(DMA1_Channel1_IRQn, 0);
  569. NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  570. /* DMA1_Channel2_3_IRQn interrupt configuration */
  571. NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0);
  572. NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
  573. }
  574. /**
  575. * @brief GPIO Initialization Function
  576. * @param None
  577. * @retval None
  578. */
  579. static void MX_GPIO_Init(void)
  580. {
  581. LL_EXTI_InitTypeDef EXTI_InitStruct = {0};
  582. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  583. /* GPIO Ports Clock Enable */
  584. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  585. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
  586. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
  587. /**/
  588. LL_GPIO_ResetOutputPin(LC0_GPIO_Port, LC0_Pin);
  589. /**/
  590. LL_GPIO_ResetOutputPin(LC1_GPIO_Port, LC1_Pin);
  591. /**/
  592. LL_GPIO_ResetOutputPin(LC2_GPIO_Port, LC2_Pin);
  593. /**/
  594. LL_GPIO_ResetOutputPin(LC3_GPIO_Port, LC3_Pin);
  595. /**/
  596. LL_GPIO_ResetOutputPin(SHDN_GPIO_Port, SHDN_Pin);
  597. /**/
  598. LL_GPIO_ResetOutputPin(Latch_GPIO_Port, Latch_Pin);
  599. /**/
  600. GPIO_InitStruct.Pin = LL_GPIO_PIN_9;
  601. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  602. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  603. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  604. /**/
  605. GPIO_InitStruct.Pin = LL_GPIO_PIN_14;
  606. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  607. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  608. LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  609. /**/
  610. GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
  611. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  612. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  613. LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  614. /**/
  615. GPIO_InitStruct.Pin = LC0_Pin;
  616. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  617. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  618. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  619. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  620. LL_GPIO_Init(LC0_GPIO_Port, &GPIO_InitStruct);
  621. /**/
  622. GPIO_InitStruct.Pin = LC1_Pin;
  623. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  624. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  625. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  626. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  627. LL_GPIO_Init(LC1_GPIO_Port, &GPIO_InitStruct);
  628. /**/
  629. GPIO_InitStruct.Pin = LC2_Pin;
  630. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  631. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  632. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  633. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  634. LL_GPIO_Init(LC2_GPIO_Port, &GPIO_InitStruct);
  635. /**/
  636. GPIO_InitStruct.Pin = LC3_Pin;
  637. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  638. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  639. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  640. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  641. LL_GPIO_Init(LC3_GPIO_Port, &GPIO_InitStruct);
  642. /**/
  643. GPIO_InitStruct.Pin = SHDN_Pin;
  644. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  645. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  646. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  647. GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
  648. LL_GPIO_Init(SHDN_GPIO_Port, &GPIO_InitStruct);
  649. /**/
  650. GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
  651. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  652. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  653. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  654. /**/
  655. GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
  656. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  657. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  658. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  659. /**/
  660. GPIO_InitStruct.Pin = BTN1_Pin;
  661. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  662. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  663. LL_GPIO_Init(BTN1_GPIO_Port, &GPIO_InitStruct);
  664. /**/
  665. GPIO_InitStruct.Pin = BTN2_Pin;
  666. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  667. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  668. LL_GPIO_Init(BTN2_GPIO_Port, &GPIO_InitStruct);
  669. /**/
  670. GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
  671. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  672. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  673. LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  674. /**/
  675. GPIO_InitStruct.Pin = BTN3_Pin;
  676. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  677. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  678. LL_GPIO_Init(BTN3_GPIO_Port, &GPIO_InitStruct);
  679. /**/
  680. GPIO_InitStruct.Pin = BTN4_Pin;
  681. GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
  682. GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
  683. LL_GPIO_Init(BTN4_GPIO_Port, &GPIO_InitStruct);
  684. /**/
  685. GPIO_InitStruct.Pin = LL_GPIO_PIN_12;
  686. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  687. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  688. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  689. /**/
  690. GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
  691. GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  692. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  693. LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  694. /**/
  695. GPIO_InitStruct.Pin = Latch_Pin;
  696. GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
  697. GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  698. GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  699. GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  700. LL_GPIO_Init(Latch_GPIO_Port, &GPIO_InitStruct);
  701. /**/
  702. LL_EXTI_SetEXTISource(LL_EXTI_CONFIG_PORTB, LL_EXTI_CONFIG_LINE8);
  703. /**/
  704. EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_8;
  705. EXTI_InitStruct.LineCommand = ENABLE;
  706. EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
  707. EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING;
  708. LL_EXTI_Init(&EXTI_InitStruct);
  709. /**/
  710. LL_GPIO_SetPinPull(IRQ_GPIO_Port, IRQ_Pin, LL_GPIO_PULL_UP);
  711. /**/
  712. LL_GPIO_SetPinMode(IRQ_GPIO_Port, IRQ_Pin, LL_GPIO_MODE_INPUT);
  713. /* EXTI interrupt init*/
  714. NVIC_SetPriority(EXTI4_15_IRQn, 0);
  715. NVIC_EnableIRQ(EXTI4_15_IRQn);
  716. }
  717. /* USER CODE BEGIN 4 */
  718. /**
  719. * S U B R O U T I N E S
  720. */
  721. static void showDigit(tube_pos_t pos, uint8_t dig)
  722. {
  723. if (dig > 9) {
  724. dig = 0;
  725. }
  726. switch (pos) {
  727. case Tube_A:
  728. nixieTubes[0] = (uint8_t)nixieCathodeMap[Tube_A][dig];
  729. nixieTubes[1] &= ~nixieCathodeMask[Tube_A][1];
  730. nixieTubes[1] |= (uint8_t)(nixieCathodeMap[Tube_A][dig] >> 8);
  731. break;
  732. case Tube_B:
  733. nixieTubes[1] &= ~nixieCathodeMask[Tube_B][0];
  734. nixieTubes[1] |= (uint8_t)nixieCathodeMap[Tube_B][dig];
  735. nixieTubes[2] &= ~nixieCathodeMask[Tube_B][1];
  736. nixieTubes[2] |= (uint8_t)(nixieCathodeMap[Tube_B][dig] >> 8);
  737. break;
  738. case Tube_D:
  739. nixieTubes[2] &= ~nixieCathodeMask[Tube_D][0];
  740. nixieTubes[2] |= (uint8_t)nixieCathodeMap[Tube_D][dig];
  741. nixieTubes[3] &= ~nixieCathodeMask[Tube_D][1];
  742. nixieTubes[3] |= (uint8_t)(nixieCathodeMap[Tube_D][dig] >> 8);
  743. break;
  744. case Tube_E:
  745. nixieTubes[3] &= ~nixieCathodeMask[Tube_E][0];
  746. nixieTubes[3] |= (uint8_t)nixieCathodeMap[Tube_E][dig];
  747. nixieTubes[4] = (uint8_t)(nixieCathodeMap[Tube_E][dig] >> 8);
  748. break;
  749. default:
  750. break;
  751. }
  752. }
  753. /* USER CODE END 4 */
  754. /**
  755. * @brief This function is executed in case of error occurrence.
  756. * @retval None
  757. */
  758. void Error_Handler(void)
  759. {
  760. /* USER CODE BEGIN Error_Handler_Debug */
  761. /* User can add his own implementation to report the HAL error return state */
  762. __disable_irq();
  763. while (1)
  764. {
  765. }
  766. /* USER CODE END Error_Handler_Debug */
  767. }
  768. #ifdef USE_FULL_ASSERT
  769. /**
  770. * @brief Reports the name of the source file and the source line number
  771. * where the assert_param error has occurred.
  772. * @param file: pointer to the source file name
  773. * @param line: assert_param error line source number
  774. * @retval None
  775. */
  776. void assert_failed(uint8_t *file, uint32_t line)
  777. {
  778. /* USER CODE BEGIN 6 */
  779. /* User can add his own implementation to report the file name and line number,
  780. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  781. /* USER CODE END 6 */
  782. }
  783. #endif /* USE_FULL_ASSERT */
  784. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/