Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Masters/DS248x/DS2484/DS2484.cpp@91:e80108bc870a, 2016-06-20 (annotated)
- Committer:
- j3
- Date:
- Mon Jun 20 19:39:21 2016 +0000
- Revision:
- 91:e80108bc870a
- Child:
- 104:3f48daed532b
Created derived classes for DS248x series
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 91:e80108bc870a | 1 | /********************************************************************** |
j3 | 91:e80108bc870a | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 91:e80108bc870a | 3 | * |
j3 | 91:e80108bc870a | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 91:e80108bc870a | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 91:e80108bc870a | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 91:e80108bc870a | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 91:e80108bc870a | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 91:e80108bc870a | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 91:e80108bc870a | 10 | * |
j3 | 91:e80108bc870a | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 91:e80108bc870a | 12 | * in all copies or substantial portions of the Software. |
j3 | 91:e80108bc870a | 13 | * |
j3 | 91:e80108bc870a | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 91:e80108bc870a | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 91:e80108bc870a | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 91:e80108bc870a | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 91:e80108bc870a | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 91:e80108bc870a | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 91:e80108bc870a | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 91:e80108bc870a | 21 | * |
j3 | 91:e80108bc870a | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 91:e80108bc870a | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 91:e80108bc870a | 24 | * Products, Inc. Branding Policy. |
j3 | 91:e80108bc870a | 25 | * |
j3 | 91:e80108bc870a | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 91:e80108bc870a | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 91:e80108bc870a | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 91:e80108bc870a | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 91:e80108bc870a | 30 | * ownership rights. |
j3 | 91:e80108bc870a | 31 | **********************************************************************/ |
j3 | 91:e80108bc870a | 32 | |
j3 | 91:e80108bc870a | 33 | |
j3 | 91:e80108bc870a | 34 | #include "OneWire/Masters/DS248x/DS2484/DS2484.h" |
j3 | 91:e80108bc870a | 35 | |
j3 | 91:e80108bc870a | 36 | |
j3 | 91:e80108bc870a | 37 | using OneWire::OneWireMaster; |
j3 | 91:e80108bc870a | 38 | using OneWire::DS2484; |
j3 | 91:e80108bc870a | 39 | |
j3 | 91:e80108bc870a | 40 | |
j3 | 91:e80108bc870a | 41 | //********************************************************************* |
j3 | 91:e80108bc870a | 42 | DS2484::DS2484(mbed::I2C & i2c_bus) |
j3 | 91:e80108bc870a | 43 | :DS248x(i2c_bus, I2C_ADRS) |
j3 | 91:e80108bc870a | 44 | { |
j3 | 91:e80108bc870a | 45 | } |
j3 | 91:e80108bc870a | 46 | |
j3 | 91:e80108bc870a | 47 | |
j3 | 91:e80108bc870a | 48 | //********************************************************************* |
j3 | 91:e80108bc870a | 49 | OneWireMaster::CmdResult DS2484::adjustOwPort(OwAdjustParam param, uint8_t val) |
j3 | 91:e80108bc870a | 50 | { |
j3 | 91:e80108bc870a | 51 | OneWireMaster::CmdResult result; |
j3 | 91:e80108bc870a | 52 | |
j3 | 91:e80108bc870a | 53 | uint8_t read_port_config; |
j3 | 91:e80108bc870a | 54 | uint8_t control_byte; |
j3 | 91:e80108bc870a | 55 | |
j3 | 91:e80108bc870a | 56 | control_byte = (((param & 0x0F) << 4) | (val & 0x0F)); |
j3 | 91:e80108bc870a | 57 | |
j3 | 91:e80108bc870a | 58 | result = sendCommand(AdjustOwPortCmd, control_byte); |
j3 | 91:e80108bc870a | 59 | if (result != Success) |
j3 | 91:e80108bc870a | 60 | { |
j3 | 91:e80108bc870a | 61 | return result; |
j3 | 91:e80108bc870a | 62 | } |
j3 | 91:e80108bc870a | 63 | |
j3 | 91:e80108bc870a | 64 | result = readRegister(PortConfigReg, read_port_config, true); |
j3 | 91:e80108bc870a | 65 | if (result != Success) |
j3 | 91:e80108bc870a | 66 | { |
j3 | 91:e80108bc870a | 67 | return result; |
j3 | 91:e80108bc870a | 68 | } |
j3 | 91:e80108bc870a | 69 | |
j3 | 91:e80108bc870a | 70 | if ((control_byte & 0x0F) != read_port_config) |
j3 | 91:e80108bc870a | 71 | { |
j3 | 91:e80108bc870a | 72 | result = OneWireMaster::OperationFailure; |
j3 | 91:e80108bc870a | 73 | } |
j3 | 91:e80108bc870a | 74 | |
j3 | 91:e80108bc870a | 75 | return result; |
j3 | 91:e80108bc870a | 76 | } |