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: DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#
MaximInterfaceDevices/DS2480B.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_DS2480B_hpp | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 34 | #define MaximInterfaceDevices_DS2480B_hpp | 
| IanBenzMaxim | 7:9cd16581b578 | 35 | |
| IanBenzMaxim | 7:9cd16581b578 | 36 | #include <MaximInterfaceCore/OneWireMaster.hpp> | 
| IanBenzMaxim | 7:9cd16581b578 | 37 | #include <MaximInterfaceCore/Sleep.hpp> | 
| IanBenzMaxim | 7:9cd16581b578 | 38 | #include <MaximInterfaceCore/Uart.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 | /// Serial to 1-Wire Line Driver | 
| IanBenzMaxim | 7:9cd16581b578 | 44 | class DS2480B : public Core::OneWireMaster { | 
| IanBenzMaxim | 7:9cd16581b578 | 45 | public: | 
| IanBenzMaxim | 7:9cd16581b578 | 46 | enum ErrorValue { HardwareError = 1 }; | 
| IanBenzMaxim | 7:9cd16581b578 | 47 | |
| IanBenzMaxim | 7:9cd16581b578 | 48 | DS2480B(Core::Sleep & sleep, Core::Uart & uart) | 
| IanBenzMaxim | 7:9cd16581b578 | 49 | : sleep(&sleep), uart(&uart) {} | 
| IanBenzMaxim | 7:9cd16581b578 | 50 | |
| IanBenzMaxim | 7:9cd16581b578 | 51 | void setSleep(Core::Sleep & sleep) { this->sleep = &sleep; } | 
| IanBenzMaxim | 7:9cd16581b578 | 52 | |
| IanBenzMaxim | 7:9cd16581b578 | 53 | void setUart(Core::Uart & uart) { this->uart = &uart; } | 
| IanBenzMaxim | 7:9cd16581b578 | 54 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 55 | MaximInterfaceDevices_EXPORT Core::Result<void> initialize(); | 
| IanBenzMaxim | 7:9cd16581b578 | 56 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 57 | MaximInterfaceDevices_EXPORT virtual Core::Result<void> reset(); | 
| IanBenzMaxim | 7:9cd16581b578 | 58 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 59 | MaximInterfaceDevices_EXPORT virtual Core::Result<bool> | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 60 | touchBitSetLevel(bool sendBit, Level afterLevel); | 
| IanBenzMaxim | 7:9cd16581b578 | 61 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 62 | MaximInterfaceDevices_EXPORT virtual Core::Result<void> | 
| IanBenzMaxim | 7:9cd16581b578 | 63 | writeByteSetLevel(uint_least8_t sendByte, Level afterLevel); | 
| IanBenzMaxim | 7:9cd16581b578 | 64 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 65 | MaximInterfaceDevices_EXPORT virtual Core::Result<uint_least8_t> | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 66 | readByteSetLevel(Level afterLevel); | 
| IanBenzMaxim | 7:9cd16581b578 | 67 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 68 | MaximInterfaceDevices_EXPORT virtual Core::Result<void> | 
| IanBenzMaxim | 7:9cd16581b578 | 69 | setSpeed(Speed newSpeed); | 
| IanBenzMaxim | 7:9cd16581b578 | 70 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 71 | MaximInterfaceDevices_EXPORT virtual Core::Result<void> | 
| IanBenzMaxim | 7:9cd16581b578 | 72 | setLevel(Level newLevel); | 
| IanBenzMaxim | 7:9cd16581b578 | 73 | |
| IanBenzMaxim | 7:9cd16581b578 | 74 | MaximInterfaceDevices_EXPORT static const Core::error_category & | 
| IanBenzMaxim | 7:9cd16581b578 | 75 | errorCategory(); | 
| IanBenzMaxim | 7:9cd16581b578 | 76 | |
| IanBenzMaxim | 7:9cd16581b578 | 77 | protected: | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 78 | MaximInterfaceDevices_EXPORT Core::Result<void> | 
| IanBenzMaxim | 7:9cd16581b578 | 79 | sendCommand(uint_least8_t command); | 
| IanBenzMaxim | 7:9cd16581b578 | 80 | |
| IanBenzMaxim | 7:9cd16581b578 | 81 | private: | 
| IanBenzMaxim | 7:9cd16581b578 | 82 | const Core::Sleep * sleep; | 
| IanBenzMaxim | 7:9cd16581b578 | 83 | Core::Uart * uart; | 
| IanBenzMaxim | 7:9cd16581b578 | 84 | |
| IanBenzMaxim | 7:9cd16581b578 | 85 | Level level; | 
| IanBenzMaxim | 7:9cd16581b578 | 86 | uint_least8_t mode; | 
| IanBenzMaxim | 7:9cd16581b578 | 87 | uint_least8_t speed; | 
| IanBenzMaxim | 7:9cd16581b578 | 88 | }; | 
| IanBenzMaxim | 7:9cd16581b578 | 89 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 90 | } // namespace MaximInterfaceDevices | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 91 | namespace MaximInterfaceCore { | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 92 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 93 | template <> | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 94 | struct is_error_code_enum<MaximInterfaceDevices::DS2480B::ErrorValue> | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 95 | : true_type {}; | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 96 | |
| IanBenzMaxim | 8:5ea891c7d1a1 | 97 | } // namespace MaximInterfaceCore | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 98 | namespace MaximInterfaceDevices { | 
| IanBenzMaxim | 8:5ea891c7d1a1 | 99 | |
| IanBenzMaxim | 7:9cd16581b578 | 100 | inline Core::error_code make_error_code(DS2480B::ErrorValue e) { | 
| IanBenzMaxim | 7:9cd16581b578 | 101 | return Core::error_code(e, DS2480B::errorCategory()); | 
| IanBenzMaxim | 7:9cd16581b578 | 102 | } | 
| IanBenzMaxim | 7:9cd16581b578 | 103 | |
| IanBenzMaxim | 7:9cd16581b578 | 104 | } // namespace MaximInterfaceDevices | 
| IanBenzMaxim | 7:9cd16581b578 | 105 | |
| IanBenzMaxim | 7:9cd16581b578 | 106 | #endif |