Aleksandrs Gumenuks / MaximInterface_Extended

Dependents:   mbed_DS28EC20_GPIO

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DS2413.hpp Source File

DS2413.hpp

00001 /*******************************************************************************
00002 * Copyright (C) 2017 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 MaximInterface_DS2413
00034 #define MaximInterface_DS2413
00035 
00036 #include <stdint.h>
00037 #include <MaximInterface/Links/SelectRom.hpp>
00038 #include <MaximInterface/Utilities/Export.h>
00039 #include <MaximInterface/Utilities/FlagSet.hpp>
00040 
00041 namespace MaximInterface {
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 FlagSet<StatusFlags, 4> Status;
00064 
00065   DS2413(OneWireMaster & master, const SelectRom & selectRom)
00066       : selectRom(selectRom), master(&master) {}
00067 
00068   void setMaster(OneWireMaster & master) { this->master = &master; }
00069   
00070   void setSelectRom(const SelectRom & selectRom) {
00071     this->selectRom = selectRom;
00072   }
00073 
00074   /// Read the input and output logic states for all PIO pins.
00075   MaximInterface_EXPORT error_code readStatus(Status & status) const;
00076 
00077   /// Write the output logic states for all PIO pins.
00078   MaximInterface_EXPORT error_code writeOutputState(bool pioAState,
00079                                                     bool pioBState);
00080 
00081   MaximInterface_EXPORT static const error_category & errorCategory();
00082 
00083 private:
00084   error_code pioAccessRead(uint_least8_t & val) const;
00085   error_code pioAccessWrite(uint_least8_t val);
00086 
00087   SelectRom selectRom;
00088   OneWireMaster * master;
00089 };
00090 
00091 /// Write the output logic state for only PIOA.
00092 MaximInterface_EXPORT error_code writePioAOutputState(DS2413 & ds2413,
00093                                                       bool pioAState);
00094 
00095 /// Write the output logic state for only PIOB.
00096 MaximInterface_EXPORT error_code writePioBOutputState(DS2413 & ds2413,
00097                                                       bool pioBState);
00098 
00099 inline error_code make_error_code(DS2413::ErrorValue e) {
00100   return error_code(e, DS2413::errorCategory());
00101 }
00102 
00103 } // namespace MaximInterface
00104 
00105 #endif