![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
xDotBridge/src/DS2408.cpp
- Committer:
- Matt Briggs
- Date:
- 2017-01-26
- Revision:
- 40:2ec4be320961
- Child:
- 50:e89647e77fd5
File content as of revision 40:2ec4be320961:
#include "DS2408.h" enum DS2408Cmd { registerReadCmd = 0xF0, channelAccessReadCmd = 0xF5, channelAccessWriteCmd = 0x5A }; DS2408::DS2408(OneWire *owMaster, uint8_t romAddr[8]) { mMaster = owMaster; std::memcpy(mRomAddr, romAddr, sizeof(mRomAddr)); } CmdResult DS2408::init() { mMaster->reset(); // TODO implement safety cancel test mode recommendation return cmdSuccess; } CmdResult DS2408::registerRead(uint8_t addr, uint8_t &val) { uint8_t addrArray[] = {0x00, 0x00}; addrArray[0] = addr; mMaster->reset(); mMaster->select(mRomAddr); mMaster->write(registerReadCmd); // Read Register Command mMaster->write_bytes(addrArray, 2); // Write 2 byte addr val = mMaster->read(); // logDebug("Reg Value: %02x\n", result); return cmdSuccess; } CmdResult DS2408::pioLogicRead(uint8_t &val) { return registerRead(pioLogicStateReg, val); } CmdResult DS2408::pioLogicWrite(uint8_t val) { mMaster->reset(); mMaster->select(mRomAddr); mMaster->write(channelAccessWriteCmd); mMaster->write(val); mMaster->write(~val); // Need to write complement to ensure no bit errors uint8_t result = mMaster->read(); if (result == 0xAA) { return cmdSuccess; } else { return cmdError; } }