Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed_DS28EC20_GPIO
DS9481P_300.hpp
00001 /******************************************************************************* 00002 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 *******************************************************************************/ 00032 00033 #ifndef MaximInterface_DS9481P_300 00034 #define MaximInterface_DS9481P_300 00035 00036 #include <MaximInterface/Devices/DS2480B.hpp> 00037 #include <MaximInterface/Devices/DS9400.hpp> 00038 #include <MaximInterface/Links/I2CMasterDecorator.hpp> 00039 #include <MaximInterface/Links/OneWireMasterDecorator.hpp> 00040 #include <MaximInterface/Links/SerialPort.hpp> 00041 #include <MaximInterface/Links/Sleep.hpp> 00042 #include <MaximInterface/Utilities/Export.h> 00043 00044 namespace MaximInterface { 00045 00046 /// DS9481P-300 USB to 1-Wire and I2C adapter. 00047 class DS9481P_300 { 00048 public: 00049 MaximInterface_EXPORT DS9481P_300(Sleep & sleep, SerialPort & serialPort); 00050 00051 void setSleep(Sleep & sleep) { ds2480b.setSleep(sleep); } 00052 00053 void setSerialPort(SerialPort & serialPort) { 00054 this->serialPort = &serialPort; 00055 ds2480b.setUart(serialPort); 00056 ds9400.setUart(serialPort); 00057 } 00058 00059 MaximInterface_EXPORT error_code connect(const std::string & portName); 00060 00061 MaximInterface_EXPORT error_code disconnect(); 00062 00063 MaximInterface_EXPORT bool connected() const; 00064 00065 MaximInterface_EXPORT std::string portName() const; 00066 00067 /// Access the 1-Wire master when connected to an adapter. 00068 OneWireMaster & oneWireMaster() { return oneWireMaster_; } 00069 00070 /// Access the I2C master when connected to an adapter. 00071 I2CMaster & i2cMaster() { return i2cMaster_; } 00072 00073 private: 00074 class OneWireMasterImpl : public OneWireMasterDecorator { 00075 public: 00076 explicit OneWireMasterImpl(DS9481P_300 & parent) 00077 : OneWireMasterDecorator(parent.ds2480b), parent(&parent) {} 00078 00079 MaximInterface_EXPORT virtual error_code reset(); 00080 00081 MaximInterface_EXPORT virtual error_code 00082 touchBitSetLevel(bool & sendRecvBit, Level afterLevel); 00083 00084 MaximInterface_EXPORT virtual error_code 00085 writeByteSetLevel(uint_least8_t sendByte, Level afterLevel); 00086 00087 MaximInterface_EXPORT virtual error_code 00088 readByteSetLevel(uint_least8_t & recvByte, Level afterLevel); 00089 00090 MaximInterface_EXPORT virtual error_code 00091 writeBlock(span<const uint_least8_t> sendBuf); 00092 00093 MaximInterface_EXPORT virtual error_code 00094 readBlock(span<uint_least8_t> recvBuf); 00095 00096 MaximInterface_EXPORT virtual error_code setSpeed(Speed newSpeed); 00097 00098 MaximInterface_EXPORT virtual error_code setLevel(Level newLevel); 00099 00100 MaximInterface_EXPORT virtual error_code triplet(TripletData & data); 00101 00102 private: 00103 DS9481P_300 * parent; 00104 }; 00105 00106 class I2CMasterImpl : public I2CMasterDecorator { 00107 public: 00108 explicit I2CMasterImpl(DS9481P_300 & parent) 00109 : I2CMasterDecorator(parent.ds9400), parent(&parent) {} 00110 00111 MaximInterface_EXPORT virtual error_code start(uint_least8_t address); 00112 00113 MaximInterface_EXPORT virtual error_code stop(); 00114 00115 MaximInterface_EXPORT virtual error_code writeByte(uint_least8_t data); 00116 00117 MaximInterface_EXPORT virtual error_code 00118 writeBlock(span<const uint_least8_t> data); 00119 00120 MaximInterface_EXPORT virtual error_code readByte(AckStatus status, 00121 uint_least8_t & data); 00122 MaximInterface_EXPORT virtual error_code 00123 readBlock(AckStatus status, span<uint_least8_t> data); 00124 00125 protected: 00126 MaximInterface_EXPORT virtual error_code 00127 writePacketImpl(uint_least8_t address, span<const uint_least8_t> data, 00128 bool sendStop); 00129 00130 MaximInterface_EXPORT virtual error_code 00131 readPacketImpl(uint_least8_t address, span<uint_least8_t> data, 00132 bool sendStop); 00133 00134 private: 00135 DS9481P_300 * parent; 00136 }; 00137 00138 class DS2480BWithEscape : public DS2480B { 00139 public: 00140 DS2480BWithEscape(Sleep & sleep, Uart & uart) : DS2480B(sleep, uart) {} 00141 00142 error_code escape(); 00143 }; 00144 00145 class DS9400WithEscape : public DS9400 { 00146 public: 00147 explicit DS9400WithEscape(Uart & uart) : DS9400(uart) {} 00148 00149 error_code escape(); 00150 }; 00151 00152 enum Bus { OneWire, I2C }; 00153 00154 SerialPort * serialPort; 00155 Bus currentBus; 00156 DS2480BWithEscape ds2480b; 00157 OneWireMasterImpl oneWireMaster_; 00158 DS9400WithEscape ds9400; 00159 I2CMasterImpl i2cMaster_; 00160 00161 error_code selectOneWire(); 00162 error_code selectBus(Bus newBus); 00163 00164 friend class OneWireMasterImpl; 00165 friend class I2CMasterImpl; 00166 }; 00167 00168 } // namespace MaximInterface 00169 00170 #endif
Generated on Tue Jul 12 2022 23:29:45 by
1.7.2