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

Superseded by MaximInterface.

Committer:
j3
Date:
Mon Jun 20 20:02:28 2016 +0000
Revision:
92:aa40c49b8563
Parent:
84:708b7be59fb2
Child:
109:5c9180b4be25
Updated DS2482 class names to work with doxygen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 3:644fc630f958 1 /******************************************************************//**
j3 3:644fc630f958 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 3:644fc630f958 3 *
j3 3:644fc630f958 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 3:644fc630f958 5 * copy of this software and associated documentation files (the "Software"),
j3 3:644fc630f958 6 * to deal in the Software without restriction, including without limitation
j3 3:644fc630f958 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 3:644fc630f958 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 3:644fc630f958 9 * Software is furnished to do so, subject to the following conditions:
j3 3:644fc630f958 10 *
j3 3:644fc630f958 11 * The above copyright notice and this permission notice shall be included
j3 3:644fc630f958 12 * in all copies or substantial portions of the Software.
j3 3:644fc630f958 13 *
j3 3:644fc630f958 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 3:644fc630f958 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 3:644fc630f958 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 3:644fc630f958 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 3:644fc630f958 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 3:644fc630f958 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 3:644fc630f958 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 3:644fc630f958 21 *
j3 3:644fc630f958 22 * Except as contained in this notice, the name of Maxim Integrated
j3 3:644fc630f958 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 3:644fc630f958 24 * Products, Inc. Branding Policy.
j3 3:644fc630f958 25 *
j3 3:644fc630f958 26 * The mere transfer of this software does not imply any licenses
j3 3:644fc630f958 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 3:644fc630f958 28 * trademarks, maskwork rights, or any other form of intellectual
j3 3:644fc630f958 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 3:644fc630f958 30 * ownership rights.
j3 3:644fc630f958 31 **********************************************************************/
j3 3:644fc630f958 32
IanBenzMaxim 73:2cecc1372acc 33 #ifndef OneWire_Masters_DS2480B
IanBenzMaxim 73:2cecc1372acc 34 #define OneWire_Masters_DS2480B
j3 3:644fc630f958 35
IanBenzMaxim 73:2cecc1372acc 36 #include "PinNames.h"
IanBenzMaxim 73:2cecc1372acc 37 #include "Masters/OneWireMaster.h"
j3 3:644fc630f958 38
IanBenzMaxim 73:2cecc1372acc 39 namespace mbed { class Serial; }
j3 3:644fc630f958 40
IanBenzMaxim 73:2cecc1372acc 41 namespace OneWire
j3 3:644fc630f958 42 {
j3 92:aa40c49b8563 43 ///UART to 1-wire master interface
IanBenzMaxim 76:84e6c4994e29 44 class DS2480B : public OneWireMaster
j3 63:422be898443a 45 {
IanBenzMaxim 76:84e6c4994e29 46 public:
j3 92:aa40c49b8563 47
j3 92:aa40c49b8563 48 ///Valid baud rates for DS2480B
IanBenzMaxim 76:84e6c4994e29 49 enum Baud
IanBenzMaxim 73:2cecc1372acc 50 {
IanBenzMaxim 76:84e6c4994e29 51 Bps9600 = 0,
IanBenzMaxim 76:84e6c4994e29 52 Bps19200 = 2,
IanBenzMaxim 76:84e6c4994e29 53 Bps57600 = 4,
IanBenzMaxim 76:84e6c4994e29 54 Bps115200 = 6
IanBenzMaxim 76:84e6c4994e29 55 };
IanBenzMaxim 74:23be10c32fa3 56
IanBenzMaxim 76:84e6c4994e29 57 /**********************************************************//**
IanBenzMaxim 76:84e6c4994e29 58 * @brief DS2480B constructor
IanBenzMaxim 76:84e6c4994e29 59 *
IanBenzMaxim 76:84e6c4994e29 60 * @details allows user to use existing Serial object
IanBenzMaxim 76:84e6c4994e29 61 *
IanBenzMaxim 76:84e6c4994e29 62 * On Entry:
IanBenzMaxim 76:84e6c4994e29 63 * @param[in] p_serial - pointer to existing serial object
IanBenzMaxim 76:84e6c4994e29 64 *
IanBenzMaxim 76:84e6c4994e29 65 * On Exit:
IanBenzMaxim 76:84e6c4994e29 66 * @return
IanBenzMaxim 76:84e6c4994e29 67 **************************************************************/
IanBenzMaxim 76:84e6c4994e29 68 DS2480B(mbed::Serial &p_serial);
IanBenzMaxim 74:23be10c32fa3 69
IanBenzMaxim 74:23be10c32fa3 70
IanBenzMaxim 76:84e6c4994e29 71 /**********************************************************//**
IanBenzMaxim 76:84e6c4994e29 72 * @brief DS2480B destructor
IanBenzMaxim 76:84e6c4994e29 73 *
IanBenzMaxim 76:84e6c4994e29 74 * @details deletes serial object if owner
IanBenzMaxim 76:84e6c4994e29 75 *
IanBenzMaxim 76:84e6c4994e29 76 * On Entry:
IanBenzMaxim 76:84e6c4994e29 77 *
IanBenzMaxim 76:84e6c4994e29 78 * On Exit:
IanBenzMaxim 76:84e6c4994e29 79 * @return
IanBenzMaxim 76:84e6c4994e29 80 **************************************************************/
IanBenzMaxim 76:84e6c4994e29 81 virtual ~DS2480B();
IanBenzMaxim 74:23be10c32fa3 82
IanBenzMaxim 74:23be10c32fa3 83
IanBenzMaxim 76:84e6c4994e29 84 OneWireMaster::CmdResult DS2480B_ChangeBaud(Baud newBaud);
j3 3:644fc630f958 85
IanBenzMaxim 76:84e6c4994e29 86 virtual OneWireMaster::CmdResult OWInitMaster();
IanBenzMaxim 76:84e6c4994e29 87 virtual OneWireMaster::CmdResult OWReset();
IanBenzMaxim 76:84e6c4994e29 88 virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel);
IanBenzMaxim 76:84e6c4994e29 89 virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel);
IanBenzMaxim 76:84e6c4994e29 90 virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel);
IanBenzMaxim 76:84e6c4994e29 91 virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed newSpeed);
IanBenzMaxim 76:84e6c4994e29 92 virtual OneWireMaster::CmdResult OWSetLevel(OWLevel newLevel);
IanBenzMaxim 74:23be10c32fa3 93
IanBenzMaxim 76:84e6c4994e29 94 private:
IanBenzMaxim 76:84e6c4994e29 95 void rx_callback(void);
IanBenzMaxim 74:23be10c32fa3 96
IanBenzMaxim 76:84e6c4994e29 97 OneWireMaster::CmdResult DS2480B_Detect(void);
IanBenzMaxim 76:84e6c4994e29 98 OneWireMaster::CmdResult WriteCOM(uint32_t outlen, uint8_t *outbuf);
IanBenzMaxim 76:84e6c4994e29 99 OneWireMaster::CmdResult ReadCOM(uint32_t inlen, uint8_t *inbuf);
IanBenzMaxim 76:84e6c4994e29 100 void BreakCOM(void);
IanBenzMaxim 76:84e6c4994e29 101 void FlushCOM(void);
IanBenzMaxim 76:84e6c4994e29 102 void SetBaudCOM(uint8_t new_baud);
IanBenzMaxim 76:84e6c4994e29 103 int32_t bitacc(uint32_t op, uint32_t state, uint32_t loc, uint8_t *buf);
IanBenzMaxim 74:23be10c32fa3 104
IanBenzMaxim 76:84e6c4994e29 105 mbed::Serial *_p_serial;
IanBenzMaxim 76:84e6c4994e29 106 bool _serial_owner;
IanBenzMaxim 74:23be10c32fa3 107
IanBenzMaxim 76:84e6c4994e29 108 // DS2480B state
IanBenzMaxim 76:84e6c4994e29 109 OWLevel _ULevel; // 1-Wire level
IanBenzMaxim 76:84e6c4994e29 110 Baud _UBaud; // baud rate
IanBenzMaxim 76:84e6c4994e29 111 uint8_t _UMode; // command or data mode state
IanBenzMaxim 76:84e6c4994e29 112 uint8_t _USpeed; // 1-Wire communication speed
IanBenzMaxim 76:84e6c4994e29 113
IanBenzMaxim 76:84e6c4994e29 114 static const size_t MAX_RX_BUFFER_LEN = 256;
IanBenzMaxim 76:84e6c4994e29 115 volatile struct ds2480b_circular_buff_s
IanBenzMaxim 76:84e6c4994e29 116 {
IanBenzMaxim 76:84e6c4994e29 117 uint8_t w_idx;
IanBenzMaxim 76:84e6c4994e29 118 uint8_t r_idx;
IanBenzMaxim 76:84e6c4994e29 119 uint8_t rx_bytes_available;
IanBenzMaxim 76:84e6c4994e29 120 bool wrap_error;
IanBenzMaxim 76:84e6c4994e29 121 uint8_t buff[MAX_RX_BUFFER_LEN];
IanBenzMaxim 76:84e6c4994e29 122 }rx_buffer;
IanBenzMaxim 76:84e6c4994e29 123 };
IanBenzMaxim 73:2cecc1372acc 124 }
j3 3:644fc630f958 125
IanBenzMaxim 74:23be10c32fa3 126 #endif
j3 3:644fc630f958 127