AS7341.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #ifndef __AS7341_H
  2. #define __AS7341_H
  3. #define UBYTE unsigned char
  4. #define UWORD unsigned int
  5. #define UDOUBLE unsigned long
  6. #define AS7341_ADDRESS 0x39
  7. #define Write_BIT 0
  8. #define Read_BIT 1
  9. #define true 1
  10. #define false 0
  11. #define INPUT 0
  12. #define OUTPUT 1
  13. #define AS7341_ASTATUS (0X60) // ASTATUS Register (Address 0x60 or 0x94)
  14. #define AS7341_CONFIG (0X70)
  15. #define AS7341_STAT (0X71)
  16. #define AS7341_EDGE (0X72)
  17. #define AS7341_CPIO (0X73)
  18. #define AS7341_LED (0X74)
  19. #define AS7341_ENABLE (0X80)
  20. #define AS7341_ATIME (0X81)
  21. #define AS7341_WTIME (0X83)
  22. #define AS7341_SP_TH_L_LSB (0X84)
  23. #define AS7341_SP_TH_L_MSB (0X85)
  24. #define AS7341_SP_TH_H_LSB (0X86)
  25. #define AS7341_SP_TH_H_MSB (0X87)
  26. #define AS7341_AUXID (0X90)
  27. #define AS7341_REVID (0X91)
  28. #define AS7341_ID (0X92)
  29. #define AS7341_STATUS_1 (0X93)
  30. // #define AS7341_ASTATUS (0X94)
  31. #define AS7341_CH0_DATA_L (0X95)
  32. #define AS7341_CH0_DATA_H (0X96)
  33. #define AS7341_CH1_DATA_L (0X97)
  34. #define AS7341_CH1_DATA_H (0X98)
  35. #define AS7341_CH2_DATA_L (0X99)
  36. #define AS7341_CH2_DATA_H (0X9A)
  37. #define AS7341_CH3_DATA_L (0X9B)
  38. #define AS7341_CH3_DATA_H (0X9C)
  39. #define AS7341_CH4_DATA_L (0X9D)
  40. #define AS7341_CH4_DATA_H (0X9E)
  41. #define AS7341_CH5_DATA_L (0X9F)
  42. #define AS7341_CH5_DATA_H (0XA0)
  43. #define AS7341_STATUS_2 (0XA3)
  44. #define AS7341_STATUS_3 (0XA4)
  45. #define AS7341_STATUS_5 (0XA6)
  46. #define AS7341_STATUS_6 (0XA7)
  47. #define AS7341_CFG_0 (0XA9)
  48. #define AS7341_CFG_1 (0XAA)
  49. #define AS7341_CFG_3 (0XAC)
  50. #define AS7341_CFG_6 (0XAF)
  51. #define AS7341_CFG_8 (0XB1)
  52. #define AS7341_CFG_9 (0XB2)
  53. #define AS7341_CFG_10 (0XB3)
  54. #define AS7341_CFG_12 (0XB5)
  55. #define AS7341_PERS (0XBD)
  56. #define AS7341_GPIO_2 (0XBE)
  57. #define AS7341_ASTEP_L (0XCA)
  58. #define AS7341_ASTEP_H (0XCB)
  59. #define AS7341_AGC_GAIN_MAX (0XCF)
  60. #define AS7341_AZ_CONFIG (0XD6)
  61. #define AS7341_FD_TIME_1 (0XD8)
  62. #define AS7341_TIME_2 (0XDA)
  63. #define AS7341_CFG0 (0XD7)
  64. #define AS7341_STATUS (0XDB)
  65. #define AS7341_INTENAB (0XF9)
  66. #define AS7341_CONTROL (0XFA)
  67. #define AS7341_FIFO_MAP (0XFC)
  68. #define AS7341_FIFO_LVL (0XFD)
  69. #define AS7341_FDATA_L (0XFE)
  70. #define AS7341_FDATA_H (0XFF)
  71. #define AS7341_GPIO 4
  72. /**
  73. The measurement mode of spectrum snesor
  74. */
  75. typedef enum
  76. {
  77. eSpm = 0, /**<SPM>*/
  78. eSyns = 1, /**<SYNS*/
  79. eSynd = 3, /**<SYND>*/
  80. } eMode_t;
  81. /**
  82. The modes of channel mapping
  83. */
  84. typedef enum
  85. {
  86. eF1F4ClearNIR, /**<Map the values of the registers of 6 channels to F1,F2,F3,F4,clear,NIR>*/
  87. eF5F8ClearNIR, /**<Map the values of the registers of 6 channels to F5,F6,F7,F8,clear,NIR>*/
  88. } eChChoose_t;
  89. /**
  90. Represent 10 different photodiode measurement channels
  91. */
  92. typedef enum
  93. {
  94. eCH_F1,
  95. eCH_F2,
  96. eCH_F3,
  97. eCH_F4,
  98. eCH_F5,
  99. eCH_F6,
  100. eCH_F7,
  101. eCH_F8,
  102. eCH_CLEAR,
  103. eCH_NIR,
  104. } eChannel_t;
  105. /**
  106. The values of the registers of 6 channels under eF1F4ClearNIR
  107. */
  108. typedef struct
  109. {
  110. UWORD channel1; /**<channel1 diode data>*/
  111. UWORD channel2; /**<channel2 diode data>*/
  112. UWORD channel3; /**<channel3 diode data>*/
  113. UWORD channel4; /**<channel4 diode data>*/
  114. UWORD CLEAR; /**<clear diode data>*/
  115. UWORD NIR; /**<NIR diode data>*/
  116. } sModeOneData_t;
  117. /**
  118. The values of the registers of 6 channels under eF5F8ClearNIR
  119. */
  120. typedef struct
  121. {
  122. UWORD channel5; /**<channel5 diode data>*/
  123. UWORD channel6; /**<channel6 diode data>*/
  124. UWORD channel7; /**<channel7 diode data>*/
  125. UWORD channel8; /**<channel8 diode data>*/
  126. UWORD CLEAR; /**<clear diode data>*/
  127. UWORD NIR; /**<NIR diode data>*/
  128. } sModeTwoData_t;
  129. UBYTE AS7341_Init(eMode_t mode);
  130. void AS7341_Enable(int flag);
  131. void AS7341_EnableSpectralMeasure(int flag);
  132. void AS7341_EnableSMUX(int flag);
  133. void AS7341_EnableFlickerDetection(int flag);
  134. void F1F4_Clear_NIR(void);
  135. void F5F8_Clear_NIR(void);
  136. void FDConfig(void);
  137. void AS7341_startMeasure(eChChoose_t mode);
  138. UBYTE AS7341_ReadFlickerData(void);
  139. UWORD AS7341_GetChannelData(UBYTE channel);
  140. sModeOneData_t AS7341_ReadSpectralDataOne(void);
  141. sModeTwoData_t AS7341_ReadSpectralDataTwo(void);
  142. void AS7341_Config(eMode_t mode);
  143. int AS7341_MeasureComplete(void);
  144. void AS7341_SetGpioMode(UBYTE mode);
  145. void AS7341_SetBank(UBYTE addr);
  146. void AS7341_EnableLED(int flag);
  147. void AS7341_ControlLed(UBYTE LED, UBYTE current);
  148. void AS7341_INTerrupt(void);
  149. void AS7341_ClearInterrupt(void);
  150. void AS7341_EnableSpectralInterrupt(int flag);
  151. void AS7341_SetThreshold(UWORD lowThre, UWORD highThre);
  152. UWORD AS7341_GetLowThreshold(void);
  153. UWORD AS7341_GetHighThreshold(void);
  154. void AS7341_ATIME_config(UBYTE value);
  155. void AS7341_ASTEP_config(UWORD value);
  156. void AS7341_AGAIN_config(UBYTE value);
  157. void AS7341_SetInterruptPersistence(UBYTE value);
  158. void AS7341_SetSpectralThresholdChannel(UBYTE value);
  159. void AS7341_SynsINT_sel(void);
  160. void AS7341_disableALL(void);
  161. #endif