Device interface library for multiple platforms including Mbed.

Dependents:   DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DS2413.hpp Source File

DS2413.hpp

00001 /*******************************************************************************
00002 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a
00005 * copy of this software and associated documentation files (the "Software"),
00006 * to deal in the Software without restriction, including without limitation
00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 * and/or sell copies of the Software, and to permit persons to whom the
00009 * Software is furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included
00012 * in all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 * OTHER DEALINGS IN THE SOFTWARE.
00021 *
00022 * Except as contained in this notice, the name of Maxim Integrated
00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 * Products, Inc. Branding Policy.
00025 *
00026 * The mere transfer of this software does not imply any licenses
00027 * of trade secrets, proprietary technology, copyrights, patents,
00028 * trademarks, maskwork rights, or any other form of intellectual
00029 * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 * ownership rights.
00031 *******************************************************************************/
00032 
00033 #ifndef MaximInterfaceDevices_DS2413_hpp
00034 #define MaximInterfaceDevices_DS2413_hpp
00035 
00036 #include <stdint.h>
00037 #include <MaximInterfaceCore/FlagSet.hpp>
00038 #include <MaximInterfaceCore/SelectRom.hpp>
00039 #include "Config.hpp"
00040 
00041 namespace MaximInterfaceDevices {
00042 
00043 /// @brief DS2413 1-Wire Dual Channel Addressable Switch
00044 /// @details The DS2413 is a dual-channel programmable I/O 1-Wire®
00045 /// chip. The PIO outputs are configured as open-drain and provide up
00046 /// to 20mA continuous sink capability and off-state operating voltage
00047 /// up to 28V. Control and sensing of the PIO pins is performed with
00048 /// a dedicated device-level command protocol. To provide a high level
00049 /// of fault tolerance in the end application, the 1-Wire I/O and PIO
00050 /// pins are all capable of withstanding continuous application of
00051 /// voltages up to 28V max. Communication and operation of the DS2413
00052 /// is performed with the single contact Maxim 1-Wire serial interface.
00053 class DS2413 {
00054 public:
00055   enum ErrorValue { CommunicationError = 1 };
00056 
00057   enum StatusFlags {
00058     PioAInputState = 0x1,
00059     PioAOutputState = 0x2,
00060     PioBInputState = 0x4,
00061     PioBOutputState = 0x8
00062   };
00063   typedef Core::FlagSet<StatusFlags, 4> Status;
00064 
00065   DS2413(Core::OneWireMaster & master, const Core::SelectRom & selectRom)
00066       : selectRom(selectRom), master(&master) {}
00067 
00068   void setMaster(Core::OneWireMaster & master) { this->master = &master; }
00069 
00070   void setSelectRom(const Core::SelectRom & selectRom) {
00071     this->selectRom = selectRom;
00072   }
00073 
00074   /// Read the input and output logic states for all PIO pins.
00075   MaximInterfaceDevices_EXPORT Core::Result<Status> readStatus() const;
00076 
00077   /// Write the output logic states for all PIO pins.
00078   MaximInterfaceDevices_EXPORT Core::Result<void>
00079   writeOutputState(bool pioAState, bool pioBState);
00080 
00081   MaximInterfaceDevices_EXPORT static const Core::error_category &
00082   errorCategory();
00083 
00084 private:
00085   Core::Result<uint_least8_t> pioAccessRead() const;
00086   Core::Result<void> pioAccessWrite(uint_least8_t val);
00087 
00088   Core::SelectRom selectRom;
00089   Core::OneWireMaster * master;
00090 };
00091 
00092 /// Write the output logic state for only PIOA.
00093 MaximInterfaceDevices_EXPORT Core::Result<void>
00094 writePioAOutputState(DS2413 & ds2413, bool pioAState);
00095 
00096 /// Write the output logic state for only PIOB.
00097 MaximInterfaceDevices_EXPORT Core::Result<void>
00098 writePioBOutputState(DS2413 & ds2413, bool pioBState);
00099 
00100 } // namespace MaximInterfaceDevices
00101 namespace MaximInterfaceCore {
00102 
00103 template <>
00104 struct is_error_code_enum<MaximInterfaceDevices::DS2413::ErrorValue>
00105     : true_type {};
00106 
00107 } // namespace MaximInterfaceCore
00108 namespace MaximInterfaceDevices {
00109 
00110 inline Core::error_code make_error_code(DS2413::ErrorValue e) {
00111   return Core::error_code(e, DS2413::errorCategory());
00112 }
00113 
00114 } // namespace MaximInterfaceDevices
00115 
00116 #endif