clock.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. #include "clock.h"
  2. /* type defs */
  3. typedef struct t_btn {
  4. uint8_t time;
  5. es_event_t pressed;
  6. es_event_t holded;
  7. uint32_t pin;
  8. //(GPIO_TypeDef *) GPIOA; // ?->IDR
  9. } btn_t;
  10. /* variables */
  11. rtc_t Clock;
  12. static rtc_t setClock;
  13. static btn_t Button[BTN_NUM] = {
  14. {0, evBTN1Pressed, evBTN1Holded, BTN1_PIN},
  15. {0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN},
  16. {0, evBTN3Pressed, evBTN3Pressed, BTN3_PIN},
  17. {0, evBTN4Pressed, evBTN4Holded, BTN4_PIN}
  18. };
  19. //convert linear bright level to logariphmic
  20. const uint8_t cie[8] = { 0, 5, 14, 33, 64, 109, 172, 255 };
  21. volatile static uint8_t dispWDT = 0;
  22. static in15_pin_t symToFade = 0;
  23. static brigh_level_t BrightLevel;
  24. /* function prototypes */
  25. static void check_DayNight(void);
  26. static void MinusFadeIn(void);
  27. static void MinusFadeOut(void);
  28. static void PlusFadeIn(void);
  29. static void PercentFadeIn(void);
  30. static void PressureFadeIn(void);
  31. static void IN15_FadeIn(void);
  32. static void IN15_FadeOut(void);
  33. static void valIncrease(uint8_t * val, uint8_t max);
  34. static void valDecrease(uint8_t * val, uint8_t max);
  35. static void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val);
  36. /* funcions */
  37. void Clock_Init(void) {
  38. RTC_ReadAll(&Clock);
  39. showTime();
  40. check_DayNight();
  41. }
  42. static void check_DayNight(void) {
  43. if ((Clock.Hr >= MORNING_HOUR) && (Clock.Hr < EVENING_HOUR)) {
  44. Flag.Now_Day = 1;
  45. BrightLevel = cie[DAY_BR_LVL];
  46. } else {
  47. Flag.Now_Day = 0;
  48. BrightLevel = cie[NIGHT_BR_LVL];
  49. }
  50. tube_BrightLevel(Tube_All, BrightLevel);
  51. //TUBES_BRIGHT(BrightLevel);
  52. }
  53. /**
  54. * @brief Обработка кнопок.
  55. * @param : None
  56. * @retval : None
  57. */
  58. void btnProcess(void) {
  59. /* get pin state */
  60. uint32_t pins = BTNS_STATE;
  61. int i;
  62. for (i=0; i<BTN_NUM; i++) {
  63. if ((pins & Button[i].pin) == 0) {
  64. /* button pressed */
  65. Button[i].time ++;
  66. if (Button[i].time >= (BTN_TIME_HOLDED/BTN_SCAN_PERIOD)) {
  67. Button[i].time -= (BTN_TIME_REPEATED/BTN_SCAN_PERIOD);
  68. if (Button[i].holded == Button[i].pressed) {
  69. /* if pressed and holded - same function, then button pressed auto repeat */
  70. ES_PlaceEvent(Button[i].pressed);
  71. }
  72. }
  73. } else if (Button[i].time != 0) {
  74. /* button released */
  75. if (Button[i].time >= ((BTN_TIME_HOLDED - BTN_TIME_REPEATED)/BTN_SCAN_PERIOD)) {
  76. /* process long press */
  77. ES_PlaceEvent(Button[i].holded);
  78. } else if (Button[i].time >= (BTN_TIME_PRESSED/BTN_SCAN_PERIOD)) {
  79. /* process short press */
  80. ES_PlaceEvent(Button[i].pressed);
  81. }
  82. Button[i].time = 0;
  83. RTOS_SetTask(btnProcess, BTN_SCAN_PAUSE, BTN_SCAN_PERIOD);
  84. }
  85. } /* end FOR */
  86. }
  87. void new_Second(void) {
  88. RTC_ReadAll(&Clock);
  89. // new hour
  90. if (Clock.Min == 0 && Clock.Sec == 0) {
  91. check_DayNight();
  92. }
  93. // check display watch dog timer
  94. if (dispWDT != 0) {
  95. dispWDT--;
  96. if (dispWDT == 0) {
  97. Flag.Blink_1 = 0;
  98. Flag.Blink_2 = 0;
  99. Flag.Blink_3 = 0;
  100. Flag.Blink_4 = 0;
  101. Flag.Blink_5 = 0;
  102. Blink_Stop();
  103. ES_PlaceEvent(evDisplayWDT);
  104. }
  105. }
  106. }
  107. /**
  108. * On/off symbols on IN-15 tube.
  109. */
  110. void in15Off(void) {
  111. IN15_OFF;
  112. TUBE_C_OFF;
  113. }
  114. void in15Minus(void) {
  115. IN15_OFF;
  116. IN15_Minus;
  117. TUBE_C_ON;
  118. }
  119. void in15Plus(void) {
  120. IN15_OFF;
  121. IN15_Plus;
  122. TUBE_C_ON;
  123. }
  124. void in15Percent(void) {
  125. IN15_OFF;
  126. IN15_Percent;
  127. TUBE_C_ON;
  128. }
  129. void in15P(void) {
  130. IN15_OFF;
  131. IN15_P;
  132. TUBE_C_ON;
  133. }
  134. /** 'Faded' funcions */
  135. static void MinusFadeIn(void) {
  136. static uint8_t on = FADE_START;
  137. static uint8_t off = FADE_STOP;
  138. static uint8_t st = 0;
  139. if (st == 0) {
  140. st = 1;
  141. IN15_Minus;
  142. on += FADE_STEP;
  143. if (on < FADE_STOP) {
  144. RTOS_SetTask(MinusFadeIn, on, 0);
  145. } else {
  146. on = FADE_START; off = FADE_STOP; st = 0;
  147. }
  148. } else {
  149. st = 0;
  150. IN15_OFF;
  151. off -= FADE_STEP;
  152. RTOS_SetTask(MinusFadeIn, off, 0);
  153. }
  154. }
  155. static void MinusFadeOut(void) {
  156. static uint8_t off = FADE_START;
  157. static uint8_t on = FADE_STOP;
  158. static uint8_t st = 0;
  159. if (st == 0) {
  160. st = 1;
  161. IN15_OFF;
  162. off += FADE_STEP;
  163. if (off < FADE_STOP) {
  164. RTOS_SetTask(MinusFadeOut, off, 0);
  165. } else {
  166. off = FADE_START; on = FADE_STOP; st = 0;
  167. }
  168. } else {
  169. st = 0;
  170. IN15_Minus;
  171. on -= FADE_STEP;
  172. RTOS_SetTask(MinusFadeOut, on, 0);
  173. }
  174. }
  175. static void PlusFadeIn(void) {
  176. static uint8_t on = FADE_START;
  177. static uint8_t off = FADE_STOP;
  178. static uint8_t st = 0;
  179. if (st == 0) {
  180. st = 1;
  181. IN15_Plus;
  182. on += FADE_STEP;
  183. if (on < FADE_STOP) {
  184. RTOS_SetTask(PlusFadeIn, on, 0);
  185. } else {
  186. on = FADE_START; off = FADE_STOP; st = 0;
  187. }
  188. } else {
  189. st = 0;
  190. IN15_OFF;
  191. off -= FADE_STEP;
  192. RTOS_SetTask(PlusFadeIn, off, 0);
  193. }
  194. }
  195. static void PercentFadeIn(void) {
  196. static uint8_t on = FADE_START;
  197. static uint8_t off = FADE_STOP;
  198. static uint8_t st = 0;
  199. if (st == 0) {
  200. st = 1;
  201. IN15_Percent;
  202. on += FADE_STEP;
  203. if (on < FADE_STOP) {
  204. RTOS_SetTask(PercentFadeIn, on, 0);
  205. } else {
  206. on = FADE_START; off = FADE_STOP; st = 0;
  207. }
  208. } else {
  209. st = 0;
  210. IN15_OFF;
  211. off -= FADE_STEP;
  212. RTOS_SetTask(PercentFadeIn, off, 0);
  213. }
  214. }
  215. static void PressureFadeIn(void) {
  216. static uint8_t on = FADE_START;
  217. static uint8_t off = FADE_STOP;
  218. static uint8_t st = 0;
  219. if (st == 0) {
  220. st = 1;
  221. IN15_P;
  222. on += FADE_STEP;
  223. if (on < FADE_STOP) {
  224. RTOS_SetTask(PressureFadeIn, on, 0);
  225. } else {
  226. on = FADE_START; off = FADE_STOP; st = 0;
  227. }
  228. } else {
  229. st = 0;
  230. IN15_OFF;
  231. off -= FADE_STEP;
  232. RTOS_SetTask(PressureFadeIn, off, 0);
  233. }
  234. }
  235. static void IN15_FadeIn(void) {
  236. static uint8_t on = FADE_START;
  237. static uint8_t off = FADE_STOP;
  238. static uint8_t st = 0;
  239. if (symToFade != 0) {
  240. if (st == 0) {
  241. st = 1;
  242. GPIOA->BSRR = symToFade;
  243. on += FADE_STEP;
  244. if (on < FADE_STOP) {
  245. RTOS_SetTask(IN15_FadeIn, on, 0);
  246. } else {
  247. on = FADE_START; off = FADE_STOP; st = 0; symToFade = 0;
  248. }
  249. } else {
  250. st = 0;
  251. IN15_OFF;
  252. off -= FADE_STEP;
  253. RTOS_SetTask(IN15_FadeIn, off, 0);
  254. }
  255. }
  256. }
  257. static void IN15_FadeOut(void) {
  258. static uint8_t off = FADE_START;
  259. static uint8_t on = FADE_STOP;
  260. static uint8_t st = 0;
  261. if (symToFade != 0) {
  262. if (st == 0) {
  263. st = 1;
  264. IN15_OFF;
  265. off += FADE_STEP;
  266. if (off < FADE_STOP) {
  267. RTOS_SetTask(IN15_FadeOut, off, 0);
  268. } else {
  269. off = FADE_START; on = FADE_STOP; st = 0; symToFade = 0;
  270. }
  271. } else {
  272. st = 0;
  273. GPIOA->BSRR = symToFade;
  274. on -= FADE_STEP;
  275. RTOS_SetTask(IN15_FadeOut, on, 0);
  276. }
  277. }
  278. }
  279. /**
  280. * @brief HSV to RGB convertion
  281. * @param hue: 0-(6*256)-1 /59/, sat: 0-255, val (lightness): 0-255
  282. * @return none. RGB value output direct to LED.
  283. */
  284. static void HSV2LED(const uint8_t hue, const uint8_t sat, const uint8_t val) {
  285. int base;
  286. uint32_t r=0, g=0, b=0;
  287. if (sat == 0)
  288. { // Achromatic color (gray).
  289. r = val;
  290. g = val;
  291. b = val;
  292. } else {
  293. base = ((255 - sat) * val) >> 8;
  294. switch (hue / 10) {
  295. case 0:
  296. r = val;
  297. g = (((val - base) * hue) / 10) + base;
  298. b = base;
  299. break;
  300. case 1:
  301. r = (((val - base) * (10 - (hue % 10))) / 10) + base;
  302. g = val;
  303. b = base;
  304. break;
  305. case 2:
  306. r = base;
  307. g = val;
  308. b = (((val - base) * (hue % 10)) / 10) + base;
  309. break;
  310. case 3:
  311. r = base;
  312. g = (((val - base) * (10 - (hue % 10))) / 10) + base;
  313. b = val;
  314. break;
  315. case 4:
  316. r = (((val - base) * (hue % 10)) / 10) + base;
  317. g = base;
  318. b = val;
  319. break;
  320. case 5:
  321. r = val;
  322. g = base;
  323. b = (((val - base) * (10 - (hue % 10))) / 10) + base;
  324. break;
  325. }
  326. }
  327. COLOR_R((uint8_t)r);
  328. COLOR_G((uint8_t)g);
  329. COLOR_B((uint8_t)b);
  330. }
  331. /**
  332. * Show info on tubes.
  333. */
  334. void showTime(void) {
  335. MinusFadeIn();
  336. RTOS_SetTask(MinusFadeOut, 500, 0);
  337. if (Flag.Now_Day != 0) {
  338. // new hsv2led
  339. //uint16_t hue = (uint16_t)(bcd2bin(Clock.Sec) * 256) / 10;
  340. uint8_t hue = bcd2bin(Clock.Sec);
  341. HSV2LED(hue, 255, BrightLevel);
  342. } else {
  343. HSV2LED(COLOUR_NIXIE, 255, BrightLevel);
  344. }
  345. tube4_t buf;
  346. buf.s8.tA = Clock.Hr >> 4;
  347. buf.s8.tB = Clock.Hr & 0xf;
  348. buf.s8.tD = Clock.Min >> 4;
  349. buf.s8.tE = Clock.Min & 0xf;
  350. showDigits(buf);
  351. }
  352. void showMMSS(void) {
  353. RTOS_DeleteTask(MinusFadeOut);
  354. IN15_Minus;
  355. uint8_t hue = bcd2bin(Clock.Sec);
  356. HSV2LED(hue, 255, BrightLevel);
  357. tube4_t buf;
  358. buf.s8.tA = Clock.Min >> 4;
  359. buf.s8.tB = Clock.Min & 0xf;
  360. buf.s8.tD = Clock.Sec >> 4;
  361. buf.s8.tE = Clock.Sec & 0xf;
  362. showDigits(buf);
  363. }
  364. void showWD(void) {
  365. dispWDT = DISP_WDT_TIME;
  366. IN15_OFF;
  367. tube4_t buf;
  368. buf.s8.tA = 0xf;
  369. buf.s8.tB = Clock.WD & 0xf;
  370. buf.s8.tD = 0xf;
  371. buf.s8.tE = 0xf;
  372. showDigits(buf);
  373. }
  374. void showDayMon(void) {
  375. dispWDT = DISP_WDT_TIME;
  376. IN15_OFF;
  377. tube4_t buf;
  378. buf.s8.tA = Clock.Day >> 4;
  379. buf.s8.tB = Clock.Day & 0xf;
  380. buf.s8.tD = Clock.Mon >> 4;
  381. buf.s8.tE = Clock.Mon & 0xf;
  382. showDigits(buf);
  383. }
  384. void showYear(void) {
  385. dispWDT = DISP_WDT_TIME;
  386. IN15_OFF;
  387. tube4_t buf;
  388. buf.s8.tA = 2;
  389. buf.s8.tB = 0;
  390. buf.s8.tD = Clock.Year >> 4;
  391. buf.s8.tE = Clock.Year & 0xf;
  392. showDigits(buf);
  393. }
  394. void showHumidity(void) {
  395. dispWDT = DISP_WDT_TIME;
  396. HSV2LED(COLOUR_BLUE, 255, BrightLevel);
  397. //in15Percent();
  398. symToFade = sym_Percent;
  399. IN15_FadeIn();
  400. //PercentFadeIn();
  401. tube4_t buf;
  402. buf.s8.tA = Humidity / 10;
  403. buf.s8.tB = Humidity % 10;
  404. buf.s8.tD = 0xf;
  405. buf.s8.tE = 0xf;
  406. showDigits(buf);
  407. }
  408. void showTemperature(void) {
  409. dispWDT = DISP_WDT_TIME;
  410. HSV2LED(COLOUR_RED, 255, BrightLevel);
  411. //in15Plus();
  412. symToFade = sym_Plus;
  413. IN15_FadeIn();
  414. //PlusFadeIn();
  415. tube4_t buf;
  416. buf.s8.tA = 0xf;
  417. buf.s8.tB = 0xf;
  418. buf.s8.tD = Temperature / 10;
  419. buf.s8.tE = Temperature % 10;
  420. showDigits(buf);
  421. }
  422. void showPressure(void) {
  423. dispWDT = DISP_WDT_TIME;
  424. HSV2LED(COLOUR_GREEN, 255, cie[Lvl_Mdl]); // GREEN
  425. //in15P();
  426. symToFade = sym_Pressure;
  427. IN15_FadeIn();
  428. //PressureFadeIn();
  429. tube4_t buf;
  430. int tmp;
  431. buf.s8.tA = 0xf;
  432. buf.s8.tB = Pressure / 100;
  433. tmp = Pressure % 100;
  434. buf.s8.tD = tmp / 10;
  435. buf.s8.tE = tmp % 10;
  436. showDigits(buf);
  437. }
  438. /* Simple function for cyclic show all sensor data */
  439. void showSensorData(void) {
  440. RTOS_DeleteTask(MinusFadeOut);
  441. showTemperature();
  442. tdelay_ms(3000);
  443. showHumidity();
  444. tdelay_ms(3000);
  445. showPressure();
  446. tdelay_ms(2700);
  447. ES_SetState(stShowTime);
  448. // showTime();
  449. }
  450. void setTimeShow(void) {
  451. dispWDT = DISP_WDT_TIME;
  452. tube4_t buf;
  453. buf.s8.tA = setClock.Hr >> 4;
  454. buf.s8.tB = setClock.Hr & 0xf;
  455. buf.s8.tD = setClock.Min >> 4;
  456. buf.s8.tE = setClock.Min & 0xf;
  457. showDigits(buf);
  458. }
  459. void setTimeBegin(void) {
  460. dispWDT = DISP_WDT_TIME;
  461. in15Minus();
  462. HSV2LED(COLOUR_NIXIE, 255, BrightLevel);
  463. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  464. RTC_ReadAll(&setClock);
  465. }
  466. void setHHBegin(void) {
  467. dispWDT = DISP_WDT_TIME;
  468. Flag.Blink_1 = 1;
  469. Flag.Blink_2 = 1;
  470. Flag.Blink_4 = 0;
  471. Flag.Blink_5 = 0;
  472. Blink_Start();
  473. setTimeShow();
  474. }
  475. void setHHInc(void) {
  476. valIncrease(&setClock.Hr, 23);
  477. }
  478. void setHHDec(void) {
  479. valDecrease(&setClock.Hr, 23);
  480. }
  481. void setMMBegin(void) {
  482. dispWDT = DISP_WDT_TIME;
  483. Flag.Blink_1 = 0;
  484. Flag.Blink_2 = 0;
  485. Flag.Blink_4 = 1;
  486. Flag.Blink_5 = 1;
  487. Blink_Start();
  488. setTimeShow();
  489. }
  490. void setMMInc(void) {
  491. valIncrease(&setClock.Min, 59);
  492. }
  493. void setMMDec(void) {
  494. valDecrease(&setClock.Min, 59);
  495. }
  496. void setTimeEnd(void) {
  497. dispWDT = 0;
  498. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  499. setClock.Sec = 0;
  500. RTC_WriteTime(&setClock);
  501. Flag.Blink_1 = 0;
  502. Flag.Blink_2 = 0;
  503. Flag.Blink_4 = 0;
  504. Flag.Blink_5 = 0;
  505. Blink_Stop();
  506. RTC_ReadAll(&Clock);
  507. }
  508. void setDateBegin(void) {
  509. dispWDT = DISP_WDT_TIME;
  510. IN15_OFF;
  511. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  512. RTC_ReadAll(&setClock);
  513. }
  514. void setDateEnd(void) {
  515. dispWDT = 0;
  516. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  517. RTC_WriteCalendar(&setClock);
  518. Flag.Blink_1 = 0;
  519. Flag.Blink_2 = 0;
  520. Flag.Blink_4 = 0;
  521. Flag.Blink_5 = 0;
  522. Blink_Stop();
  523. RTC_ReadAll(&Clock);
  524. }
  525. void setWDBegin(void) {
  526. dispWDT = DISP_WDT_TIME;
  527. Flag.Blink_1 = 0;
  528. Flag.Blink_2 = 1;
  529. Flag.Blink_4 = 0;
  530. Flag.Blink_5 = 0;
  531. Blink_Start();
  532. setWDShow();
  533. }
  534. void setWDShow(void) {
  535. dispWDT = DISP_WDT_TIME;
  536. tube4_t buf;
  537. buf.s8.tA = 0xf;
  538. buf.s8.tB = setClock.WD & 0xf;
  539. buf.s8.tD = 0xf;
  540. buf.s8.tE = 0xf;
  541. showDigits(buf);
  542. }
  543. void setDMShow(void) {
  544. dispWDT = DISP_WDT_TIME;
  545. tube4_t buf;
  546. buf.s8.tA = setClock.Day >> 4;
  547. buf.s8.tB = setClock.Day & 0xf;
  548. buf.s8.tD = setClock.Mon >> 4;
  549. buf.s8.tE = setClock.Mon & 0xf;
  550. showDigits(buf);
  551. }
  552. void setYearShow(void) {
  553. dispWDT = DISP_WDT_TIME;
  554. tube4_t buf;
  555. buf.s8.tA = 2;
  556. buf.s8.tB = 0;
  557. buf.s8.tD = setClock.Year >> 4;
  558. buf.s8.tE = setClock.Year & 0xf;
  559. showDigits(buf);
  560. }
  561. void setMDBegin(void) {
  562. dispWDT = DISP_WDT_TIME;
  563. Flag.Blink_1 = 1;
  564. Flag.Blink_2 = 1;
  565. Flag.Blink_4 = 0;
  566. Flag.Blink_5 = 0;
  567. Blink_Start();
  568. setDMShow();
  569. }
  570. void setMonthBegin(void) {
  571. dispWDT = DISP_WDT_TIME;
  572. Flag.Blink_1 = 0;
  573. Flag.Blink_2 = 0;
  574. Flag.Blink_4 = 1;
  575. Flag.Blink_5 = 1;
  576. Blink_Start();
  577. setDMShow();
  578. }
  579. void setYearBegin(void) {
  580. dispWDT = DISP_WDT_TIME;
  581. Flag.Blink_1 = 0;
  582. Flag.Blink_2 = 0;
  583. Flag.Blink_4 = 1;
  584. Flag.Blink_5 = 1;
  585. Blink_Start();
  586. setYearShow();
  587. }
  588. void setIncWDay(void) {
  589. valIncrease(&setClock.WD, 7);
  590. }
  591. void setIncMDay(void) {
  592. valIncrease(&setClock.Day, 31);
  593. }
  594. void setIncMonth(void) {
  595. valIncrease(&setClock.Mon, 12);
  596. }
  597. void setIncYear(void) {
  598. valIncrease(&setClock.Year, 99);
  599. }
  600. void setDecWDay(void) {
  601. valDecrease(&setClock.WD, 7);
  602. }
  603. void setDecMDay(void) {
  604. valDecrease(&setClock.Day, 31);
  605. }
  606. void setDecMonth(void) {
  607. valDecrease(&setClock.Mon, 12);
  608. }
  609. void setDecYear(void) {
  610. valDecrease(&setClock.Year, 99);
  611. }
  612. /**
  613. * @brief Increase BCD value.
  614. * @param : val, max
  615. * @retval : None
  616. */
  617. static void valIncrease(uint8_t * val, uint8_t max) {
  618. uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f);
  619. if (bin < max) {
  620. bin ++;
  621. } else {
  622. bin = 0;
  623. }
  624. *val = ((bin / 10 ) << 4) | (bin % 10);
  625. }
  626. /**
  627. * @brief Decrease BCD value.
  628. * @param : value, max
  629. * @retval : None
  630. */
  631. static void valDecrease(uint8_t * val, uint8_t max) {
  632. uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f);
  633. if (bin > 0) {
  634. bin --;
  635. } else {
  636. bin = max;
  637. }
  638. *val = ((bin / 10 ) << 4) | (bin % 10);
  639. }