Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Diff: Masters/DS2465/DS2465.cpp
- Revision:
- 75:8b627804927c
- Parent:
- 74:23be10c32fa3
- Child:
- 76:84e6c4994e29
--- a/Masters/DS2465/DS2465.cpp Fri May 13 07:48:35 2016 -0500 +++ b/Masters/DS2465/DS2465.cpp Fri May 13 14:52:50 2016 -0500 @@ -1,3 +1,35 @@ +/******************************************************************//** +* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +**********************************************************************/ + #include "DS2465.h" #include "I2C.h" #include "wait_api.h" @@ -225,10 +257,10 @@ OneWireMaster::CmdResult DS2465::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 @@ -238,33 +270,33 @@ return result; } -OneWireMaster::CmdResult DS2465::OWSetLevel(OWLevel new_level) +OneWireMaster::CmdResult DS2465::OWSetLevel(OWLevel newLevel) { - if (new_level == LEVEL_STRONG) + if (newLevel == StrongLevel) { return OneWireMaster::OperationFailure; } - return configureLevel(new_level); + return configureLevel(newLevel); } -OneWireMaster::CmdResult DS2465::OWSetSpeed(OWSpeed new_speed) +OneWireMaster::CmdResult DS2465::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 DS2465::OWTriplet(SearchDirection & search_direction, uint8_t & sbr, uint8_t & tsb) +OneWireMaster::CmdResult DS2465::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 @@ -274,7 +306,7 @@ // SS indicates byte containing search direction bit value in msbit OneWireMaster::CmdResult result; - uint8_t command[2] = { CMD_1WT, (uint8_t)((search_direction == DIRECTION_WRITE_ONE) ? 0x80 : 0x00) }; + uint8_t command[2] = { CMD_1WT, (uint8_t)((searchDirection == WriteOne) ? 0x80 : 0x00) }; result = writeMemory(ADDR_CMD_REG, command, 2); if (result == OneWireMaster::Success) { @@ -285,13 +317,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 DS2465::OWReadBlock(uint8_t *rx_buf, uint8_t rx_len) +OneWireMaster::CmdResult DS2465::OWReadBlock(uint8_t *recvBuf, uint8_t recvLen) { // 1-Wire Receive Block (Case A) // S AD,0 [A] ADDR_CMD_REG [A] 1WRF [A] PR [A] P @@ -299,7 +331,7 @@ // PR indicates byte containing parameter OneWireMaster::CmdResult result; - uint8_t command[2] = { CMD_1WRF, rx_len }; + uint8_t command[2] = { CMD_1WRF, recvLen }; result = writeMemory(ADDR_CMD_REG, command, 2); if (result == OneWireMaster::Success) @@ -308,15 +340,15 @@ } if (result == OneWireMaster::Success) { - result = readMemory(ADDR_SPAD, rx_buf, rx_len, false); + result = readMemory(ADDR_SPAD, recvBuf, recvLen, false); } return result; } -OneWireMaster::CmdResult DS2465::OWWriteBlock(const uint8_t *tran_buf, uint8_t tran_len) +OneWireMaster::CmdResult DS2465::OWWriteBlock(const uint8_t *sendBuf, uint8_t sendLen) { - return OWWriteBlock(false, tran_buf, tran_len); + return OWWriteBlock(false, sendBuf, sendLen); } OneWireMaster::CmdResult DS2465::OWWriteBlockMac() @@ -354,7 +386,7 @@ return result; } -OneWireMaster::CmdResult DS2465::OWReadByteSetLevel(uint8_t & recvbyte, OWLevel after_level) +OneWireMaster::CmdResult DS2465::OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel) { // 1-Wire Read Bytes (Case C) // S AD,0 [A] ADDR_CMD_REG [A] 1WRB [A] Sr AD,1 [A] [Status] A [Status] A @@ -368,7 +400,7 @@ OneWireMaster::CmdResult result; uint8_t buf; - result = configureLevel(after_level); + result = configureLevel(afterLevel); if (result != OneWireMaster::Success) { return result; @@ -389,13 +421,13 @@ if (result == OneWireMaster::Success) { - recvbyte = buf; + recvByte = buf; } return result; } -OneWireMaster::CmdResult DS2465::OWWriteByteSetLevel(uint8_t sendbyte, OWLevel after_level) +OneWireMaster::CmdResult DS2465::OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel) { // 1-Wire Write Byte (Case B) // S AD,0 [A] ADDR_CMD_REG [A] 1WWB [A] DD [A] Sr AD,1 [A] [Status] A [Status] A\ P @@ -406,13 +438,13 @@ OneWireMaster::CmdResult result; - result = configureLevel(after_level); + result = configureLevel(afterLevel); if (result != OneWireMaster::Success) { return result; } - uint8_t command[2] = { CMD_1WWB, sendbyte }; + uint8_t command[2] = { CMD_1WWB, sendByte }; result = writeMemory(ADDR_CMD_REG, command, 2); if (result == OneWireMaster::Success) @@ -423,7 +455,7 @@ return result; } -OneWireMaster::CmdResult DS2465::OWTouchBitSetLevel(uint8_t & sendrecvbit, OWLevel after_level) +OneWireMaster::CmdResult DS2465::OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel) { // 1-Wire bit (Case B) // S AD,0 [A] ADDR_CMD_REG [A] 1WSB [A] BB [A] Sr AD,1 [A] [Status] A [Status] A\ P @@ -434,13 +466,13 @@ OneWireMaster::CmdResult result; - result = configureLevel(after_level); + result = configureLevel(afterLevel); if (result != OneWireMaster::Success) { return result; } - uint8_t command[2] = { CMD_1WSB, (uint8_t)(sendrecvbit ? 0x80 : 0x00) }; + uint8_t command[2] = { CMD_1WSB, (uint8_t)(sendRecvBit ? 0x80 : 0x00) }; uint8_t status; result = writeMemory(ADDR_CMD_REG, command, 2); @@ -452,7 +484,7 @@ if (result == OneWireMaster::Success) { - sendrecvbit = (status & STATUS_SBR); + sendRecvBit = (status & STATUS_SBR); } return result; @@ -594,7 +626,7 @@ return OneWireMaster::Success; } -OneWireMaster::CmdResult DS2465::OWReset(void) +OneWireMaster::CmdResult DS2465::OWReset() { // 1-Wire reset (Case B) // S AD,0 [A] ADDR_CMD_REG [A] 1WRS [A] Sr AD,1 [A] [Status] A [Status] A\ P @@ -625,7 +657,7 @@ return result; } -OneWireMaster::CmdResult DS2465::reset(void) +OneWireMaster::CmdResult DS2465::reset() { // Device Reset // S AD,0 [A] ADDR_CMD_REG [A] 1WMR [A] Sr AD,1 [A] [SS] A\ P