2016-03-01 17:56:55 +00:00
|
|
|
/**
|
|
|
|
* \file Driver for PCF8574 compartible remote 8-bit I/O expanders for I2C-bus
|
2016-03-01 21:17:07 +00:00
|
|
|
* \author Ruslan V. Uss
|
2016-03-01 17:56:55 +00:00
|
|
|
*/
|
|
|
|
#ifndef PCF8574_PCF8574_H_
|
|
|
|
#define PCF8574_PCF8574_H_
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2017-09-01 09:29:32 +00:00
|
|
|
#include <i2c/i2c.h>
|
2016-03-01 17:56:55 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Read GPIO port value
|
|
|
|
* \param addr I2C register address (0b0100<A2><A1><A0> for PCF8574)
|
|
|
|
* \return 8-bit GPIO port value
|
|
|
|
*/
|
2017-09-01 09:29:32 +00:00
|
|
|
uint8_t pcf8574_port_read(i2c_dev_t* dev);
|
2016-03-01 17:56:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Continiously read GPIO port values to buffer
|
|
|
|
* @param addr I2C register address (0b0100<A2><A1><A0> for PCF8574)
|
|
|
|
* @param buf Target buffer
|
|
|
|
* @param len Buffer length
|
|
|
|
* @return Number of bytes read
|
|
|
|
*/
|
2017-09-01 09:29:32 +00:00
|
|
|
size_t pcf8574_port_read_buf(i2c_dev_t* dev, void *buf, size_t len);
|
2016-03-01 17:56:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Write value to GPIO port
|
|
|
|
* \param addr I2C register address (0b0100<A2><A1><A0> for PCF8574)
|
|
|
|
* \param value GPIO port value
|
|
|
|
*/
|
2017-09-01 09:29:32 +00:00
|
|
|
void pcf8574_port_write(const i2c_dev_t* dev, uint8_t value);
|
2016-03-01 17:56:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Continiously write GPIO values to GPIO port
|
|
|
|
* \param addr I2C register address (0b0100<A2><A1><A0> for PCF8574)
|
|
|
|
* @param buf Buffer with values
|
|
|
|
* @param len Buffer length
|
|
|
|
* @return Number of bytes written
|
|
|
|
*/
|
2017-09-01 09:29:32 +00:00
|
|
|
size_t pcf8574_port_write_buf(const i2c_dev_t* dev, void *buf, size_t len);
|
2016-03-01 17:56:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Read input value of a GPIO pin
|
|
|
|
* \param addr I2C register address (0b0100<A2><A1><A0> for PCF8574)
|
|
|
|
* \param num pin number (0..7)
|
|
|
|
* \return GPIO pin value
|
|
|
|
*/
|
2017-09-01 09:29:32 +00:00
|
|
|
bool pcf8574_gpio_read(i2c_dev_t* dev, uint8_t num);
|
2016-03-01 17:56:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set GPIO pin output
|
2016-03-01 21:19:46 +00:00
|
|
|
* Note this is READ - MODIFY - WRITE operation! Please read PCF8574
|
2016-03-01 17:56:55 +00:00
|
|
|
* datasheet first.
|
|
|
|
* \param addr I2C register address (0b0100<A2><A1><A0> for PCF8574)
|
|
|
|
* \param num pin number (0..7)
|
|
|
|
* \param value true for high level
|
|
|
|
*/
|
2017-09-01 09:29:32 +00:00
|
|
|
void pcf8574_gpio_write(i2c_dev_t* dev, uint8_t num, bool value);
|
2016-03-01 17:56:55 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* PCF8574_PCF8574_H_ */
|