From 80339e6073d25b58ce0c8dbc0d7c5bbabb8a441f Mon Sep 17 00:00:00 2001 From: "U-MarquisSeven\\Brandon" Date: Mon, 26 Jun 2017 18:57:49 -0500 Subject: [PATCH 1/2] checking out work from master --- STM32F1/libraries/Wire/HardWire.cpp | 6 +++++- STM32F1/libraries/Wire/HardWire.h | 1 + STM32F1/libraries/Wire/Wire.cpp | 22 ++++++++++++++++++++-- STM32F1/libraries/Wire/Wire.h | 8 +++++++- STM32F1/libraries/Wire/WireBase.cpp | 8 ++++++-- STM32F1/libraries/Wire/WireBase.h | 2 ++ 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/STM32F1/libraries/Wire/HardWire.cpp b/STM32F1/libraries/Wire/HardWire.cpp index 1f3ebf2..d81f584 100644 --- a/STM32F1/libraries/Wire/HardWire.cpp +++ b/STM32F1/libraries/Wire/HardWire.cpp @@ -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) { diff --git a/STM32F1/libraries/Wire/HardWire.h b/STM32F1/libraries/Wire/HardWire.h index 6f30cb3..bf59a2f 100644 --- a/STM32F1/libraries/Wire/HardWire.h +++ b/STM32F1/libraries/Wire/HardWire.h @@ -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: /* diff --git a/STM32F1/libraries/Wire/Wire.cpp b/STM32F1/libraries/Wire/Wire.cpp index 01ee72f..8e8d3e5 100644 --- a/STM32F1/libraries/Wire/Wire.cpp +++ b/STM32F1/libraries/Wire/Wire.cpp @@ -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 stop 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++; } } - i2c_stop(); + 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) { diff --git a/STM32F1/libraries/Wire/Wire.h b/STM32F1/libraries/Wire/Wire.h index c7edfef..df474da 100644 --- a/STM32F1/libraries/Wire/Wire.h +++ b/STM32F1/libraries/Wire/Wire.h @@ -86,7 +86,12 @@ class TwoWire : public WireBase { * Creates a Stop condition on the bus */ 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: /* diff --git a/STM32F1/libraries/Wire/WireBase.cpp b/STM32F1/libraries/Wire/WireBase.cpp index ff0dae3..73d0398 100644 --- a/STM32F1/libraries/Wire/WireBase.cpp +++ b/STM32F1/libraries/Wire/WireBase.cpp @@ -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 diff --git a/STM32F1/libraries/Wire/WireBase.h b/STM32F1/libraries/Wire/WireBase.h index 4e51c0d..4038428 100644 --- a/STM32F1/libraries/Wire/WireBase.h +++ b/STM32F1/libraries/Wire/WireBase.h @@ -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); /* From 54044592fb4a05149c6694d429a26b4d3a014626 Mon Sep 17 00:00:00 2001 From: "U-MarquisSeven\\Brandon" Date: Mon, 26 Jun 2017 18:59:33 -0500 Subject: [PATCH 2/2] changing comment --- STM32F1/libraries/Wire/Wire.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STM32F1/libraries/Wire/Wire.cpp b/STM32F1/libraries/Wire/Wire.cpp index 8e8d3e5..fff850b 100644 --- a/STM32F1/libraries/Wire/Wire.cpp +++ b/STM32F1/libraries/Wire/Wire.cpp @@ -41,7 +41,7 @@ * 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. + * Updated by Brandon Green. 20172306. Implementing the repeated start functionality. */ #include "Wire.h"