Device interface library for multiple platforms including Mbed.
Dependents: DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#
Maxim Interface is a library framework focused on providing flexible and expressive hardware interfaces. Both communication interfaces such as I2C and 1-Wire and device interfaces such as DS18B20 are supported. Modern C++ concepts are used extensively while keeping compatibility with C++98/C++03 and requiring no external dependencies. The embedded-friendly design does not depend on exceptions or RTTI.
The full version of the project is hosted on GitLab: https://gitlab.com/iabenz/MaximInterface
MaximInterfaceDevices/DS2413.hpp@12:7eb41621ba22, 2020-05-29 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Fri May 29 16:19:22 2020 -0500
- Revision:
- 12:7eb41621ba22
- Parent:
- 8:5ea891c7d1a1
Updated to version 2.2.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IanBenzMaxim | 7:9cd16581b578 | 1 | /******************************************************************************* |
IanBenzMaxim | 8:5ea891c7d1a1 | 2 | * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. |
IanBenzMaxim | 7:9cd16581b578 | 3 | * |
IanBenzMaxim | 7:9cd16581b578 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
IanBenzMaxim | 7:9cd16581b578 | 5 | * copy of this software and associated documentation files (the "Software"), |
IanBenzMaxim | 7:9cd16581b578 | 6 | * to deal in the Software without restriction, including without limitation |
IanBenzMaxim | 7:9cd16581b578 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
IanBenzMaxim | 7:9cd16581b578 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
IanBenzMaxim | 7:9cd16581b578 | 9 | * Software is furnished to do so, subject to the following conditions: |
IanBenzMaxim | 7:9cd16581b578 | 10 | * |
IanBenzMaxim | 7:9cd16581b578 | 11 | * The above copyright notice and this permission notice shall be included |
IanBenzMaxim | 7:9cd16581b578 | 12 | * in all copies or substantial portions of the Software. |
IanBenzMaxim | 7:9cd16581b578 | 13 | * |
IanBenzMaxim | 7:9cd16581b578 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
IanBenzMaxim | 7:9cd16581b578 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
IanBenzMaxim | 7:9cd16581b578 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
IanBenzMaxim | 7:9cd16581b578 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
IanBenzMaxim | 7:9cd16581b578 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
IanBenzMaxim | 7:9cd16581b578 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
IanBenzMaxim | 7:9cd16581b578 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
IanBenzMaxim | 7:9cd16581b578 | 21 | * |
IanBenzMaxim | 7:9cd16581b578 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
IanBenzMaxim | 7:9cd16581b578 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
IanBenzMaxim | 7:9cd16581b578 | 24 | * Products, Inc. Branding Policy. |
IanBenzMaxim | 7:9cd16581b578 | 25 | * |
IanBenzMaxim | 7:9cd16581b578 | 26 | * The mere transfer of this software does not imply any licenses |
IanBenzMaxim | 7:9cd16581b578 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
IanBenzMaxim | 7:9cd16581b578 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
IanBenzMaxim | 7:9cd16581b578 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
IanBenzMaxim | 7:9cd16581b578 | 30 | * ownership rights. |
IanBenzMaxim | 7:9cd16581b578 | 31 | *******************************************************************************/ |
IanBenzMaxim | 7:9cd16581b578 | 32 | |
IanBenzMaxim | 8:5ea891c7d1a1 | 33 | #ifndef MaximInterfaceDevices_DS2413_hpp |
IanBenzMaxim | 8:5ea891c7d1a1 | 34 | #define MaximInterfaceDevices_DS2413_hpp |
IanBenzMaxim | 7:9cd16581b578 | 35 | |
IanBenzMaxim | 7:9cd16581b578 | 36 | #include <stdint.h> |
IanBenzMaxim | 7:9cd16581b578 | 37 | #include <MaximInterfaceCore/FlagSet.hpp> |
IanBenzMaxim | 7:9cd16581b578 | 38 | #include <MaximInterfaceCore/SelectRom.hpp> |
IanBenzMaxim | 7:9cd16581b578 | 39 | #include "Config.hpp" |
IanBenzMaxim | 7:9cd16581b578 | 40 | |
IanBenzMaxim | 7:9cd16581b578 | 41 | namespace MaximInterfaceDevices { |
IanBenzMaxim | 7:9cd16581b578 | 42 | |
IanBenzMaxim | 7:9cd16581b578 | 43 | /// @brief DS2413 1-Wire Dual Channel Addressable Switch |
IanBenzMaxim | 7:9cd16581b578 | 44 | /// @details The DS2413 is a dual-channel programmable I/O 1-Wire® |
IanBenzMaxim | 7:9cd16581b578 | 45 | /// chip. The PIO outputs are configured as open-drain and provide up |
IanBenzMaxim | 7:9cd16581b578 | 46 | /// to 20mA continuous sink capability and off-state operating voltage |
IanBenzMaxim | 7:9cd16581b578 | 47 | /// up to 28V. Control and sensing of the PIO pins is performed with |
IanBenzMaxim | 7:9cd16581b578 | 48 | /// a dedicated device-level command protocol. To provide a high level |
IanBenzMaxim | 7:9cd16581b578 | 49 | /// of fault tolerance in the end application, the 1-Wire I/O and PIO |
IanBenzMaxim | 7:9cd16581b578 | 50 | /// pins are all capable of withstanding continuous application of |
IanBenzMaxim | 7:9cd16581b578 | 51 | /// voltages up to 28V max. Communication and operation of the DS2413 |
IanBenzMaxim | 7:9cd16581b578 | 52 | /// is performed with the single contact Maxim 1-Wire serial interface. |
IanBenzMaxim | 7:9cd16581b578 | 53 | class DS2413 { |
IanBenzMaxim | 7:9cd16581b578 | 54 | public: |
IanBenzMaxim | 7:9cd16581b578 | 55 | enum ErrorValue { CommunicationError = 1 }; |
IanBenzMaxim | 7:9cd16581b578 | 56 | |
IanBenzMaxim | 7:9cd16581b578 | 57 | enum StatusFlags { |
IanBenzMaxim | 7:9cd16581b578 | 58 | PioAInputState = 0x1, |
IanBenzMaxim | 7:9cd16581b578 | 59 | PioAOutputState = 0x2, |
IanBenzMaxim | 7:9cd16581b578 | 60 | PioBInputState = 0x4, |
IanBenzMaxim | 7:9cd16581b578 | 61 | PioBOutputState = 0x8 |
IanBenzMaxim | 7:9cd16581b578 | 62 | }; |
IanBenzMaxim | 7:9cd16581b578 | 63 | typedef Core::FlagSet<StatusFlags, 4> Status; |
IanBenzMaxim | 7:9cd16581b578 | 64 | |
IanBenzMaxim | 7:9cd16581b578 | 65 | DS2413(Core::OneWireMaster & master, const Core::SelectRom & selectRom) |
IanBenzMaxim | 7:9cd16581b578 | 66 | : selectRom(selectRom), master(&master) {} |
IanBenzMaxim | 7:9cd16581b578 | 67 | |
IanBenzMaxim | 7:9cd16581b578 | 68 | void setMaster(Core::OneWireMaster & master) { this->master = &master; } |
IanBenzMaxim | 7:9cd16581b578 | 69 | |
IanBenzMaxim | 7:9cd16581b578 | 70 | void setSelectRom(const Core::SelectRom & selectRom) { |
IanBenzMaxim | 7:9cd16581b578 | 71 | this->selectRom = selectRom; |
IanBenzMaxim | 7:9cd16581b578 | 72 | } |
IanBenzMaxim | 7:9cd16581b578 | 73 | |
IanBenzMaxim | 7:9cd16581b578 | 74 | /// Read the input and output logic states for all PIO pins. |
IanBenzMaxim | 8:5ea891c7d1a1 | 75 | MaximInterfaceDevices_EXPORT Core::Result<Status> readStatus() const; |
IanBenzMaxim | 7:9cd16581b578 | 76 | |
IanBenzMaxim | 7:9cd16581b578 | 77 | /// Write the output logic states for all PIO pins. |
IanBenzMaxim | 8:5ea891c7d1a1 | 78 | MaximInterfaceDevices_EXPORT Core::Result<void> |
IanBenzMaxim | 7:9cd16581b578 | 79 | writeOutputState(bool pioAState, bool pioBState); |
IanBenzMaxim | 7:9cd16581b578 | 80 | |
IanBenzMaxim | 7:9cd16581b578 | 81 | MaximInterfaceDevices_EXPORT static const Core::error_category & |
IanBenzMaxim | 7:9cd16581b578 | 82 | errorCategory(); |
IanBenzMaxim | 7:9cd16581b578 | 83 | |
IanBenzMaxim | 7:9cd16581b578 | 84 | private: |
IanBenzMaxim | 8:5ea891c7d1a1 | 85 | Core::Result<uint_least8_t> pioAccessRead() const; |
IanBenzMaxim | 8:5ea891c7d1a1 | 86 | Core::Result<void> pioAccessWrite(uint_least8_t val); |
IanBenzMaxim | 7:9cd16581b578 | 87 | |
IanBenzMaxim | 7:9cd16581b578 | 88 | Core::SelectRom selectRom; |
IanBenzMaxim | 7:9cd16581b578 | 89 | Core::OneWireMaster * master; |
IanBenzMaxim | 7:9cd16581b578 | 90 | }; |
IanBenzMaxim | 7:9cd16581b578 | 91 | |
IanBenzMaxim | 7:9cd16581b578 | 92 | /// Write the output logic state for only PIOA. |
IanBenzMaxim | 8:5ea891c7d1a1 | 93 | MaximInterfaceDevices_EXPORT Core::Result<void> |
IanBenzMaxim | 7:9cd16581b578 | 94 | writePioAOutputState(DS2413 & ds2413, bool pioAState); |
IanBenzMaxim | 7:9cd16581b578 | 95 | |
IanBenzMaxim | 7:9cd16581b578 | 96 | /// Write the output logic state for only PIOB. |
IanBenzMaxim | 8:5ea891c7d1a1 | 97 | MaximInterfaceDevices_EXPORT Core::Result<void> |
IanBenzMaxim | 7:9cd16581b578 | 98 | writePioBOutputState(DS2413 & ds2413, bool pioBState); |
IanBenzMaxim | 7:9cd16581b578 | 99 | |
IanBenzMaxim | 8:5ea891c7d1a1 | 100 | } // namespace MaximInterfaceDevices |
IanBenzMaxim | 8:5ea891c7d1a1 | 101 | namespace MaximInterfaceCore { |
IanBenzMaxim | 8:5ea891c7d1a1 | 102 | |
IanBenzMaxim | 8:5ea891c7d1a1 | 103 | template <> |
IanBenzMaxim | 8:5ea891c7d1a1 | 104 | struct is_error_code_enum<MaximInterfaceDevices::DS2413::ErrorValue> |
IanBenzMaxim | 8:5ea891c7d1a1 | 105 | : true_type {}; |
IanBenzMaxim | 8:5ea891c7d1a1 | 106 | |
IanBenzMaxim | 8:5ea891c7d1a1 | 107 | } // namespace MaximInterfaceCore |
IanBenzMaxim | 8:5ea891c7d1a1 | 108 | namespace MaximInterfaceDevices { |
IanBenzMaxim | 8:5ea891c7d1a1 | 109 | |
IanBenzMaxim | 7:9cd16581b578 | 110 | inline Core::error_code make_error_code(DS2413::ErrorValue e) { |
IanBenzMaxim | 7:9cd16581b578 | 111 | return Core::error_code(e, DS2413::errorCategory()); |
IanBenzMaxim | 7:9cd16581b578 | 112 | } |
IanBenzMaxim | 7:9cd16581b578 | 113 | |
IanBenzMaxim | 7:9cd16581b578 | 114 | } // namespace MaximInterfaceDevices |
IanBenzMaxim | 7:9cd16581b578 | 115 | |
IanBenzMaxim | 7:9cd16581b578 | 116 | #endif |