slcd.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief SAM Segment Liquid Crystal Display(SLCD) Controller.
  6. *
  7. * This file defines a useful set of functions for the SLCD on SAM devices.
  8. *
  9. * Copyright (c) 2015-2016 Atmel Corporation. All rights reserved.
  10. *
  11. * \asf_license_start
  12. *
  13. * \page License
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * 1. Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. *
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. *
  25. * 3. The name of Atmel may not be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * 4. This software may only be redistributed and used in connection with an
  29. * Atmel microcontroller product.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  32. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  33. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  34. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  35. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  40. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. * \asf_license_stop
  44. *
  45. */
  46. /*
  47. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  48. */
  49. #include <slcd.h>
  50. #include <conf_slcd.h>
  51. #include <system.h>
  52. #if !defined(CONF_SLCD_CLOCK_SOURCE)
  53. # warning SLCD_CLOCK_SOURCE is not defined, assuming 0.
  54. # define CONF_SLCD_CLOCK_SOURCE 0
  55. #endif
  56. #if !defined(CONF_SLCD_DUTY)
  57. # warning CONF_SLCD_DUTY is not defined, assuming 0.
  58. # define CONF_SLCD_DUTY 0
  59. #endif
  60. #if !defined(CONF_SLCD_BIAS)
  61. # warning CONF_SLCD_BIAS is not defined, assuming 0.
  62. # define CONF_SLCD_BIAS 0
  63. #endif
  64. #if !defined(CONF_SLCD_PVAL)
  65. # warning CONF_SLCD_PVAL is not defined, assuming 0.
  66. # define CONF_SLCD_PVAL 0
  67. #endif
  68. #if !defined(CONF_SLCD_CKDIV)
  69. # warning CONF_SLCD_CKDIV is not defined, assuming 0.
  70. # define CONF_SLCD_CKDIV 0
  71. #endif
  72. #if !defined(CONF_SLCD_VLCD_SEL)
  73. # warning CONF_SLCD_VLCD_SEL is not defined, assuming 0.
  74. # define CONF_SLCD_VLCD_SEL 0
  75. #endif
  76. #if !defined(CONF_SLCD_REF_REFRESH_FREQ)
  77. # warning CONF_SLCD_REF_REFRESH_FREQ is not defined, assuming 0.
  78. # define CONF_SLCD_REF_REFRESH_FREQ 0
  79. #endif
  80. #if !defined(CONF_SLCD_POWER_REFRESH_FREQ)
  81. # warning CONF_SLCD_POWER_REFRESH_FREQ is not defined, assuming 0.
  82. # define CONF_SLCD_POWER_REFRESH_FREQ 0
  83. #endif
  84. #if !defined(CONF_SLCD_POWER_MODE)
  85. # warning CONF_SLCD_POWER_MODE is not defined, assuming 0.
  86. # define CONF_SLCD_POWER_MODE 0
  87. #endif
  88. #if !defined(CONF_SLCD_PIN_L_MASK)
  89. # warning CONF_SLCD_PIN_L_MASK is not defined, assuming 0.
  90. # define CONF_SLCD_PIN_L_MASK 0
  91. #endif
  92. #if !defined(CONF_SLCD_PIN_H_MASK)
  93. # warning CONF_SLCD_PIN_H_MASK is not defined, assuming 0.
  94. # define CONF_SLCD_PIN_H_MASK 0
  95. #endif
  96. /**
  97. * \brief Initializes SLCD configurations struct to defaults
  98. *
  99. * Initailizes SLCD configuration struct to predefined safe default settings.
  100. *
  101. * \param[in] config Pointer to an instance of \ref struct slcd_config
  102. *
  103. */
  104. void slcd_get_config_defaults(struct slcd_config *config)
  105. {
  106. Assert(config);
  107. config->run_in_standby = false;
  108. config->waveform_mode = SLCD_LOW_POWER_WAVEFORM_MODE;
  109. config->low_resistance_duration = 0;
  110. config->enable_low_resistance = false;
  111. config->bias_buffer_duration = 0;
  112. config->enable_bias_buffer = false;
  113. }
  114. /**
  115. * \brief Initialize SLCD module
  116. *
  117. * \param[in] config Pointer to an SLCD configuration structure
  118. *
  119. * \note SLCD cannot be Initialized while it is enabled.
  120. *
  121. * \return Status of the configuration procedure.
  122. * \retval STATUS_OK SLCD configuration went successful
  123. * \retval STATUS_ERR_INVALID_ARG If an invalid configuration was supplied
  124. */
  125. enum status_code slcd_init(struct slcd_config *const config)
  126. {
  127. if (!config) {
  128. return STATUS_ERR_INVALID_ARG;
  129. }
  130. system_apb_clock_set_mask(SYSTEM_CLOCK_APB_APBC, MCLK_APBCMASK_SLCD);
  131. /* Select SLCD clock */
  132. OSC32KCTRL->SLCDCTRL.reg = CONF_SLCD_CLOCK_SOURCE & OSC32KCTRL_SLCDCTRL_MASK;
  133. slcd_disable();
  134. slcd_reset();
  135. SLCD->CTRLA.reg = SLCD_CTRLA_DUTY(CONF_SLCD_DUTY) | SLCD_CTRLA_BIAS(CONF_SLCD_BIAS)
  136. | SLCD_CTRLA_PRESC(CONF_SLCD_PVAL) | SLCD_CTRLA_CKDIV(CONF_SLCD_CKDIV)
  137. | (CONF_SLCD_VLCD_SEL << SLCD_CTRLA_XVLCD_Pos)
  138. | (config->run_in_standby << SLCD_CTRLA_RUNSTDBY_Pos)
  139. | SLCD_CTRLA_RRF(CONF_SLCD_REF_REFRESH_FREQ)
  140. | SLCD_CTRLA_PRF(CONF_SLCD_POWER_REFRESH_FREQ)
  141. | (config->waveform_mode << SLCD_CTRLA_WMOD_Pos);
  142. SLCD->CTRLB.reg = SLCD_CTRLB_BBD(config->bias_buffer_duration)
  143. | (config->enable_bias_buffer << SLCD_CTRLB_BBEN_Pos)
  144. | SLCD_CTRLB_LRD(config->low_resistance_duration)
  145. | (config->enable_low_resistance << SLCD_CTRLB_LREN_Pos);
  146. SLCD->CTRLC.reg |= SLCD_CTRLC_LPPM(CONF_SLCD_POWER_MODE) | SLCD_CTRLC_CTST(0x0F);
  147. SLCD->LPENL.reg = CONF_SLCD_PIN_L_MASK & SLCD_LPENL_MASK;
  148. SLCD->LPENH.reg = CONF_SLCD_PIN_H_MASK & SLCD_LPENH_MASK;
  149. return STATUS_OK;
  150. }
  151. /**
  152. * \brief Enables the SLCD module
  153. *
  154. * Enables the SLCD module once it has been configured, ready for use. Most
  155. * module configuration parameters cannot be altered while the module is enabled.
  156. */
  157. void slcd_enable(void)
  158. {
  159. SLCD->CTRLA.reg |= SLCD_CTRLA_ENABLE;
  160. while (slcd_is_syncing()) {
  161. /* Wait for synchronization */
  162. }
  163. while (!slcd_get_vlcd_ready_status()) {
  164. }
  165. }
  166. /**
  167. * \brief Disables the SLCD module
  168. *
  169. * Disables the SLCD module.
  170. */
  171. void slcd_disable(void)
  172. {
  173. SLCD->INTENCLR.reg = SLCD_INTENCLR_MASK;
  174. SLCD->INTFLAG.reg = SLCD_INTFLAG_MASK;
  175. SLCD->CTRLA.reg &= ~(SLCD_CTRLA_ENABLE);
  176. while (slcd_is_syncing()) {
  177. /* Wait for synchronization */
  178. }
  179. }
  180. /**
  181. * \brief Check if SLCD module is enabled or not
  182. *
  183. * Check if SLCD module is enabled or not.
  184. *
  185. * \return Enable status.
  186. * \retval true SLCD module is enabled
  187. * \retval false SLCD module is disabled
  188. */
  189. bool slcd_is_enabled(void)
  190. {
  191. return ((SLCD->CTRLA.reg & SLCD_CTRLA_ENABLE) == SLCD_CTRLA_ENABLE);
  192. }
  193. /**
  194. * \brief Reset the SLCD module
  195. *
  196. * Reset the SLCD module.
  197. */
  198. void slcd_reset(void)
  199. {
  200. slcd_disable();
  201. SLCD->CTRLA.reg |= SLCD_CTRLA_SWRST;
  202. while (slcd_is_syncing()) {
  203. /* Wait for synchronization */
  204. }
  205. }
  206. /**
  207. * \brief Set the SLCD fine contrast
  208. *
  209. * The LCD contrast is defined by the value of VLCD voltage. The higher is the
  210. * VLCD voltage, the higher is the contrast. The software contrast adjustment
  211. * is only possible in internal supply mode.
  212. * In internal supply mode, VLCD is in the range 2.5V to 3.5V. VLCD can be
  213. * adjusted with 16 steps, each step is 60 mV.The contrast value can be written
  214. * at any time.
  215. *
  216. * \param[in] contrast Contrast value
  217. *
  218. * \return Status of set contrast.
  219. * \retval STATUS_OK SLCD contrast set successful
  220. * \retval STATUS_ERR_INVALID_ARG SLCD is not working in internal supply mode
  221. */
  222. enum status_code slcd_set_contrast(uint8_t contrast)
  223. {
  224. if (SLCD->CTRLA.bit.XVLCD) {
  225. return STATUS_ERR_INVALID_ARG;
  226. }
  227. uint16_t temp = SLCD->CTRLC.reg;
  228. temp &= ~ SLCD_CTRLC_CTST(0xf);
  229. temp |= SLCD_CTRLC_CTST(contrast);
  230. SLCD->CTRLC.reg = temp;
  231. return STATUS_OK;
  232. }
  233. /**
  234. * \brief Initializes SLCD blink configurations struct to defaults
  235. *
  236. * Initailizes SLCD blink configuration struct to predefined safe default settings.
  237. *
  238. * \param[in] config Pointer to an instance of \ref struct slcd_blink_config
  239. *
  240. */
  241. void slcd_blink_get_config_defaults(struct slcd_blink_config *blink_config)
  242. {
  243. Assert(blink_config);
  244. blink_config->fc = SLCD_FRAME_COUNTER_0;
  245. blink_config->blink_all_seg = true;
  246. }
  247. /**
  248. * \brief Set SLCD blink mode
  249. *
  250. * Set SLCD blink mode.
  251. *
  252. * \note SLCD blink cannot be set while module or blink is enabled.
  253. *
  254. * \param[in] config Pointer to an SLCD blink configuration structure
  255. *
  256. * \return Status of the configuration procedure.
  257. * \retval STATUS_OK SLCD blink configuration went successful
  258. * \retval STATUS_ERR_INVALID_ARG If blink configuration failed
  259. */
  260. enum status_code slcd_blink_set_config(struct slcd_blink_config *const blink_config)
  261. {
  262. if (!blink_config) {
  263. return STATUS_ERR_INVALID_ARG;
  264. }
  265. SLCD->BCFG.bit.MODE = (!(blink_config->blink_all_seg) << SLCD_BCFG_MODE_Pos);
  266. SLCD->BCFG.bit.FCS = SLCD_BCFG_FCS(blink_config->fc);
  267. return STATUS_OK;
  268. }
  269. /**
  270. * \brief Start an SLCD pixel/segment blinking
  271. *
  272. * \param[in] pix_com Pixel/segment COM coordinate
  273. * \param[in] pix_seg Pixel/segment SEG coordinate (range 0 to 1 inclusive)
  274. */
  275. void slcd_set_blink_pixel(
  276. uint8_t pix_com,
  277. uint8_t pix_seg)
  278. {
  279. /* Validate parameters. */
  280. Assert(pix_seg<=1);
  281. if (pix_seg == 0) {
  282. SLCD->BCFG.reg |= SLCD_BCFG_BSS0(1 << pix_com);
  283. }
  284. if (pix_seg == 1) {
  285. SLCD->BCFG.reg |= SLCD_BCFG_BSS1(1 << pix_com);
  286. }
  287. }
  288. /**
  289. * \brief Stop a specified SLCD pixel/segment from blinking
  290. *
  291. * \param[in] pix_com Pixel/segment COM coordinate
  292. * \param[in] pix_seg Pixel/segment SEG coordinate (range 0 to 1 inclusive)
  293. */
  294. void slcd_clear_blink_pixel(
  295. uint8_t pix_com,
  296. uint8_t pix_seg)
  297. {
  298. /* Validate parameters. */
  299. Assert(pix_seg<=1);
  300. if (pix_seg == 0) {
  301. SLCD->BCFG.reg &= ~ SLCD_BCFG_BSS0(1 << pix_com);
  302. }
  303. if (pix_seg == 1) {
  304. SLCD->BCFG.reg &= ~ SLCD_BCFG_BSS1(1 << pix_com);
  305. }
  306. }
  307. /**
  308. * \brief Stop all SLCD pixels/segments from blinking
  309. */
  310. void slcd_clear_blink_all_pixel(void)
  311. {
  312. SLCD->BCFG.bit.BSS0 = 0;
  313. SLCD->BCFG.bit.BSS1 = 0;
  314. }
  315. /**
  316. * \brief Set all bits in the SLCD display memory high
  317. */
  318. void slcd_set_display_memory(void)
  319. {
  320. SLCD->SDATAH0.reg = SLCD_SDATAH0_MASK;
  321. SLCD->SDATAL0.reg = SLCD_SDATAL0_MASK;
  322. SLCD->SDATAH1.reg = SLCD_SDATAH1_MASK;
  323. SLCD->SDATAL1.reg = SLCD_SDATAL1_MASK;
  324. SLCD->SDATAH2.reg = SLCD_SDATAH2_MASK;
  325. SLCD->SDATAL2.reg = SLCD_SDATAL2_MASK;
  326. SLCD->SDATAH3.reg = SLCD_SDATAH3_MASK;
  327. SLCD->SDATAL3.reg = SLCD_SDATAL3_MASK;
  328. SLCD->SDATAH4.reg = SLCD_SDATAH4_MASK;
  329. SLCD->SDATAL4.reg = SLCD_SDATAL4_MASK;
  330. SLCD->SDATAH5.reg = SLCD_SDATAH5_MASK;
  331. SLCD->SDATAL5.reg = SLCD_SDATAL5_MASK;
  332. SLCD->SDATAH6.reg = SLCD_SDATAH6_MASK;
  333. SLCD->SDATAL6.reg = SLCD_SDATAL6_MASK;
  334. SLCD->SDATAH7.reg = SLCD_SDATAH7_MASK;
  335. SLCD->SDATAL7.reg = SLCD_SDATAL7_MASK;
  336. }
  337. /**
  338. * \brief Enable the specified pixel/segment in the SLCD display memory
  339. *
  340. * \param[in] pix_com Pixel/segment COM coordinate,within [0-7]
  341. * \param[in] pix_seg Pixel/segment SEG coordinate within [0-43]
  342. */
  343. void slcd_set_pixel(
  344. uint8_t pix_com,
  345. uint8_t pix_seg)
  346. {
  347. if ((pix_com < SLCD_MAX_COM) &&
  348. (pix_seg < SLCD_MAX_SEG)) {
  349. switch(pix_com){
  350. case 0:
  351. if (pix_seg >= 32) {
  352. SLCD->SDATAH0.reg |= (1 <<(pix_seg-32));
  353. } else {
  354. SLCD->SDATAL0.reg |= 1 <<pix_seg;
  355. }
  356. break;
  357. case 1:
  358. if (pix_seg >= 32) {
  359. SLCD->SDATAH1.reg |= (1 <<(pix_seg-32));
  360. } else {
  361. SLCD->SDATAL1.reg |= 1 <<pix_seg;
  362. }
  363. break;
  364. case 2:
  365. if (pix_seg >= 32) {
  366. SLCD->SDATAH2.reg |= (1 <<(pix_seg-32));
  367. } else {
  368. SLCD->SDATAL2.reg |= 1 <<pix_seg;
  369. }
  370. break;
  371. case 3:
  372. if (pix_seg >= 32) {
  373. SLCD->SDATAH3.reg |= (1 <<(pix_seg-32));
  374. } else {
  375. SLCD->SDATAL3.reg |= 1 <<pix_seg;
  376. }
  377. break;
  378. case 4:
  379. if (pix_seg >= 32) {
  380. SLCD->SDATAH4.reg |= (1 <<(pix_seg-32));
  381. } else {
  382. SLCD->SDATAL4.reg |= 1 <<pix_seg;
  383. }
  384. break;
  385. case 5:
  386. if (pix_seg >= 32) {
  387. SLCD->SDATAH5.reg |= (1 <<(pix_seg-32));
  388. } else {
  389. SLCD->SDATAL5.reg |= 1 <<pix_seg;
  390. }
  391. break;
  392. case 6:
  393. if (pix_seg >= 32) {
  394. SLCD->SDATAH6.reg |= (1 <<(pix_seg-32));
  395. } else {
  396. SLCD->SDATAL6.reg |= 1 <<pix_seg;
  397. }
  398. break;
  399. case 7:
  400. if (pix_seg >= 32) {
  401. SLCD->SDATAH7.reg |= (1 <<(pix_seg-32));
  402. } else {
  403. SLCD->SDATAL7.reg |= 1 <<pix_seg;
  404. }
  405. break;
  406. }
  407. while (slcd_get_char_writing_status()) {
  408. }
  409. }
  410. }
  411. /**
  412. * \brief Disable the specified pixel/segment in the SLCD display memory
  413. *
  414. * \param[in] pix_com Pixel/segment COM coordinate
  415. * \param[in] pix_seg Pixel/segment SEG coordinate
  416. */
  417. void slcd_clear_pixel(uint8_t pix_com, uint8_t pix_seg)
  418. {
  419. if ((pix_com < SLCD_MAX_COM) &&
  420. (pix_seg < SLCD_MAX_SEG)) {
  421. switch(pix_com){
  422. case 0:
  423. if (pix_seg >= 32) {
  424. SLCD->SDATAH0.reg &= ~(1 <<(pix_seg-32));
  425. } else {
  426. SLCD->SDATAL0.reg &= ~(1 <<pix_seg);
  427. }
  428. break;
  429. case 1:
  430. if (pix_seg >= 32) {
  431. SLCD->SDATAH1.reg &= ~(1 <<(pix_seg-32));
  432. } else {
  433. SLCD->SDATAL1.reg &= ~(1 <<pix_seg);
  434. }
  435. break;
  436. case 2:
  437. if (pix_seg >= 32) {
  438. SLCD->SDATAH2.reg &= (1 <<(pix_seg-32));
  439. } else {
  440. SLCD->SDATAL2.reg &= ~(1 <<pix_seg);
  441. }
  442. break;
  443. case 3:
  444. if (pix_seg >= 32) {
  445. SLCD->SDATAH3.reg &= ~(1 <<(pix_seg-32));
  446. } else {
  447. SLCD->SDATAL3.reg &= ~(1 <<pix_seg);
  448. }
  449. break;
  450. case 4:
  451. if (pix_seg >= 32) {
  452. SLCD->SDATAH4.reg &= ~(1 <<(pix_seg-32));
  453. } else {
  454. SLCD->SDATAL4.reg &= ~(1 <<pix_seg);
  455. }
  456. break;
  457. case 5:
  458. if (pix_seg >= 32) {
  459. SLCD->SDATAH5.reg &= ~(1 <<(pix_seg-32));
  460. } else {
  461. SLCD->SDATAL5.reg &= ~(1 <<pix_seg);
  462. }
  463. break;
  464. case 6:
  465. if (pix_seg >= 32) {
  466. SLCD->SDATAH6.reg &= ~(1 <<(pix_seg-32));
  467. } else {
  468. SLCD->SDATAL6.reg &= ~(1 <<pix_seg);
  469. }
  470. break;
  471. case 7:
  472. if (pix_seg >= 32) {
  473. SLCD->SDATAH7.reg &= ~(1 <<(pix_seg-32));
  474. } else {
  475. SLCD->SDATAL7.reg &= ~(1 <<pix_seg);
  476. }
  477. break;
  478. }
  479. while (slcd_get_char_writing_status()) {
  480. }
  481. }
  482. }
  483. /**
  484. * \brief Set the specified segment in the SLCD display memory
  485. *
  486. * \param[in] pix_seg Pixel/segment SEG coordinate
  487. * \param[in] byte_offset Byte offset in display memory
  488. * \param[in] seg_mask Byte offset in display memory
  489. */
  490. void slcd_set_seg_data(uint8_t seg_data,uint8_t byte_offset,uint8_t seg_mask)
  491. {
  492. SLCD->ISDATA.reg = SLCD_ISDATA_SDATA(seg_data)
  493. | SLCD_ISDATA_OFF(byte_offset)
  494. | SLCD_ISDATA_SDMASK(seg_mask);
  495. while (slcd_get_char_writing_status()) {
  496. }
  497. }
  498. /**
  499. * \brief Initializes SLCD Automated Character configurations struct to defaults
  500. *
  501. * Initailizes SLCD Automated Character configuration struct to predefined safe default settings.
  502. *
  503. * \param[in] config Pointer to an instance of \ref struct slcd_automated_char_config
  504. *
  505. */
  506. void slcd_automated_char_get_config_default(
  507. struct slcd_automated_char_config *config)
  508. {
  509. Assert(config);
  510. config->order = SLCD_AUTOMATED_CHAR_START_FROM_BOTTOM_RIGHT;
  511. config->fc = SLCD_FRAME_COUNTER_0;
  512. config->mode = SLCD_AUTOMATED_CHAR_SEQ;
  513. config->seg_line_num = 0;
  514. config->start_seg_line = 0;
  515. config->row_digit_num = 1;
  516. config->digit_num = 0;
  517. config->scrolling_step = 1;
  518. config->com_line_num = 1;
  519. config->data_mask = 0;
  520. }
  521. /**
  522. * \brief Set SLCD automated character
  523. *
  524. * Set automated character mode.
  525. *
  526. * \note SLCD automated character mode cannot be set while module or
  527. * automated character is enabled.
  528. *
  529. * \param[in] config Pointer to an SLCD automated character configuration structure
  530. *
  531. * \return Status of the configuration procedure.
  532. * \retval STATUS_OK SLCD automated character configuration went successful
  533. * \retval STATUS_ERR_INVALID_ARG If automated character configuration failed
  534. */
  535. enum status_code slcd_automated_char_set_config(
  536. struct slcd_automated_char_config *const config)
  537. {
  538. if (!config) {
  539. return STATUS_ERR_INVALID_ARG;
  540. }
  541. SLCD->CMCFG.reg = SLCD_CMCFG_NSEG(config->seg_line_num)
  542. | (config->order << SLCD_CMCFG_DEC_Pos);
  543. SLCD->ACMCFG.reg = SLCD_ACMCFG_FCS(config->fc)
  544. | (config->mode << SLCD_ACMCFG_MODE_Pos)
  545. | SLCD_ACMCFG_STSEG(config->start_seg_line)
  546. | SLCD_ACMCFG_NDROW(config->row_digit_num)
  547. | SLCD_ACMCFG_NDIG(config->digit_num)
  548. | SLCD_ACMCFG_STEPS(config->scrolling_step)
  549. | SLCD_ACMCFG_NCOM(config->com_line_num);
  550. SLCD->CMDMASK.reg = SLCD_CMDMASK_SDMASK(config->data_mask);
  551. return STATUS_OK;
  552. }
  553. /**
  554. * \brief Set SLCD character mapping
  555. *
  556. * Set Character mode amd SEG line per digit.
  557. *
  558. * \param[in] order Mapping order in char mode
  559. * \param[in] seg_line_num Define the number of SEG line per digit,
  560. * it equal to number of SEG line - 1
  561. */
  562. void slcd_character_map_set(
  563. enum slcd_automated_char_order order,
  564. uint8_t seg_line_num)
  565. {
  566. SLCD->CMCFG.reg = SLCD_CMCFG_NSEG(seg_line_num)
  567. | (order << SLCD_CMCFG_DEC_Pos);
  568. }
  569. /**
  570. * \brief Write segments data to display memory in character mode
  571. *
  572. * \param[in] seg_data Pixel/segment data
  573. * \param[in] data_mask Segments data mask
  574. * \param[in] com_line_index COM line index
  575. * \param[in] seg_line_index Segments line index
  576. */
  577. void slcd_character_write_data(uint8_t com_line_index,
  578. uint8_t seg_line_index,
  579. uint32_t seg_data,uint32_t data_mask)
  580. {
  581. SLCD->CMINDEX.reg = SLCD_CMINDEX_SINDEX(seg_line_index)
  582. | SLCD_CMINDEX_CINDEX(com_line_index);
  583. SLCD->CMDMASK.reg = SLCD_CMDMASK_SDMASK(data_mask);
  584. SLCD->CMDATA.reg = SLCD_CMDATA_SDATA(seg_data);
  585. while (slcd_get_char_writing_status()) {
  586. }
  587. }
  588. /**
  589. * \brief Initializes circular shift configurations struct to defaults
  590. *
  591. * Initailizes circular shift configuration struct to predefined safe default settings.
  592. *
  593. * \param[in] config Pointer to an instance of \ref struct slcd_circular_shift_config
  594. *
  595. */
  596. void slcd_circular_shift_get_config_defaults(
  597. struct slcd_circular_shift_config *const config)
  598. {
  599. Assert(config);
  600. config->fc = SLCD_FRAME_COUNTER_0;
  601. config->dir = SLCD_CIRCULAR_SHIFT_LEFT;
  602. config->size = 0;
  603. config->data = 0;
  604. }
  605. /**
  606. * \brief Set SLCD circular shift
  607. *
  608. * Set circular shift mode.
  609. *
  610. * \note SLCD circular shift mode cannot be set while module or circular shift is enabled.
  611. *
  612. * \param[in] config Pointer to an SLCD circular shift configuration structure
  613. *
  614. * \return Status of the configuration procedure.
  615. * \retval STATUS_OK SLCD circular shift configuration went successful
  616. * \retval STATUS_ERR_INVALID_ARG If circular shift configuration failed
  617. */
  618. enum status_code slcd_circular_shift_set_config(
  619. struct slcd_circular_shift_config *const config)
  620. {
  621. if (!config) {
  622. return STATUS_ERR_INVALID_ARG;
  623. }
  624. SLCD->CSRCFG.reg = SLCD_CSRCFG_FCS(config->fc)
  625. | (config->dir << SLCD_CSRCFG_DIR_Pos)
  626. | SLCD_CSRCFG_SIZE(config->size)
  627. | SLCD_CSRCFG_DATA(config->data);
  628. return STATUS_OK;
  629. }