AfInter.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //********************************************************************************
  2. //
  3. // LC89821x Interface module
  4. //
  5. // Program Name : AfInter.c
  6. // Design : Rex.Tang
  7. // History : First edition 2013.07.13 Rex.Tang
  8. //
  9. // Description : User needs to complete the interface functions
  10. //********************************************************************************
  11. //#define DEBUG_LOG
  12. #ifdef DEBUG_LOG
  13. #include <linux/fs.h>
  14. #endif
  15. #include <linux/i2c.h>
  16. #include <linux/delay.h>
  17. #define DeviceAddr 0xE4 // Device address of driver IC
  18. #ifdef DEBUG_LOG
  19. #define AF_REGDUMP "REGDUMP"
  20. #define LOG_INF(format, args...) pr_info(AF_REGDUMP " " format, ##args)
  21. #endif
  22. extern int s4AF_WriteReg_LC898212XDAF(u8 *a_pSendData , u16 a_sizeSendData, u16 i2cId);
  23. extern int s4AF_ReadReg_LC898212XDAF(u8 *a_pSendData , u16 a_sizeSendData, u8 *a_pRecvData, u16 a_sizeRecvData, u16 i2cId);
  24. /*--------------------------------------------------------
  25. IIC wrtie 2 bytes function
  26. Parameters: addr, data
  27. --------------------------------------------------------*/
  28. void RamWriteA(unsigned short addr, unsigned short data)
  29. {
  30. #ifdef DEBUG_LOG
  31. LOG_INF("RAMW\t%x\t%x\n", addr, data );
  32. #endif
  33. // To call your IIC function here
  34. u8 puSendCmd[3] = {(u8)(addr & 0xFF) ,(u8)(data >> 8),(u8)(data & 0xFF)};
  35. s4AF_WriteReg_LC898212XDAF(puSendCmd , sizeof(puSendCmd), DeviceAddr);
  36. }
  37. /*------------------------------------------------------
  38. IIC read 2 bytes function
  39. Parameters: addr, *data
  40. -------------------------------------------------------*/
  41. void RamReadA(unsigned short addr, unsigned short *data)
  42. {
  43. // To call your IIC function here
  44. u8 buf[2];
  45. u8 puSendCmd[1] = {(u8)(addr & 0xFF) };
  46. s4AF_ReadReg_LC898212XDAF(puSendCmd , sizeof(puSendCmd), buf, 2, DeviceAddr);
  47. *data = (buf[0] << 8) | (buf[1] & 0x00FF);
  48. #ifdef DEBUG_LOG
  49. LOG_INF("RAMR\t%x\t%x\n", addr, *data );
  50. #endif
  51. }
  52. /*--------------------------------------------------------
  53. IIC wrtie 1 byte function
  54. Parameters: addr, data
  55. --------------------------------------------------------*/
  56. void RegWriteA(unsigned short addr, unsigned char data)
  57. {
  58. #ifdef DEBUG_LOG
  59. LOG_INF("REGW\t%x\t%x\n", addr, data );
  60. #endif
  61. // To call your IIC function here
  62. u8 puSendCmd[2] = {(u8)(addr & 0xFF) ,(u8)(data & 0xFF)};
  63. s4AF_WriteReg_LC898212XDAF(puSendCmd , sizeof(puSendCmd), DeviceAddr);
  64. }
  65. /*--------------------------------------------------------
  66. IIC read 1 byte function
  67. Parameters: addr, *data
  68. --------------------------------------------------------*/
  69. void RegReadA(unsigned short addr, unsigned char *data)
  70. {
  71. // To call your IIC function here
  72. u8 puSendCmd[1] = {(u8)(addr & 0xFF) };
  73. s4AF_ReadReg_LC898212XDAF(puSendCmd , sizeof(puSendCmd), data, 1, DeviceAddr);
  74. #ifdef DEBUG_LOG
  75. LOG_INF("REGR\t%x\t%x\n", addr, *data );
  76. #endif
  77. }
  78. /*--------------------------------------------------------
  79. Wait function
  80. Parameters: msec
  81. --------------------------------------------------------*/
  82. void WaitTime(unsigned short msec)
  83. {
  84. // To call your Wait function here
  85. usleep_range(msec * 1000, (msec + 1) * 1000);
  86. }