gd_ir.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*!
  2. *******************************************************************************
  3. **
  4. ** \file gd_ir.h
  5. **
  6. ** \brief Infrared driver.
  7. **
  8. ** The infrared driver is designed for GOKE decoder and
  9. ** supports two functions:
  10. ** - IR Receiver
  11. ** - IR Transmitter
  12. **
  13. ** The first one is to receive the remote controller signal and
  14. ** decode it. The other function is to generate the infrared signal
  15. ** and transmit it to other devices. The transmitter can be used to
  16. ** control external devices for example a VCR or TV set.
  17. ** The driver supports only the access to the hardware layer and
  18. ** does not handle any IR protocols like RC5, RC6 or Kaseikyou.
  19. ** These protocols have to be implemented on the top of this driver.
  20. **
  21. ** The IR receiver is a pulse-width counter and is clocked by the
  22. ** output of a 54MHz clocked pre-scaler.
  23. ** Every time the pre-scaler generates an enable signal the IR
  24. ** receiver checks if an edge on the input signal has occurred.
  25. ** The edge sensitivity of the IR receiver is programmable.
  26. ** After the time value is received, the upper level application
  27. ** should analyse the stored data and parse them.
  28. **
  29. ** The IR transmitter is a pulse generator. It consists of two
  30. ** 32bit registers to hold the data to be sent and
  31. ** a send_clock, a shift_clock, a compare and a mode register.
  32. ** Each time the sent clock counter counts to 0, the phase of the
  33. ** shift clock is inverted. The shift clock counter defines how
  34. ** many shift clocks are needed before shifting the data by one bit.
  35. ** The total number of 54MHz cycles per bit is therefore:
  36. ** 2 x (prescaler +1) x (shift_clock_count + 1).
  37. **
  38. ** In IRDA mode the compare register defines how many of the
  39. ** sent clocks are output. When starting
  40. ** the module the data of the first register are sent (MSB first).
  41. ** When a data word (32bit) is finished the module checks if data
  42. ** is available in the second register. If yes, this register is
  43. ** copied into the first register and sent afterwards.
  44. ** At the same time, an IRQ is generated to tell the system that
  45. ** new data are required.
  46. ** All data have to be written to register1 except the first 32bit
  47. ** to be sent.
  48. **
  49. ** Following are the IR sending out signal:
  50. **
  51. ** \image html gd_ir_timings.gif
  52. **
  53. ** - T1 = 2 x 1/54MHz x ( prescaler + 1 )
  54. ** - T2 = T1 x ( shift_clock_count + 1 )
  55. ** - T3 = T1 x ( comp_val + 1 )
  56. **
  57. ** Copyright: 2012 - 2013 (C) GoKe Microelectronics ShangHai Branch
  58. **
  59. ** \attention THIS SAMPLE CODE IS PROVIDED AS IS. GOKE MICROELECTRONICS
  60. ** ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR
  61. ** OMMISSIONS.
  62. **
  63. ** \version
  64. **
  65. ******************************************************************************/
  66. #ifndef _GD_IR_H_
  67. #define _GD_IR_H_
  68. #include <gtypes.h>
  69. #include <gmodids.h>
  70. /*---------------------------------------------------------------------------*/
  71. /* constants and macros */
  72. /*---------------------------------------------------------------------------*/
  73. #ifdef BOARD_FPGA
  74. #define IR_INPUT_CLK 24000000 // for 27MHZ Crystal
  75. #else
  76. #define IR_INPUT_CLK 24000000 // for 24MHZ Crystal
  77. #endif
  78. #define IR_FREQ 38 // for NEC unit:MHz
  79. /********************************/
  80. /* IRQ_EN_MASK Register */
  81. /********************************/
  82. #define IRQ_EN_RTC (1<<0)
  83. #define IRQ_EN_IRR (1<<1)
  84. #define IRQ_EN_GPIO (1<<3)
  85. #define IRQ_EN_IRT (1<<6)
  86. #define GD_IR_ERR_BASE (GD_IR_MODULE_ID<<16) //!< Error base value.
  87. #define GD_IR_EDGE_FLAG 0x0100
  88. #define GD_IR_VAL_BIT_MASK 0x00FF
  89. #define GD_IR_TRANSFER_MAX_DATA 32
  90. /*!
  91. *******************************************************************************
  92. **
  93. ** \brief IR driver error codes.
  94. **
  95. ******************************************************************************/
  96. enum
  97. {
  98. GD_ERR_IR_NO_SEQUENCE = GD_IR_ERR_BASE, //!< No sequence stored in IR buffer.
  99. GD_ERR_IR_TRANSMIT_INPROCESS, //!< IR transmission not finished yet.
  100. GD_ERR_IR_TRANSMIT_FAILURE, //!< IR transmission failed.
  101. };
  102. /*---------------------------------------------------------------------------*/
  103. /* types, enums and structures */
  104. /*---------------------------------------------------------------------------*/
  105. /*!
  106. *******************************************************************************
  107. **
  108. ** \brief IR type definitions.
  109. **
  110. ******************************************************************************/
  111. typedef enum
  112. {
  113. GD_IR_RECEIVER = 1, //!< Receiver function.
  114. GD_IR_TRANSMITTER, //!< Transmitter function.
  115. } GD_IR_TYPE_E;
  116. /*!
  117. *******************************************************************************
  118. **
  119. ** \brief IR driver status.
  120. **
  121. ******************************************************************************/
  122. typedef enum
  123. {
  124. GD_IR_RECEIVER_OPENED = 1, //!< IR receiver is open.
  125. GD_IR_TRANSMITTER_OPENED = 2, //!< IR transmitter is open.
  126. } GD_IR_STATUS_E;
  127. /*!
  128. *******************************************************************************
  129. **
  130. ** \brief Transmitter configuration parameters.
  131. **
  132. ******************************************************************************/
  133. typedef struct
  134. {
  135. U8 programming; //!< Programming register configuration.
  136. U16 prescaler; //!< IRDA clock register configuration.
  137. U8 shift_counter; //!< IRDA shift clock register configuration.
  138. U8 compare_value; //!< Compare value register configuration.
  139. S8 gpioIrtPin; //!< GPIO Pin to be assigned for IRT function.
  140. } GD_IR_TRANS_CONFIG_S;
  141. /*!
  142. *******************************************************************************
  143. **
  144. ** \brief Receiver configuration parameters.
  145. **
  146. ******************************************************************************/
  147. typedef struct
  148. {
  149. U16 prescaler; //!< Prescaler for IR receiver.
  150. S8 gpioIrrPin; //!< GPIO Pin to be assigned for IRR function.
  151. } GD_IR_RECEV_CONFIG_S;
  152. /*!
  153. *******************************************************************************
  154. **
  155. ** \brief Driver init parameters.
  156. **
  157. ** \sa GD_IR_Init()
  158. **
  159. ******************************************************************************/
  160. typedef struct
  161. {
  162. void (*notifyFunction)(); //!< Pointer to notification function.
  163. } GD_IR_INIT_PARAMS_S;
  164. /*!
  165. *******************************************************************************
  166. **
  167. ** \brief Open parameters.
  168. **
  169. ** \sa GD_IR_Open()
  170. **
  171. ******************************************************************************/
  172. typedef struct
  173. {
  174. GD_IR_TYPE_E type; //!< Receiver or transmitter.
  175. GD_IR_TRANS_CONFIG_S irt_config_s; //!< Configuration of transmitter.
  176. GD_IR_RECEV_CONFIG_S irr_config_s; //!< Configuration of receiver.
  177. } GD_IR_OPEN_PARAMS_S;
  178. /*!
  179. *******************************************************************************
  180. **
  181. ** \brief Data property for IR transmitter.
  182. **
  183. ** This structure defines the property of the transmitting
  184. ** data, the width for logic 1 and logic 0
  185. ** and the valid bits of the value of width.
  186. **
  187. ** \sa GD_IR_SetParams()
  188. **
  189. ******************************************************************************/
  190. typedef struct
  191. {
  192. U16 nValidbit0; //!< Valid bits of the value for logic 0.
  193. U16 bitvalue0; //!< Value for logic 0.
  194. U16 nValidbit1; //!< Valid bits of the value for logic 1.
  195. U16 bitvalue1; //!< Value for logic 1.
  196. } GD_IR_DATA_PROPERTY_S;
  197. /*!
  198. *******************************************************************************
  199. **
  200. ** \brief Insert data structure for IR transmitter.
  201. **
  202. ** This structure defines the header and footer or some other parts
  203. ** for the transmitter to insert the logic 0 or logic 1 into the
  204. ** output buffer.
  205. **
  206. ** \sa GD_IR_SetParams()
  207. **
  208. ******************************************************************************/
  209. typedef struct
  210. {
  211. U16 number; //!< Number of logic bit to be inserted.
  212. U8 bit; //!< Logic 0 or logic 1.
  213. } GD_IR_INSERT_S;
  214. /*!
  215. *******************************************************************************
  216. **
  217. ** \brief Output data structure for IR transmitter.
  218. **
  219. ** This structure defines the data value and the valid bits of this
  220. ** data.
  221. **
  222. ** \sa GD_IR_SetParams()
  223. **
  224. ******************************************************************************/
  225. typedef struct
  226. {
  227. U8 value; //!< Data value in byte.
  228. U8 validbit; //!< Valid bit of this data.
  229. } GD_IR_DATA_S;
  230. /*---------------------------------------------------------------------------*/
  231. /* function prototypes */
  232. /*---------------------------------------------------------------------------*/
  233. #ifdef __cplusplus
  234. extern "C" {
  235. #endif
  236. GERR GD_IR_Close(GD_HANDLE *pHandle);
  237. GERR GD_IR_Init(GD_IR_INIT_PARAMS_S *pInitParams);
  238. GERR GD_IR_IrtOpen(GD_IR_OPEN_PARAMS_S *pOpenParams, GD_HANDLE *pHandle);
  239. GERR GD_IR_IrrOpen(GD_IR_OPEN_PARAMS_S *pOpenParams, GD_HANDLE *pHandle);
  240. GERR GD_IR_Receive(GD_HANDLE handle, U16 *pData, U16 num);
  241. void GD_IR_SetNotifyFunction(void(*nfyFunc)());
  242. GERR GD_IR_SetParams(GD_HANDLE handle,
  243. GD_IR_INSERT_S *header,
  244. U8 nheader,
  245. GD_IR_DATA_S *data,
  246. U8 ndata,
  247. GD_IR_DATA_PROPERTY_S *dataproperty,
  248. GD_IR_INSERT_S* footer,
  249. U8 nfooter,
  250. U32 *pSendBuffer,
  251. U16 *pSendNumber);
  252. GERR GD_IR_Status(GD_HANDLE handle, U16* pNum);
  253. GERR GD_IR_Transmit(GD_HANDLE handle, U32 *pData, U16 num);
  254. typedef void (*GD_RTC_NOTIFY)(void);
  255. void GD_RTC_RegisterNotify(GD_RTC_NOTIFY rtcNotifyFunc,U32 preCount);
  256. #ifdef __cplusplus
  257. }
  258. #endif
  259. #endif /* _GD_IR_H_ */
  260. /* end of gd_ir.h */