Extended MaximInterface
Dependents: mbed_DS28EC20_GPIO
Devices/DS9481P_300.hpp@6:a8c83a2e6fa4, 2019-01-23 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Wed Jan 23 13:11:04 2019 -0600
- Revision:
- 6:a8c83a2e6fa4
- Parent:
- 3:f818ea5172ed
Updated to version 1.6 and removed platform files that are incompatible with mbed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IanBenzMaxim | 3:f818ea5172ed | 1 | /******************************************************************************* |
IanBenzMaxim | 3:f818ea5172ed | 2 | * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. |
IanBenzMaxim | 3:f818ea5172ed | 3 | * |
IanBenzMaxim | 3:f818ea5172ed | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
IanBenzMaxim | 3:f818ea5172ed | 5 | * copy of this software and associated documentation files (the "Software"), |
IanBenzMaxim | 3:f818ea5172ed | 6 | * to deal in the Software without restriction, including without limitation |
IanBenzMaxim | 3:f818ea5172ed | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
IanBenzMaxim | 3:f818ea5172ed | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
IanBenzMaxim | 3:f818ea5172ed | 9 | * Software is furnished to do so, subject to the following conditions: |
IanBenzMaxim | 3:f818ea5172ed | 10 | * |
IanBenzMaxim | 3:f818ea5172ed | 11 | * The above copyright notice and this permission notice shall be included |
IanBenzMaxim | 3:f818ea5172ed | 12 | * in all copies or substantial portions of the Software. |
IanBenzMaxim | 3:f818ea5172ed | 13 | * |
IanBenzMaxim | 3:f818ea5172ed | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
IanBenzMaxim | 3:f818ea5172ed | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
IanBenzMaxim | 3:f818ea5172ed | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
IanBenzMaxim | 3:f818ea5172ed | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
IanBenzMaxim | 3:f818ea5172ed | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
IanBenzMaxim | 3:f818ea5172ed | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
IanBenzMaxim | 3:f818ea5172ed | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
IanBenzMaxim | 3:f818ea5172ed | 21 | * |
IanBenzMaxim | 3:f818ea5172ed | 22 | * Except as contained in this notice, the name of Maxim Integrated |
IanBenzMaxim | 3:f818ea5172ed | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
IanBenzMaxim | 3:f818ea5172ed | 24 | * Products, Inc. Branding Policy. |
IanBenzMaxim | 3:f818ea5172ed | 25 | * |
IanBenzMaxim | 3:f818ea5172ed | 26 | * The mere transfer of this software does not imply any licenses |
IanBenzMaxim | 3:f818ea5172ed | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
IanBenzMaxim | 3:f818ea5172ed | 28 | * trademarks, maskwork rights, or any other form of intellectual |
IanBenzMaxim | 3:f818ea5172ed | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
IanBenzMaxim | 3:f818ea5172ed | 30 | * ownership rights. |
IanBenzMaxim | 3:f818ea5172ed | 31 | *******************************************************************************/ |
IanBenzMaxim | 3:f818ea5172ed | 32 | |
IanBenzMaxim | 3:f818ea5172ed | 33 | #ifndef MaximInterface_DS9481P_300 |
IanBenzMaxim | 3:f818ea5172ed | 34 | #define MaximInterface_DS9481P_300 |
IanBenzMaxim | 3:f818ea5172ed | 35 | |
IanBenzMaxim | 3:f818ea5172ed | 36 | #include <MaximInterface/Devices/DS2480B.hpp> |
IanBenzMaxim | 3:f818ea5172ed | 37 | #include <MaximInterface/Devices/DS9400.hpp> |
IanBenzMaxim | 3:f818ea5172ed | 38 | #include <MaximInterface/Links/I2CMasterDecorator.hpp> |
IanBenzMaxim | 3:f818ea5172ed | 39 | #include <MaximInterface/Links/OneWireMasterDecorator.hpp> |
IanBenzMaxim | 3:f818ea5172ed | 40 | #include <MaximInterface/Links/SerialPort.hpp> |
IanBenzMaxim | 3:f818ea5172ed | 41 | #include <MaximInterface/Links/Sleep.hpp> |
IanBenzMaxim | 3:f818ea5172ed | 42 | #include <MaximInterface/Utilities/Export.h> |
IanBenzMaxim | 3:f818ea5172ed | 43 | |
IanBenzMaxim | 3:f818ea5172ed | 44 | namespace MaximInterface { |
IanBenzMaxim | 3:f818ea5172ed | 45 | |
IanBenzMaxim | 3:f818ea5172ed | 46 | /// DS9481P-300 USB to 1-Wire and I2C adapter. |
IanBenzMaxim | 3:f818ea5172ed | 47 | class DS9481P_300 { |
IanBenzMaxim | 3:f818ea5172ed | 48 | public: |
IanBenzMaxim | 6:a8c83a2e6fa4 | 49 | MaximInterface_EXPORT DS9481P_300(Sleep & sleep, SerialPort & serialPort); |
IanBenzMaxim | 3:f818ea5172ed | 50 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 51 | void setSleep(Sleep & sleep) { ds2480b.setSleep(sleep); } |
IanBenzMaxim | 6:a8c83a2e6fa4 | 52 | |
IanBenzMaxim | 3:f818ea5172ed | 53 | void setSerialPort(SerialPort & serialPort) { |
IanBenzMaxim | 3:f818ea5172ed | 54 | this->serialPort = &serialPort; |
IanBenzMaxim | 3:f818ea5172ed | 55 | ds2480b.setUart(serialPort); |
IanBenzMaxim | 3:f818ea5172ed | 56 | ds9400.setUart(serialPort); |
IanBenzMaxim | 3:f818ea5172ed | 57 | } |
IanBenzMaxim | 3:f818ea5172ed | 58 | |
IanBenzMaxim | 3:f818ea5172ed | 59 | MaximInterface_EXPORT error_code connect(const std::string & portName); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 60 | |
IanBenzMaxim | 3:f818ea5172ed | 61 | MaximInterface_EXPORT error_code disconnect(); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 62 | |
IanBenzMaxim | 3:f818ea5172ed | 63 | MaximInterface_EXPORT bool connected() const; |
IanBenzMaxim | 6:a8c83a2e6fa4 | 64 | |
IanBenzMaxim | 3:f818ea5172ed | 65 | MaximInterface_EXPORT std::string portName() const; |
IanBenzMaxim | 3:f818ea5172ed | 66 | |
IanBenzMaxim | 3:f818ea5172ed | 67 | /// Access the 1-Wire master when connected to an adapter. |
IanBenzMaxim | 3:f818ea5172ed | 68 | OneWireMaster & oneWireMaster() { return oneWireMaster_; } |
IanBenzMaxim | 6:a8c83a2e6fa4 | 69 | |
IanBenzMaxim | 3:f818ea5172ed | 70 | /// Access the I2C master when connected to an adapter. |
IanBenzMaxim | 3:f818ea5172ed | 71 | I2CMaster & i2cMaster() { return i2cMaster_; } |
IanBenzMaxim | 3:f818ea5172ed | 72 | |
IanBenzMaxim | 3:f818ea5172ed | 73 | private: |
IanBenzMaxim | 3:f818ea5172ed | 74 | class OneWireMasterImpl : public OneWireMasterDecorator { |
IanBenzMaxim | 3:f818ea5172ed | 75 | public: |
IanBenzMaxim | 3:f818ea5172ed | 76 | explicit OneWireMasterImpl(DS9481P_300 & parent) |
IanBenzMaxim | 3:f818ea5172ed | 77 | : OneWireMasterDecorator(parent.ds2480b), parent(&parent) {} |
IanBenzMaxim | 3:f818ea5172ed | 78 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 79 | MaximInterface_EXPORT virtual error_code reset(); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 80 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 81 | MaximInterface_EXPORT virtual error_code |
IanBenzMaxim | 6:a8c83a2e6fa4 | 82 | touchBitSetLevel(bool & sendRecvBit, Level afterLevel); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 83 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 84 | MaximInterface_EXPORT virtual error_code |
IanBenzMaxim | 6:a8c83a2e6fa4 | 85 | writeByteSetLevel(uint_least8_t sendByte, Level afterLevel); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 86 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 87 | MaximInterface_EXPORT virtual error_code |
IanBenzMaxim | 6:a8c83a2e6fa4 | 88 | readByteSetLevel(uint_least8_t & recvByte, Level afterLevel); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 89 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 90 | MaximInterface_EXPORT virtual error_code |
IanBenzMaxim | 6:a8c83a2e6fa4 | 91 | writeBlock(span<const uint_least8_t> sendBuf); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 92 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 93 | MaximInterface_EXPORT virtual error_code |
IanBenzMaxim | 6:a8c83a2e6fa4 | 94 | readBlock(span<uint_least8_t> recvBuf); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 95 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 96 | MaximInterface_EXPORT virtual error_code setSpeed(Speed newSpeed); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 97 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 98 | MaximInterface_EXPORT virtual error_code setLevel(Level newLevel); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 99 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 100 | MaximInterface_EXPORT virtual error_code triplet(TripletData & data); |
IanBenzMaxim | 3:f818ea5172ed | 101 | |
IanBenzMaxim | 3:f818ea5172ed | 102 | private: |
IanBenzMaxim | 3:f818ea5172ed | 103 | DS9481P_300 * parent; |
IanBenzMaxim | 3:f818ea5172ed | 104 | }; |
IanBenzMaxim | 3:f818ea5172ed | 105 | |
IanBenzMaxim | 3:f818ea5172ed | 106 | class I2CMasterImpl : public I2CMasterDecorator { |
IanBenzMaxim | 3:f818ea5172ed | 107 | public: |
IanBenzMaxim | 3:f818ea5172ed | 108 | explicit I2CMasterImpl(DS9481P_300 & parent) |
IanBenzMaxim | 3:f818ea5172ed | 109 | : I2CMasterDecorator(parent.ds9400), parent(&parent) {} |
IanBenzMaxim | 3:f818ea5172ed | 110 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 111 | MaximInterface_EXPORT virtual error_code start(uint_least8_t address); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 112 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 113 | MaximInterface_EXPORT virtual error_code stop(); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 114 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 115 | MaximInterface_EXPORT virtual error_code writeByte(uint_least8_t data); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 116 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 117 | MaximInterface_EXPORT virtual error_code |
IanBenzMaxim | 6:a8c83a2e6fa4 | 118 | writeBlock(span<const uint_least8_t> data); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 119 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 120 | MaximInterface_EXPORT virtual error_code readByte(AckStatus status, |
IanBenzMaxim | 6:a8c83a2e6fa4 | 121 | uint_least8_t & data); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 122 | MaximInterface_EXPORT virtual error_code |
IanBenzMaxim | 6:a8c83a2e6fa4 | 123 | readBlock(AckStatus status, span<uint_least8_t> data); |
IanBenzMaxim | 3:f818ea5172ed | 124 | |
IanBenzMaxim | 3:f818ea5172ed | 125 | protected: |
IanBenzMaxim | 6:a8c83a2e6fa4 | 126 | MaximInterface_EXPORT virtual error_code |
IanBenzMaxim | 6:a8c83a2e6fa4 | 127 | writePacketImpl(uint_least8_t address, span<const uint_least8_t> data, |
IanBenzMaxim | 6:a8c83a2e6fa4 | 128 | bool sendStop); |
IanBenzMaxim | 6:a8c83a2e6fa4 | 129 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 130 | MaximInterface_EXPORT virtual error_code |
IanBenzMaxim | 6:a8c83a2e6fa4 | 131 | readPacketImpl(uint_least8_t address, span<uint_least8_t> data, |
IanBenzMaxim | 6:a8c83a2e6fa4 | 132 | bool sendStop); |
IanBenzMaxim | 3:f818ea5172ed | 133 | |
IanBenzMaxim | 3:f818ea5172ed | 134 | private: |
IanBenzMaxim | 3:f818ea5172ed | 135 | DS9481P_300 * parent; |
IanBenzMaxim | 3:f818ea5172ed | 136 | }; |
IanBenzMaxim | 3:f818ea5172ed | 137 | |
IanBenzMaxim | 3:f818ea5172ed | 138 | class DS2480BWithEscape : public DS2480B { |
IanBenzMaxim | 3:f818ea5172ed | 139 | public: |
IanBenzMaxim | 6:a8c83a2e6fa4 | 140 | DS2480BWithEscape(Sleep & sleep, Uart & uart) : DS2480B(sleep, uart) {} |
IanBenzMaxim | 3:f818ea5172ed | 141 | |
IanBenzMaxim | 3:f818ea5172ed | 142 | error_code escape(); |
IanBenzMaxim | 3:f818ea5172ed | 143 | }; |
IanBenzMaxim | 3:f818ea5172ed | 144 | |
IanBenzMaxim | 3:f818ea5172ed | 145 | class DS9400WithEscape : public DS9400 { |
IanBenzMaxim | 3:f818ea5172ed | 146 | public: |
IanBenzMaxim | 3:f818ea5172ed | 147 | explicit DS9400WithEscape(Uart & uart) : DS9400(uart) {} |
IanBenzMaxim | 3:f818ea5172ed | 148 | |
IanBenzMaxim | 3:f818ea5172ed | 149 | error_code escape(); |
IanBenzMaxim | 3:f818ea5172ed | 150 | }; |
IanBenzMaxim | 3:f818ea5172ed | 151 | |
IanBenzMaxim | 3:f818ea5172ed | 152 | enum Bus { OneWire, I2C }; |
IanBenzMaxim | 3:f818ea5172ed | 153 | |
IanBenzMaxim | 3:f818ea5172ed | 154 | SerialPort * serialPort; |
IanBenzMaxim | 3:f818ea5172ed | 155 | Bus currentBus; |
IanBenzMaxim | 3:f818ea5172ed | 156 | DS2480BWithEscape ds2480b; |
IanBenzMaxim | 3:f818ea5172ed | 157 | OneWireMasterImpl oneWireMaster_; |
IanBenzMaxim | 3:f818ea5172ed | 158 | DS9400WithEscape ds9400; |
IanBenzMaxim | 3:f818ea5172ed | 159 | I2CMasterImpl i2cMaster_; |
IanBenzMaxim | 3:f818ea5172ed | 160 | |
IanBenzMaxim | 3:f818ea5172ed | 161 | error_code selectOneWire(); |
IanBenzMaxim | 3:f818ea5172ed | 162 | error_code selectBus(Bus newBus); |
IanBenzMaxim | 3:f818ea5172ed | 163 | |
IanBenzMaxim | 3:f818ea5172ed | 164 | friend class OneWireMasterImpl; |
IanBenzMaxim | 3:f818ea5172ed | 165 | friend class I2CMasterImpl; |
IanBenzMaxim | 3:f818ea5172ed | 166 | }; |
IanBenzMaxim | 3:f818ea5172ed | 167 | |
IanBenzMaxim | 3:f818ea5172ed | 168 | } // namespace MaximInterface |
IanBenzMaxim | 3:f818ea5172ed | 169 | |
IanBenzMaxim | 6:a8c83a2e6fa4 | 170 | #endif |