main.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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 = 3,
  29. Tube_B = 2,
  30. Tube_D = 1,
  31. Tube_E = 0
  32. } tube_pos_t;
  33. /* USER CODE END PTD */
  34. /* Private define ------------------------------------------------------------*/
  35. /* USER CODE BEGIN PD */
  36. #define SPI_BUFFER_SIZE 5
  37. /* Display timeout, sec */
  38. #define DISP_WDT_TIME 10
  39. /* USER CODE END PD */
  40. /* Private macro -------------------------------------------------------------*/
  41. /* USER CODE BEGIN PM */
  42. /* USER CODE END PM */
  43. /* Private variables ---------------------------------------------------------*/
  44. /* USER CODE BEGIN PV */
  45. volatile flag_t Flag = {0};
  46. static LL_RCC_ClocksTypeDef rcc_clocks;
  47. /**
  48. * Nixi Tube cathodes map in Byte Array:
  49. * {E0 E9 E8 E7 E6 E5 E4 E3}
  50. * {E2 E1 D0 D9 D8 D7 D6 D5}
  51. * {D4 D3 D2 D1 B0 B9 B8 B7}
  52. * {B6 B5 B4 B3 B2 B1 A0 A9}
  53. * {A8 A7 A6 A5 A4 A3 A2 A1}
  54. *
  55. * Shift register bit map in Tube cathodes (from 0 to 1):
  56. * {5.7 5.6 5.5 5.4 5.3 5.2 5.1 5.0 4.7 4.6} VL5/E
  57. * {4.5 4.4 4.3 4.2 4.1 4.0 3.7 3.6 3.5 3.4} VL4/D
  58. * {3.3 3.2 3.1 3.0 2.7 2.6 2.5 2.4 2.3 2.2} VL2/B
  59. * {2.1 2.0 1.7 1.6 1.5 1.4 1.3 1.2 1.1 1.0} VL1/A
  60. */
  61. static const uint16_t nixieCathodeMap[4][10] = {
  62. {0x8000, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000},
  63. {0x2000, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000},
  64. {0x0800, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400},
  65. {0x0200, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100}
  66. };
  67. //static const uint8_t nixieCathodeMask[4][2] = {{0x00, 0x3f}, {0xc0, 0x0f}, {0xf0, 0x03}, {0xc0, 0x00}};
  68. static uint8_t tubesBuffer[SPI_BUFFER_SIZE] = {0};
  69. static rtc_t Clock;
  70. static struct bme280_dev SensorDev;
  71. static struct bme280_data SensorData;
  72. static int8_t Humidity, Temperature;
  73. static nt16_t Pressure;
  74. static btn_t Button[BTN_NUM] = {
  75. {0, evBTN1Pressed, evBTN1Holded, BTN1_PIN},
  76. {0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN},
  77. {0, evBTN3Pressed, evBTN3Pressed, BTN3_PIN},
  78. {0, evBTN4Pressed, evBTN4Holded, BTN4_PIN}
  79. };
  80. static volatile uint8_t dispWDT = 0;
  81. /* USER CODE END PV */
  82. /* Private function prototypes -----------------------------------------------*/
  83. static void MX_SPI1_Init(void);
  84. /* USER CODE BEGIN PFP */
  85. static void showDigits(uint8_t * dig);
  86. static void sensor_Init(void);
  87. static void sensorStartMeasure(void);
  88. static void sensorGetData(void);
  89. static void btnProcess(void);
  90. static void Color_RGB(uint8_t r, uint8_t g, uint8_t b);
  91. /* USER CODE END PFP */
  92. /* Private user code ---------------------------------------------------------*/
  93. /* USER CODE BEGIN 0 */
  94. /* USER CODE END 0 */
  95. /**
  96. * @brief The application entry point.
  97. * @retval int
  98. */
  99. int main(void)
  100. {
  101. /* Initialize onBoard Hardware */
  102. Board_Init();
  103. /* Initialize all configured peripherals */
  104. MX_SPI1_Init();
  105. /* USER CODE BEGIN 2 */
  106. /* Initialize Scheduler */
  107. RTOS_Init();
  108. /* Initialize Event State Machine */
  109. ES_Init(stShowTime);
  110. /* Enable tube power */
  111. TUBE_PWR_ON;
  112. RTC_Init();
  113. sensor_Init();
  114. /** Star SPI transfer to shift registers */
  115. /* Set DMA source and destination addresses. */
  116. /* Source: Address of the SPI buffer. */
  117. DMA1_Channel1->CMAR = (uint32_t)&tubesBuffer;
  118. /* Destination: SPI1 data register. */
  119. DMA1_Channel1->CPAR = (uint32_t)&(SPI1->DR);
  120. /* Set DMA data transfer length (SPI buffer length). */
  121. DMA1_Channel1->CNDTR = SPI_BUFFER_SIZE;
  122. /* Enable SPI+DMA transfer */
  123. SPI1->CR2 |= SPI_CR2_TXDMAEN;
  124. SPI1->CR1 |= SPI_CR1_SPE;
  125. Flag.SPI_TX_End = 1;
  126. /** Set tasks for Sheduler */
  127. RTOS_SetTask(btnProcess, 1, BTN_SCAN_PERIOD);
  128. /* USER CODE END 2 */
  129. /* USER CODE BEGIN WHILE */
  130. RTC_ReadAll(&Clock);
  131. es_event_t event = eventNull;
  132. Color_RGB(0xFF, 0x12, 0x0); // Nixie color. FF1200 or FF7E00 or FFBF00
  133. showTime();
  134. /* Infinite loop */
  135. while (1)
  136. {
  137. /* new second interrupt from RTC */
  138. if (Flag.RTC_IRQ != 0) {
  139. Flag.RTC_IRQ = 0;
  140. Blink_Start(); // !!! TODO
  141. RTC_ReadAll(&Clock);
  142. if (dispWDT != 0) {
  143. dispWDT --;
  144. if (dispWDT == 0) {
  145. ES_PlaceEvent(evDisplayWDT);
  146. }
  147. }
  148. } /* end of New second */
  149. /* USER CODE END WHILE */
  150. /* USER CODE BEGIN 3 */
  151. event = ES_GetEvent();
  152. if (event) {
  153. ES_Dispatch(event);
  154. }
  155. RTOS_DispatchTask();
  156. __WFI();
  157. }
  158. /* USER CODE END 3 */
  159. } /* End of mine() */
  160. /**
  161. * Sensor
  162. */
  163. static void sensor_Init(void) {
  164. int8_t rsltSensor;
  165. Flag.BME280 = 0;
  166. SensorDev.dev_id = (BME280_I2C_ADDR_PRIM << 1);
  167. SensorDev.intf = BME280_I2C_INTF;
  168. SensorDev.read = user_i2c_read;
  169. SensorDev.write = user_i2c_write;
  170. SensorDev.delay_ms = tdelay_ms;
  171. rsltSensor = bme280_init(&SensorDev);
  172. if (rsltSensor == BME280_OK) {
  173. Flag.BME280 = 1;
  174. /* BME280 Recommended mode of operation: Indoor navigation */
  175. SensorDev.settings.osr_h = BME280_OVERSAMPLING_1X;
  176. SensorDev.settings.osr_p = BME280_OVERSAMPLING_16X;
  177. SensorDev.settings.osr_t = BME280_OVERSAMPLING_2X;
  178. SensorDev.settings.filter = BME280_FILTER_COEFF_16;
  179. rsltSensor = bme280_set_sensor_settings((BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL), &SensorDev);
  180. RTOS_SetTask(sensorStartMeasure, 103, 1000);
  181. RTOS_SetTask(sensorGetData, 603, 1000);
  182. }
  183. }
  184. static void sensorStartMeasure(void) {
  185. bme280_set_sensor_mode(BME280_FORCED_MODE, &SensorDev);
  186. }
  187. static void sensorGetData(void) {
  188. bme280_get_sensor_data(BME280_ALL, &SensorData, &SensorDev);
  189. int32_t tmp;
  190. tmp = SensorData.humidity + 512;
  191. Humidity = (int8_t)(tmp / 1024);
  192. tmp = SensorData.temperature + 50;
  193. Temperature = (int8_t)(tmp / 100);
  194. /* in 32-bit arithmetics pressure in Pa */
  195. tmp = SensorData.pressure * 1000;
  196. tmp += 66661;
  197. tmp /= 133322;
  198. /* pressure in mmHg */
  199. Pressure.s16.u8H = (uint8_t)(tmp / 100);
  200. Pressure.s16.u8L = (uint8_t)(tmp % 100);
  201. }
  202. /**
  203. * @brief SPI1 Initialization Function
  204. * @param None
  205. * @retval None
  206. */
  207. static void MX_SPI1_Init(void)
  208. {
  209. /* USER CODE BEGIN SPI1_Init 0 */
  210. /* USER CODE END SPI1_Init 0 */
  211. LL_SPI_InitTypeDef SPI_InitStruct = {0};
  212. LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
  213. /* Peripheral clock enable */
  214. LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
  215. LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
  216. /**SPI1 GPIO Configuration
  217. PB3 ------> SPI1_SCK
  218. PB5 ------> SPI1_MOSI
  219. */
  220. GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
  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_NO;
  225. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  226. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  227. GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
  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_NO;
  232. GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
  233. LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  234. /* SPI1 DMA Init */
  235. /* SPI1_TX Init */
  236. LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_SPI1_TX);
  237. LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
  238. LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_HIGH);
  239. LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR);
  240. LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT);
  241. LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT);
  242. LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_BYTE);
  243. LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_BYTE);
  244. /* SPI1 interrupt Init */
  245. NVIC_SetPriority(SPI1_IRQn, 0);
  246. NVIC_EnableIRQ(SPI1_IRQn);
  247. /* USER CODE BEGIN SPI1_Init 1 */
  248. /* Enable DMA transfer complete/error interrupts */
  249. LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
  250. LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
  251. /* USER CODE END SPI1_Init 1 */
  252. /* SPI1 parameter configuration*/
  253. SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
  254. SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
  255. SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
  256. SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
  257. SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
  258. SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
  259. SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV16;
  260. SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
  261. SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
  262. SPI_InitStruct.CRCPoly = 7;
  263. LL_SPI_Init(SPI1, &SPI_InitStruct);
  264. LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
  265. LL_SPI_DisableNSSPulseMgt(SPI1);
  266. /* USER CODE BEGIN SPI1_Init 2 */
  267. /* USER CODE END SPI1_Init 2 */
  268. }
  269. /* USER CODE BEGIN 4 */
  270. /*************************
  271. * S U B R O U T I N E S *
  272. *************************/
  273. /**
  274. * @brief Out digits to SPI buffer. ON/off tube power.
  275. * @param : array with four BCD digits
  276. * @retval : None
  277. */
  278. static void showDigits(uint8_t * dig)
  279. {
  280. /* Clear buffer */
  281. tubesBuffer[0] = 0;
  282. tubesBuffer[1] = 0;
  283. tubesBuffer[2] = 0;
  284. tubesBuffer[3] = 0;
  285. tubesBuffer[4] = 0;
  286. /* check values range */
  287. int i;
  288. for (i=0; i<4; i++) {
  289. if (dig[i] > 9) {
  290. if (dig[i] != 0xf) {
  291. dig[i] = 0;
  292. }
  293. }
  294. }
  295. /* Wait for SPI */
  296. while (Flag.SPI_TX_End == 0) {};
  297. Flag.SPI_TX_End = 0;
  298. /* Feel buffer */
  299. tubesBuffer[0] = (uint8_t)(nixieCathodeMap[Tube_E][dig[Tube_E]] >> 8);
  300. tubesBuffer[1] = (uint8_t)((nixieCathodeMap[Tube_E][dig[Tube_E]]) | (nixieCathodeMap[Tube_D][dig[Tube_D]] >> 8));
  301. tubesBuffer[2] = (uint8_t)((nixieCathodeMap[Tube_D][dig[Tube_D]]) | (nixieCathodeMap[Tube_B][dig[Tube_B]] >> 8));
  302. tubesBuffer[3] = (uint8_t)((nixieCathodeMap[Tube_B][dig[Tube_B]]) | (nixieCathodeMap[Tube_A][dig[Tube_A]] >> 8));
  303. tubesBuffer[4] = (uint8_t)(nixieCathodeMap[Tube_A][dig[Tube_A]]);
  304. /* Start DMA transfer to SPI */
  305. DMA1_Channel1->CCR |= DMA_CCR_EN;
  306. /* On/Off tube power */
  307. if (dig[Tube_A] == 0xf) {
  308. TUBE_A_OFF;
  309. } else {
  310. TUBE_A_ON;
  311. }
  312. if (dig[Tube_B] == 0xf) {
  313. TUBE_B_OFF;
  314. } else {
  315. TUBE_B_ON;
  316. }
  317. if (dig[Tube_D] == 0xf) {
  318. TUBE_D_OFF;
  319. } else {
  320. TUBE_D_ON;
  321. }
  322. if (dig[Tube_E] == 0xf) {
  323. TUBE_E_OFF;
  324. } else {
  325. TUBE_E_ON;
  326. }
  327. }
  328. /**
  329. * @brief Вывод HEX значений цвета в таймер.
  330. * @param : RGB value in range 0x00-0xFF
  331. * @retval : None
  332. */
  333. static void Color_RGB(uint8_t r, uint8_t g, uint8_t b) {
  334. /* Более быстрый вариант, на пробу. */
  335. COLOR_R(r * 4);
  336. COLOR_G(g * 4);
  337. COLOR_B(b * 4);
  338. /* Предварительный обсчёт в переменные сделан для того,
  339. что-бы вывести значения в таймер максимально одновременно. */
  340. /*
  341. uint32_t val_r, val_g, val_b;
  342. // * 999 + 127 / 255 ???
  343. val_r = ((uint32_t)(r * 1000) + 128) / 256;
  344. val_g = ((uint32_t)(g * 1000) + 128) / 256;
  345. val_b = ((uint32_t)(b * 1000) + 128) / 256;
  346. COLOR_R((uint16_t)val_r);
  347. COLOR_G((uint16_t)val_g);
  348. COLOR_B((uint16_t)val_b);
  349. */
  350. }
  351. /**
  352. * @brief Обработка кнопок.
  353. * @param : None
  354. * @retval : None
  355. */
  356. static void btnProcess(void) {
  357. /* get pin state */
  358. uint32_t pins = BTNS_STATE;
  359. int i;
  360. for (i=0; i<BTN_NUM; i++) {
  361. if ((pins & Button[i].pin) == 0) {
  362. /* button pressed */
  363. Button[i].time ++;
  364. if (Button[i].time >= (BTN_TIME_HOLDED/BTN_SCAN_PERIOD)) {
  365. Button[i].time -= (BTN_TIME_REPEATED/BTN_SCAN_PERIOD);
  366. if (Button[i].holded == Button[i].pressed) {
  367. /* if pressed and holded - same function, then button pressed auto repeat */
  368. ES_PlaceEvent(Button[i].pressed);
  369. }
  370. }
  371. } else if (Button[i].time != 0) {
  372. /* button released */
  373. if (Button[i].time >= ((BTN_TIME_HOLDED - BTN_TIME_REPEATED)/BTN_SCAN_PERIOD)) {
  374. /* process long press */
  375. ES_PlaceEvent(Button[i].holded);
  376. } else if (Button[i].time >= (BTN_TIME_PRESSED/BTN_SCAN_PERIOD)) {
  377. /* process short press */
  378. ES_PlaceEvent(Button[i].pressed);
  379. }
  380. Button[i].time = 0;
  381. RTOS_SetTask(btnProcess, BTN_SCAN_PAUSE, BTN_SCAN_PERIOD);
  382. }
  383. } /* end FOR */
  384. }
  385. /**
  386. * On/off symbols on IN-15 tube.
  387. */
  388. void in15Off(void) {
  389. IN15_OFF;
  390. TUBE_C_OFF;
  391. }
  392. void in15Minus(void) {
  393. IN15_OFF;
  394. IN15_Minus;
  395. TUBE_C_ON;
  396. }
  397. void in15Plus(void) {
  398. IN15_OFF;
  399. IN15_Plus;
  400. TUBE_C_ON;
  401. }
  402. void in15Percent(void) {
  403. IN15_OFF;
  404. IN15_Percent;
  405. TUBE_C_ON;
  406. }
  407. void in15P(void) {
  408. IN15_OFF;
  409. IN15_P;
  410. TUBE_C_ON;
  411. }
  412. void showTime(void) {
  413. in15Minus();
  414. RTOS_SetTask(in15Off, 500, 0);
  415. uint8_t buf[4];
  416. buf[Tube_A] = Clock.Hr >> 4;
  417. buf[Tube_B] = Clock.Hr & 0xf;
  418. buf[Tube_D] = Clock.Min >> 4;
  419. buf[Tube_E] = Clock.Min & 0xf;
  420. showDigits(buf);
  421. }
  422. /**
  423. * Show info on tubes.
  424. */
  425. void showWD(void) {
  426. dispWDT = DISP_WDT_TIME;
  427. IN15_OFF;
  428. uint8_t buf[4];
  429. buf[Tube_A] = 0xf;
  430. buf[Tube_B] = Clock.WD & 0xf;
  431. buf[Tube_D] = 0xf;
  432. buf[Tube_E] = 0xf;
  433. showDigits(buf);
  434. }
  435. void showDay(void) {
  436. dispWDT = DISP_WDT_TIME;
  437. IN15_OFF;
  438. uint8_t buf[4];
  439. buf[Tube_A] = Clock.Day >> 4;
  440. buf[Tube_B] = Clock.Day & 0xf;
  441. buf[Tube_D] = 0xf;
  442. buf[Tube_E] = 0xf;
  443. showDigits(buf);
  444. }
  445. void showMonth(void) {
  446. dispWDT = DISP_WDT_TIME;
  447. IN15_OFF;
  448. uint8_t buf[4];
  449. buf[Tube_A] = 0xf;
  450. buf[Tube_B] = 0xf;
  451. buf[Tube_D] = Clock.Mon >> 4;
  452. buf[Tube_E] = Clock.Mon & 0xf;
  453. showDigits(buf);
  454. }
  455. void showDayMon(void) {
  456. dispWDT = DISP_WDT_TIME;
  457. IN15_OFF;
  458. uint8_t buf[4];
  459. buf[Tube_A] = Clock.Day >> 4;
  460. buf[Tube_B] = Clock.Day & 0xf;
  461. buf[Tube_D] = Clock.Mon >> 4;
  462. buf[Tube_E] = Clock.Mon & 0xf;
  463. showDigits(buf);
  464. }
  465. void showYear(void) {
  466. dispWDT = DISP_WDT_TIME;
  467. IN15_OFF;
  468. uint8_t buf[4];
  469. buf[Tube_A] = 2;
  470. buf[Tube_B] = 0;
  471. buf[Tube_D] = Clock.Year >> 4;
  472. buf[Tube_E] = Clock.Year & 0xf;
  473. showDigits(buf);
  474. }
  475. void showHumidity(void) {
  476. dispWDT = DISP_WDT_TIME;
  477. in15Percent();
  478. uint8_t buf[4];
  479. buf[Tube_A] = Humidity / 10;
  480. buf[Tube_B] = Humidity % 10;
  481. buf[Tube_D] = 0xf;
  482. buf[Tube_E] = 0xf;
  483. showDigits(buf);
  484. }
  485. void showTemperature(void) {
  486. dispWDT = DISP_WDT_TIME;
  487. in15Plus();
  488. uint8_t buf[4];
  489. buf[Tube_A] = 0xf;
  490. buf[Tube_B] = 0xf;
  491. buf[Tube_D] = Temperature / 10;
  492. buf[Tube_E] = Temperature % 10;
  493. showDigits(buf);
  494. }
  495. void showPressure(void) {
  496. dispWDT = DISP_WDT_TIME;
  497. in15P();
  498. uint8_t buf[4];
  499. buf[Tube_A] = 0xf;
  500. buf[Tube_B] = Pressure.s16.u8H & 0xf;
  501. buf[Tube_D] = Pressure.s16.u8L >> 4;
  502. buf[Tube_E] = Pressure.s16.u8L & 0xf;
  503. showDigits(buf);
  504. }
  505. /* Simple function for cyclic show all sensor data */
  506. void showSensorData(void) {
  507. ES_SetState(stShowSensorData);
  508. showTemperature();
  509. tdelay_ms(3000);
  510. showHumidity();
  511. tdelay_ms(3000);
  512. showPressure();
  513. tdelay_ms(3000);
  514. ES_SetState(stShowTime);
  515. showTime();
  516. }
  517. /* USER CODE END 4 */
  518. /**
  519. * @brief This function is executed in case of error occurrence.
  520. * @retval None
  521. */
  522. void Error_Handler(void)
  523. {
  524. /* USER CODE BEGIN Error_Handler_Debug */
  525. /* User can add his own implementation to report the HAL error return state */
  526. __disable_irq();
  527. while (1)
  528. {
  529. }
  530. /* USER CODE END Error_Handler_Debug */
  531. }
  532. #ifdef USE_FULL_ASSERT
  533. /**
  534. * @brief Reports the name of the source file and the source line number
  535. * where the assert_param error has occurred.
  536. * @param file: pointer to the source file name
  537. * @param line: assert_param error line source number
  538. * @retval None
  539. */
  540. void assert_failed(uint8_t *file, uint32_t line)
  541. {
  542. /* USER CODE BEGIN 6 */
  543. /* User can add his own implementation to report the file name and line number,
  544. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  545. /* USER CODE END 6 */
  546. }
  547. #endif /* USE_FULL_ASSERT */
  548. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/