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