dmdif_ssd2119_ebi16.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*************************************************************************//**
  2. * @file dmdif_ssd2119_ebi.c
  3. * @brief Dot matrix display interface using EBI
  4. * @author Energy Micro AS
  5. ******************************************************************************
  6. * @section License
  7. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  8. ******************************************************************************
  9. *
  10. * Permission is granted to anyone to use this software for any purpose,
  11. * including commercial applications, and to alter it and redistribute it
  12. * freely, subject to the following restrictions:
  13. *
  14. * 1. The origin of this software must not be misrepresented; you must not
  15. * claim that you wrote the original software.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. * 4. The source and compiled code may only be used on Energy Micro "EFM32"
  20. * microcontrollers and "EFR4" radios.
  21. *
  22. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  23. * obligation to support this Software. Energy Micro AS is providing the
  24. * Software "AS IS", with no express or implied warranties of any kind,
  25. * including, but not limited to, any implied warranties of merchantability
  26. * or fitness for any particular purpose or warranties against infringement
  27. * of any proprietary rights of a third party.
  28. *
  29. * Energy Micro AS will not be liable for any consequential, incidental, or
  30. * special damages, or any other relief, or for any claim by any third party,
  31. * arising from your use of this Software.
  32. *
  33. *****************************************************************************/
  34. #include <stdint.h>
  35. #include "dmd_ssd2119_registers.h"
  36. #include "dmd_ssd2119.h"
  37. #include "dmdif_ssd2119_ebi.h"
  38. #include "dvk.h"
  39. /* Local function prototypes */
  40. static EMSTATUS setNextReg(uint8_t reg);
  41. static volatile uint16_t *command_register;
  42. static volatile uint16_t *data_register;
  43. /**************************************************************************//**
  44. * @brief
  45. * Initializes the data interface to the LCD controller SSD2119
  46. *
  47. *
  48. * @param cmdRegAddr
  49. * The address in memory where data to the command register in the display
  50. * controller are written
  51. * @param dataRegAddr
  52. * The address in memory where data to the data register in the display
  53. * controller are written
  54. *
  55. * @return
  56. * DMD_OK on success, otherwise error code
  57. ******************************************************************************/
  58. EMSTATUS DMDIF_init(uint32_t cmdRegAddr, uint32_t dataRegAddr)
  59. {
  60. command_register = (volatile uint16_t*) cmdRegAddr;
  61. data_register = (volatile uint16_t*) dataRegAddr;
  62. return DMD_OK;
  63. }
  64. /**************************************************************************//**
  65. * @brief
  66. * Writes a value to a control register in the LCD controller
  67. *
  68. * @param reg
  69. * The register that will be written to
  70. * @param data
  71. * The value to write to the register
  72. *
  73. * @return
  74. * DMD_OK on success, otherwise error code
  75. ******************************************************************************/
  76. EMSTATUS DMDIF_writeReg(uint8_t reg, uint16_t data)
  77. {
  78. setNextReg(reg);
  79. *data_register = data;
  80. return DMD_OK;
  81. }
  82. /**************************************************************************//**
  83. * @brief
  84. * Reads the device code of the LCD controller
  85. * DOESN'T WORK
  86. *
  87. * @return
  88. * The device code of the LCD controller
  89. ******************************************************************************/
  90. uint16_t DMDIF_readDeviceCode(void)
  91. {
  92. uint16_t deviceCode;
  93. /* Reading from the oscillation control register gives the device code */
  94. setNextReg(DMD_SSD2119_DEVICE_CODE_READ);
  95. deviceCode = *data_register;
  96. return deviceCode;
  97. }
  98. /**************************************************************************//**
  99. * @brief
  100. * Sends the data access command to the LCD controller to prepare for one or more
  101. * writes or reads using the DMDIF_writeData() and DMDIF_readData()
  102. *
  103. * @return
  104. * DMD_OK on success, otherwise error code
  105. ******************************************************************************/
  106. EMSTATUS DMDIF_prepareDataAccess(void)
  107. {
  108. setNextReg(DMD_SSD2119_ACCESS_DATA);
  109. return DMD_OK;
  110. }
  111. /**************************************************************************//**
  112. * @brief
  113. * Writes one pixel to the LCD controller. DMDIF_prepareDataAccess() needs to be
  114. * called before writing data using this function.
  115. *
  116. * @param data
  117. * The color value of the pixel to be written in 18bpp format
  118. *
  119. * @return
  120. * DMD_OK on success, otherwise error code
  121. ******************************************************************************/
  122. EMSTATUS DMDIF_writeData(uint32_t data)
  123. {
  124. *data_register = (data & 0x0000FFFF);
  125. return DMD_OK;
  126. }
  127. /**************************************************************************//**
  128. * @brief
  129. * Writes one pixel to the LCD controller. DMDIF_prepareDataAccess() needs to be
  130. * called before writing data using this function.
  131. *
  132. * @param data
  133. * The color value of the pixel to be written in 18bpp format
  134. *
  135. * @return
  136. * DMD_OK on success, otherwise error code
  137. ******************************************************************************/
  138. EMSTATUS DMDIF_writeDataRepeated( uint32_t data, int len ){
  139. uint16_t pixelData;
  140. int i;
  141. /* Write bits [8:0] of the pixel data to bits [8:0] on the output lines */
  142. pixelData = data & 0x0000FFFF;
  143. for (i=0; i<len; i++) {
  144. *data_register = pixelData;
  145. }
  146. return DMD_OK;
  147. }
  148. /**************************************************************************//**
  149. * @brief
  150. * Writes one pixel to the LCD controller. DMDIF_prepareDataAccess() needs to be
  151. * called before writing data using this function.
  152. *
  153. * @param a
  154. * The upper 9 bits of color value of the pixel to be written in 18bpp format
  155. *
  156. * @param b
  157. * The low 9 bits of color value of the pixel to be written in 18bpp format
  158. *
  159. * @return
  160. * DMD_OK on success, otherwise error code
  161. ******************************************************************************/
  162. EMSTATUS DMDIF_writeDataConverted( uint16_t a, uint16_t b ){
  163. uint16_t pixel;
  164. pixel = b >> 1;
  165. pixel |= (a << 8) & 0xFF00;
  166. *data_register = pixel;
  167. return DMD_OK;
  168. }
  169. /**************************************************************************//**
  170. * @brief
  171. * Reads a byte of data from the memory of the LCD controller.
  172. * DMDIF_prepareDataAccess() needs to be called before using this function.
  173. * DOESN'T WORK
  174. *
  175. * @return
  176. * 18bpp value of pixel
  177. ******************************************************************************/
  178. uint32_t DMDIF_readData(void)
  179. {
  180. uint32_t data;
  181. data = *data_register;
  182. return data;
  183. }
  184. /**************************************************************************//**
  185. * \brief
  186. * Sets the register in the LCD controller to write commands to
  187. *
  188. * \param reg
  189. * The next register in the LCD controller to write to
  190. *
  191. * @return
  192. * DMD_OK on success, otherwise error code
  193. ******************************************************************************/
  194. static EMSTATUS setNextReg(uint8_t reg)
  195. {
  196. uint16_t data;
  197. data = reg & 0xff;
  198. /* Write the register address to bits [8:1] in the index register */
  199. *command_register = data;
  200. return DMD_OK;
  201. }