dmdif_ssd2119_spi.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*************************************************************************//**
  2. * @file dmdif_ssd2119_ebi.c
  3. * @brief Dot matrix display SSD2119 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_spi.h"
  38. #include "dvk.h"
  39. /* Local function prototypes */
  40. static EMSTATUS setNextReg(uint8_t reg);
  41. static uint32_t command_register;
  42. static uint32_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 = cmdRegAddr;
  61. data_register = dataRegAddr;
  62. DVK_displayControl(DVK_Display_SPI);
  63. return DMD_OK;
  64. }
  65. /**************************************************************************//**
  66. * @brief
  67. * Writes a value to a control register in the LCD controller
  68. *
  69. * @param reg
  70. * The register that will be written to
  71. * @param data
  72. * The value to write to the register
  73. *
  74. * @return
  75. * DMD_OK on success, otherwise error code
  76. ******************************************************************************/
  77. EMSTATUS DMDIF_writeReg(uint8_t reg, uint16_t data)
  78. {
  79. setNextReg(reg);
  80. /* Write bits [15:8] of the data to bits [8:1] of the output lines */
  81. DVK_writeRegister( (uint16_t *) data_register, ((data & 0xff00) >> 8) << 1);
  82. /* Write bits [7:0] of the data to bits [8:1] of the output lines */
  83. DVK_writeRegister( (uint16_t *) data_register, (data & 0x00ff) << 1);
  84. return DMD_OK;
  85. }
  86. /**************************************************************************//**
  87. * @brief
  88. * Reads the device code of the LCD controller
  89. * DOESN'T WORK
  90. *
  91. * @return
  92. * The device code of the LCD controller
  93. ******************************************************************************/
  94. uint16_t DMDIF_readDeviceCode(void)
  95. {
  96. uint16_t readData;
  97. uint16_t deviceCode;
  98. /* Reading from the oscillation control register gives the device code */
  99. setNextReg(DMD_SSD2119_DEVICE_CODE_READ);
  100. readData = DVK_readRegister( (uint16_t *) data_register );
  101. deviceCode = ((readData >> 1) & 0x00ff) << 8;
  102. readData = DVK_readRegister( (uint16_t *) data_register );
  103. deviceCode |= ((readData >> 1) & 0x00ff);
  104. return deviceCode;
  105. }
  106. /**************************************************************************//**
  107. * @brief
  108. * Sends the data access command to the LCD controller to prepare for one or more
  109. * writes or reads using the DMDIF_writeData() and DMDIF_readData()
  110. *
  111. * @return
  112. * DMD_OK on success, otherwise error code
  113. ******************************************************************************/
  114. EMSTATUS DMDIF_prepareDataAccess(void)
  115. {
  116. setNextReg(DMD_SSD2119_ACCESS_DATA);
  117. return DMD_OK;
  118. }
  119. /**************************************************************************//**
  120. * @brief
  121. * Writes one pixel to the LCD controller. DMDIF_prepareDataAccess() needs to be
  122. * called before writing data using this function.
  123. *
  124. * @param data
  125. * The color value of the pixel to be written in 18bpp format
  126. *
  127. * @return
  128. * DMD_OK on success, otherwise error code
  129. ******************************************************************************/
  130. EMSTATUS DMDIF_writeData(uint32_t data)
  131. {
  132. /* Write bits [17:9] of the pixel data to bits [8:0] on the output lines */
  133. DVK_writeRegister( (uint16_t *) data_register, (data & 0x0003FE00) >> 9);
  134. /* Write bits [8:0] of the pixel data to bits [8:0] on the output lines */
  135. DVK_writeRegister( (uint16_t *) data_register, (data & 0x000001FF));
  136. return DMD_OK;
  137. }
  138. /**************************************************************************//**
  139. * @brief
  140. * Reads a byte of data from the memory of the LCD controller.
  141. * DMDIF_prepareDataAccess() needs to be called before using this function.
  142. * DOESN'T WORK
  143. *
  144. * @return
  145. * 18bpp value of pixel
  146. ******************************************************************************/
  147. uint32_t DMDIF_readData(void)
  148. {
  149. uint32_t data;
  150. /* Read bits [17:9] of the pixel */
  151. data = DVK__readRegister( (uint16_t *) data_register ) << 9;
  152. /* Read bits [8:0] of the pixel */
  153. data |= DVK_readRegister( (uint16_t *) data_register );
  154. return data;
  155. }
  156. /**************************************************************************//**
  157. * \brief
  158. * Sets the register in the LCD controller to write commands to
  159. *
  160. * \param reg
  161. * The next register in the LCD controller to write to
  162. *
  163. * @return
  164. * DMD_OK on success, otherwise error code
  165. ******************************************************************************/
  166. static EMSTATUS setNextReg(uint8_t reg)
  167. {
  168. uint16_t data;
  169. data = ((uint16_t) reg) << 1;
  170. /* First 9 bits is 0 */
  171. DVK_writeRegister( (uint16_t *) command_register, 0 );
  172. /* Write the register address to bits [8:1] in the index register */
  173. DVK_writeRegister( (uint16_t *) command_register, data );
  174. return DMD_OK;
  175. }