onewire for esp32 improved, retry for sensors

This commit is contained in:
MichaelDvP
2020-08-02 08:54:30 +02:00
parent e735ac0338
commit 91573f5594
4 changed files with 39 additions and 15 deletions

View File

@@ -161,7 +161,11 @@ void OneWire::begin(uint8_t pin) {
//
// Returns 1 if a device asserted a presence pulse, 0 otherwise.
//
#ifdef ARDUINO_ARCH_ESP32
uint8_t IRAM_ATTR OneWire::reset(void) {
#else
uint8_t OneWire::reset(void) {
#endif
IO_REG_TYPE mask IO_REG_MASK_ATTR = bitmask;
volatile IO_REG_TYPE * reg IO_REG_BASE_ATTR = baseReg;
uint8_t r;
@@ -195,7 +199,11 @@ uint8_t OneWire::reset(void) {
// Write a bit. Port and bit is used to cut lookup time and provide
// more certain timing.
//
#ifdef ARDUINO_ARCH_ESP32
void IRAM_ATTR OneWire::write_bit(uint8_t v) {
#else
void OneWire::write_bit(uint8_t v) {
#endif
IO_REG_TYPE mask IO_REG_MASK_ATTR = bitmask;
volatile IO_REG_TYPE * reg IO_REG_BASE_ATTR = baseReg;
@@ -222,7 +230,11 @@ void OneWire::write_bit(uint8_t v) {
// Read a bit. Port and bit is used to cut lookup time and provide
// more certain timing.
//
#ifdef ARDUINO_ARCH_ESP32
uint8_t IRAM_ATTR OneWire::read_bit(void) {
#else
uint8_t OneWire::read_bit(void) {
#endif
IO_REG_TYPE mask IO_REG_MASK_ATTR = bitmask;
volatile IO_REG_TYPE * reg IO_REG_BASE_ATTR = baseReg;
uint8_t r;
@@ -473,6 +485,7 @@ bool OneWire::search(uint8_t * newAddr, bool search_mode /* = true */) {
for (int i = 0; i < 8; i++)
newAddr[i] = ROM_NO[i];
}
// depower(); // https://github.com/PaulStoffregen/OneWire/pull/80
return search_result;
}