Tabs replaced to spaces

This commit is contained in:
UncleRus 2016-03-02 02:17:07 +05:00
parent 875db616ae
commit 03ee667d5d
2 changed files with 27 additions and 26 deletions

View file

@ -17,52 +17,52 @@
uint8_t pcf8574_port_read(uint8_t addr) uint8_t pcf8574_port_read(uint8_t addr)
{ {
i2c_start(); i2c_start();
uint8_t res = i2c_write((addr << 1) | 1) ? i2c_read(1) : 0; uint8_t res = i2c_write((addr << 1) | 1) ? i2c_read(1) : 0;
i2c_stop(); i2c_stop();
return res; return res;
} }
size_t pcf8574_port_read_buf(uint8_t addr, void *buf, size_t len) size_t pcf8574_port_read_buf(uint8_t addr, void *buf, size_t len)
{ {
if (!len || !buf) return 0; if (!len || !buf) return 0;
uint8_t *_buf = (uint8_t *)buf; uint8_t *_buf = (uint8_t *)buf;
i2c_start(); i2c_start();
if (!i2c_write((addr << 1) | 1)) return 0; if (!i2c_write((addr << 1) | 1)) return 0;
for (size_t i = 0; i < len; i++) for (size_t i = 0; i < len; i++)
*_buf++ = i2c_read(i == len - 1); *_buf++ = i2c_read(i == len - 1);
i2c_stop(); i2c_stop();
return len; return len;
} }
size_t pcf8574_port_write_buf(uint8_t addr, void *buf, size_t len) size_t pcf8574_port_write_buf(uint8_t addr, void *buf, size_t len)
{ {
if (!len || !buf) return 0; if (!len || !buf) return 0;
uint8_t *_buf = (uint8_t *)buf; uint8_t *_buf = (uint8_t *)buf;
i2c_start(); i2c_start();
if (!i2c_write(addr << 1)) return 0; if (!i2c_write(addr << 1)) return 0;
for (size_t i = 0; i < len; i++) for (size_t i = 0; i < len; i++)
i2c_write(*_buf++); i2c_write(*_buf++);
return len; return len;
} }
void pcf8574_port_write(uint8_t addr, uint8_t value) void pcf8574_port_write(uint8_t addr, uint8_t value)
{ {
i2c_start(); i2c_start();
if (i2c_write(addr << 1)) i2c_write(value); if (i2c_write(addr << 1)) i2c_write(value);
i2c_stop(); i2c_stop();
} }
bool pcf8574_gpio_read(uint8_t addr, uint8_t num) bool pcf8574_gpio_read(uint8_t addr, uint8_t num)
{ {
return (bool)((pcf8574_port_read(addr) >> num) & 1); return (bool)((pcf8574_port_read(addr) >> num) & 1);
} }
void pcf8574_gpio_write(uint8_t addr, uint8_t num, bool value) void pcf8574_gpio_write(uint8_t addr, uint8_t num, bool value)
{ {
uint8_t bit = (uint8_t)value << num; uint8_t bit = (uint8_t)value << num;
uint8_t mask = ~(1 << num); uint8_t mask = ~(1 << num);
pcf8574_port_write (addr, (pcf8574_port_read(addr) & mask) | bit); pcf8574_port_write (addr, (pcf8574_port_read(addr) & mask) | bit);
} }

View file

@ -14,6 +14,7 @@
*/ */
/** /**
* \file Driver for PCF8574 compartible remote 8-bit I/O expanders for I2C-bus * \file Driver for PCF8574 compartible remote 8-bit I/O expanders for I2C-bus
* \author Ruslan V. Uss
*/ */
#ifndef PCF8574_PCF8574_H_ #ifndef PCF8574_PCF8574_H_
#define PCF8574_PCF8574_H_ #define PCF8574_PCF8574_H_