2017-04-23 08:35:23 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "pcf8591.h"
|
|
|
|
|
2017-04-25 16:57:40 +00:00
|
|
|
/**
|
2017-09-01 09:29:32 +00:00
|
|
|
* CAUTION: PLEASE SET LOW FREQUENCY
|
2017-04-25 16:57:40 +00:00
|
|
|
*/
|
2017-04-23 08:35:23 +00:00
|
|
|
|
2017-04-25 16:57:40 +00:00
|
|
|
#define PCF8591_CTRL_REG_READ 0x03
|
|
|
|
|
2017-09-01 09:29:32 +00:00
|
|
|
uint8_t pcf8591_read(i2c_dev_t* dev, uint8_t analog_pin)
|
2017-04-23 08:35:23 +00:00
|
|
|
{
|
2017-04-25 16:57:40 +00:00
|
|
|
uint8_t res = 0;
|
|
|
|
uint8_t control_reg = PCF8591_CTRL_REG_READ & analog_pin;
|
|
|
|
|
2017-09-01 09:29:32 +00:00
|
|
|
i2c_slave_read(dev->bus, dev->addr, &control_reg, &res, 1);
|
2017-04-25 16:57:40 +00:00
|
|
|
|
|
|
|
return res;
|
2017-04-23 08:35:23 +00:00
|
|
|
}
|