Merge pull request #302 from bmarquismarkail/rcmclone
Adding i2C repeated start condition from @bmarquismarkail
This commit is contained in:
commit
bd8ef73bef
|
@ -38,7 +38,7 @@
|
|||
|
||||
#include "HardWire.h"
|
||||
|
||||
uint8 HardWire::process() {
|
||||
uint8 HardWire::process(uint8 stop) {
|
||||
int8 res = i2c_master_xfer(sel_hard, &itc_msg, 1, 0);
|
||||
if (res == I2C_ERROR_PROTOCOL) {
|
||||
if (sel_hard->error_flags & I2C_SR1_AF) { /* NACK */
|
||||
|
@ -55,6 +55,10 @@ uint8 HardWire::process() {
|
|||
return res;
|
||||
}
|
||||
|
||||
uint8 HardWire::process(){
|
||||
return process(true);
|
||||
}
|
||||
|
||||
// TODO: Add in Error Handling if devsel is out of range for other Maples
|
||||
HardWire::HardWire(uint8 dev_sel, uint8 flags) {
|
||||
if (dev_sel == 1) {
|
||||
|
|
|
@ -52,6 +52,7 @@ protected:
|
|||
* Processes the incoming I2C message defined by WireBase to the
|
||||
* hardware. If an error occured, restart the I2C device.
|
||||
*/
|
||||
uint8 process(uint8);
|
||||
uint8 process();
|
||||
public:
|
||||
/*
|
||||
|
|
|
@ -40,6 +40,9 @@
|
|||
* Updated by Roger Clark. 20141111. Fixed issue when process() returned because of missing ACK (often caused by invalid device address being used), caused SCL to be left
|
||||
* LOW so that in the next call to process() , the first clock pulse was not sent, because SCL was LOW when it should have been high.
|
||||
*/
|
||||
/*
|
||||
* Updated by Brandon Green. 20172306. Implementing the repeated start functionality.
|
||||
*/
|
||||
|
||||
#include "Wire.h"
|
||||
|
||||
|
@ -76,6 +79,12 @@ void TwoWire::i2c_stop() {
|
|||
set_sda(HIGH);
|
||||
}
|
||||
|
||||
void TwoWire::i2c_repeated_start() {
|
||||
set_sda(HIGH);
|
||||
set_scl(HIGH);
|
||||
set_sda(LOW);
|
||||
}
|
||||
|
||||
bool TwoWire::i2c_get_ack() {
|
||||
set_scl(LOW);
|
||||
set_sda(HIGH);
|
||||
|
@ -121,7 +130,8 @@ void TwoWire::i2c_shift_out(uint8 val) {
|
|||
}
|
||||
}
|
||||
|
||||
uint8 TwoWire::process() {
|
||||
//process needs to be updated for repeated start.
|
||||
uint8 TwoWire::process(uint8 stop) {
|
||||
itc_msg.xferred = 0;
|
||||
|
||||
uint8 sla_addr = (itc_msg.addr << 1);
|
||||
|
@ -162,10 +172,18 @@ uint8 TwoWire::process() {
|
|||
itc_msg.xferred++;
|
||||
}
|
||||
}
|
||||
if(stop == true)
|
||||
i2c_stop();
|
||||
else i2c_repeated_start();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// For compatibility with legacy code
|
||||
uint8 TwoWire::process(){
|
||||
return process(true);
|
||||
}
|
||||
|
||||
// TODO: Add in Error Handling if pins is out of range for other Maples
|
||||
// TODO: Make delays more capable
|
||||
TwoWire::TwoWire(uint8 scl, uint8 sda, uint8 delay) : i2c_delay(delay) {
|
||||
|
|
|
@ -87,6 +87,11 @@ class TwoWire : public WireBase {
|
|||
*/
|
||||
void i2c_stop();
|
||||
|
||||
/*
|
||||
* Created a Repeated Start condition on the bus
|
||||
*/
|
||||
void i2c_repeated_start();
|
||||
|
||||
/*
|
||||
* Gets an ACK condition from a slave device on the bus
|
||||
*/
|
||||
|
@ -119,6 +124,7 @@ class TwoWire : public WireBase {
|
|||
/*
|
||||
* Processes the incoming I2C message defined by WireBase
|
||||
*/
|
||||
uint8 process(uint8);
|
||||
uint8 process();
|
||||
public:
|
||||
/*
|
||||
|
|
|
@ -59,17 +59,21 @@ void WireBase::beginTransmission(int slave_address) {
|
|||
beginTransmission((uint8)slave_address);
|
||||
}
|
||||
|
||||
uint8 WireBase::endTransmission(void) {
|
||||
uint8 WireBase::endTransmission(uint8 stop) {
|
||||
uint8 retVal;
|
||||
if (tx_buf_overflow) {
|
||||
return EDATA;
|
||||
}
|
||||
retVal = process();// Changed so that the return value from process is returned by this function see also the return line below
|
||||
retVal = process(stop);// Changed so that the return value from process is returned by this function see also the return line below
|
||||
tx_buf_idx = 0;
|
||||
tx_buf_overflow = false;
|
||||
return retVal;//SUCCESS;
|
||||
}
|
||||
|
||||
uint8 WireBase::endTransmission(){
|
||||
endTransmission(true);
|
||||
}
|
||||
|
||||
//TODO: Add the ability to queue messages (adding a boolean to end of function
|
||||
// call, allows for the Arduino style to stay while also giving the flexibility
|
||||
// to bulk send
|
||||
|
|
|
@ -65,6 +65,7 @@ protected:
|
|||
boolean tx_buf_overflow;
|
||||
|
||||
// Force derived classes to define process function
|
||||
virtual uint8 process(uint8) = 0;
|
||||
virtual uint8 process() = 0;
|
||||
public:
|
||||
WireBase() {}
|
||||
|
@ -90,6 +91,7 @@ public:
|
|||
* Call the process function to process the message if the TX
|
||||
* buffer has not overflowed.
|
||||
*/
|
||||
uint8 endTransmission(uint8);
|
||||
uint8 endTransmission(void);
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue