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

Committer:
IanBenzMaxim
Date:
Tue Dec 03 10:52:28 2019 -0600
Revision:
11:3f3bf6bf5e6c
Parent:
8:5ea891c7d1a1
Updated to version 2.1.

Who changed what in which revision?

UserRevisionLine numberNew 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 7:9cd16581b578 33 /// @file
IanBenzMaxim 7:9cd16581b578 34 /// @brief ROM Commands for enumerating and selecting 1-Wire devices.
IanBenzMaxim 7:9cd16581b578 35
IanBenzMaxim 8:5ea891c7d1a1 36 #ifndef MaximInterfaceCore_RomCommands_hpp
IanBenzMaxim 8:5ea891c7d1a1 37 #define MaximInterfaceCore_RomCommands_hpp
IanBenzMaxim 7:9cd16581b578 38
IanBenzMaxim 7:9cd16581b578 39 #include <stdint.h>
IanBenzMaxim 7:9cd16581b578 40 #include "Algorithm.hpp"
IanBenzMaxim 7:9cd16581b578 41 #include "Config.hpp"
IanBenzMaxim 7:9cd16581b578 42 #include "OneWireMaster.hpp"
IanBenzMaxim 7:9cd16581b578 43 #include "RomId.hpp"
IanBenzMaxim 7:9cd16581b578 44
IanBenzMaxim 7:9cd16581b578 45 namespace MaximInterfaceCore {
IanBenzMaxim 7:9cd16581b578 46
IanBenzMaxim 7:9cd16581b578 47 /// State used by Search ROM command.
IanBenzMaxim 7:9cd16581b578 48 struct SearchRomState {
IanBenzMaxim 7:9cd16581b578 49 RomId::array romId;
IanBenzMaxim 7:9cd16581b578 50 int_least8_t lastDiscrepancy;
IanBenzMaxim 7:9cd16581b578 51 int_least8_t lastFamilyDiscrepancy;
IanBenzMaxim 7:9cd16581b578 52 bool lastDevice;
IanBenzMaxim 7:9cd16581b578 53
IanBenzMaxim 7:9cd16581b578 54 SearchRomState()
IanBenzMaxim 7:9cd16581b578 55 : romId(), lastDiscrepancy(0), lastFamilyDiscrepancy(0),
IanBenzMaxim 7:9cd16581b578 56 lastDevice(false) {}
IanBenzMaxim 7:9cd16581b578 57
IanBenzMaxim 7:9cd16581b578 58 explicit SearchRomState(RomId::const_span romId)
IanBenzMaxim 7:9cd16581b578 59 : lastDiscrepancy(64), lastFamilyDiscrepancy(0), lastDevice(false) {
IanBenzMaxim 7:9cd16581b578 60 copy(romId, make_span(this->romId));
IanBenzMaxim 7:9cd16581b578 61 }
IanBenzMaxim 7:9cd16581b578 62
IanBenzMaxim 7:9cd16581b578 63 explicit SearchRomState(RomId::element familyCode)
IanBenzMaxim 7:9cd16581b578 64 : romId(), lastDiscrepancy(64), lastFamilyDiscrepancy(0),
IanBenzMaxim 7:9cd16581b578 65 lastDevice(false) {
IanBenzMaxim 8:5ea891c7d1a1 66 romId.front() = familyCode;
IanBenzMaxim 7:9cd16581b578 67 }
IanBenzMaxim 7:9cd16581b578 68 };
IanBenzMaxim 7:9cd16581b578 69
IanBenzMaxim 7:9cd16581b578 70 /// @brief
IanBenzMaxim 7:9cd16581b578 71 /// Set the search state to skip the current device family on the next
IanBenzMaxim 7:9cd16581b578 72 /// Search ROM command.
IanBenzMaxim 7:9cd16581b578 73 MaximInterfaceCore_EXPORT void skipCurrentFamily(SearchRomState & searchState);
IanBenzMaxim 7:9cd16581b578 74
IanBenzMaxim 7:9cd16581b578 75 /// Verify that the device with the specified ROM ID is present.
IanBenzMaxim 8:5ea891c7d1a1 76 MaximInterfaceCore_EXPORT Result<void> verifyRom(OneWireMaster & master,
IanBenzMaxim 8:5ea891c7d1a1 77 RomId::const_span romId);
IanBenzMaxim 7:9cd16581b578 78
IanBenzMaxim 7:9cd16581b578 79 /// @brief Use Read ROM command to read ROM ID from device on bus.
IanBenzMaxim 7:9cd16581b578 80 /// @note
IanBenzMaxim 7:9cd16581b578 81 /// Only use this command with a single-drop bus.
IanBenzMaxim 7:9cd16581b578 82 /// Data collisions will occur if there is more than one device on the bus.
IanBenzMaxim 7:9cd16581b578 83 /// @param master 1-Wire master for operation.
IanBenzMaxim 8:5ea891c7d1a1 84 /// @returns ROM ID read from device.
IanBenzMaxim 8:5ea891c7d1a1 85 MaximInterfaceCore_EXPORT Result<RomId::array> readRom(OneWireMaster & master);
IanBenzMaxim 7:9cd16581b578 86
IanBenzMaxim 7:9cd16581b578 87 /// @brief Issue Skip ROM command on bus.
IanBenzMaxim 7:9cd16581b578 88 /// @note
IanBenzMaxim 7:9cd16581b578 89 /// Only use this command with a single-drop bus.
IanBenzMaxim 7:9cd16581b578 90 /// Data collisions will occur if there is more than one device on the bus.
IanBenzMaxim 8:5ea891c7d1a1 91 MaximInterfaceCore_EXPORT Result<void> skipRom(OneWireMaster & master);
IanBenzMaxim 7:9cd16581b578 92
IanBenzMaxim 7:9cd16581b578 93 /// @brief Use the Match ROM command to select the device by its known ID.
IanBenzMaxim 7:9cd16581b578 94 /// @note
IanBenzMaxim 7:9cd16581b578 95 /// This command causes all devices supporting Overdrive mode to switch to
IanBenzMaxim 7:9cd16581b578 96 /// Overdrive timing.
IanBenzMaxim 7:9cd16581b578 97 /// @param master 1-Wire master for operation.
IanBenzMaxim 7:9cd16581b578 98 /// @param[in] romId ROM ID of device to select.
IanBenzMaxim 8:5ea891c7d1a1 99 MaximInterfaceCore_EXPORT Result<void> matchRom(OneWireMaster & master,
IanBenzMaxim 8:5ea891c7d1a1 100 RomId::const_span romId);
IanBenzMaxim 7:9cd16581b578 101
IanBenzMaxim 7:9cd16581b578 102 /// @brief Issue Overdrive Skip ROM command on bus.
IanBenzMaxim 7:9cd16581b578 103 /// @note
IanBenzMaxim 7:9cd16581b578 104 /// This command causes all devices supporting Overdrive mode to switch to
IanBenzMaxim 7:9cd16581b578 105 /// Overdrive timing.
IanBenzMaxim 7:9cd16581b578 106 /// @note
IanBenzMaxim 7:9cd16581b578 107 /// Only use this command with a single-drop bus.
IanBenzMaxim 7:9cd16581b578 108 /// Data collisions will occur if there is more than one device on the bus.
IanBenzMaxim 8:5ea891c7d1a1 109 MaximInterfaceCore_EXPORT Result<void> overdriveSkipRom(OneWireMaster & master);
IanBenzMaxim 7:9cd16581b578 110
IanBenzMaxim 7:9cd16581b578 111 /// @brief
IanBenzMaxim 7:9cd16581b578 112 /// Use the Overdrive Match ROM command to select the device by its known ID.
IanBenzMaxim 7:9cd16581b578 113 /// @param master 1-Wire master for operation.
IanBenzMaxim 7:9cd16581b578 114 /// @param[in] romId ROM ID of device to select.
IanBenzMaxim 8:5ea891c7d1a1 115 MaximInterfaceCore_EXPORT Result<void>
IanBenzMaxim 8:5ea891c7d1a1 116 overdriveMatchRom(OneWireMaster & master, RomId::const_span romId);
IanBenzMaxim 7:9cd16581b578 117
IanBenzMaxim 7:9cd16581b578 118 /// @brief Perform a Resume ROM command on bus.
IanBenzMaxim 7:9cd16581b578 119 /// @details
IanBenzMaxim 7:9cd16581b578 120 /// Resumes communication with the last device selected through a Match ROM or
IanBenzMaxim 7:9cd16581b578 121 /// Search ROM operation.
IanBenzMaxim 8:5ea891c7d1a1 122 MaximInterfaceCore_EXPORT Result<void> resumeRom(OneWireMaster & master);
IanBenzMaxim 7:9cd16581b578 123
IanBenzMaxim 7:9cd16581b578 124 /// @brief Find device on the 1-Wire bus.
IanBenzMaxim 7:9cd16581b578 125 /// @details
IanBenzMaxim 7:9cd16581b578 126 /// This command uses the Search ROM command to enumerate all 1-Wire devices in
IanBenzMaxim 7:9cd16581b578 127 /// sequence. Begin with a new search state and continue using the same search
IanBenzMaxim 7:9cd16581b578 128 /// state until the last device flag is set which indicates that all devices
IanBenzMaxim 7:9cd16581b578 129 /// have been discovered.
IanBenzMaxim 8:5ea891c7d1a1 130 MaximInterfaceCore_EXPORT Result<void> searchRom(OneWireMaster & master,
IanBenzMaxim 8:5ea891c7d1a1 131 SearchRomState & searchState);
IanBenzMaxim 7:9cd16581b578 132
IanBenzMaxim 7:9cd16581b578 133 } // namespace MaximInterfaceCore
IanBenzMaxim 7:9cd16581b578 134
IanBenzMaxim 7:9cd16581b578 135 #endif