rgb381.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * ALS308.h
  3. *
  4. * Created on: 2022年4月11日
  5. * Author: amos
  6. */
  7. #ifndef RGB381_H_
  8. #define RGB381_H_
  9. #include "onechip_include_header.h"
  10. #define max3v(v1, v2, v3) ((v1)<(v2)? ((v2)<(v3)?(v3):(v2)):((v1)<(v3)?(v3):(v1)))
  11. #define min3v(v1, v2, v3) ((v1)>(v2)? ((v2)>(v3)?(v3):(v2)):((v1)>(v3)?(v3):(v1)))
  12. /****************************************************/
  13. #define SMPTIME 30 //sample times
  14. #define SAMP_SIZE 18
  15. #define CALCU_SAMP_SIZE 180
  16. #define CS_MAX 10
  17. #define CS_RDR_MIN 50 //光信号最小值
  18. /***************LTR381RGB address********************/
  19. #define RGB381_ADDR 0x53
  20. /***************LTR381RGB register define************/
  21. #define RGB381_MainCtrl 0x00 /*RGB operation mode control, SW reset*/
  22. #define RGB381_MeasRate 0x04 /*RGB measurement rate and resolution in Active Mode*/
  23. #define RGB381_Gain 0x05 /*RGB analog Gain*/
  24. #define RGB381_PartID 0x06 /*Part number ID and revision ID*/
  25. #define RGB381_MainState 0x07 /*Power-On status, Interrupt status, Data status*/
  26. #define RGB381_IR_DataLow 0x0A /*IR ADC measurement data, LSB*/
  27. #define RGB381_IR_DataMid 0x0B /*IR ADC measurement data*/
  28. #define RGB381_IR_DataHIG 0x0C /*IR ADC measurement data, MSB*/
  29. #define RGB381_G_DataLow 0x0D /*G ADC measurement data, LSB*/
  30. #define RGB381_G_DataMid 0x0E /*G ADC measurement data*/
  31. #define RGB381_G_DataHIG 0x0F /*G ADC measurement data, MSB*/
  32. #define RGB381_R_DataLow 0x10 /*red ADC measurement data, LSB*/
  33. #define RGB381_R_DataMid 0x11 /*red ADC measurement data*/
  34. #define RGB381_R_DataHIG 0x12 /*CS red ADC measurement data, MSB*/
  35. #define RGB381_B_DataLow 0x13 /*CS blue ADC measurement data, LSB*/
  36. #define RGB381_B_DataMid 0x14 /*CS blue ADC measurement data*/
  37. #define RGB381_B_DataHIG 0x15 /*CS blue ADC measurement data, MSB*/
  38. #define RGB381_INTCFG 0x19 /*Interrupt configuration*/
  39. #define RGB381_INTPST 0x1A /*Interrupt persist setting*/
  40. #define RGB381_THRUP0 0x21 /*RGB interrupt upper threshold, LSB*/
  41. #define RGB381_THRUP1 0x22 /*RGB interrupt upper threshold, intervening bits*/
  42. #define RGB381_THRUP2 0x23 /*RGB interrupt upper threshold, MSB*/
  43. #define RGB381_THRLW0 0x24 /*RGB interrupt lower threshold, LSB*/
  44. #define RGB381_THRLW1 0x25 /*RGB interrupt lower threshold, intervening bits*/
  45. #define RGB381_THRLW2 0x26 /*RGB interrupt lower threshold, MSB*/
  46. /*************************LTR381RGB function define******************/
  47. #define ALS_MeasRes_20B 0x00 /**< data 20 bit,conversion time 400ms */
  48. #define ALS_MeasRes_19B 0x10 /**< data 19 bit,conversion time 200ms */
  49. #define ALS_MeasRes_18B 0x20 /**< data 18 bit,conversion time 100ms */
  50. #define ALS_MeasRes_17B 0x30 /**< data 17 bit,conversion time 50ms */
  51. #define ALS_MeasRes_16B 0x40 /**< data 16 bit,conversion time 25ms */
  52. /*********************************************************************/
  53. #define ALS_MeasRate_25ms 0x00 /**< measurement time 25ms */
  54. #define ALS_MeasRate_50ms 0x01 /**< measurement time 50ms */
  55. #define ALS_MeasRate_100ms 0x02 /**< measurement time 100ms */
  56. #define ALS_MeasRate_200ms 0x03 /**< measurement time 500ms */
  57. #define ALS_MeasRate_500ms 0x04 /**< measurement time 500ms */
  58. #define ALS_MeasRate_1000ms 0x05 /**< measurement time 1000ms */
  59. #define ALS_MeasRate_2000ms 0x06 /**< measurement time 2000ms */
  60. /*******************************************************************/
  61. #define ALS_Gain_1X 0x00 /**< 1x gain */
  62. #define ALS_Gain_3X 0x01 /**< 3x gain */
  63. #define ALS_Gain_6X 0x02 /**< 6x gain */
  64. #define ALS_Gain_9X 0x03 /**< 9x gain */
  65. #define ALS_Gain_18X 0x04 /**< 18x gain */
  66. #define CS_Modle 0x02 /* RGB is active mode */
  67. #define ALS_Active 0x04 /* RGB is active mode */
  68. /****************************************************/
  69. typedef struct
  70. {
  71. uint32_t RDC; //color data clear raw data 原始值
  72. uint32_t RDR; //color data red raw data 原始值带小数
  73. // uint32_t RDG; //color data green raw data
  74. // uint32_t RDB; //color data blue raw data
  75. float CDR; //color data red calibration data 校零值(原始值带小数)
  76. // float CDG; //color data green calibration data
  77. // float CDB; //color data blue calibration data
  78. float RtR; //color data red convert data (CDR - RDR)*gain
  79. // float RtG; //color data green convert data
  80. // float RtB; //color data blue convert data
  81. float Tt;
  82. float TtMin;
  83. float TtMax; // original Tt
  84. uint8_t std_num;
  85. float gain; //归一化值
  86. //float sum;
  87. float STD; //标准差
  88. float average; //均值
  89. float SAMP[SAMP_SIZE];
  90. // uint16_t CALCU_SAMP[CALCU_SAMP_SIZE];
  91. //float AccArea; //accumulation area
  92. uint8_t Result;
  93. uint8_t ID; //color sensor ID
  94. }ColorSensor;
  95. extern ColorSensor CS[CS_MAX];
  96. extern uint8_t SensorState1,SensorState2,SensorState3,SensorState4,SensorState5,SensorState6,SensorState7,SensorState8,SensorState9,SensorState10;
  97. //extern uint8_t SensorState1,SensorState2,SensorState3,SensorState4,SensorState5,SensorState6,SensorState7,SensorState8,SensorState9;
  98. /**************************************************/
  99. void SensorMeasurementFactor(uint8_t measfactor);
  100. void SensorSetGain(uint8_t gain);
  101. uint8_t SensorGetID(uint8_t ID);
  102. void SensorGetRawData(ColorSensor *CS);
  103. void SensorCalculatedCalibrationFactor(ColorSensor *CS);
  104. void RGBtoHSV(ColorSensor *CS);
  105. void SensorEnable(void);
  106. uint8_t SensorInit(ColorSensor *CS);
  107. int SensorSelfCheck(void);
  108. void SensorRGBInit(ColorSensor *CS);
  109. void SensorGetCalData(ColorSensor *CS);
  110. void sample_first_zero(void);
  111. void SensorInitial(void);
  112. int check_first_zero(void);
  113. void sample_calibrate_calc(uint32_t times);
  114. void sample_calc_avg_std(void);
  115. void sample_calc_tt(void);
  116. void sample_calc_result(void);
  117. void calc_balance(void);
  118. /**************************************************/
  119. #endif /* RGB381_H_ */