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.
OneWire_Masters/DS2480B/ds2480b.h@71:562f5c702094, 2016-05-09 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Mon May 09 15:04:23 2016 -0500
- Revision:
- 71:562f5c702094
- Parent:
- 67:76776130aec9
- Child:
- 72:6892702709ee
Added default implementation of OWWriteBlock() and OWReadBlock() to OneWireMaster.
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 DS2480B_H |
j3 | 3:644fc630f958 | 35 | #define DS2480B_H |
j3 | 3:644fc630f958 | 36 | |
j3 | 3:644fc630f958 | 37 | |
j3 | 3:644fc630f958 | 38 | #include "mbed.h" |
IanBenzMaxim | 24:8942d8478d68 | 39 | #include "OneWire_Masters/OneWireMaster.h" |
j3 | 3:644fc630f958 | 40 | |
j3 | 3:644fc630f958 | 41 | |
j3 | 15:f6cb0d906fb6 | 42 | class Ds2480b: public OneWireMaster |
j3 | 3:644fc630f958 | 43 | { |
j3 | 3:644fc630f958 | 44 | public: |
j3 | 3:644fc630f958 | 45 | |
j3 | 63:422be898443a | 46 | enum DS2480B_BPS |
j3 | 63:422be898443a | 47 | { |
j3 | 63:422be898443a | 48 | BPS_9600 = 0, |
j3 | 63:422be898443a | 49 | BPS_19200 = 2, |
j3 | 63:422be898443a | 50 | BPS_57600 = 4, |
j3 | 63:422be898443a | 51 | BPS_115200 = 6 |
j3 | 63:422be898443a | 52 | }; |
j3 | 63:422be898443a | 53 | |
j3 | 3:644fc630f958 | 54 | /**********************************************************//** |
j3 | 3:644fc630f958 | 55 | * @brief Ds2480b constructor |
j3 | 3:644fc630f958 | 56 | * |
j3 | 3:644fc630f958 | 57 | * @details allows user to use existing Serial object |
j3 | 3:644fc630f958 | 58 | * |
j3 | 3:644fc630f958 | 59 | * On Entry: |
j3 | 3:644fc630f958 | 60 | * @param[in] p_serial - pointer to existing serial object |
j3 | 3:644fc630f958 | 61 | * |
j3 | 3:644fc630f958 | 62 | * On Exit: |
j3 | 3:644fc630f958 | 63 | * @return |
j3 | 3:644fc630f958 | 64 | **************************************************************/ |
j3 | 16:883becbd85f8 | 65 | Ds2480b(Serial &p_serial); |
j3 | 3:644fc630f958 | 66 | |
j3 | 3:644fc630f958 | 67 | |
j3 | 3:644fc630f958 | 68 | /**********************************************************//** |
j3 | 3:644fc630f958 | 69 | * @brief Ds2480b constructor |
j3 | 3:644fc630f958 | 70 | * |
j3 | 3:644fc630f958 | 71 | * @details Object instantiates a new serial object with no |
j3 | 3:644fc630f958 | 72 | * public access |
j3 | 3:644fc630f958 | 73 | * |
j3 | 3:644fc630f958 | 74 | * On Entry: |
j3 | 3:644fc630f958 | 75 | * @param[in] tx - tx pin of uart to be used |
j3 | 3:644fc630f958 | 76 | * @param[in] rx - rx pin of uart to be used |
j3 | 3:644fc630f958 | 77 | * @param[in] baud - baudrate for uart |
j3 | 3:644fc630f958 | 78 | * |
j3 | 3:644fc630f958 | 79 | * On Exit: |
j3 | 3:644fc630f958 | 80 | * @return |
j3 | 3:644fc630f958 | 81 | **************************************************************/ |
j3 | 63:422be898443a | 82 | Ds2480b(PinName tx, PinName rx); |
j3 | 3:644fc630f958 | 83 | |
j3 | 3:644fc630f958 | 84 | |
j3 | 3:644fc630f958 | 85 | /**********************************************************//** |
j3 | 3:644fc630f958 | 86 | * @brief Ds2480b destructor |
j3 | 3:644fc630f958 | 87 | * |
j3 | 3:644fc630f958 | 88 | * @details deletes serial object if owner |
j3 | 3:644fc630f958 | 89 | * |
j3 | 3:644fc630f958 | 90 | * On Entry: |
j3 | 3:644fc630f958 | 91 | * |
j3 | 3:644fc630f958 | 92 | * On Exit: |
j3 | 3:644fc630f958 | 93 | * @return |
j3 | 3:644fc630f958 | 94 | **************************************************************/ |
j3 | 15:f6cb0d906fb6 | 95 | virtual ~Ds2480b(); |
j3 | 3:644fc630f958 | 96 | |
j3 | 63:422be898443a | 97 | OneWireMaster::CmdResult DS2480B_ChangeBaud(DS2480B_BPS newbaud); |
j3 | 63:422be898443a | 98 | |
j3 | 3:644fc630f958 | 99 | |
j3 | 23:e8e403d61359 | 100 | //Part of OneWireMaster that should be implemented for each master |
j3 | 23:e8e403d61359 | 101 | //See OneWireMaster.h for documentation |
j3 | 15:f6cb0d906fb6 | 102 | |
j3 | 23:e8e403d61359 | 103 | virtual OneWireMaster::CmdResult OWInitMaster(void); |
j3 | 14:7b2886a50321 | 104 | |
j3 | 23:e8e403d61359 | 105 | virtual OneWireMaster::CmdResult OWReset(void); |
j3 | 3:644fc630f958 | 106 | |
IanBenzMaxim | 32:bce180b544ed | 107 | virtual OneWireMaster::CmdResult OWTouchBit(uint8_t & sendrecvbit, OWLevel after_level); |
j3 | 17:b646b1e3970b | 108 | |
IanBenzMaxim | 32:bce180b544ed | 109 | virtual OneWireMaster::CmdResult OWWriteByte(uint8_t sendbyte, OWLevel after_level); |
j3 | 3:644fc630f958 | 110 | |
IanBenzMaxim | 32:bce180b544ed | 111 | virtual OneWireMaster::CmdResult OWReadByte(uint8_t & recvbyte, OWLevel after_level); |
j3 | 23:e8e403d61359 | 112 | |
IanBenzMaxim | 32:bce180b544ed | 113 | virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed new_speed); |
j3 | 3:644fc630f958 | 114 | |
IanBenzMaxim | 32:bce180b544ed | 115 | virtual OneWireMaster::CmdResult OWSetLevel(OWLevel new_level); |
j3 | 3:644fc630f958 | 116 | |
j3 | 3:644fc630f958 | 117 | private: |
j3 | 3:644fc630f958 | 118 | |
j3 | 63:422be898443a | 119 | void rx_callback(void); |
j3 | 63:422be898443a | 120 | |
j3 | 63:422be898443a | 121 | OneWireMaster::CmdResult DS2480B_Detect(void); |
j3 | 63:422be898443a | 122 | OneWireMaster::CmdResult WriteCOM(uint32_t outlen, uint8_t *outbuf); |
j3 | 63:422be898443a | 123 | OneWireMaster::CmdResult ReadCOM(uint32_t inlen, uint8_t *inbuf); |
j3 | 63:422be898443a | 124 | void BreakCOM(void); |
j3 | 63:422be898443a | 125 | void FlushCOM(void); |
j3 | 63:422be898443a | 126 | void SetBaudCOM(uint8_t new_baud); |
j3 | 63:422be898443a | 127 | int32_t bitacc(uint32_t op, uint32_t state, uint32_t loc, uint8_t *buf); |
j3 | 63:422be898443a | 128 | |
j3 | 3:644fc630f958 | 129 | Serial *_p_serial; |
j3 | 3:644fc630f958 | 130 | bool _serial_owner; |
j3 | 63:422be898443a | 131 | |
j3 | 63:422be898443a | 132 | // DS2480B state |
j3 | 63:422be898443a | 133 | OWLevel _ULevel; // 1-Wire level |
j3 | 63:422be898443a | 134 | DS2480B_BPS _UBaud; // baud rate |
j3 | 63:422be898443a | 135 | uint8_t _UMode; // command or data mode state |
j3 | 63:422be898443a | 136 | uint8_t _USpeed; // 1-Wire communication speed |
j3 | 63:422be898443a | 137 | |
j3 | 63:422be898443a | 138 | static const size_t MAX_RX_BUFFER_LEN = 256; |
j3 | 65:a28ac52ca127 | 139 | volatile struct ds2480b_circular_buff_s |
j3 | 63:422be898443a | 140 | { |
j3 | 63:422be898443a | 141 | uint8_t w_idx; |
j3 | 63:422be898443a | 142 | uint8_t r_idx; |
j3 | 65:a28ac52ca127 | 143 | uint8_t rx_bytes_available; |
j3 | 63:422be898443a | 144 | bool wrap_error; |
j3 | 63:422be898443a | 145 | uint8_t buff[MAX_RX_BUFFER_LEN]; |
j3 | 63:422be898443a | 146 | }rx_buffer; |
j3 | 3:644fc630f958 | 147 | }; |
j3 | 3:644fc630f958 | 148 | |
j3 | 3:644fc630f958 | 149 | #endif /*DS2480B_H*/ |
j3 | 3:644fc630f958 | 150 |