checking out work from master
This commit is contained in:
parent
f7a576f2e0
commit
80339e6073
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
#include "HardWire.h"
|
#include "HardWire.h"
|
||||||
|
|
||||||
uint8 HardWire::process() {
|
uint8 HardWire::process(uint8 stop) {
|
||||||
int8 res = i2c_master_xfer(sel_hard, &itc_msg, 1, 0);
|
int8 res = i2c_master_xfer(sel_hard, &itc_msg, 1, 0);
|
||||||
if (res == I2C_ERROR_PROTOCOL) {
|
if (res == I2C_ERROR_PROTOCOL) {
|
||||||
if (sel_hard->error_flags & I2C_SR1_AF) { /* NACK */
|
if (sel_hard->error_flags & I2C_SR1_AF) { /* NACK */
|
||||||
|
@ -55,6 +55,10 @@ uint8 HardWire::process() {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8 HardWire::process(){
|
||||||
|
return process(true);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Add in Error Handling if devsel is out of range for other Maples
|
// TODO: Add in Error Handling if devsel is out of range for other Maples
|
||||||
HardWire::HardWire(uint8 dev_sel, uint8 flags) {
|
HardWire::HardWire(uint8 dev_sel, uint8 flags) {
|
||||||
if (dev_sel == 1) {
|
if (dev_sel == 1) {
|
||||||
|
|
|
@ -52,6 +52,7 @@ protected:
|
||||||
* Processes the incoming I2C message defined by WireBase to the
|
* Processes the incoming I2C message defined by WireBase to the
|
||||||
* hardware. If an error occured, restart the I2C device.
|
* hardware. If an error occured, restart the I2C device.
|
||||||
*/
|
*/
|
||||||
|
uint8 process(uint8);
|
||||||
uint8 process();
|
uint8 process();
|
||||||
public:
|
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
|
* 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.
|
* 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 stop functionality.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
|
|
||||||
|
@ -76,6 +79,12 @@ void TwoWire::i2c_stop() {
|
||||||
set_sda(HIGH);
|
set_sda(HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TwoWire::i2c_repeated_start() {
|
||||||
|
set_sda(HIGH);
|
||||||
|
set_scl(HIGH);
|
||||||
|
set_sda(LOW);
|
||||||
|
}
|
||||||
|
|
||||||
bool TwoWire::i2c_get_ack() {
|
bool TwoWire::i2c_get_ack() {
|
||||||
set_scl(LOW);
|
set_scl(LOW);
|
||||||
set_sda(HIGH);
|
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;
|
itc_msg.xferred = 0;
|
||||||
|
|
||||||
uint8 sla_addr = (itc_msg.addr << 1);
|
uint8 sla_addr = (itc_msg.addr << 1);
|
||||||
|
@ -162,10 +172,18 @@ uint8 TwoWire::process() {
|
||||||
itc_msg.xferred++;
|
itc_msg.xferred++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(stop == true)
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
|
else i2c_repeated_start();
|
||||||
|
|
||||||
return SUCCESS;
|
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: Add in Error Handling if pins is out of range for other Maples
|
||||||
// TODO: Make delays more capable
|
// TODO: Make delays more capable
|
||||||
TwoWire::TwoWire(uint8 scl, uint8 sda, uint8 delay) : i2c_delay(delay) {
|
TwoWire::TwoWire(uint8 scl, uint8 sda, uint8 delay) : i2c_delay(delay) {
|
||||||
|
|
|
@ -87,6 +87,11 @@ class TwoWire : public WireBase {
|
||||||
*/
|
*/
|
||||||
void i2c_stop();
|
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
|
* 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
|
* Processes the incoming I2C message defined by WireBase
|
||||||
*/
|
*/
|
||||||
|
uint8 process(uint8);
|
||||||
uint8 process();
|
uint8 process();
|
||||||
public:
|
public:
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -59,17 +59,21 @@ void WireBase::beginTransmission(int slave_address) {
|
||||||
beginTransmission((uint8)slave_address);
|
beginTransmission((uint8)slave_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 WireBase::endTransmission(void) {
|
uint8 WireBase::endTransmission(uint8 stop) {
|
||||||
uint8 retVal;
|
uint8 retVal;
|
||||||
if (tx_buf_overflow) {
|
if (tx_buf_overflow) {
|
||||||
return EDATA;
|
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_idx = 0;
|
||||||
tx_buf_overflow = false;
|
tx_buf_overflow = false;
|
||||||
return retVal;//SUCCESS;
|
return retVal;//SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8 WireBase::endTransmission(){
|
||||||
|
endTransmission(true);
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Add the ability to queue messages (adding a boolean to end of function
|
//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
|
// call, allows for the Arduino style to stay while also giving the flexibility
|
||||||
// to bulk send
|
// to bulk send
|
||||||
|
|
|
@ -65,6 +65,7 @@ protected:
|
||||||
boolean tx_buf_overflow;
|
boolean tx_buf_overflow;
|
||||||
|
|
||||||
// Force derived classes to define process function
|
// Force derived classes to define process function
|
||||||
|
virtual uint8 process(uint8) = 0;
|
||||||
virtual uint8 process() = 0;
|
virtual uint8 process() = 0;
|
||||||
public:
|
public:
|
||||||
WireBase() {}
|
WireBase() {}
|
||||||
|
@ -90,6 +91,7 @@ public:
|
||||||
* Call the process function to process the message if the TX
|
* Call the process function to process the message if the TX
|
||||||
* buffer has not overflowed.
|
* buffer has not overflowed.
|
||||||
*/
|
*/
|
||||||
|
uint8 endTransmission(uint8);
|
||||||
uint8 endTransmission(void);
|
uint8 endTransmission(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue