2017-04-23 08:35:23 +00:00
|
|
|
/**
|
2017-10-12 19:49:15 +00:00
|
|
|
* Driver for 8-bit analog-to-digital conversion and
|
2017-04-23 08:35:23 +00:00
|
|
|
* an 8-bit digital-to-analog conversion PCF8591
|
|
|
|
*
|
|
|
|
* Part of esp-open-rtos
|
|
|
|
* Copyright (C) 2017 Pham Ngoc Thanh <pnt239@gmail.com>
|
2017-10-12 19:49:15 +00:00
|
|
|
* 2017 Ruslan V. Uss <unclerus@gmail.com>
|
2017-04-23 08:35:23 +00:00
|
|
|
* BSD Licensed as described in the file LICENSE
|
|
|
|
*/
|
|
|
|
#ifndef _EXTRAS_PCF8591_H_
|
|
|
|
#define _EXTRAS_PCF8591_H_
|
|
|
|
|
2017-10-12 19:49:15 +00:00
|
|
|
#include <stdint.h>
|
2017-09-01 09:29:32 +00:00
|
|
|
#include <i2c/i2c.h>
|
|
|
|
|
2017-04-23 08:35:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2017-04-25 16:57:40 +00:00
|
|
|
#define PCF8591_DEFAULT_ADDRESS 0x48
|
|
|
|
|
2017-10-12 19:49:15 +00:00
|
|
|
/**
|
|
|
|
* Analog inputs configuration, see datasheet
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
PCF8591_IC_4_SINGLES = 0, //!< Four single-ended inputs
|
|
|
|
PCF8591_IC_DIFF, //!< Three differential inputs
|
|
|
|
PCF8591_IC_2_SINGLES_DIFF, //!< Two single-ended and differnetial mixed
|
|
|
|
PCF8591_IC_2_DIFFS //!< Two differential inputs
|
|
|
|
} pcf8591_input_conf_t;
|
2017-04-23 08:35:23 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-25 16:57:40 +00:00
|
|
|
* Read input value of an analog pin.
|
2017-10-12 19:49:15 +00:00
|
|
|
* @param[in] dev Pointer to device
|
|
|
|
* @param[in] conf Analog inputs configuration
|
|
|
|
* @param[in] channel Analog channel
|
2017-04-25 16:57:40 +00:00
|
|
|
* @return analog value
|
2017-04-23 08:35:23 +00:00
|
|
|
*/
|
2017-10-12 19:49:15 +00:00
|
|
|
uint8_t pcf8591_read(i2c_dev_t *dev, pcf8591_input_conf_t conf, uint8_t channel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write value to analog output
|
|
|
|
* @param[in] dev Pointer to device
|
|
|
|
* @param[in] value DAC value
|
|
|
|
*/
|
|
|
|
void pcf8591_write(i2c_dev_t *dev, uint8_t value);
|
2017-04-23 08:35:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _EXTRAS_PCF8591_H_ */
|