diff -r bdc123ae7b49 -r bb72d448e282 esp-idf-lib/components/apds9930/apds9930.h --- a/esp-idf-lib/components/apds9930/apds9930.h Mon Apr 03 11:08:09 2023 +0200 +++ b/esp-idf-lib/components/apds9930/apds9930.h Mon Apr 03 16:07:34 2023 +0200 @@ -47,6 +47,13 @@ #define APDS9930_AGAIN_16X 2 #define APDS9930_AGAIN_120X 3 +/** + * Device descriptor + */ +typedef struct { + i2c_dev_t i2c_dev; + uint8_t id; +} apds9930_t; /** @@ -61,39 +68,28 @@ * @param scl_gpio SCL GPIO * @return `ESP_OK` on success */ -esp_err_t apds9930_init_desc(i2c_dev_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio); +esp_err_t apds9930_init_desc(apds9930_t *dev, uint8_t addr, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio); /** * @brief Free device descriptor * @param dev Pointer to I2C device descriptor * @return `ESP_OK` on success */ -esp_err_t apds9930_free_desc(i2c_dev_t *dev); - - - -/* APDS9930 Class */ -//class APDS9930 { -//public: - - - /* Initialization methods */ -// APDS9930(); -// ~APDS9930(); +esp_err_t apds9930_free_desc(apds9930_t *dev); /** * @brief Setup APDS9930 and initializes registers to defaults * @param dev Pointer to I2C device descriptor * @return `ESP_OK` on success */ -esp_err_t apds9930_init(i2c_dev_t *dev); +esp_err_t apds9930_init(apds9930_t *dev); /** * @brief Reads and returns the contents of the ENABLE register * @param dev Pointer to I2C device descriptor * @return Contents of the ENABLE register. 0xFF if error. */ -uint8_t apds9930_getMode(i2c_dev_t *dev); +uint8_t apds9930_getMode(apds9930_t *dev); /** * @brief Enables or disables a feature in the APDS-9930 @@ -102,21 +98,21 @@ * @param enable ON (1) or OFF (0) * @return `ESP_OK` on success */ -esp_err_t apds9930_setMode(i2c_dev_t *dev, uint8_t mode, uint8_t enable); +esp_err_t apds9930_setMode(apds9930_t *dev, uint8_t mode, uint8_t enable); /** * @brief Turn the APDS-9930 on * @param dev Pointer to I2C device descriptor * @return ESP_OK if operation successful. */ -esp_err_t apds9930_enablePower(i2c_dev_t *dev); +esp_err_t apds9930_enablePower(apds9930_t *dev); /** * @brief Turn the APDS-9930 off * @param dev Pointer to I2C device descriptor * @return ESP_OK if operation successful. False otherwise. */ -esp_err_t apds9930_disablePower(i2c_dev_t *dev); +esp_err_t apds9930_disablePower(apds9930_t *dev); /** * @brief Starts the light (Ambient/IR) sensor on the APDS-9930 @@ -124,14 +120,14 @@ * @param interrupts true to enable hardware interrupt on high or low light * @return ESP_OK if sensor enabled correctly. */ -esp_err_t apds9930_enableLightSensor(i2c_dev_t *dev, bool interrupts); +esp_err_t apds9930_enableLightSensor(apds9930_t *dev, bool interrupts); /** * @brief Ends the light sensor on the APDS-9930 * @param dev Pointer to I2C device descriptor * @return ESP_OK if sensor disabled correctly. */ -esp_err_t apds9930_disableLightSensor(i2c_dev_t *dev); +esp_err_t apds9930_disableLightSensor(apds9930_t *dev); /** * @brief Starts the proximity sensor on the APDS-9930 @@ -139,14 +135,14 @@ * @param interrupts true to enable hardware external interrupt on proximity * @return ESP_OK if sensor enabled correctly. */ -esp_err_t apds9930_enableProximitySensor(i2c_dev_t *dev, bool interrupts); +esp_err_t apds9930_enableProximitySensor(apds9930_t *dev, bool interrupts); /** * @brief Ends the proximity sensor on the APDS-9930 * @param dev Pointer to I2C device descriptor * @return ESP_OK if sensor disabled correctly. */ -esp_err_t apds9930_disableProximitySensor(i2c_dev_t *dev); +esp_err_t apds9930_disableProximitySensor(apds9930_t *dev); /** @@ -161,7 +157,7 @@ * * @return the value of the LED drive strength. 0xFF on failure. */ -uint8_t APDS9930_getLEDDrive(i2c_dev_t *dev); +uint8_t APDS9930_getLEDDrive(apds9930_t *dev); /** * @brief Sets the LED drive strength for proximity and ALS @@ -176,7 +172,7 @@ * @param drive the value (0-3) for the LED drive strength * @return ESP_OK if operation successful. */ -esp_err_t apds9930_setLEDDrive(i2c_dev_t *dev, uint8_t drive); +esp_err_t apds9930_setLEDDrive(apds9930_t *dev, uint8_t drive); /** * @brief Gets the receiver ALS gain level for the ambient light sensor. @@ -184,7 +180,7 @@ * @param dev Pointer to I2C device descriptor * @return 1 if extra ALS gain level is enabled, 0 if not. 0xFF on error. */ -uint8_t apds9930_getAmbientGainLevel(i2c_dev_t *dev); +uint8_t apds9930_getAmbientGainLevel(apds9930_t *dev); /** * @brief Sets the receiver ALS gain level for the ambient light sensor @@ -194,7 +190,7 @@ * @param enable the value (0-1) for the gain level. * @return ESP_OK if operation successful. */ -esp_err_t apds9930_setAmbientGainLevel(i2c_dev_t *dev, uint8_t enable); +esp_err_t apds9930_setAmbientGainLevel(apds9930_t *dev, uint8_t enable); /** * @brief Returns receiver gain for the ambient light sensor (ALS) @@ -208,7 +204,7 @@ * * @return the value of the ALS gain. 0xFF on failure. */ -uint8_t apds9930_getAmbientLightGain(i2c_dev_t *dev); +uint8_t apds9930_getAmbientLightGain(apds9930_t *dev); /** * @brief Sets the receiver gain for the ambient light sensor (ALS) @@ -223,7 +219,7 @@ * @param drive the value (0-3) for the gain * @return ESP_OK if operation successful. False otherwise. */ -esp_err_t apds9930_setAmbientLightGain(i2c_dev_t *dev, uint8_t gain); +esp_err_t apds9930_setAmbientLightGain(apds9930_t *dev, uint8_t gain); /** * @brief Returns receiver gain for proximity detection @@ -237,7 +233,7 @@ * * @return the value of the proximity gain. 0xFF on failure. */ -uint8_t apds9930_getProximityGain(i2c_dev_t *dev); +uint8_t apds9930_getProximityGain(apds9930_t *dev); /** * @brief Sets the receiver gain for proximity detection @@ -252,7 +248,7 @@ * @param drive the value (0-3) for the gain * @return True if operation successful. False otherwise. */ -esp_err_t apds9930_setProximityGain(i2c_dev_t *dev, uint8_t gain); +esp_err_t apds9930_setProximityGain(apds9930_t *dev, uint8_t gain); /** * @brief Selects the proximity diode @@ -267,7 +263,7 @@ * @param[in] drive the value (0-3) for the diode * @return True if operation successful. False otherwise. */ -esp_err_t apds9930_setProximityDiode(i2c_dev_t *dev, uint8_t drive); +esp_err_t apds9930_setProximityDiode(apds9930_t *dev, uint8_t drive); /** * @brief Returns the proximity diode @@ -281,7 +277,7 @@ * * @return the selected diode. 0xFF on failure. */ -uint8_t apds9930_getProximityDiode(i2c_dev_t *dev); +uint8_t apds9930_getProximityDiode(apds9930_t *dev); /** * @brief Gets the low threshold for ambient light interrupts @@ -289,7 +285,7 @@ * @param threshold current low threshold stored on the APDS-9930 * @return ESP_OK if operation successful. */ -esp_err_t apds9930_getLightIntLowThreshold(i2c_dev_t *dev, uint16_t *threshold); +esp_err_t apds9930_getLightIntLowThreshold(apds9930_t *dev, uint16_t *threshold); /** * @brief Sets the low threshold for ambient light interrupts @@ -297,7 +293,7 @@ * @param threshold low threshold value for interrupt to trigger * @return ESP_OK if operation successful. */ -esp_err_t apds9930_setLightIntLowThreshold(i2c_dev_t *dev, uint16_t threshold); +esp_err_t apds9930_setLightIntLowThreshold(apds9930_t *dev, uint16_t threshold); /** * @brief Gets the high threshold for ambient light interrupts @@ -305,7 +301,7 @@ * @param threshold current low threshold stored on the APDS-9930 * @return ESP_OK if operation successful. */ -esp_err_t apds9930_getLightIntHighThreshold(i2c_dev_t *dev, uint16_t *threshold); +esp_err_t apds9930_getLightIntHighThreshold(apds9930_t *dev, uint16_t *threshold); /** * @brief Sets the high threshold for ambient light interrupts @@ -313,14 +309,14 @@ * @param threshold low threshold value for interrupt to trigger * @return ESP_OK if operation successful. */ -esp_err_t apds9930_setLightIntHighThreshold(i2c_dev_t *dev, uint16_t threshold); +esp_err_t apds9930_setLightIntHighThreshold(apds9930_t *dev, uint16_t threshold); /** * @brief Gets if ambient light interrupts are enabled or not * @param dev Pointer to I2C device descriptor * @return 1 if interrupts are enabled, 0 if not. 0xFF on error. */ -uint8_t apds9930_getAmbientLightIntEnable(i2c_dev_t *dev); +uint8_t apds9930_getAmbientLightIntEnable(apds9930_t *dev); /** * @brief Turns ambient light interrupts on or off @@ -328,14 +324,14 @@ * @param[in] enable 1 to enable interrupts, 0 to turn them off * @return ESP_OK if operation successful. */ -esp_err_t apds9930_setAmbientLightIntEnable(i2c_dev_t *dev, uint8_t enable); +esp_err_t apds9930_setAmbientLightIntEnable(apds9930_t *dev, uint8_t enable); /** * @brief Gets if proximity interrupts are enabled or not * @param dev Pointer to I2C device descriptor * @return 1 if interrupts are enabled, 0 if not. 0xFF on error. */ -uint8_t apds9930_getProximityIntEnable(i2c_dev_t *dev); +uint8_t apds9930_getProximityIntEnable(apds9930_t *dev); /** * @brief Turns proximity interrupts on or off @@ -343,28 +339,28 @@ * @param[in] enable 1 to enable interrupts, 0 to turn them off * @return ESP_OK if operation successful. */ -esp_err_t apds9930_setProximityIntEnable(i2c_dev_t *dev, uint8_t enable); +esp_err_t apds9930_setProximityIntEnable(apds9930_t *dev, uint8_t enable); /** * @brief Clears the ambient light interrupt * @param dev Pointer to I2C device descriptor * @return ESP_OK if operation completed successfully. */ -esp_err_t apds9930_clearAmbientLightInt(i2c_dev_t *dev); +esp_err_t apds9930_clearAmbientLightInt(apds9930_t *dev); /** * @brief Clears the proximity interrupt * @param dev Pointer to I2C device descriptor * @return ESP_OK if operation completed successfully. */ -esp_err_t apds9930_clearProximityInt(i2c_dev_t *dev); +esp_err_t apds9930_clearProximityInt(apds9930_t *dev); /** * @brief Clears all interrupts * @param dev Pointer to I2C device descriptor * @return ESP_OK if operation completed successfully. */ -esp_err_t apds9930_clearAllInts(i2c_dev_t *dev); +esp_err_t apds9930_clearAllInts(apds9930_t *dev); /** * @brief Reads the proximity level as an 16-bit value @@ -372,7 +368,7 @@ * @param val value of the proximity sensor. * @return ESP_OK if operation successful. */ -esp_err_t apds9930_readProximity(i2c_dev_t *dev, uint16_t *val); +esp_err_t apds9930_readProximity(apds9930_t *dev, uint16_t *val); /** * @brief Reads the ambient (clear) light level as a float value @@ -380,7 +376,7 @@ * @param val value of the light sensor. * @return ESP_OK if operation successful. */ -esp_err_t apds9930_readAmbientLightLux(i2c_dev_t *dev, float *val); +esp_err_t apds9930_readAmbientLightLux(apds9930_t *dev, float *val); /** * @brief Reads the ambient (clear) light level as a unsigned long value @@ -388,11 +384,11 @@ * @param val value of the light sensor. * @return ESP_OK if operation successful. */ -esp_err_t apds9930_readulAmbientLightLux(i2c_dev_t *dev, unsigned long *val); +esp_err_t apds9930_readulAmbientLightLux(apds9930_t *dev, unsigned long *val); -float apds9930_floatAmbientToLux(i2c_dev_t *dev, uint16_t Ch0, uint16_t Ch1); +float apds9930_floatAmbientToLux(apds9930_t *dev, uint16_t Ch0, uint16_t Ch1); -unsigned long apds9930_ulongAmbientToLux(i2c_dev_t *dev, uint16_t Ch0, uint16_t Ch1); +unsigned long apds9930_ulongAmbientToLux(apds9930_t *dev, uint16_t Ch0, uint16_t Ch1); /** * @brief Read the channel 0 light value from the APDS-9930 @@ -400,7 +396,7 @@ * @param val The value read. * @return ESP_OK if read is correctly. */ -esp_err_t apds9930_readCh0Light(i2c_dev_t *dev, uint16_t *val); +esp_err_t apds9930_readCh0Light(apds9930_t *dev, uint16_t *val); /** * @brief Read the channel 1 light value from the APDS-9930 @@ -408,14 +404,14 @@ * @param val The value read. * @return ESP_OK if read is correctly. */ -esp_err_t apds9930_readCh1Light(i2c_dev_t *dev, uint16_t *val); +esp_err_t apds9930_readCh1Light(apds9930_t *dev, uint16_t *val); /** * @brief Returns the lower threshold for proximity detection * @param dev Pointer to I2C device descriptor * @return lower threshold */ -uint16_t apds9930_getProximityIntLowThreshold(i2c_dev_t *dev); +uint16_t apds9930_getProximityIntLowThreshold(apds9930_t *dev); /** * @brief Sets the lower threshold for proximity detection @@ -423,14 +419,14 @@ * @param threshold the lower proximity threshold * @return ESP_OK if operation successful. */ -esp_err_t apds9930_setProximityIntLowThreshold(i2c_dev_t *dev, uint16_t threshold); +esp_err_t apds9930_setProximityIntLowThreshold(apds9930_t *dev, uint16_t threshold); /** * @brief Returns the high threshold for proximity detection * @param dev Pointer to I2C device descriptor * @return high threshold */ -uint16_t apds9930_getProximityIntHighThreshold(i2c_dev_t *dev); +uint16_t apds9930_getProximityIntHighThreshold(apds9930_t *dev); /** * @brief Sets the high threshold for proximity detection @@ -438,7 +434,7 @@ * @param threshold the high proximity threshold * @return ESP_OK if operation successful. */ -esp_err_t apds9930_setProximityIntHighThreshold(i2c_dev_t *dev, uint16_t threshold); +esp_err_t apds9930_setProximityIntHighThreshold(apds9930_t *dev, uint16_t threshold); #ifdef __cplusplus