1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.
Dependents: MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more
Superseded by MaximInterface.
Diff: OneWire_Masters/OneWireMaster.h
- Revision:
- 48:6f9208ae280e
- Parent:
- 47:307dc45952db
- Child:
- 49:36954b62f503
diff -r 307dc45952db -r 6f9208ae280e OneWire_Masters/OneWireMaster.h --- a/OneWire_Masters/OneWireMaster.h Thu Apr 07 10:26:26 2016 -0500 +++ b/OneWire_Masters/OneWireMaster.h Thu Apr 07 11:26:20 2016 -0500 @@ -39,28 +39,33 @@ #include "RomId.hpp" +/// Base class for all 1-Wire Masters. class OneWireMaster { public: + /// Speed of the 1-Wire bus enum OWSpeed { SPEED_STANDARD = 0x00, SPEED_OVERDRIVE = 0x01 }; + /// Level of the 1-Wire bus enum OWLevel { LEVEL_NORMAL = 0x00, LEVEL_STRONG = 0x02 }; + /// Search direction for the Triplet enum SearchDirection { DIRECTION_WRITE_ZERO = 0, DIRECTION_WRITE_ONE = 1 }; + /// Result of all 1-Wire commands enum CmdResult { Success, @@ -70,6 +75,7 @@ OperationFailure }; + /// State used by all ROM ID search functions. struct SearchState { RomId romId; @@ -77,6 +83,7 @@ std::uint8_t last_family_discrepancy; bool last_device_flag; + /// Reset to the search state to start at the beginning. void reset() { last_discrepancy = 0; @@ -88,10 +95,21 @@ SearchState() { reset(); } }; + /// Perform a CRC16 calculation. + /// @param CRC16 Beginning state of the CRC generator. + /// @param data Data to pass though the CRC generator. + /// @returns The calculated CRC16. static std::uint16_t calculateCRC16(std::uint16_t CRC16, std::uint16_t data); + /// Perform a CRC calculation with variable length data. + /// @param[in] data Data array to pass through the CRC generator. + /// @param data_offset Offset of the data array to begin processing. + /// @param data_len Length of the data array to process. + /// @param crc Beginning state of the CRC generator. + /// @returns The calculated CRC16. static std::uint16_t calculateCRC16(const std::uint8_t * data, std::size_t data_offset, std::size_t data_len, std::uint16_t crc = 0); + /// Allow freeing through a base class pointer. virtual ~OneWireMaster() { } @@ -259,10 +277,13 @@ **************************************************************/ virtual CmdResult OWTriplet(SearchDirection & search_direction, std::uint8_t & sbr, std::uint8_t & tsb); + /// OWWriteBit() + CmdResult OWWriteBit(std::uint8_t sendbit, OWLevel after_level) { return OWTouchBit(sendbit, after_level); } - CmdResult OWWriteBit(std::uint8_t sendbit, OWLevel after_level) { return OWTouchBit(sendbit, after_level); } + /// OWReadBit() CmdResult OWReadBit(std::uint8_t & recvbit, OWLevel after_level) { recvbit = 0x01; return OWTouchBit(recvbit, after_level); } + // Alternate forms of read and write functions CmdResult OWWriteBit(std::uint8_t sendbit) { return OWWriteBit(sendbit, LEVEL_NORMAL); } CmdResult OWReadBit(std::uint8_t & recvbit) { return OWReadBit(recvbit, LEVEL_NORMAL); } CmdResult OWWriteBitPower(std::uint8_t sendbit) { return OWWriteBit(sendbit, LEVEL_STRONG); } @@ -272,7 +293,6 @@ CmdResult OWWriteBytePower(std::uint8_t sendbyte) { return OWWriteByte(sendbyte, LEVEL_STRONG); } CmdResult OWReadBytePower(std::uint8_t & recvbyte) { return OWReadByte(recvbyte, LEVEL_STRONG); } - /**********************************************************//** * @brief OWFirst() * @@ -285,7 +305,6 @@ **************************************************************/ CmdResult OWFirst(SearchState & searchState); - /**********************************************************//** * @brief OWNext() * @@ -298,7 +317,6 @@ **************************************************************/ CmdResult OWNext(SearchState & searchState); - /**********************************************************//** * @brief OWVerify() * @@ -312,7 +330,6 @@ **************************************************************/ CmdResult OWVerify(const RomId & romId); - /**********************************************************//** * @brief OWTargetSetup() * @@ -327,7 +344,6 @@ **************************************************************/ void OWTargetSetup(SearchState & searchState); - /**********************************************************//** * @brief OWFamilySkipSetup() * @@ -341,7 +357,6 @@ **************************************************************/ void OWFamilySkipSetup(SearchState & searchState); - /**********************************************************//** * @brief OWReadROM() * @@ -356,7 +371,6 @@ **************************************************************/ CmdResult OWReadROM(RomId & romId); - /**********************************************************//** * @brief OWSkipROM() * @@ -369,7 +383,6 @@ **************************************************************/ CmdResult OWSkipROM(void); - /**********************************************************//** * @brief OWMatchROM() * @@ -383,7 +396,6 @@ **************************************************************/ CmdResult OWMatchROM(const RomId & romId); - /**********************************************************//** * @brief OWOverdriveSkipROM() * @@ -397,7 +409,6 @@ **************************************************************/ CmdResult OWOverdriveSkipROM(void); - /**********************************************************//** * @brief OWOverdriveMatchROM() * @@ -411,7 +422,6 @@ **************************************************************/ CmdResult OWOverdriveMatchROM(const RomId & romId); - /**********************************************************//** * @brief OWResume() * @@ -428,7 +438,6 @@ **************************************************************/ CmdResult OWResume(void); - /**********************************************************//** * @brief OWSearch() * @@ -450,8 +459,4 @@ CmdResult OWSearch(SearchState & searchState); }; - - - - #endif /*ONEWIREMASTER_H*/