8000 proposal for I2C master/slave example by suculent · Pull Request #5360 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

proposal for I2C master/slave example #5360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a1b60e0
added proposal for I2C peer-to-peer communication (master/slave) exam…
Nov 21, 2018
ace0b37
fixes with regards to Travis CI help
Nov 21, 2018
ba488f7
oh, the warnings. now the goes to default but address needs to be set…
Nov 21, 2018
716f3a0
proposing new init method with pins and address, because pins() is de…
Nov 21, 2018
f692b85
Merge branch 'master' into i2c_master_slave_example
devyte Nov 23, 2018
0473dbd
type fixed in 3rd party code, removing I2C scanner (duplicate of anot…
Nov 26, 2018
d558bfe
type fix in onReceive callback
Nov 26, 2018 8000
21dfde2
implemented changes proposed by code review
Nov 26, 2018
8d1066a
Merge branch 'i2c_master_slave_example' of github.com:suculent/Arduin…
Nov 26, 2018
57bcd96
Merge commit 'cd05bae0e8b69eea94adbf153eca4e7c9b96a901' into i2c_mast…
Nov 26, 2018
88de8da
partial fixes after travis check; still missing merge of yesterday's …
Nov 26, 2018
fe21c28
Merge branch 'master' into i2c_master_slave_example
suculent Nov 28, 2018
9f019a8
Merge branch 'master' into i2c_master_slave_example
suculent Dec 8, 2018
983fc47
no message
Dec 8, 2018
4faa715
fixes after functional testing
Dec 8, 2018
d18f57e
Merge branch 'master' into i2c_master_slave_example
devyte Dec 8, 2018
fabca64
minor style fixes
Dec 8, 2018
35f4dac
Merge branch 'i2c_master_slave_example' of github.com:suculent/Arduin…
Dec 8, 2018
a8f7d63
style fix and unused variable fix
Dec 9, 2018
0272be2
style check fix
Dec 9, 2018
20e78d0
Merge branch 'master' into i2c_master_slave_example
devyte Dec 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
type fixed in 3rd party code, removing I2C scanner (duplicate of anot…
…her example)
  • Loading branch information
Matěj Sychra committed Nov 26, 2018
commit 0473dbd9cdd49c21e954cb1cec21289da28ed048
75 changes: 40 additions & 35 deletions libraries/Wire/examples/i2c-P2P-master/crc16.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// History
// 0.1.0 31/05/2014: First public code release
// 0.1.1 17/12/2014: Minor revision and commented code
// 0.1.2 24/11/2018: Minor code style fixes (by @devyte and @suculent)
//
// License
// "MIT Open Source Software License":
Expand All @@ -27,7 +28,7 @@
//-------------------------------------------------------------------------------------
#ifndef CRC16_H
#define CRC16_H
#define LIBRARY_VERSION_CRC16_H "0.1.1"
#define LIBRARY_VERSION_CRC16_H "0.1.2"

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
Expand All @@ -45,12 +46,12 @@ class Crc16 {
uint16_t _xorIn;
uint16_t _xorOut;
uint16_t _polynomial;
uint8_t _reflectIn;
uint8_t _reflectOut;
bool _reflectIn;
bool _reflectOut;
//Crc value
uint16_t _crc;
uint8_t reflect(uint8_t data, uint8_t bits = 32);

public:
inline Crc16()
{
Expand All @@ -64,7 +65,7 @@ class Crc16 {
_mask = 0xFFFF;
_crc = _xorIn;
}
inline Crc16(uint8_t reflectIn, uint8_t reflectOut, uint16_t polynomial, uint16_t xorIn, uint16_t xorOut, uint16_t msbMask, uint16_t mask)
inline Crc16(bool reflectIn, bool reflectOut, uint16_t polynomial, uint16_t xorIn, uint16_t xorOut, uint16_t msbMask, uint16_t mask)
{
_reflectIn = reflectIn;
_reflectOut = reflectOut;
Expand All @@ -78,8 +79,8 @@ class Crc16 {
inline void clearCrc();
inline void updateCrc(uint8_t data);
inline uint16_t getCrc();
inline unsigned int fastCrc(uint8_t data[], uint8_t start, uint16_t length, uint8_t reflectIn, uint8_t reflectOut, uint16_t polynomial, uint16_t xorIn, uint16_t xorOut, uint16_t msbMask, uint16_t mask);
inline unsigned int XModemCrc(uint8_t data[], uint8_t start, uint16_t length)
inline unsigned int fastCrc(const uint8_t *data, uint8_t start, uint16_t length, bool reflectIn, bool reflectOut, uint16_t polynomial, uint16_t xorIn, uint16_t xorOut, uint16_t msbMask, uint16_t mask);
inline unsigned int XModemCrc(const uint8_t *data, const uint8_t start, const uint16_t length)
{
// XModem parameters: poly=0x1021 init=0x0000 refin=false refout=false xorout=0x0000
return fastCrc(data, start, length, false, false, 0x1021, 0x0000, 0x0000, 0x8000, 0xffff);
Expand All @@ -98,27 +99,28 @@ void Crc16::clearCrc()
//---------------------------------------------------
void Crc16::updateCrc(uint8_t data)
{
if (_reflectIn != 0)
if (_reflectIn != 0) {
data = (uint8_t) reflect(data, 8);

}

int j = 0x80;

while (j > 0)
{
uint16_t bit = (uint16_t)(_crc & _msbMask);

_crc <<= 1;

if ((data & j) != 0)
{
bit = (uint16_t)(bit ^ _msbMask);
}

if (bit != 0)
{
_crc ^= _polynomial;
}

j >>= 1;
}
}
Expand All @@ -128,9 +130,10 @@ void Crc16::updateCrc(uint8_t data)
//---------------------------------------------------
uint16_t Crc16::getCrc()
{
if (_reflectOut != 0)
if (_reflectOut != 0) {
_crc = (unsigned int)((reflect(_crc) ^ _xorOut) & _mask);

}

return _crc;
}

Expand All @@ -142,47 +145,50 @@ uint16_t Crc16::getCrc()
// XModem: width=16 poly=0x1021 init=0x0000 refin=false refout=false xorout=0x0000 check=0x31c3
// CCITT-False: width=16 poly=0x1021 init=0xffff refin=false refout=false xorout=0x0000 check=0x29b1
//---------------------------------------------------
unsigned int Crc16::fastCrc(uint8_t data[], uint8_t start, uint16_t length, uint8_t reflectIn, uint8_t reflectOut, uint16_t polynomial, uint16_t xorIn, uint16_t xorOut, uint16_t msbMask, uint16_t mask)
unsigned int Crc16::fastCrc(const uint8_t *data, uint8_t start, uint16_t length, bool reflectIn, bool reflectOut, uint16_t polynomial, uint16_t xorIn, uint16_t xorOut, uint16_t msbMask, uint16_t mask)
{
unsigned int crc = xorIn;

int j;
uint8_t c;
unsigned int bit;

if (length == 0) return crc;

for (int i = start; i < (start + length); i++)

if (length == 0) {
return crc;
}

for (int i = start; i < (start + length); ++i)
{
c = data[i];

if (reflectIn != 0)
c = (uint8_t) reflect(c, 8);

j = 0x80;

while (j > 0)
{
bit = (unsigned int)(crc & msbMask);
crc <<= 1;

if ((c & j) != 0)
{
bit = (unsigned int)(bit ^ msbMask);
}

if (bit != 0)
{
crc ^= polynomial;
}

j >>= 1;
}
}
if (reflectOut != 0)

if (reflectOut != 0) {
crc = (unsigned int)((reflect(crc) ^ xorOut) & mask);

}

return crc;
}

Expand All @@ -196,14 +202,13 @@ uint8_t Crc16::reflect(uint8_t data, uint8_t bits)
for (uint8_t bit = 0; bit < bits; bit++)
{
// If the LSB bit is set, set the reflection of it.
if ((data & 0x01) != 0)
{
if ((data & 0x01) != 0) {
reflection |= (unsigned long)(1 << ((bits - 1) - bit));
}

data = (uint8_t)(data >> 1);
}

return reflection;
}
#endif
43 changes: 0 additions & 43 deletions libraries/Wire/examples/i2c-P2P-master/i2c-scanner.h

This file was deleted.

Loading
0