Mike Fruge / OneWire

Dependents:   Max32630_One_Wire_Interface

Committer:
j3
Date:
Fri Mar 18 20:21:05 2016 +0000
Revision:
17:b646b1e3970b
Parent:
15:f6cb0d906fb6
Child:
23:e8e403d61359
Updated library with error codes on return statements

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
j3 3:644fc630f958 33
j3 3:644fc630f958 34 #ifndef OWGPIO_H
j3 3:644fc630f958 35 #define OWGPIO_H
j3 3:644fc630f958 36
j3 3:644fc630f958 37
j3 10:0df2cc66fc47 38 #if(TARGET_MAX32600)
j3 10:0df2cc66fc47 39
j3 10:0df2cc66fc47 40
j3 3:644fc630f958 41 #include "mbed.h"
j3 3:644fc630f958 42 #include "OneWireInterface.h"
j3 15:f6cb0d906fb6 43 #include "OneWireMaster.h"
j3 3:644fc630f958 44
j3 3:644fc630f958 45
j3 15:f6cb0d906fb6 46 class OwGpio: public OneWireMaster
j3 3:644fc630f958 47 {
j3 3:644fc630f958 48 public:
j3 3:644fc630f958 49
j3 10:0df2cc66fc47 50 //1-wire timming constants for bit-bang.
j3 10:0df2cc66fc47 51 //Bit-Bang Master only supported on MAX32600MBED board
j3 10:0df2cc66fc47 52 //All times are in terms of micro seconds
j3 9:641516a3f0dc 53
j3 10:0df2cc66fc47 54 static const uint16_t TRSTL_STD = 560;
j3 10:0df2cc66fc47 55 static const uint16_t TRSTL_OVD = 56;
j3 9:641516a3f0dc 56
j3 9:641516a3f0dc 57 //Master sample time for PD
j3 10:0df2cc66fc47 58 static const uint16_t TMSP_STD = 68;
j3 10:0df2cc66fc47 59 static const uint16_t TMSP_OVD = 8;
j3 9:641516a3f0dc 60
j3 9:641516a3f0dc 61 //Write 0
j3 10:0df2cc66fc47 62 static const uint16_t TW0L_STD = 64;
j3 10:0df2cc66fc47 63 static const uint16_t TW0L_OVD = 8;
j3 9:641516a3f0dc 64
j3 9:641516a3f0dc 65 //Write 1, Read low time
j3 10:0df2cc66fc47 66 static const uint16_t TW1L_STD = 8;
j3 11:2833f27ba319 67 static const uint16_t TW1L_OVD = 0; //closest to 1us I can get
j3 9:641516a3f0dc 68
j3 9:641516a3f0dc 69 //Master sample time for bit
j3 10:0df2cc66fc47 70 static const uint16_t TMSR_STD = 12;
j3 11:2833f27ba319 71 static const uint16_t TMSR_OVD = 0; //closest to 1us I can get
j3 9:641516a3f0dc 72
j3 10:0df2cc66fc47 73 //make sure to use TSLOT for recoveries
j3 10:0df2cc66fc47 74 static const uint16_t TSLOT_STD = 70;
j3 10:0df2cc66fc47 75 static const uint16_t TSLOT_OVD = 10;
j3 9:641516a3f0dc 76
j3 9:641516a3f0dc 77
j3 14:7b2886a50321 78 //counts instances of this class being created
j3 14:7b2886a50321 79 static uint32_t ow_instance_cnt;
j3 14:7b2886a50321 80
j3 14:7b2886a50321 81
j3 3:644fc630f958 82 /**********************************************************//**
j3 10:0df2cc66fc47 83 * @brief Owgpio constructor
j3 10:0df2cc66fc47 84 *
j3 10:0df2cc66fc47 85 * @details Initializes given pin for open-drain operation
j3 10:0df2cc66fc47 86 *
j3 10:0df2cc66fc47 87 * On Entry:
j3 10:0df2cc66fc47 88 *
j3 10:0df2cc66fc47 89 * @para[in] ow_gpio - GPIO pin to use for One Wire bus
j3 10:0df2cc66fc47 90 *
j3 10:0df2cc66fc47 91 * @param[in] ext_spu - GPIO pin to use for Strong Pull-Up
j3 10:0df2cc66fc47 92 *
j3 10:0df2cc66fc47 93 * On Exit:
j3 10:0df2cc66fc47 94 *
j3 10:0df2cc66fc47 95 * @return
j3 10:0df2cc66fc47 96 **************************************************************/
j3 10:0df2cc66fc47 97 OwGpio(PinName ow_gpio, PinName ext_spu = NC);
j3 10:0df2cc66fc47 98
j3 10:0df2cc66fc47 99
j3 10:0df2cc66fc47 100 /**********************************************************//**
j3 10:0df2cc66fc47 101 * @brief OwGpio destructor
j3 10:0df2cc66fc47 102 *
j3 10:0df2cc66fc47 103 * @details
j3 10:0df2cc66fc47 104 *
j3 10:0df2cc66fc47 105 * On Entry:
j3 10:0df2cc66fc47 106 *
j3 10:0df2cc66fc47 107 * On Exit:
j3 10:0df2cc66fc47 108 *
j3 10:0df2cc66fc47 109 * @return
j3 10:0df2cc66fc47 110 **************************************************************/
j3 10:0df2cc66fc47 111 virtual ~OwGpio();
j3 10:0df2cc66fc47 112
j3 10:0df2cc66fc47 113
j3 15:f6cb0d906fb6 114 //Part of OneWireInterface that should be implemented for each master
j3 15:f6cb0d906fb6 115 //See OneWireInterface.h for documentation
j3 15:f6cb0d906fb6 116
j3 17:b646b1e3970b 117 virtual OneWireInterface::CmdResult OWInitMaster(void);
j3 3:644fc630f958 118
j3 17:b646b1e3970b 119 virtual OneWireInterface::CmdResult OWReset(void);
j3 3:644fc630f958 120
j3 17:b646b1e3970b 121 virtual OneWireInterface::CmdResult OWTouchBit(uint8_t & sendrecvbit);
j3 17:b646b1e3970b 122
j3 17:b646b1e3970b 123 virtual OneWireInterface::CmdResult OWWriteByte(uint8_t sendbyte);
j3 3:644fc630f958 124
j3 17:b646b1e3970b 125 virtual OneWireInterface::CmdResult OWReadByte(uint8_t & recvbyte);
j3 17:b646b1e3970b 126
j3 17:b646b1e3970b 127 virtual OneWireInterface::CmdResult OWWriteBlock(const uint8_t *tran_buf, uint8_t tran_len);
j3 3:644fc630f958 128
j3 17:b646b1e3970b 129 virtual OneWireInterface::CmdResult OWReadBlock(uint8_t *rx_buf, uint8_t rx_len);
j3 17:b646b1e3970b 130
j3 17:b646b1e3970b 131 virtual OneWireInterface::CmdResult OWSearch(RomId & romId);
j3 3:644fc630f958 132
j3 17:b646b1e3970b 133 virtual OneWireInterface::CmdResult OWSpeed(OW_SPEED new_speed);
j3 3:644fc630f958 134
j3 17:b646b1e3970b 135 virtual OneWireInterface::CmdResult OWLevel(OW_LEVEL new_level);
j3 3:644fc630f958 136
j3 17:b646b1e3970b 137 virtual OneWireInterface::CmdResult OWWriteBytePower(uint8_t sendbyte);
j3 3:644fc630f958 138
j3 17:b646b1e3970b 139 virtual OneWireInterface::CmdResult OWReadBitPower(uint8_t applyPowerResponse);
j3 3:644fc630f958 140
j3 3:644fc630f958 141 private:
j3 3:644fc630f958 142
j3 14:7b2886a50321 143 static void init_ow_timer(void);
j3 14:7b2886a50321 144 static void release_ow_timer(void);
j3 14:7b2886a50321 145
j3 14:7b2886a50321 146 void init_ow_gpio(uint32_t ow_port, uint32_t ow_pin);
j3 14:7b2886a50321 147 void release_ow_gpio();
j3 14:7b2886a50321 148
j3 14:7b2886a50321 149 //specific instance of this class
j3 14:7b2886a50321 150 uint32_t _ow_instance;
j3 10:0df2cc66fc47 151
j3 5:ce108eeb878d 152 DigitalOut _ext_spu;
j3 9:641516a3f0dc 153 OW_SPEED _ow_speed;
j3 9:641516a3f0dc 154 OW_LEVEL _ow_level;
j3 9:641516a3f0dc 155
j3 10:0df2cc66fc47 156 uint32_t _ow_port;
j3 15:f6cb0d906fb6 157 uint32_t _ow_pin;
j3 3:644fc630f958 158 };
j3 3:644fc630f958 159
j3 10:0df2cc66fc47 160 #endif/* TARGET_MAX32600*/
j3 3:644fc630f958 161 #endif /*OWGPIO_H*/