1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.

Dependents:   MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RomIterator.h Source File

RomIterator.h

00001 /******************************************************************//**
00002 * Copyright (C) 2016 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 OneWire_RomIterator
00034 #define OneWire_RomIterator
00035 
00036 #include <stdint.h>
00037 #include "RomId/RomCommands.h "
00038 
00039 namespace OneWire
00040 {
00041     class OneWireMaster;
00042     
00043     /// Controls selection of 1-Wire devices on the bus through ROM commands.
00044     class RomIterator
00045     {
00046     private:
00047         OneWireMaster & owMaster;
00048         
00049     protected:
00050         /// @param master 1-Wire master to use to issue ROM commands.
00051         RomIterator (OneWireMaster & master) : owMaster(master) { }
00052         
00053     public:
00054         virtual ~RomIterator() { }
00055         
00056         /// The 1-Wire master used to issue ROM commands.
00057         OneWireMaster & master() const { return owMaster; }
00058     };
00059     
00060     /// Iterates through all 1-Wire devices in a sequential first to last order.
00061     class ForwardRomIterator : public RomIterator
00062     {
00063     public:
00064         /// @param master 1-Wire master to use to issue ROM commands.
00065         ForwardRomIterator (OneWireMaster & master) : RomIterator(master) { }
00066         
00067         /// Indicates that current device is the last.
00068         virtual bool lastDevice() const = 0;
00069         
00070         /// Select the first device in the sequence.
00071         virtual OneWireMaster::CmdResult selectFirstDevice() = 0;
00072         
00073         /// Select the next device in the sequence.
00074         virtual OneWireMaster::CmdResult selectNextDevice() = 0;
00075         
00076         /// Reselect the current device for an additional operation.
00077         virtual OneWireMaster::CmdResult reselectCurrentDevice() = 0;
00078     };
00079     
00080     /// Iterates through all 1-Wire devices sequentially using the search procedure.
00081     class ForwardSearchRomIterator : public ForwardRomIterator
00082     {
00083     protected:
00084         RomCommands::SearchState searchState;
00085         
00086     public:
00087         /// @param master 1-Wire master to use to issue ROM commands.
00088         ForwardSearchRomIterator (OneWireMaster & master) : ForwardRomIterator(master) { }
00089         
00090         /// ROM ID of the currently selected device.
00091         const RomId & selectedDevice() const { return searchState.romId; }
00092         
00093         virtual bool lastDevice() const;
00094         virtual OneWireMaster::CmdResult selectFirstDevice();
00095         virtual OneWireMaster::CmdResult selectNextDevice();
00096         virtual OneWireMaster::CmdResult reselectCurrentDevice();
00097         
00098         /// Select the first device in the sequence beginning with the given family.
00099         /// @param familyCode Family code to select.
00100         OneWireMaster::CmdResult selectFirstDeviceInFamily(uint8_t familyCode);
00101         
00102         /// Select the first device in the next sequential family skipping all remaining devices
00103         /// in the current family.
00104         OneWireMaster::CmdResult selectNextFamilyDevice();
00105     };
00106     
00107     /// Iterates though 1-Wire devices on the bus using random selection by ROM ID.
00108     class RandomAccessRomIterator : public RomIterator
00109     {
00110     public:
00111         /// @param master 1-Wire master to use to issue ROM commands.
00112         RandomAccessRomIterator (OneWireMaster & master) : RomIterator(master) { }
00113         
00114         /// Select the device with the given ROM ID.
00115         virtual OneWireMaster::CmdResult selectDevice(const RomId & romId) = 0;
00116     };
00117     
00118     /// Iterator for a singledrop 1-Wire bus.
00119     class SingledropRomIterator : public RandomAccessRomIterator
00120     {
00121     public:
00122         /// @param master 1-Wire master to use to issue ROM commands.
00123         SingledropRomIterator (OneWireMaster & master) : RandomAccessRomIterator(master) { }
00124         
00125         /// Select the one and only device.
00126         OneWireMaster::CmdResult selectDevice() { return RomCommands::OWSkipRom(master()); }
00127         virtual OneWireMaster::CmdResult selectDevice(const RomId & romId);
00128     };
00129     
00130     /// Iterator for a multidrop 1-Wire bus.
00131     class MultidropRomIterator : public RandomAccessRomIterator
00132     {        
00133     public:
00134         /// @param master 1-Wire master to use to issue ROM commands.
00135         MultidropRomIterator (OneWireMaster & master) : RandomAccessRomIterator(master) { }
00136         
00137         virtual OneWireMaster::CmdResult selectDevice(const RomId & romId);
00138     };
00139     
00140     /// Iterator for a multidrop 1-Wire bus where slaves support the Resume ROM command.
00141     class MultidropRomIteratorWithResume : public RandomAccessRomIterator
00142     {
00143     private:
00144         RomId lastRom;
00145         
00146     public:
00147         /// @param master 1-Wire master to use to issue ROM commands.
00148         MultidropRomIteratorWithResume (OneWireMaster & master)
00149             : RandomAccessRomIterator(master), lastRom() { }
00150         
00151         virtual OneWireMaster::CmdResult selectDevice(const RomId & romId);
00152     };
00153 }
00154 
00155 #endif