Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

Committer:
IanBenzMaxim
Date:
Thu Jan 11 13:50:39 2018 -0600
Revision:
3:f818ea5172ed
Parent:
0:f77ad7f72d04
Child:
6:a8c83a2e6fa4
Updated to version 1.1.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 0:f77ad7f72d04 1 /*******************************************************************************
IanBenzMaxim 0:f77ad7f72d04 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 0:f77ad7f72d04 3 *
IanBenzMaxim 0:f77ad7f72d04 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 0:f77ad7f72d04 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 0:f77ad7f72d04 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 0:f77ad7f72d04 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 0:f77ad7f72d04 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 0:f77ad7f72d04 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 0:f77ad7f72d04 10 *
IanBenzMaxim 0:f77ad7f72d04 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 0:f77ad7f72d04 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 0:f77ad7f72d04 13 *
IanBenzMaxim 0:f77ad7f72d04 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 0:f77ad7f72d04 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 0:f77ad7f72d04 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 0:f77ad7f72d04 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 0:f77ad7f72d04 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 0:f77ad7f72d04 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 0:f77ad7f72d04 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 0:f77ad7f72d04 21 *
IanBenzMaxim 0:f77ad7f72d04 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 24 * Products, Inc. Branding Policy.
IanBenzMaxim 0:f77ad7f72d04 25 *
IanBenzMaxim 0:f77ad7f72d04 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 0:f77ad7f72d04 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 0:f77ad7f72d04 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 0:f77ad7f72d04 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 0:f77ad7f72d04 30 * ownership rights.
IanBenzMaxim 0:f77ad7f72d04 31 *******************************************************************************/
IanBenzMaxim 0:f77ad7f72d04 32
IanBenzMaxim 0:f77ad7f72d04 33 #ifndef MaximInterface_DS2480B
IanBenzMaxim 0:f77ad7f72d04 34 #define MaximInterface_DS2480B
IanBenzMaxim 0:f77ad7f72d04 35
IanBenzMaxim 0:f77ad7f72d04 36 #include <MaximInterface/Links/OneWireMaster.hpp>
IanBenzMaxim 0:f77ad7f72d04 37 #include <MaximInterface/Links/Sleep.hpp>
IanBenzMaxim 0:f77ad7f72d04 38 #include <MaximInterface/Links/Uart.hpp>
IanBenzMaxim 0:f77ad7f72d04 39 #include <MaximInterface/Utilities/Export.h>
IanBenzMaxim 0:f77ad7f72d04 40
IanBenzMaxim 0:f77ad7f72d04 41 namespace MaximInterface {
IanBenzMaxim 0:f77ad7f72d04 42
IanBenzMaxim 0:f77ad7f72d04 43 /// Serial to 1-Wire Line Driver
IanBenzMaxim 0:f77ad7f72d04 44 class DS2480B : public OneWireMaster {
IanBenzMaxim 0:f77ad7f72d04 45 public:
IanBenzMaxim 0:f77ad7f72d04 46 enum ErrorValue {
IanBenzMaxim 3:f818ea5172ed 47 HardwareError = 1
IanBenzMaxim 0:f77ad7f72d04 48 };
IanBenzMaxim 0:f77ad7f72d04 49
IanBenzMaxim 0:f77ad7f72d04 50 DS2480B(const Sleep & sleep, Uart & uart) : sleep(&sleep), uart(&uart) {}
IanBenzMaxim 0:f77ad7f72d04 51
IanBenzMaxim 0:f77ad7f72d04 52 void setSleep(const Sleep & sleep) { this->sleep = &sleep; }
IanBenzMaxim 0:f77ad7f72d04 53 void setUart(Uart & uart) { this->uart = &uart; }
IanBenzMaxim 0:f77ad7f72d04 54
IanBenzMaxim 0:f77ad7f72d04 55 MaximInterface_EXPORT error_code initialize();
IanBenzMaxim 0:f77ad7f72d04 56
IanBenzMaxim 0:f77ad7f72d04 57 MaximInterface_EXPORT virtual error_code reset();
IanBenzMaxim 0:f77ad7f72d04 58 MaximInterface_EXPORT virtual error_code touchBitSetLevel(bool & sendRecvBit,
IanBenzMaxim 0:f77ad7f72d04 59 Level afterLevel);
IanBenzMaxim 0:f77ad7f72d04 60 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 61 writeByteSetLevel(uint_least8_t sendByte, Level afterLevel);
IanBenzMaxim 0:f77ad7f72d04 62 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 63 readByteSetLevel(uint_least8_t & recvByte, Level afterLevel);
IanBenzMaxim 0:f77ad7f72d04 64 MaximInterface_EXPORT virtual error_code setSpeed(Speed newSpeed);
IanBenzMaxim 0:f77ad7f72d04 65 MaximInterface_EXPORT virtual error_code setLevel(Level newLevel);
IanBenzMaxim 0:f77ad7f72d04 66
IanBenzMaxim 0:f77ad7f72d04 67 MaximInterface_EXPORT static const error_category & errorCategory();
IanBenzMaxim 0:f77ad7f72d04 68
IanBenzMaxim 3:f818ea5172ed 69 protected:
IanBenzMaxim 3:f818ea5172ed 70 MaximInterface_EXPORT error_code sendCommand(uint_least8_t command);
IanBenzMaxim 3:f818ea5172ed 71
IanBenzMaxim 0:f77ad7f72d04 72 private:
IanBenzMaxim 0:f77ad7f72d04 73 /// Baud rates for DS2480B
IanBenzMaxim 0:f77ad7f72d04 74 enum BaudRate {
IanBenzMaxim 0:f77ad7f72d04 75 Baud9600bps = 0, ///< 9600 bps
IanBenzMaxim 0:f77ad7f72d04 76 Baud19200bps = 2, ///< 19200 bps
IanBenzMaxim 0:f77ad7f72d04 77 Baud57600bps = 4, ///< 57600 bps
IanBenzMaxim 0:f77ad7f72d04 78 Baud115200bps = 6 ///< 115200 bps
IanBenzMaxim 0:f77ad7f72d04 79 };
IanBenzMaxim 0:f77ad7f72d04 80
IanBenzMaxim 0:f77ad7f72d04 81 error_code changeBaud(BaudRate newBaud);
IanBenzMaxim 0:f77ad7f72d04 82 error_code setComBaud(BaudRate newBaud);
IanBenzMaxim 0:f77ad7f72d04 83 error_code breakCom();
IanBenzMaxim 0:f77ad7f72d04 84
IanBenzMaxim 0:f77ad7f72d04 85 const Sleep * sleep;
IanBenzMaxim 0:f77ad7f72d04 86 Uart * uart;
IanBenzMaxim 0:f77ad7f72d04 87
IanBenzMaxim 0:f77ad7f72d04 88 Level level;
IanBenzMaxim 0:f77ad7f72d04 89 BaudRate baud;
IanBenzMaxim 0:f77ad7f72d04 90 uint_least8_t mode;
IanBenzMaxim 0:f77ad7f72d04 91 uint_least8_t speed;
IanBenzMaxim 0:f77ad7f72d04 92 };
IanBenzMaxim 0:f77ad7f72d04 93
IanBenzMaxim 0:f77ad7f72d04 94 inline error_code make_error_code(DS2480B::ErrorValue e) {
IanBenzMaxim 0:f77ad7f72d04 95 return error_code(e, DS2480B::errorCategory());
IanBenzMaxim 0:f77ad7f72d04 96 }
IanBenzMaxim 0:f77ad7f72d04 97
IanBenzMaxim 0:f77ad7f72d04 98 } // namespace MaximInterface
IanBenzMaxim 0:f77ad7f72d04 99
IanBenzMaxim 0:f77ad7f72d04 100 #endif