clock.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. #include "clock.h"
  2. /* type defs */
  3. typedef struct {
  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-59, sat: 0-255, val (lightness): 0-255
  282. * @return none. RGB value out 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. uint8_t hue = bcd2bin(Clock.Sec);
  338. HSV2LED(hue, 255, BrightLevel);
  339. tube4_t buf;
  340. buf.s8.tA = Clock.Hr >> 4;
  341. buf.s8.tB = Clock.Hr & 0xf;
  342. buf.s8.tD = Clock.Min >> 4;
  343. buf.s8.tE = Clock.Min & 0xf;
  344. showDigits(buf);
  345. }
  346. void showMMSS(void) {
  347. RTOS_DeleteTask(MinusFadeOut);
  348. IN15_Minus;
  349. uint8_t hue = bcd2bin(Clock.Sec);
  350. HSV2LED(hue, 255, BrightLevel);
  351. tube4_t buf;
  352. buf.s8.tA = Clock.Min >> 4;
  353. buf.s8.tB = Clock.Min & 0xf;
  354. buf.s8.tD = Clock.Sec >> 4;
  355. buf.s8.tE = Clock.Sec & 0xf;
  356. showDigits(buf);
  357. }
  358. void showWD(void) {
  359. dispWDT = DISP_WDT_TIME;
  360. IN15_OFF;
  361. tube4_t buf;
  362. buf.s8.tA = 0xf;
  363. buf.s8.tB = Clock.WD & 0xf;
  364. buf.s8.tD = 0xf;
  365. buf.s8.tE = 0xf;
  366. showDigits(buf);
  367. }
  368. void showDayMon(void) {
  369. dispWDT = DISP_WDT_TIME;
  370. IN15_OFF;
  371. tube4_t buf;
  372. buf.s8.tA = Clock.Day >> 4;
  373. buf.s8.tB = Clock.Day & 0xf;
  374. buf.s8.tD = Clock.Mon >> 4;
  375. buf.s8.tE = Clock.Mon & 0xf;
  376. showDigits(buf);
  377. }
  378. void showYear(void) {
  379. dispWDT = DISP_WDT_TIME;
  380. IN15_OFF;
  381. tube4_t buf;
  382. buf.s8.tA = 2;
  383. buf.s8.tB = 0;
  384. buf.s8.tD = Clock.Year >> 4;
  385. buf.s8.tE = Clock.Year & 0xf;
  386. showDigits(buf);
  387. }
  388. void showHumidity(void) {
  389. dispWDT = DISP_WDT_TIME;
  390. HSV2LED(COLOUR_BLUE, 255, BrightLevel);
  391. //in15Percent();
  392. symToFade = sym_Percent;
  393. IN15_FadeIn();
  394. //PercentFadeIn();
  395. tube4_t buf;
  396. buf.s8.tA = Humidity / 10;
  397. buf.s8.tB = Humidity % 10;
  398. buf.s8.tD = 0xf;
  399. buf.s8.tE = 0xf;
  400. showDigits(buf);
  401. }
  402. void showTemperature(void) {
  403. dispWDT = DISP_WDT_TIME;
  404. HSV2LED(COLOUR_RED, 255, BrightLevel);
  405. //in15Plus();
  406. symToFade = sym_Plus;
  407. IN15_FadeIn();
  408. //PlusFadeIn();
  409. tube4_t buf;
  410. buf.s8.tA = 0xf;
  411. buf.s8.tB = 0xf;
  412. buf.s8.tD = Temperature / 10;
  413. buf.s8.tE = Temperature % 10;
  414. showDigits(buf);
  415. }
  416. void showPressure(void) {
  417. dispWDT = DISP_WDT_TIME;
  418. HSV2LED(COLOUR_GREEN, 255, cie[Lvl_Mdl]); // GREEN
  419. //in15P();
  420. symToFade = sym_Pressure;
  421. IN15_FadeIn();
  422. //PressureFadeIn();
  423. tube4_t buf;
  424. int tmp;
  425. buf.s8.tA = 0xf;
  426. buf.s8.tB = Pressure / 100;
  427. tmp = Pressure % 100;
  428. buf.s8.tD = tmp / 10;
  429. buf.s8.tE = tmp % 10;
  430. showDigits(buf);
  431. }
  432. /* Simple function for cyclic show all sensor data */
  433. void showSensorData(void) {
  434. RTOS_DeleteTask(MinusFadeOut);
  435. showTemperature();
  436. tdelay_ms(3000);
  437. showHumidity();
  438. tdelay_ms(3000);
  439. showPressure();
  440. tdelay_ms(2700);
  441. ES_SetState(stShowTime);
  442. // showTime();
  443. }
  444. void setTimeShow(void) {
  445. dispWDT = DISP_WDT_TIME;
  446. tube4_t buf;
  447. buf.s8.tA = setClock.Hr >> 4;
  448. buf.s8.tB = setClock.Hr & 0xf;
  449. buf.s8.tD = setClock.Min >> 4;
  450. buf.s8.tE = setClock.Min & 0xf;
  451. showDigits(buf);
  452. }
  453. void setTimeBegin(void) {
  454. dispWDT = DISP_WDT_TIME;
  455. in15Minus();
  456. HSV2LED(COLOUR_NIXIE, 255, BrightLevel);
  457. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  458. RTC_ReadAll(&setClock);
  459. }
  460. void setHHBegin(void) {
  461. dispWDT = DISP_WDT_TIME;
  462. Flag.Blink_1 = 1;
  463. Flag.Blink_2 = 1;
  464. Flag.Blink_4 = 0;
  465. Flag.Blink_5 = 0;
  466. Blink_Start();
  467. setTimeShow();
  468. }
  469. void setHHInc(void) {
  470. valIncrease(&setClock.Hr, 23);
  471. }
  472. void setHHDec(void) {
  473. valDecrease(&setClock.Hr, 23);
  474. }
  475. void setMMBegin(void) {
  476. dispWDT = DISP_WDT_TIME;
  477. Flag.Blink_1 = 0;
  478. Flag.Blink_2 = 0;
  479. Flag.Blink_4 = 1;
  480. Flag.Blink_5 = 1;
  481. Blink_Start();
  482. setTimeShow();
  483. }
  484. void setMMInc(void) {
  485. valIncrease(&setClock.Min, 59);
  486. }
  487. void setMMDec(void) {
  488. valDecrease(&setClock.Min, 59);
  489. }
  490. void setTimeEnd(void) {
  491. dispWDT = 0;
  492. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  493. setClock.Sec = 0;
  494. RTC_WriteTime(&setClock);
  495. Flag.Blink_1 = 0;
  496. Flag.Blink_2 = 0;
  497. Flag.Blink_4 = 0;
  498. Flag.Blink_5 = 0;
  499. Blink_Stop();
  500. RTC_ReadAll(&Clock);
  501. }
  502. void setDateBegin(void) {
  503. dispWDT = DISP_WDT_TIME;
  504. IN15_OFF;
  505. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  506. RTC_ReadAll(&setClock);
  507. }
  508. void setDateEnd(void) {
  509. dispWDT = 0;
  510. RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
  511. RTC_WriteCalendar(&setClock);
  512. Flag.Blink_1 = 0;
  513. Flag.Blink_2 = 0;
  514. Flag.Blink_4 = 0;
  515. Flag.Blink_5 = 0;
  516. Blink_Stop();
  517. RTC_ReadAll(&Clock);
  518. }
  519. void setWDBegin(void) {
  520. dispWDT = DISP_WDT_TIME;
  521. Flag.Blink_1 = 0;
  522. Flag.Blink_2 = 1;
  523. Flag.Blink_4 = 0;
  524. Flag.Blink_5 = 0;
  525. Blink_Start();
  526. setWDShow();
  527. }
  528. void setWDShow(void) {
  529. dispWDT = DISP_WDT_TIME;
  530. tube4_t buf;
  531. buf.s8.tA = 0xf;
  532. buf.s8.tB = setClock.WD & 0xf;
  533. buf.s8.tD = 0xf;
  534. buf.s8.tE = 0xf;
  535. showDigits(buf);
  536. }
  537. void setDMShow(void) {
  538. dispWDT = DISP_WDT_TIME;
  539. tube4_t buf;
  540. buf.s8.tA = setClock.Day >> 4;
  541. buf.s8.tB = setClock.Day & 0xf;
  542. buf.s8.tD = setClock.Mon >> 4;
  543. buf.s8.tE = setClock.Mon & 0xf;
  544. showDigits(buf);
  545. }
  546. void setYearShow(void) {
  547. dispWDT = DISP_WDT_TIME;
  548. tube4_t buf;
  549. buf.s8.tA = 2;
  550. buf.s8.tB = 0;
  551. buf.s8.tD = setClock.Year >> 4;
  552. buf.s8.tE = setClock.Year & 0xf;
  553. showDigits(buf);
  554. }
  555. void setMDBegin(void) {
  556. dispWDT = DISP_WDT_TIME;
  557. Flag.Blink_1 = 1;
  558. Flag.Blink_2 = 1;
  559. Flag.Blink_4 = 0;
  560. Flag.Blink_5 = 0;
  561. Blink_Start();
  562. setDMShow();
  563. }
  564. void setMonthBegin(void) {
  565. dispWDT = DISP_WDT_TIME;
  566. Flag.Blink_1 = 0;
  567. Flag.Blink_2 = 0;
  568. Flag.Blink_4 = 1;
  569. Flag.Blink_5 = 1;
  570. Blink_Start();
  571. setDMShow();
  572. }
  573. void setYearBegin(void) {
  574. dispWDT = DISP_WDT_TIME;
  575. Flag.Blink_1 = 0;
  576. Flag.Blink_2 = 0;
  577. Flag.Blink_4 = 1;
  578. Flag.Blink_5 = 1;
  579. Blink_Start();
  580. setYearShow();
  581. }
  582. void setIncWDay(void) {
  583. valIncrease(&setClock.WD, 7);
  584. }
  585. void setIncMDay(void) {
  586. valIncrease(&setClock.Day, 31);
  587. }
  588. void setIncMonth(void) {
  589. valIncrease(&setClock.Mon, 12);
  590. }
  591. void setIncYear(void) {
  592. valIncrease(&setClock.Year, 99);
  593. }
  594. void setDecWDay(void) {
  595. valDecrease(&setClock.WD, 7);
  596. }
  597. void setDecMDay(void) {
  598. valDecrease(&setClock.Day, 31);
  599. }
  600. void setDecMonth(void) {
  601. valDecrease(&setClock.Mon, 12);
  602. }
  603. void setDecYear(void) {
  604. valDecrease(&setClock.Year, 99);
  605. }
  606. /**
  607. * @brief Increase BCD value.
  608. * @param : val, max
  609. * @retval : None
  610. */
  611. static void valIncrease(uint8_t * val, uint8_t max) {
  612. uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f);
  613. if (bin < max) {
  614. bin ++;
  615. } else {
  616. bin = 0;
  617. }
  618. *val = ((bin / 10 ) << 4) | (bin % 10);
  619. }
  620. /**
  621. * @brief Decrease BCD value.
  622. * @param : value, max
  623. * @retval : None
  624. */
  625. static void valDecrease(uint8_t * val, uint8_t max) {
  626. uint8_t bin = 10 * (*val >> 4) + (*val & 0x0f);
  627. if (bin > 0) {
  628. bin --;
  629. } else {
  630. bin = max;
  631. }
  632. *val = ((bin / 10 ) << 4) | (bin % 10);
  633. }