-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAPDS9960_proc.h
136 lines (113 loc) · 5.37 KB
/
APDS9960_proc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*!\file APDS9960_proc.h
** \author SMFSW
** \copyright MIT (c) 2017-2024, SMFSW
** \brief APDS9960 Driver procedures
** \details APDS9960: Digital Proximity, Ambient Light, RGB and Gesture Sensor
**/
/****************************************************************/
#ifndef __APDS9960_PROC_H__
#define __APDS9960_PROC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "sarmfsw.h"
#include "APDS9960.h"
#include "shared_ALS.h"
#include "shared_CLS.h"
#if defined(HAL_I2C_MODULE_ENABLED)
/****************************************************************/
// *****************************************************************************
// Section: Constants
// *****************************************************************************
#define APDS9960_CHIP_ID 0xAB //!< APDS9960 Chip ID to check against
// *****************************************************************************
// Section: Types
// *****************************************************************************
/*!\struct APDS9960_t
** \brief APDS9960 user interface struct
**/
typedef struct APDS9960_t {
uint16_t Red; //!< Current Red conversion
uint16_t Green; //!< Current Green conversion
uint16_t Blue; //!< Current Blue conversion
uint16_t Clear; //!< Current Clear conversion
uint8_t Prox; //!< Current Proximity raw value
uint32_t Lux; //!< Current Illuminance (lux)
uint32_t Temp; //!< Current Color temperature (in Kelvin)
float xy[2]; //!< Current CIE1931 chromacity coordinates
float IR_Ratio; //!< Current IR ratio (in percent)
float Saturation_Ratio; //!< Current Saturation ratio (in percent)
bool SaturationRipple; //!< Current Ripple saturation status (75% of saturation value)
bool Saturation; //!< Current Sensor saturation status
struct {
I2C_slave_t * slave_inst; //!< Slave structure
PeripheralGPIO_t INT_GPIO; //!< Interrupt GPIO struct
float mat[3][3]; //!< RGB to XYZ matrix
APDS9960_als_gain ADC_Gain; //!< ADC (ALS & Color) sensor gain config
APDS9960_prox_gain Prox_Gain; //!< Proximity sensor gain config
APDS9960_pulse_length Prox_Length; //!< Proximity LED pulse length
APDS9960_drive_strength Prox_Strength; //!< Proximity LED drive strength
uint8_t Prox_Pulses; //!< Proximity pulses sent in a cycle
uint8_t ADC_Integ_reg; //!< ADC (ALS & Color) sensor integration time config (value written to register)
uint16_t ADC_Integ; //!< ADC (ALS & Color) sensor integration time config
uint16_t Wait; //!< Sensor wait time config
uint16_t ADC_LowThreshold; //!< ADC (ALS & Color) Low Threshold config
uint16_t ADC_HighThreshold; //!< ADC (ALS & Color) High Threshold config
uint8_t Prox_LowThreshold; //!< Proximity Low Threshold config
uint8_t Prox_HighThreshold; //!< Proximity High Threshold config
bool AIEN; //!< Sensor ALS (Ambient Light Sensing) interrupts enabled config
bool PIEN; //!< Sensor Proximity interrupts enabled config
bool GIEN; //!< Gestures enabled config
bool WEN; //!< Wait between conversions enabled config
uint8_t Id; //!< APDS9960 chip ID
} cfg;
} APDS9960_t;
extern APDS9960_t APDS9960[I2C_APDS9960_NB]; //!< APDS9960 User structure
// *****************************************************************************
// Section: Interface Routines
// *****************************************************************************
/******************/
/*** Procedures ***/
/******************/
/*!\brief Initialization Sequence for APDS9960 peripheral
** \weak APDS9960 Init sequence may be user implemented if custom initialization sequence needed
** \param[in] pCpnt - Pointer to APDS9960 component
** \return FctERR - error code
**/
FctERR NONNULL__ APDS9960_Init_Sequence(APDS9960_t * const pCpnt);
/*!\brief Handler for APDS9960 peripheral
** \weak APDS9960 handler may be user implemented to suit custom needs
** \note May be called periodically to handle APDS9960 tasks
** \note Alternately may be called when event occurs on APDS9960 pin (or by calling \ref APDS9960_handler_it instead)
** \param[in] pCpnt - Pointer to APDS9960 component
** \return FctERR - error code
**/
FctERR NONNULL__ APDS9960_handler(APDS9960_t * const pCpnt);
/*!\brief Handler for APDS9960 peripheral GPIO interrupt
** \weak APDS9960 GPIO interrupt handler may be user implemented to suit custom needs
** \note May be called periodically to handle APDS9960 tasks through interrupts
** \param[in] pCpnt - Pointer to APDS9960 component
** \return FctERR - error code
**/
FctERR NONNULL__ APDS9960_handler_it(APDS9960_t * const pCpnt);
/*!\brief Handler for all APDS9960 peripherals
** \note May be called periodically to handle all APDS9960 tasks
**/
__INLINE void INLINE__ APDS9960_handler_all(void) {
for (APDS9960_t * pCpnt = APDS9960 ; pCpnt < &APDS9960[I2C_APDS9960_NB] ; pCpnt++) {
APDS9960_handler(pCpnt); }
}
/*!\brief Handler for all APDS9960 peripherals GPIO interrupt
** \note May be called periodically to handle all APDS9960 tasks
**/
__INLINE void INLINE__ APDS9960_handler_it_all(void) {
for (APDS9960_t * pCpnt = APDS9960 ; pCpnt < &APDS9960[I2C_APDS9960_NB] ; pCpnt++) {
APDS9960_handler_it(pCpnt); }
}
/****************************************************************/
#endif
#ifdef __cplusplus
}
#endif
#endif /* __APDS9960_PROC_H__ */
/****************************************************************/