Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

Committer:
IanBenzMaxim
Date:
Mon Nov 06 14:39:18 2017 -0600
Revision:
0:f77ad7f72d04
Initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 0:f77ad7f72d04 1 /*******************************************************************************
IanBenzMaxim 0:f77ad7f72d04 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 0:f77ad7f72d04 3 *
IanBenzMaxim 0:f77ad7f72d04 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 0:f77ad7f72d04 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 0:f77ad7f72d04 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 0:f77ad7f72d04 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 0:f77ad7f72d04 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 0:f77ad7f72d04 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 0:f77ad7f72d04 10 *
IanBenzMaxim 0:f77ad7f72d04 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 0:f77ad7f72d04 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 0:f77ad7f72d04 13 *
IanBenzMaxim 0:f77ad7f72d04 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 0:f77ad7f72d04 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 0:f77ad7f72d04 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 0:f77ad7f72d04 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 0:f77ad7f72d04 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 0:f77ad7f72d04 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 0:f77ad7f72d04 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 0:f77ad7f72d04 21 *
IanBenzMaxim 0:f77ad7f72d04 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 24 * Products, Inc. Branding Policy.
IanBenzMaxim 0:f77ad7f72d04 25 *
IanBenzMaxim 0:f77ad7f72d04 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 0:f77ad7f72d04 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 0:f77ad7f72d04 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 0:f77ad7f72d04 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 0:f77ad7f72d04 30 * ownership rights.
IanBenzMaxim 0:f77ad7f72d04 31 *******************************************************************************/
IanBenzMaxim 0:f77ad7f72d04 32
IanBenzMaxim 0:f77ad7f72d04 33 #pragma once
IanBenzMaxim 0:f77ad7f72d04 34
IanBenzMaxim 0:f77ad7f72d04 35 #include <memory>
IanBenzMaxim 0:f77ad7f72d04 36 #include <string>
IanBenzMaxim 0:f77ad7f72d04 37 #include <MaximInterface/Links/OneWireMaster.hpp>
IanBenzMaxim 0:f77ad7f72d04 38 #include <MaximInterface/Utilities/Export.h>
IanBenzMaxim 0:f77ad7f72d04 39 #include "MoveOnly.hpp"
IanBenzMaxim 0:f77ad7f72d04 40
IanBenzMaxim 0:f77ad7f72d04 41 namespace MaximInterface {
IanBenzMaxim 0:f77ad7f72d04 42
IanBenzMaxim 0:f77ad7f72d04 43 /// 1-Wire interface using the OneWireLinkLayer DLL from the Compact.NET API.
IanBenzMaxim 0:f77ad7f72d04 44 class OneWireLinkLayerMaster : public OneWireMaster, private MoveOnly {
IanBenzMaxim 0:f77ad7f72d04 45 public:
IanBenzMaxim 0:f77ad7f72d04 46 enum ErrorValue {
IanBenzMaxim 0:f77ad7f72d04 47 CommunicationError = 1,
IanBenzMaxim 0:f77ad7f72d04 48 OpenPortError,
IanBenzMaxim 0:f77ad7f72d04 49 PowerDeliveryError,
IanBenzMaxim 0:f77ad7f72d04 50 AlreadyConnectedError
IanBenzMaxim 0:f77ad7f72d04 51 };
IanBenzMaxim 0:f77ad7f72d04 52
IanBenzMaxim 0:f77ad7f72d04 53 /// @param adapterName Adapter type name recogized by OneWireLinkLayer.
IanBenzMaxim 0:f77ad7f72d04 54 MaximInterface_EXPORT OneWireLinkLayerMaster(const std::string & adapterName);
IanBenzMaxim 0:f77ad7f72d04 55 MaximInterface_EXPORT ~OneWireLinkLayerMaster();
IanBenzMaxim 0:f77ad7f72d04 56
IanBenzMaxim 0:f77ad7f72d04 57 MaximInterface_EXPORT
IanBenzMaxim 0:f77ad7f72d04 58 OneWireLinkLayerMaster(OneWireLinkLayerMaster &&) noexcept;
IanBenzMaxim 0:f77ad7f72d04 59 MaximInterface_EXPORT OneWireLinkLayerMaster &
IanBenzMaxim 0:f77ad7f72d04 60 operator=(OneWireLinkLayerMaster &&) noexcept;
IanBenzMaxim 0:f77ad7f72d04 61
IanBenzMaxim 0:f77ad7f72d04 62 /// Connect to an adapter on the specified COM port.
IanBenzMaxim 0:f77ad7f72d04 63 MaximInterface_EXPORT error_code connect(const std::string & portName);
IanBenzMaxim 0:f77ad7f72d04 64
IanBenzMaxim 0:f77ad7f72d04 65 /// Disconnect from the adapter on the current COM port.
IanBenzMaxim 0:f77ad7f72d04 66 MaximInterface_EXPORT void disconnect();
IanBenzMaxim 0:f77ad7f72d04 67
IanBenzMaxim 0:f77ad7f72d04 68 /// Check if currently connected to an adapter.
IanBenzMaxim 0:f77ad7f72d04 69 /// @returns True if connected.
IanBenzMaxim 0:f77ad7f72d04 70 MaximInterface_EXPORT bool connected() const;
IanBenzMaxim 0:f77ad7f72d04 71
IanBenzMaxim 0:f77ad7f72d04 72 /// Get the adapter type name.
IanBenzMaxim 0:f77ad7f72d04 73 MaximInterface_EXPORT std::string adapterName() const;
IanBenzMaxim 0:f77ad7f72d04 74
IanBenzMaxim 0:f77ad7f72d04 75 /// Get the currently connected COM port name.
IanBenzMaxim 0:f77ad7f72d04 76 MaximInterface_EXPORT std::string portName() const;
IanBenzMaxim 0:f77ad7f72d04 77
IanBenzMaxim 0:f77ad7f72d04 78 MaximInterface_EXPORT virtual error_code reset() override;
IanBenzMaxim 0:f77ad7f72d04 79 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 80 touchBitSetLevel(bool & sendRecvBit, Level afterLevel) override;
IanBenzMaxim 0:f77ad7f72d04 81 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 82 writeByteSetLevel(uint_least8_t sendByte, Level afterLevel) override;
IanBenzMaxim 0:f77ad7f72d04 83 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 84 readByteSetLevel(uint_least8_t & recvByte, Level afterLevel) override;
IanBenzMaxim 0:f77ad7f72d04 85 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 86 writeBlock(const uint_least8_t * sendBuf, size_t sendLen) override;
IanBenzMaxim 0:f77ad7f72d04 87 MaximInterface_EXPORT virtual error_code readBlock(uint_least8_t * recvBuf,
IanBenzMaxim 0:f77ad7f72d04 88 size_t recvLen) override;
IanBenzMaxim 0:f77ad7f72d04 89 MaximInterface_EXPORT virtual error_code setSpeed(Speed newSpeed) override;
IanBenzMaxim 0:f77ad7f72d04 90 MaximInterface_EXPORT virtual error_code setLevel(Level newLevel) override;
IanBenzMaxim 0:f77ad7f72d04 91
IanBenzMaxim 0:f77ad7f72d04 92 MaximInterface_EXPORT static const error_category & errorCategory();
IanBenzMaxim 0:f77ad7f72d04 93
IanBenzMaxim 0:f77ad7f72d04 94 private:
IanBenzMaxim 0:f77ad7f72d04 95 struct Data;
IanBenzMaxim 0:f77ad7f72d04 96 std::unique_ptr<Data> data;
IanBenzMaxim 0:f77ad7f72d04 97 };
IanBenzMaxim 0:f77ad7f72d04 98
IanBenzMaxim 0:f77ad7f72d04 99 inline error_code make_error_code(OneWireLinkLayerMaster::ErrorValue e) {
IanBenzMaxim 0:f77ad7f72d04 100 return error_code(e, OneWireLinkLayerMaster::errorCategory());
IanBenzMaxim 0:f77ad7f72d04 101 }
IanBenzMaxim 0:f77ad7f72d04 102
IanBenzMaxim 0:f77ad7f72d04 103 } // namespace MaximInterface