Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Max32630_One_Wire_Interface
OneWire_Masters/GPIO/owgpio.h@10:0df2cc66fc47, 2016-03-05 (annotated)
- Committer:
- j3
- Date:
- Sat Mar 05 01:51:00 2016 +0000
- Revision:
- 10:0df2cc66fc47
- Parent:
- 9:641516a3f0dc
- Child:
- 11:2833f27ba319
updated OwGpio master to use hardware timer and gpio. OwGpio master is only supported on MAX32600MBED board, all other masters are supported across platforms.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| j3 | 3:644fc630f958 | 1 | /******************************************************************//** |
| j3 | 3:644fc630f958 | 2 | * @file owgpio.h |
| j3 | 3:644fc630f958 | 3 | * |
| j3 | 3:644fc630f958 | 4 | * @author Justin Jordan |
| j3 | 3:644fc630f958 | 5 | * |
| j3 | 3:644fc630f958 | 6 | * @version 0.0.0 |
| j3 | 3:644fc630f958 | 7 | * |
| j3 | 3:644fc630f958 | 8 | * Started: 31JAN16 |
| j3 | 3:644fc630f958 | 9 | * |
| j3 | 3:644fc630f958 | 10 | * Updated: |
| j3 | 3:644fc630f958 | 11 | * |
| j3 | 3:644fc630f958 | 12 | * @brief Header file for bit-banging a 1-wire master |
| j3 | 3:644fc630f958 | 13 | *********************************************************************** |
| j3 | 3:644fc630f958 | 14 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
| j3 | 3:644fc630f958 | 15 | * |
| j3 | 3:644fc630f958 | 16 | * Permission is hereby granted, free of charge, to any person obtaining a |
| j3 | 3:644fc630f958 | 17 | * copy of this software and associated documentation files (the "Software"), |
| j3 | 3:644fc630f958 | 18 | * to deal in the Software without restriction, including without limitation |
| j3 | 3:644fc630f958 | 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| j3 | 3:644fc630f958 | 20 | * and/or sell copies of the Software, and to permit persons to whom the |
| j3 | 3:644fc630f958 | 21 | * Software is furnished to do so, subject to the following conditions: |
| j3 | 3:644fc630f958 | 22 | * |
| j3 | 3:644fc630f958 | 23 | * The above copyright notice and this permission notice shall be included |
| j3 | 3:644fc630f958 | 24 | * in all copies or substantial portions of the Software. |
| j3 | 3:644fc630f958 | 25 | * |
| j3 | 3:644fc630f958 | 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| j3 | 3:644fc630f958 | 27 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| j3 | 3:644fc630f958 | 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| j3 | 3:644fc630f958 | 29 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
| j3 | 3:644fc630f958 | 30 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| j3 | 3:644fc630f958 | 31 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| j3 | 3:644fc630f958 | 32 | * OTHER DEALINGS IN THE SOFTWARE. |
| j3 | 3:644fc630f958 | 33 | * |
| j3 | 3:644fc630f958 | 34 | * Except as contained in this notice, the name of Maxim Integrated |
| j3 | 3:644fc630f958 | 35 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
| j3 | 3:644fc630f958 | 36 | * Products, Inc. Branding Policy. |
| j3 | 3:644fc630f958 | 37 | * |
| j3 | 3:644fc630f958 | 38 | * The mere transfer of this software does not imply any licenses |
| j3 | 3:644fc630f958 | 39 | * of trade secrets, proprietary technology, copyrights, patents, |
| j3 | 3:644fc630f958 | 40 | * trademarks, maskwork rights, or any other form of intellectual |
| j3 | 3:644fc630f958 | 41 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
| j3 | 3:644fc630f958 | 42 | * ownership rights. |
| j3 | 3:644fc630f958 | 43 | **********************************************************************/ |
| j3 | 3:644fc630f958 | 44 | |
| j3 | 3:644fc630f958 | 45 | |
| j3 | 3:644fc630f958 | 46 | #ifndef OWGPIO_H |
| j3 | 3:644fc630f958 | 47 | #define OWGPIO_H |
| j3 | 3:644fc630f958 | 48 | |
| j3 | 3:644fc630f958 | 49 | |
| j3 | 10:0df2cc66fc47 | 50 | #if(TARGET_MAX32600) |
| j3 | 10:0df2cc66fc47 | 51 | |
| j3 | 10:0df2cc66fc47 | 52 | |
| j3 | 3:644fc630f958 | 53 | #include "mbed.h" |
| j3 | 3:644fc630f958 | 54 | #include "OneWireInterface.h" |
| j3 | 5:ce108eeb878d | 55 | #include "OneWireMastersShared.h" |
| j3 | 3:644fc630f958 | 56 | |
| j3 | 3:644fc630f958 | 57 | |
| j3 | 3:644fc630f958 | 58 | class OwGpio: public OneWireInterface |
| j3 | 3:644fc630f958 | 59 | { |
| j3 | 3:644fc630f958 | 60 | public: |
| j3 | 3:644fc630f958 | 61 | |
| j3 | 10:0df2cc66fc47 | 62 | //1-wire timming constants for bit-bang. |
| j3 | 10:0df2cc66fc47 | 63 | //Bit-Bang Master only supported on MAX32600MBED board |
| j3 | 10:0df2cc66fc47 | 64 | //All times are in terms of micro seconds |
| j3 | 9:641516a3f0dc | 65 | |
| j3 | 10:0df2cc66fc47 | 66 | static const uint16_t TRSTL_STD = 560; |
| j3 | 10:0df2cc66fc47 | 67 | static const uint16_t TRSTL_OVD = 56; |
| j3 | 9:641516a3f0dc | 68 | |
| j3 | 9:641516a3f0dc | 69 | //Master sample time for PD |
| j3 | 10:0df2cc66fc47 | 70 | static const uint16_t TMSP_STD = 68; |
| j3 | 10:0df2cc66fc47 | 71 | static const uint16_t TMSP_OVD = 8; |
| j3 | 9:641516a3f0dc | 72 | |
| j3 | 9:641516a3f0dc | 73 | //Write 0 |
| j3 | 10:0df2cc66fc47 | 74 | static const uint16_t TW0L_STD = 64; |
| j3 | 10:0df2cc66fc47 | 75 | static const uint16_t TW0L_OVD = 8; |
| j3 | 9:641516a3f0dc | 76 | |
| j3 | 9:641516a3f0dc | 77 | //Write 1, Read low time |
| j3 | 10:0df2cc66fc47 | 78 | static const uint16_t TW1L_STD = 8; |
| j3 | 10:0df2cc66fc47 | 79 | static const uint16_t TW1L_OVD = 1; |
| j3 | 9:641516a3f0dc | 80 | |
| j3 | 9:641516a3f0dc | 81 | //Master sample time for bit |
| j3 | 10:0df2cc66fc47 | 82 | static const uint16_t TMSR_STD = 12; |
| j3 | 10:0df2cc66fc47 | 83 | static const uint16_t TMSR_OVD = 1; |
| j3 | 9:641516a3f0dc | 84 | |
| j3 | 10:0df2cc66fc47 | 85 | //make sure to use TSLOT for recoveries |
| j3 | 10:0df2cc66fc47 | 86 | static const uint16_t TSLOT_STD = 70; |
| j3 | 10:0df2cc66fc47 | 87 | static const uint16_t TSLOT_OVD = 10; |
| j3 | 9:641516a3f0dc | 88 | |
| j3 | 9:641516a3f0dc | 89 | |
| j3 | 3:644fc630f958 | 90 | /**********************************************************//** |
| j3 | 10:0df2cc66fc47 | 91 | * @brief Owgpio constructor |
| j3 | 10:0df2cc66fc47 | 92 | * |
| j3 | 10:0df2cc66fc47 | 93 | * @details Initializes given pin for open-drain operation |
| j3 | 10:0df2cc66fc47 | 94 | * |
| j3 | 10:0df2cc66fc47 | 95 | * On Entry: |
| j3 | 10:0df2cc66fc47 | 96 | * |
| j3 | 10:0df2cc66fc47 | 97 | * @para[in] ow_gpio - GPIO pin to use for One Wire bus |
| j3 | 10:0df2cc66fc47 | 98 | * |
| j3 | 10:0df2cc66fc47 | 99 | * @param[in] ext_spu - GPIO pin to use for Strong Pull-Up |
| j3 | 10:0df2cc66fc47 | 100 | * |
| j3 | 10:0df2cc66fc47 | 101 | * On Exit: |
| j3 | 10:0df2cc66fc47 | 102 | * |
| j3 | 10:0df2cc66fc47 | 103 | * @return |
| j3 | 10:0df2cc66fc47 | 104 | **************************************************************/ |
| j3 | 10:0df2cc66fc47 | 105 | OwGpio(PinName ow_gpio, PinName ext_spu = NC); |
| j3 | 10:0df2cc66fc47 | 106 | |
| j3 | 10:0df2cc66fc47 | 107 | |
| j3 | 10:0df2cc66fc47 | 108 | /**********************************************************//** |
| j3 | 10:0df2cc66fc47 | 109 | * @brief OwGpio destructor |
| j3 | 10:0df2cc66fc47 | 110 | * |
| j3 | 10:0df2cc66fc47 | 111 | * @details |
| j3 | 10:0df2cc66fc47 | 112 | * |
| j3 | 10:0df2cc66fc47 | 113 | * On Entry: |
| j3 | 10:0df2cc66fc47 | 114 | * |
| j3 | 10:0df2cc66fc47 | 115 | * On Exit: |
| j3 | 10:0df2cc66fc47 | 116 | * |
| j3 | 10:0df2cc66fc47 | 117 | * @return |
| j3 | 10:0df2cc66fc47 | 118 | **************************************************************/ |
| j3 | 10:0df2cc66fc47 | 119 | virtual ~OwGpio(); |
| j3 | 10:0df2cc66fc47 | 120 | |
| j3 | 10:0df2cc66fc47 | 121 | |
| j3 | 10:0df2cc66fc47 | 122 | /**********************************************************//** |
| j3 | 10:0df2cc66fc47 | 123 | * @brief initializes 16-bit counter_0 of TMR3 on MAX32600MBED |
| j3 | 3:644fc630f958 | 124 | * |
| j3 | 3:644fc630f958 | 125 | * @details |
| j3 | 3:644fc630f958 | 126 | * |
| j3 | 3:644fc630f958 | 127 | * On Entry: |
| j3 | 3:644fc630f958 | 128 | * |
| j3 | 3:644fc630f958 | 129 | * On Exit: |
| j3 | 10:0df2cc66fc47 | 130 | * |
| j3 | 10:0df2cc66fc47 | 131 | * @return |
| j3 | 3:644fc630f958 | 132 | **************************************************************/ |
| j3 | 10:0df2cc66fc47 | 133 | static void init_ow_timer(void); |
| j3 | 3:644fc630f958 | 134 | |
| j3 | 3:644fc630f958 | 135 | |
| j3 | 3:644fc630f958 | 136 | /***** OW API ****************************************************/ |
| j3 | 3:644fc630f958 | 137 | virtual bool OWReset(); |
| j3 | 3:644fc630f958 | 138 | |
| j3 | 3:644fc630f958 | 139 | virtual void OWWriteBit(uint8_t sendbit); |
| j3 | 3:644fc630f958 | 140 | |
| j3 | 3:644fc630f958 | 141 | virtual uint8_t OWReadBit(); |
| j3 | 3:644fc630f958 | 142 | |
| j3 | 3:644fc630f958 | 143 | virtual uint8_t OWTouchBit(uint8_t sendbit); |
| j3 | 3:644fc630f958 | 144 | |
| j3 | 3:644fc630f958 | 145 | virtual bool OWWriteByte(uint8_t sendbyte); |
| j3 | 3:644fc630f958 | 146 | |
| j3 | 3:644fc630f958 | 147 | virtual uint8_t OWReadByte(void); |
| j3 | 3:644fc630f958 | 148 | |
| j3 | 3:644fc630f958 | 149 | virtual uint8_t OWTouchByte(uint8_t sendbyte); |
| j3 | 3:644fc630f958 | 150 | |
| j3 | 3:644fc630f958 | 151 | virtual void OWBlock(uint8_t *tran_buf, uint8_t tran_len); |
| j3 | 5:ce108eeb878d | 152 | |
| j3 | 5:ce108eeb878d | 153 | virtual void OWWriteBlock(const uint8_t *tran_buf, uint8_t tran_len); |
| j3 | 5:ce108eeb878d | 154 | |
| j3 | 5:ce108eeb878d | 155 | virtual void OWReadBlock(uint8_t *recv_buf, uint8_t recv_len); |
| j3 | 3:644fc630f958 | 156 | |
| j3 | 3:644fc630f958 | 157 | virtual bool OWFirst(void); |
| j3 | 3:644fc630f958 | 158 | |
| j3 | 3:644fc630f958 | 159 | virtual bool OWNext(void); |
| j3 | 3:644fc630f958 | 160 | |
| j3 | 3:644fc630f958 | 161 | virtual bool OWVerify(void); |
| j3 | 3:644fc630f958 | 162 | |
| j3 | 3:644fc630f958 | 163 | virtual void OWTargetSetup(uint8_t family_code); |
| j3 | 3:644fc630f958 | 164 | |
| j3 | 3:644fc630f958 | 165 | virtual void OWFamilySkipSetup(void); |
| j3 | 3:644fc630f958 | 166 | |
| j3 | 3:644fc630f958 | 167 | virtual bool OWSearch(void); |
| j3 | 5:ce108eeb878d | 168 | |
| j3 | 5:ce108eeb878d | 169 | virtual bool OWReadROM(void); |
| j3 | 5:ce108eeb878d | 170 | |
| j3 | 5:ce108eeb878d | 171 | virtual bool OWSkipROM(void); |
| j3 | 5:ce108eeb878d | 172 | |
| j3 | 5:ce108eeb878d | 173 | virtual bool OWMatchROM(void); |
| j3 | 5:ce108eeb878d | 174 | |
| j3 | 5:ce108eeb878d | 175 | virtual bool OWOverdriveSkipROM(void); |
| j3 | 5:ce108eeb878d | 176 | |
| j3 | 5:ce108eeb878d | 177 | virtual bool OWOverdriveMatchROM(void); |
| j3 | 5:ce108eeb878d | 178 | |
| j3 | 5:ce108eeb878d | 179 | virtual bool OWResume(void); |
| j3 | 3:644fc630f958 | 180 | |
| j3 | 5:ce108eeb878d | 181 | virtual uint8_t OWSpeed(OW_SPEED new_speed); |
| j3 | 3:644fc630f958 | 182 | |
| j3 | 5:ce108eeb878d | 183 | virtual uint8_t OWLevel(OW_LEVEL new_level); |
| j3 | 3:644fc630f958 | 184 | |
| j3 | 3:644fc630f958 | 185 | virtual bool OWWriteBytePower(uint8_t sendbyte); |
| j3 | 3:644fc630f958 | 186 | |
| j3 | 3:644fc630f958 | 187 | virtual bool OWReadBitPower(uint8_t applyPowerResponse); |
| j3 | 3:644fc630f958 | 188 | |
| j3 | 5:ce108eeb878d | 189 | virtual const uint8_t (&OWgetROMnumber() const)[ROMnumberLen]; |
| j3 | 3:644fc630f958 | 190 | |
| j3 | 3:644fc630f958 | 191 | private: |
| j3 | 3:644fc630f958 | 192 | |
| j3 | 10:0df2cc66fc47 | 193 | void init_ow_gpio(PinName ow_gpio); |
| j3 | 10:0df2cc66fc47 | 194 | |
| j3 | 5:ce108eeb878d | 195 | DigitalOut _ext_spu; |
| j3 | 9:641516a3f0dc | 196 | OW_SPEED _ow_speed; |
| j3 | 9:641516a3f0dc | 197 | OW_LEVEL _ow_level; |
| j3 | 9:641516a3f0dc | 198 | |
| j3 | 10:0df2cc66fc47 | 199 | uint32_t _ow_port; |
| j3 | 10:0df2cc66fc47 | 200 | uint32_t _ow_pin; |
| j3 | 10:0df2cc66fc47 | 201 | |
| j3 | 9:641516a3f0dc | 202 | // Search state |
| j3 | 5:ce108eeb878d | 203 | uint8_t _rom_number[ROMnumberLen]; |
| j3 | 9:641516a3f0dc | 204 | uint8_t _last_discrepancy; |
| j3 | 9:641516a3f0dc | 205 | uint8_t _last_family_discrepancy; |
| j3 | 9:641516a3f0dc | 206 | uint8_t _last_device_flag; |
| j3 | 9:641516a3f0dc | 207 | uint8_t _crc8; |
| j3 | 3:644fc630f958 | 208 | }; |
| j3 | 3:644fc630f958 | 209 | |
| j3 | 10:0df2cc66fc47 | 210 | #endif/* TARGET_MAX32600*/ |
| j3 | 3:644fc630f958 | 211 | #endif /*OWGPIO_H*/ |