0.4.0 DS28CM00

This commit is contained in:
Rob Tillaart 2023-12-11 14:38:42 +01:00
parent d996306760
commit 221507bb89
10 changed files with 50 additions and 52 deletions

View File

@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.4.0] - 2023-12-11
- refactor API, begin()
- update readme.md
- update examples
----
## [0.3.0] - 2023-09-21
- add Wire1 support for ESP32
- refactored ESP32 interface, no constructor => but a begin()

View File

@ -2,7 +2,7 @@
// FILE: DS28CM00.cpp
// AUTHOR: Rob Tillaart
// PURPOSE: Library for the DS28CM00 unique identification chip.
// VERSION: 0.3.0
// VERSION: 0.4.0
// URL: https://github.com/RobTillaart/DS28CM00
@ -20,23 +20,9 @@ DS28CM00::DS28CM00(TwoWire *wire)
}
#if defined(ESP8266) || defined(ESP32)
bool DS28CM00::begin(const uint8_t dataPin, const uint8_t clockPin)
{
if ((dataPin < 255) && (clockPin < 255))
{
_wire->begin(dataPin, clockPin);
} else {
_wire->begin();
}
return setI2CMode();
}
#endif
bool DS28CM00::begin()
{
_wire->begin();
if (!isConnected()) return false;
return setI2CMode();
}

View File

@ -3,7 +3,7 @@
// FILE: DS28CM00.h
// AUTHOR: Rob Tillaart
// PURPOSE: Library for the DS28CM00 unique identification chip.
// VERSION: 0.3.0
// VERSION: 0.4.0
// HISTORY: See DS28CM00.cpp
// URL: https://github.com/RobTillaart/DS28CM00
@ -12,7 +12,7 @@
#include "Wire.h"
#define DS28CM00_LIB_VERSION (F("0.3.0"))
#define DS28CM00_LIB_VERSION (F("0.4.0"))
#define DS28CM00_I2C_MODE 0x00
#define DS28CM00_SMBUS_MODE 0x01
#define DS28CM00_MODE_UNKNOWN 0xFF
@ -23,9 +23,6 @@ class DS28CM00
public:
explicit DS28CM00(TwoWire *wire = &Wire);
#if defined(ESP8266) || defined(ESP32)
bool begin(const uint8_t dataPin, const uint8_t clockPin);
#endif
bool begin(); // default DS28CM00_I2C_MODE
bool isConnected();

View File

@ -30,6 +30,15 @@ as bonus.
The DS28CM00 can work in 2 modes, I2C and SMBus mode. Check datasheet for details.
#### 0.4.0 Breaking change
Version 0.4.0 introduced a breaking change.
You cannot set the pins in **begin()** any more.
This reduces the dependency of processor dependent Wire implementations.
The user has to call **Wire.begin()** and can optionally set the Wire pins
before calling **begin()**.
#### Related
- https://github.com/RobTillaart/UUID
@ -41,17 +50,11 @@ The DS28CM00 can work in 2 modes, I2C and SMBus mode. Check datasheet for detail
#include "DS28CM00.h"
```
### Constructor
- **DS28CM00(TwoWire \*wire = &Wire)** Constructor, with default Wire as I2C bus.
### Public
- **bool begin()** initializes I2C bus, sets default DS28CM00_I2C_MODE.
Returns false if mode cannot be set.
- **bool begin(uint8_t dataPin, uint8_t clockPin)** Constructor for ESP32, ESP8266 et al.
Returns false if mode cannot be set.
The device has a fixed address of 0x50.
- **bool begin()** initializes library, sets default DS28CM00_I2C_MODE.
Returns false if mode cannot be set or if device cannot be found.
- **bool isConnected()** returns true if device can be found on I2C bus.
- **bool getUID(uint8_t \* buffer, uint8_t size = 8)** copy unique serial number into buffer.
Size is default 8, maximum size, size = 0 returns false.
Less unique bytes can be enough sometimes.

View File

@ -6,8 +6,8 @@
// URL: https://github.com/RobTillaart/DS28CM00
#include <Wire.h>
#include <DS28CM00.h>
#include "Wire.h"
#include "DS28CM00.h"
uint8_t uid[8];
@ -94,5 +94,5 @@ void perf_test()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -10,8 +10,8 @@
#include "DS28CM00.h"
#if defined(ESP32) || defined(ESP8266)
#include "rom/crc.h" // ESP32 specific
DS28CM00 DS28(10, 12); // ESP32 I2C pins (choice)
#include "rom/crc.h" // ESP32 specific
DS28CM00 DS28(10, 12); // ESP32 I2C pins (choice)
#else
#include "util/crc16.h"
DS28CM00 DS28(&Wire);
@ -79,8 +79,8 @@ void test()
DS28.setI2CMode();
}
// CRC GENERATION
// TODO VERIFY WHICH CRC
// CRC GENERATION
// TODO VERIFY WHICH CRC
#if defined(ESP32) || defined(ESP8266)
// uint8_t crc8_le(uint8_t crc, uint8_t const *buf, uint32_t len);
@ -108,5 +108,5 @@ void test()
}
// -- END OF FILE --
// -- END OF FILE --

View File

@ -6,10 +6,10 @@
// URL: https://github.com/RobTillaart/DS28CM00
#include <Wire.h>
#include <DS28CM00.h>
#include "Wire.h"
#include "DS28CM00.h"
#include <rom/crc.h> // ESP32 specific
#include <rom/crc.h> // ESP32 specific
uint8_t uid[8];
@ -25,7 +25,8 @@ void setup()
Serial.print(F("DS28CM00 library: "));
Serial.println(DS28CM00_LIB_VERSION);
DS28.begin(10, 12);
Wire.begin(10, 12);
DS28.begin();
Serial.println();
}
@ -48,7 +49,7 @@ void test()
}
else
{
// PRINT UID
// PRINT UID
Serial.print(F("UID:\t"));
for (uint8_t i = 0; i < 8; i++)
{
@ -58,13 +59,13 @@ void test()
}
Serial.println();
// GET MODE
// GET MODE
uint8_t mode = 0;
DS28.getMode(mode);
Serial.print(F("MODE:\t"));
Serial.println(mode);
// TOGGLE MODE
// TOGGLE MODE
if (mode == DS28CM00_I2C_MODE)
{
DS28.setSMBusMode();

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/DS28CM00.git"
},
"version": "0.3.0",
"version": "0.4.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=DS28CM00
version=0.3.0
version=0.4.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for I2C DS28CM00 unique identification chip.

View File

@ -51,13 +51,14 @@ unittest(test_constructor_I)
uint8_t uid[8];
DS28CM00 DS28(&Wire);
Wire.begin();
DS28.begin();
uint8_t mode;
assertFalse(DS28.getMode(mode)); // not connected...
assertFalse(DS28.getMode(mode)); // not connected...
assertEqual(DS28CM00_MODE_UNKNOWN, mode);
assertTrue(DS28.setSMBusMode()); // apparently
assertTrue(DS28.setSMBusMode()); // apparently
assertFalse(DS28.getMode(mode));
assertEqual(DS28CM00_MODE_UNKNOWN, mode);
@ -72,14 +73,17 @@ unittest(test_constructor_II)
uint8_t uid[8];
DS28CM00 DS28; // use default Wire
Wire.begin();
DS28.begin();
uint8_t mode;
assertFalse(DS28.getMode(mode)); // not connected...
assertFalse(DS28.getMode(mode)); // not connected...
assertEqual(DS28CM00_MODE_UNKNOWN, mode);
}
unittest_main()
// --------
// -- END OF FILE --