Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Diff: Masters/DS248x/DS248x.cpp
- Revision:
- 75:8b627804927c
- Parent:
- 74:23be10c32fa3
- Child:
- 76:84e6c4994e29
--- a/Masters/DS248x/DS248x.cpp Fri May 13 07:48:35 2016 -0500 +++ b/Masters/DS248x/DS248x.cpp Fri May 13 14:52:50 2016 -0500 @@ -88,22 +88,22 @@ } DS248x::DS248x(mbed::I2C & i2c_bus, uint8_t adrs) - :_p_i2c_bus(&i2c_bus), _adrs(adrs), _i2c_owner(false) + :m_p_i2c_bus(&i2c_bus), m_adrs(adrs), m_i2c_owner(false) { } DS248x::DS248x(PinName sda, PinName scl, uint8_t adrs) - : _p_i2c_bus(new mbed::I2C(sda, scl)), _adrs(adrs), _i2c_owner(true) + : m_p_i2c_bus(new mbed::I2C(sda, scl)), m_adrs(adrs), m_i2c_owner(true) { } DS248x::~DS248x() { - if (_i2c_owner) + if (m_i2c_owner) { - delete _p_i2c_bus; + delete m_p_i2c_bus; } } @@ -134,7 +134,7 @@ OneWireMaster::CmdResult result; uint8_t buf; - result = sendCommand(CMD_DRST); + result = sendCommand(DeviceResetCmd); if (result == OneWireMaster::Success) { @@ -205,7 +205,7 @@ break; }; - result = sendCommand(CMD_CHSL, ch); + result = sendCommand(ChannelSelectCmd, ch); if (result == OneWireMaster::Success) { result = readRegister(ChannelSelectReg, ch, true); @@ -231,7 +231,7 @@ control_byte = (((param & 0x0F) << 4) | (val & 0x0F)); - result = sendCommand(CMD_A1WP, control_byte); + result = sendCommand(AdjustOwPortCmd, control_byte); if (result != Success) { return result; @@ -251,7 +251,7 @@ return result; } -OneWireMaster::CmdResult DS248x::OWTriplet(SearchDirection & search_direction, uint8_t & sbr, uint8_t & tsb) +OneWireMaster::CmdResult DS248x::OWTriplet(SearchDirection & searchDirection, uint8_t & sbr, uint8_t & tsb) { // 1-Wire Triplet (Case B) // S AD,0 [A] 1WT [A] SS [A] Sr AD,1 [A] [Status] A [Status] A\ P @@ -261,7 +261,7 @@ // SS indicates byte containing search direction bit value in msbit OneWireMaster::CmdResult result; - result = sendCommand(CMD_1WT, (uint8_t)((search_direction == DIRECTION_WRITE_ONE) ? 0x80 : 0x00)); + result = sendCommand(OwTripletCmd, (uint8_t)((searchDirection == WriteOne) ? 0x80 : 0x00)); if (result == OneWireMaster::Success) { uint8_t status; @@ -271,13 +271,13 @@ // check bit results in status byte sbr = ((status & STATUS_SBR) == STATUS_SBR); tsb = ((status & STATUS_TSB) == STATUS_TSB); - search_direction = ((status & STATUS_DIR) == STATUS_DIR) ? DIRECTION_WRITE_ONE : DIRECTION_WRITE_ZERO; + searchDirection = ((status & STATUS_DIR) == STATUS_DIR) ? WriteOne : WriteZero; } } return result; } -OneWireMaster::CmdResult DS248x::OWReset(void) +OneWireMaster::CmdResult DS248x::OWReset() { // 1-Wire reset (Case B) // S AD,0 [A] 1WRS [A] Sr AD,1 [A] [Status] A [Status] A\ P @@ -288,7 +288,7 @@ OneWireMaster::CmdResult result; uint8_t buf; - result = sendCommand(CMD_1WRS); + result = sendCommand(OwResetCmd); if (result == OneWireMaster::Success) { @@ -307,7 +307,7 @@ return result; } -OneWireMaster::CmdResult DS248x::OWTouchBitSetLevel(uint8_t & sendrecvbit, OWLevel after_level) +OneWireMaster::CmdResult DS248x::OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel) { // 1-Wire bit (Case B) // S AD,0 [A] 1WSB [A] BB [A] Sr AD,1 [A] [Status] A [Status] A\ P @@ -318,7 +318,7 @@ OneWireMaster::CmdResult result; - result = configureLevel(after_level); + result = configureLevel(afterLevel); if (result != OneWireMaster::Success) { return result; @@ -326,7 +326,7 @@ uint8_t status; - result = sendCommand(CMD_1WSB, (uint8_t)(sendrecvbit ? 0x80 : 0x00)); + result = sendCommand(OwSingleBitCmd, (uint8_t)(sendRecvBit ? 0x80 : 0x00)); if (result == OneWireMaster::Success) { @@ -335,13 +335,13 @@ if (result == OneWireMaster::Success) { - sendrecvbit = (status & STATUS_SBR); + sendRecvBit = (status & STATUS_SBR); } return result; } -OneWireMaster::CmdResult DS248x::OWWriteByteSetLevel(uint8_t sendbyte, OWLevel after_level) +OneWireMaster::CmdResult DS248x::OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel) { // 1-Wire Write Byte (Case B) // S AD,0 [A] 1WWB [A] DD [A] Sr AD,1 [A] [Status] A [Status] A\ P @@ -352,13 +352,13 @@ OneWireMaster::CmdResult result; - result = configureLevel(after_level); + result = configureLevel(afterLevel); if (result != OneWireMaster::Success) { return result; } - result = sendCommand(CMD_1WWB, sendbyte); + result = sendCommand(OwWriteByteCmd, sendByte); if (result == OneWireMaster::Success) { result = pollBusy(); @@ -367,7 +367,7 @@ return result; } -OneWireMaster::CmdResult DS248x::OWReadByteSetLevel(uint8_t & recvbyte, OWLevel after_level) +OneWireMaster::CmdResult DS248x::OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel) { // 1-Wire Read Bytes (Case C) // S AD,0 [A] 1WRB [A] Sr AD,1 [A] [Status] A [Status] A\ @@ -381,13 +381,13 @@ OneWireMaster::CmdResult result; uint8_t buf; - result = configureLevel(after_level); + result = configureLevel(afterLevel); if (result != OneWireMaster::Success) { return result; } - result = sendCommand(CMD_1WRB); + result = sendCommand(OwReadByteCmd); if (result == OneWireMaster::Success) { @@ -401,36 +401,36 @@ if (result == OneWireMaster::Success) { - recvbyte = buf; + recvByte = buf; } return result; } -OneWireMaster::CmdResult DS248x::OWSetSpeed(OWSpeed new_speed) +OneWireMaster::CmdResult DS248x::OWSetSpeed(OWSpeed newSpeed) { // Requested speed is already set - if (m_curConfig.get1WS() == (new_speed == SPEED_OVERDRIVE)) + if (m_curConfig.get1WS() == (newSpeed == OverdriveSpeed)) { return OneWireMaster::Success; } // set the speed Config newConfig = m_curConfig; - newConfig.set1WS(new_speed == SPEED_OVERDRIVE); + newConfig.set1WS(newSpeed == OverdriveSpeed); // write the new config return writeConfig(newConfig, true); } -OneWireMaster::CmdResult DS248x::OWSetLevel(OWLevel new_level) +OneWireMaster::CmdResult DS248x::OWSetLevel(OWLevel newLevel) { - if (new_level == LEVEL_STRONG) + if (newLevel == StrongLevel) { return OneWireMaster::OperationFailure; } - return configureLevel(new_level); + return configureLevel(newLevel); } OneWireMaster::CmdResult DS248x::writeConfig(const Config & config, bool verify) @@ -439,7 +439,7 @@ OneWireMaster::CmdResult result; configBuf = config.writeByte(); - result = sendCommand(CMD_WCFG, configBuf); + result = sendCommand(WriteDeviceConfigCmd, configBuf); if (verify) { if (result == OneWireMaster::Success) @@ -466,10 +466,10 @@ OneWireMaster::CmdResult DS248x::readRegister(Register reg, uint8_t & buf, bool skipSetPointer) const { CmdResult result; - result = sendCommand(CMD_SRP, reg); + result = sendCommand(SetReadPointerCmd, reg); if (result == Success) { - if (_p_i2c_bus->read(_adrs, reinterpret_cast<char *>(&buf), 1) != I2C_READ_OK) + if (m_p_i2c_bus->read(m_adrs, reinterpret_cast<char *>(&buf), 1) != I2C_READ_OK) { result = CommunicationReadError; } @@ -508,10 +508,10 @@ OneWireMaster::CmdResult DS248x::configureLevel(OWLevel level) { OneWireMaster::CmdResult result; - if (m_curConfig.getSPU() != (level == LEVEL_STRONG)) + if (m_curConfig.getSPU() != (level == StrongLevel)) { Config newConfig = m_curConfig; - newConfig.setSPU(level == LEVEL_STRONG); + newConfig.setSPU(level == StrongLevel); result = writeConfig(newConfig, true); } else @@ -521,10 +521,10 @@ return result; } -OneWireMaster::CmdResult DS248x::sendCommand(DS248X_CMDS cmd) const +OneWireMaster::CmdResult DS248x::sendCommand(Command cmd) const { CmdResult result; - if (_p_i2c_bus->write(_adrs, reinterpret_cast<const char *>(&cmd), 1) == I2C_WRITE_OK) + if (m_p_i2c_bus->write(m_adrs, reinterpret_cast<const char *>(&cmd), 1) == I2C_WRITE_OK) { result = Success; } @@ -535,11 +535,11 @@ return result; } -OneWireMaster::CmdResult DS248x::sendCommand(DS248X_CMDS cmd, uint8_t param) const +OneWireMaster::CmdResult DS248x::sendCommand(Command cmd, uint8_t param) const { CmdResult result; char buf[2] = { cmd, param }; - if (_p_i2c_bus->write(_adrs, buf, 2) == I2C_WRITE_OK) + if (m_p_i2c_bus->write(m_adrs, buf, 2) == I2C_WRITE_OK) { result = Success; }