Archived
1
0
This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
keybrd/src/PortRead_PCA9655E.cpp

32 lines
948 B
C++
Raw Normal View History

#include "PortRead_PCA9655E.h"
2016-05-09 14:05:08 +00:00
/*
configures column port's configuration, input, and pins.
*/
2016-07-15 05:15:38 +00:00
PortRead_PCA9655E::PortRead_PCA9655E (PortIOE& port, const uint8_t readPins)
: port(port), readPins(readPins),
2016-07-18 02:26:00 +00:00
configurationByteCommand(port.num + 6), inputByteCommand(port.num)
2016-05-09 14:05:08 +00:00
{}
void PortRead_PCA9655E::begin()
2016-05-09 14:05:08 +00:00
{
Wire.beginTransmission(port.ADDR);
Wire.write(configurationByteCommand);
2016-07-15 05:15:38 +00:00
Wire.write(readPins); //0=configure as output (for LED), 1=configure as input (for read)
2016-05-09 14:05:08 +00:00
Wire.endTransmission();
}
/*
2016-07-15 05:15:38 +00:00
returns port value
2016-05-09 14:05:08 +00:00
*/
uint8_t PortRead_PCA9655E::read()
2016-05-09 14:05:08 +00:00
{
Wire.beginTransmission(port.ADDR);
Wire.write(inputByteCommand); //input immediately before requestFrom
Wire.endTransmission(false); //PCA9655E needs false to send a restart
Wire.requestFrom(port.ADDR, 1u); //request one byte from input port
return Wire.read();
2016-05-09 14:05:08 +00:00
}