Maxim Integrated / OneWire

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 DS2480B.h Source File

DS2480B.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_Masters_DS2480B
00034 #define OneWire_Masters_DS2480B
00035 
00036 #include "Serial.h"
00037 #include "Masters/OneWireMaster.h"
00038 
00039 namespace OneWire
00040 {
00041     /// Serial to 1-Wire Line Driver
00042     class DS2480B : public OneWireMaster
00043     {
00044     public:
00045         /// Baud rates for DS2480B
00046         enum BaudRate
00047         {
00048             Baud9600bps = 0, ///< 9600 bps
00049             Baud19200bps = 2, ///< 19200 bps
00050             Baud57600bps = 4, ///< 57600 bps
00051             Baud115200bps = 6 ///< 115200 bps
00052         };
00053 
00054         DS2480B(PinName tx, PinName rx);
00055 
00056         virtual OneWireMaster::CmdResult OWInitMaster();
00057         virtual OneWireMaster::CmdResult OWReset();
00058         virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel);
00059         virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel);
00060         virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel);
00061         virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed newSpeed);
00062         virtual OneWireMaster::CmdResult OWSetLevel(OWLevel newLevel);
00063         
00064         OneWireMaster::CmdResult detect();
00065         OneWireMaster::CmdResult changeBaud(BaudRate newBaud);
00066 
00067     private:
00068         OneWireMaster::CmdResult writeCom(size_t outlen, uint8_t *outbuf);
00069         OneWireMaster::CmdResult readCom(size_t inlen, uint8_t *inbuf);
00070         void breakCom();
00071         void flushCom();
00072         void setComBaud(BaudRate new_baud);
00073 
00074         // COM interface
00075         mbed::Serial serial;
00076 
00077         // DS2480B state
00078         OWLevel level; // 1-Wire level
00079         BaudRate baud;  // baud rate
00080         uint8_t mode;  // command or data mode state
00081         uint8_t speed; // 1-Wire communication speed
00082     };
00083 }
00084 
00085 #endif
00086