Skip to content

Commit

Permalink
allow to skip reboot after search-rom and read-rom
Browse files Browse the repository at this point in the history
default behavior for most IC
  • Loading branch information
orgua committed Oct 10, 2022
1 parent bcb40eb commit 50b1f5d
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The main goal is to use modern sensors (mainly [I2C](https://github.com/orgua/iL
- **DS2431 (0x2D) 1kbit protected EEPROM** (also known as DS1972 or DS28E07, same FC)
- DS2432 (0x33) 1kbit protected EEPROM (basically a ds2431 with extra sha-engine)
- **DS2433 (0x23) 4Kbit EEPROM** (also known as DS1973)
- DS2434 (0x1B ???) BatteryManagement used in some IBM Notebook-Batteries (similar to DS2436 (x1B), with one less cmd)
- DS2434 (0x1B ???) BatteryManagement used in some IBM Notebook-Batteries (similar to DS2436 (x1B), but without multidrop and one less cmd)
- **DS2438 (0x26) Smart Battery Monitor, measures temperature, 2x voltage and current, 10bit**
- **DS2450 (0x20) 4 channel A/D**
- **DS2501 (0x11, 0x91) 512bit EEPROM** -> use DS2502 with different family code
Expand Down
5 changes: 5 additions & 0 deletions src/BAE910.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ BAE910::BAE910(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5,

// clear memory
memset(&memory.bytes[0], static_cast<uint8_t>(0x00), BAE910_MEMORY_SIZE);

// disable bus-features:
// TODO: test, as datasheet does not clear this up -> this settings keeps the previous behavior
fast_read_rom = false;
fast_search_rom = false;
}


Expand Down
3 changes: 3 additions & 0 deletions src/DS18B20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ DS18B20::DS18B20(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5
updateCRC(); // update scratchpad[8]

ds18s20_mode = (ID1 == 0x10); // different tempRegister

// disable bus-features:
fast_search_rom = false;
}

void DS18B20::updateCRC()
Expand Down
2 changes: 1 addition & 1 deletion src/DS18B20.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DS18B20 : public OneWireItem

public:

static constexpr uint8_t family_code { 0x28 }; // is compatible to ds1822 (0x22) and ds18S20 (0x10)
static constexpr uint8_t family_code { 0x28 }; // is compatible to ds1822 (0x22) and ds18S20 (0x10)

DS18B20(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7);

Expand Down
3 changes: 3 additions & 0 deletions src/DS2401.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

DS2401::DS2401(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7) : OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7)
{
// disable bus-features:
fast_read_rom = false;
fast_search_rom = false;
}

void DS2401::duty(OneWireHub * const hub)
Expand Down
2 changes: 1 addition & 1 deletion src/DS2405.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DS2405 : public OneWireItem

public:

static constexpr uint8_t family_code { 0x05 };
static constexpr uint8_t family_code { 0x05 };

DS2405(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7);

Expand Down
8 changes: 4 additions & 4 deletions src/DS2434.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

DS2434::DS2434(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7) : OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7)
{
// The DS2434 is NOT compatible with multidrop.
// It can be the only one of the bus
MULTIDROP = false;
// disable bus-features:
// The DS2434 is NOT compatible with multidrop -> only one device on bus!
skip_multidrop = true;

clearMemory();
clearScratchpad();
}
Expand Down
2 changes: 1 addition & 1 deletion src/DS2434.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DS2434 : public OneWireItem

public:

static constexpr uint8_t family_code { 0x53 }; // TODO: 1B seems to be right
static constexpr uint8_t family_code { 0x53 }; // TODO: 1B seems to be right (for ds2436)

DS2434(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7);

Expand Down
22 changes: 17 additions & 5 deletions src/OneWireHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,13 @@ bool OneWireHub::recvAndProcessCmd(void)
{

// If the only slave is not multidrop compatible, pass all data handling to the slave
if(slave_count == 1){
if(slave_count == 1u){

slave_selected = slave_list[getIndexOfNextSensorInList()];
// TODO: this might be expensive for weak uC and OW in Overdrive -> look into optimizations (i.e. preselect when only one device present?)
// TODO: this might be expensive for weak uC and OW in Overdrive and only one device emulated
// -> look into optimizations (i.e. preselect when only one device present?)

if( slave_selected->MULTIDROP == false ){
if( slave_selected->skip_multidrop ){
slave_selected->duty(this);
return (_error != Error::NO_ERROR);
}
Expand All @@ -431,8 +432,13 @@ bool OneWireHub::recvAndProcessCmd(void)
noInterrupts();
searchIDTree();
interrupts();
// slave_selected->duty(this);
// TODO: some ICs like DS2430 allow going for duty() right after search

// most ICs allow going for duty() right after search
if ((_error == Error::NO_ERROR) && (slave_selected != nullptr) && slave_selected->fast_search_rom)
{
slave_selected->duty(this);
}

return false; // always trigger a re-init after searchIDTree

case 0x69: // overdrive MATCH ROM
Expand Down Expand Up @@ -520,6 +526,12 @@ bool OneWireHub::recvAndProcessCmd(void)
if (slave_selected != nullptr)
{
slave_selected->sendID(this);

// most ICs allow to go to duty() without reset
if ((_error == Error::NO_ERROR) && slave_selected->fast_read_rom)
{
slave_selected->duty(this);
}
}
return false;

Expand Down
10 changes: 8 additions & 2 deletions src/OneWireItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ class OneWireItem
OneWireItem& operator=(const OneWireItem& owItem) = delete; // disallow copy assignment
OneWireItem& operator=(OneWireItem&& owItem) = delete; // disallow move assignment

// DEFAULT BUS-FEATURES:
// Specify if the device can be used on a bus with other 1-wire devices
// If FALSE all commands will be passed through directly to the duty() call of the device
bool MULTIDROP { true }; // TODO: should be lowercase, as it is no constant (yet)

// NOTE: there can be only one device on the bus (beside the controller)
bool skip_multidrop { false };
// skip reboot after a search-rom command -> feature normal, except ds2401 & ds18b20
bool fast_search_rom { true };
// skip reboot after a read-rom command -> feature normal, except ds2401
bool fast_read_rom { true };

uint8_t ID[8];

void sendID(OneWireHub * hub) const;
Expand Down

0 comments on commit 50b1f5d

Please sign in to comment.