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.

Committer:
j3
Date:
Mon Jun 20 19:39:21 2016 +0000
Revision:
91:e80108bc870a
Parent:
84:708b7be59fb2
Child:
98:c4ac93efc036
Created derived classes for DS248x series

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 1:91e52f8ab8bf 1 /******************************************************************//**
j3 1:91e52f8ab8bf 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 1:91e52f8ab8bf 3 *
j3 1:91e52f8ab8bf 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 1:91e52f8ab8bf 5 * copy of this software and associated documentation files (the "Software"),
j3 1:91e52f8ab8bf 6 * to deal in the Software without restriction, including without limitation
j3 1:91e52f8ab8bf 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 1:91e52f8ab8bf 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 1:91e52f8ab8bf 9 * Software is furnished to do so, subject to the following conditions:
j3 1:91e52f8ab8bf 10 *
j3 1:91e52f8ab8bf 11 * The above copyright notice and this permission notice shall be included
j3 1:91e52f8ab8bf 12 * in all copies or substantial portions of the Software.
j3 1:91e52f8ab8bf 13 *
j3 1:91e52f8ab8bf 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 1:91e52f8ab8bf 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 1:91e52f8ab8bf 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 1:91e52f8ab8bf 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 1:91e52f8ab8bf 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 1:91e52f8ab8bf 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 1:91e52f8ab8bf 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 1:91e52f8ab8bf 21 *
j3 1:91e52f8ab8bf 22 * Except as contained in this notice, the name of Maxim Integrated
j3 1:91e52f8ab8bf 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 1:91e52f8ab8bf 24 * Products, Inc. Branding Policy.
j3 1:91e52f8ab8bf 25 *
j3 1:91e52f8ab8bf 26 * The mere transfer of this software does not imply any licenses
j3 1:91e52f8ab8bf 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 1:91e52f8ab8bf 28 * trademarks, maskwork rights, or any other form of intellectual
j3 1:91e52f8ab8bf 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 1:91e52f8ab8bf 30 * ownership rights.
j3 1:91e52f8ab8bf 31 **********************************************************************/
j3 1:91e52f8ab8bf 32
IanBenzMaxim 73:2cecc1372acc 33 #ifndef OneWire_Masters_DS248x
IanBenzMaxim 73:2cecc1372acc 34 #define OneWire_Masters_DS248x
j3 1:91e52f8ab8bf 35
IanBenzMaxim 73:2cecc1372acc 36 #include "Masters/OneWireMaster.h"
IanBenzMaxim 73:2cecc1372acc 37 #include "PinNames.h"
j3 1:91e52f8ab8bf 38
IanBenzMaxim 73:2cecc1372acc 39 namespace mbed { class I2C; }
j3 1:91e52f8ab8bf 40
IanBenzMaxim 73:2cecc1372acc 41 namespace OneWire
j3 1:91e52f8ab8bf 42 {
IanBenzMaxim 76:84e6c4994e29 43 /// Interface to the DS2484, DS2482-100, DS2482-101, DS2482-800 1-Wire masters.
IanBenzMaxim 76:84e6c4994e29 44 class DS248x : public OneWireMaster
j3 5:ce108eeb878d 45 {
IanBenzMaxim 76:84e6c4994e29 46 public:
IanBenzMaxim 76:84e6c4994e29 47 /// Device register pointers.
IanBenzMaxim 76:84e6c4994e29 48 enum Register
IanBenzMaxim 76:84e6c4994e29 49 {
IanBenzMaxim 76:84e6c4994e29 50 ConfigReg = 0xC3,
IanBenzMaxim 76:84e6c4994e29 51 StatusReg = 0xF0,
IanBenzMaxim 76:84e6c4994e29 52 ReadDataReg = 0xE1,
IanBenzMaxim 76:84e6c4994e29 53 PortConfigReg = 0xB4,
IanBenzMaxim 76:84e6c4994e29 54 ChannelSelectReg = 0xD2 // DS2482-800 only
IanBenzMaxim 76:84e6c4994e29 55 };
IanBenzMaxim 76:84e6c4994e29 56
IanBenzMaxim 76:84e6c4994e29 57 /// Represents a DS248x configuration.
IanBenzMaxim 76:84e6c4994e29 58 class Config
IanBenzMaxim 73:2cecc1372acc 59 {
IanBenzMaxim 73:2cecc1372acc 60 public:
IanBenzMaxim 76:84e6c4994e29 61 /// @{
IanBenzMaxim 76:84e6c4994e29 62 /// 1-Wire Speed
IanBenzMaxim 76:84e6c4994e29 63 bool get1WS() const { return m_1WS; }
IanBenzMaxim 76:84e6c4994e29 64 void set1WS(bool new1WS) { m_1WS = new1WS; }
IanBenzMaxim 76:84e6c4994e29 65 /// @}
IanBenzMaxim 74:23be10c32fa3 66
IanBenzMaxim 76:84e6c4994e29 67 /// @{
IanBenzMaxim 76:84e6c4994e29 68 /// Strong Pullup
IanBenzMaxim 76:84e6c4994e29 69 bool getSPU() const { return m_SPU; }
IanBenzMaxim 76:84e6c4994e29 70 void setSPU(bool newSPU) { m_SPU = newSPU; }
IanBenzMaxim 76:84e6c4994e29 71 /// @}
IanBenzMaxim 69:f915c4c59a69 72
IanBenzMaxim 76:84e6c4994e29 73 /// @{
IanBenzMaxim 76:84e6c4994e29 74 /// 1-Wire Power Down
IanBenzMaxim 76:84e6c4994e29 75 bool getPDN() const { return m_PDN; }
IanBenzMaxim 76:84e6c4994e29 76 void setPDN(bool newPDN) { m_PDN = newPDN; }
IanBenzMaxim 76:84e6c4994e29 77 /// @}
IanBenzMaxim 74:23be10c32fa3 78
IanBenzMaxim 76:84e6c4994e29 79 /// @{
IanBenzMaxim 76:84e6c4994e29 80 /// Active Pullup
IanBenzMaxim 76:84e6c4994e29 81 bool getAPU() const { return m_APU; }
IanBenzMaxim 76:84e6c4994e29 82 void setAPU(bool newAPU) { m_APU = newAPU; }
IanBenzMaxim 76:84e6c4994e29 83 /// @}
IanBenzMaxim 74:23be10c32fa3 84
j3 91:e80108bc870a 85 /// Byte representation that is read from the DS248x.
IanBenzMaxim 76:84e6c4994e29 86 uint8_t readByte() const;
j3 91:e80108bc870a 87 /// Byte respresentation that is written to the DS248x.
IanBenzMaxim 76:84e6c4994e29 88 uint8_t writeByte() const;
IanBenzMaxim 74:23be10c32fa3 89
IanBenzMaxim 76:84e6c4994e29 90 /// Reset to the power-on default config.
IanBenzMaxim 76:84e6c4994e29 91 void reset();
IanBenzMaxim 76:84e6c4994e29 92 Config() { reset(); }
IanBenzMaxim 74:23be10c32fa3 93
IanBenzMaxim 73:2cecc1372acc 94 private:
IanBenzMaxim 76:84e6c4994e29 95 bool m_1WS, m_SPU, m_PDN, m_APU;
IanBenzMaxim 76:84e6c4994e29 96 };
j3 91:e80108bc870a 97
IanBenzMaxim 76:84e6c4994e29 98 /// Construct to use an existing I2C interface.
IanBenzMaxim 76:84e6c4994e29 99 /// @param i2c_bus Configured I2C communication interface for DS248x.
IanBenzMaxim 76:84e6c4994e29 100 /// @param adrs I2C bus address of the DS248x in mbed format.
IanBenzMaxim 76:84e6c4994e29 101 DS248x(mbed::I2C & i2c_bus, uint8_t adrs);
IanBenzMaxim 76:84e6c4994e29 102
IanBenzMaxim 76:84e6c4994e29 103 /// Destroys I2C interface if owner.
j3 91:e80108bc870a 104 virtual ~DS248x(){};
IanBenzMaxim 76:84e6c4994e29 105
IanBenzMaxim 76:84e6c4994e29 106 /// Performs a soft reset on the DS248x.
IanBenzMaxim 76:84e6c4994e29 107 /// @note This is note a 1-Wire Reset.
IanBenzMaxim 76:84e6c4994e29 108 OneWireMaster::CmdResult reset(void);
IanBenzMaxim 76:84e6c4994e29 109
IanBenzMaxim 76:84e6c4994e29 110 /// Write a new configuration to the DS248x.
IanBenzMaxim 76:84e6c4994e29 111 /// @param[in] config New configuration to write.
IanBenzMaxim 76:84e6c4994e29 112 /// @param verify Verify that the configuration was written successfully.
IanBenzMaxim 76:84e6c4994e29 113 OneWireMaster::CmdResult writeConfig(const Config & config, bool verify);
IanBenzMaxim 76:84e6c4994e29 114
IanBenzMaxim 76:84e6c4994e29 115 /// Read the current DS248x configuration.
IanBenzMaxim 76:84e6c4994e29 116 /// @returns The cached current configuration.
IanBenzMaxim 76:84e6c4994e29 117 Config currentConfig() const { return m_curConfig; }
IanBenzMaxim 76:84e6c4994e29 118
IanBenzMaxim 76:84e6c4994e29 119 /// Reads a register from the DS248x.
IanBenzMaxim 76:84e6c4994e29 120 /// @param reg Register to read from.
IanBenzMaxim 76:84e6c4994e29 121 /// @param[out] buf Buffer to hold read data.
IanBenzMaxim 76:84e6c4994e29 122 /// @param skipSetPointer Assume that the read pointer is already set to the correct register.
IanBenzMaxim 76:84e6c4994e29 123 OneWireMaster::CmdResult readRegister(Register reg, uint8_t & buf, bool skipSetPointer = false) const;
IanBenzMaxim 76:84e6c4994e29 124
IanBenzMaxim 76:84e6c4994e29 125 /// @details Performs a device reset followed by writing the configuration byte to default values:
IanBenzMaxim 76:84e6c4994e29 126 /// 1-Wire Speed Standard
IanBenzMaxim 76:84e6c4994e29 127 /// Strong Pullup Off
IanBenzMaxim 76:84e6c4994e29 128 /// 1-Wire Powerdown Off
IanBenzMaxim 76:84e6c4994e29 129 /// Active Pullup On
IanBenzMaxim 76:84e6c4994e29 130 virtual OneWireMaster::CmdResult OWInitMaster();
j3 91:e80108bc870a 131
IanBenzMaxim 76:84e6c4994e29 132 /// @note Perform a 1-Wire triplet using the DS248x command.
IanBenzMaxim 76:84e6c4994e29 133 virtual OneWireMaster::CmdResult OWTriplet(SearchDirection & searchDirection, uint8_t & sbr, uint8_t & tsb);
j3 91:e80108bc870a 134
IanBenzMaxim 76:84e6c4994e29 135 virtual OneWireMaster::CmdResult OWReset();
IanBenzMaxim 76:84e6c4994e29 136 virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel);
IanBenzMaxim 76:84e6c4994e29 137 virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel);
IanBenzMaxim 76:84e6c4994e29 138 virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel);
IanBenzMaxim 76:84e6c4994e29 139 virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed newSpeed);
IanBenzMaxim 76:84e6c4994e29 140 virtual OneWireMaster::CmdResult OWSetLevel(OWLevel newLevel);
IanBenzMaxim 73:2cecc1372acc 141
j3 91:e80108bc870a 142 protected:
j3 91:e80108bc870a 143
IanBenzMaxim 76:84e6c4994e29 144 enum Command
IanBenzMaxim 76:84e6c4994e29 145 {
IanBenzMaxim 76:84e6c4994e29 146 DeviceResetCmd = 0xF0,
IanBenzMaxim 76:84e6c4994e29 147 WriteDeviceConfigCmd = 0xD2,
IanBenzMaxim 76:84e6c4994e29 148 AdjustOwPortCmd = 0xC3, // DS2484 only
IanBenzMaxim 76:84e6c4994e29 149 ChannelSelectCmd = 0xC3, // DS2482-800 only
IanBenzMaxim 76:84e6c4994e29 150 SetReadPointerCmd = 0xE1,
IanBenzMaxim 76:84e6c4994e29 151 OwResetCmd = 0xB4,
IanBenzMaxim 76:84e6c4994e29 152 OwWriteByteCmd = 0xA5,
IanBenzMaxim 76:84e6c4994e29 153 OwReadByteCmd = 0x96,
IanBenzMaxim 76:84e6c4994e29 154 OwSingleBitCmd = 0x87,
IanBenzMaxim 76:84e6c4994e29 155 OwTripletCmd = 0x78
IanBenzMaxim 76:84e6c4994e29 156 };
j3 91:e80108bc870a 157
j3 91:e80108bc870a 158 mbed::I2C & m_i2c_bus;
IanBenzMaxim 76:84e6c4994e29 159 uint8_t m_adrs;
IanBenzMaxim 76:84e6c4994e29 160 Config m_curConfig;
IanBenzMaxim 76:84e6c4994e29 161
j3 91:e80108bc870a 162 /// Polls the DS248x status waiting for the 1-Wire Busy bit (1WB) to be cleared.
IanBenzMaxim 76:84e6c4994e29 163 /// @param[out] pStatus Optionally retrive the status byte when 1WB cleared.
IanBenzMaxim 76:84e6c4994e29 164 /// @returns Success or TimeoutError if poll limit reached.
IanBenzMaxim 76:84e6c4994e29 165 OneWireMaster::CmdResult pollBusy(uint8_t * pStatus = NULL);
IanBenzMaxim 74:23be10c32fa3 166
IanBenzMaxim 76:84e6c4994e29 167 /// Ensure that the desired 1-Wire level is set in the configuration.
IanBenzMaxim 76:84e6c4994e29 168 /// @param level Desired 1-Wire level.
IanBenzMaxim 76:84e6c4994e29 169 OneWireMaster::CmdResult configureLevel(OWLevel level);
IanBenzMaxim 76:84e6c4994e29 170
IanBenzMaxim 76:84e6c4994e29 171 /// @note Allow marking const since not public.
IanBenzMaxim 76:84e6c4994e29 172 OneWireMaster::CmdResult sendCommand(Command cmd) const;
IanBenzMaxim 76:84e6c4994e29 173
IanBenzMaxim 76:84e6c4994e29 174 /// @note Allow marking const since not public.
IanBenzMaxim 76:84e6c4994e29 175 OneWireMaster::CmdResult sendCommand(Command cmd, uint8_t param) const;
IanBenzMaxim 76:84e6c4994e29 176 };
IanBenzMaxim 73:2cecc1372acc 177 }
j3 1:91e52f8ab8bf 178
IanBenzMaxim 75:8b627804927c 179 #endif