Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

Committer:
reARMnimator
Date:
Mon Jan 06 15:54:55 2020 +0000
Revision:
10:de4b8812877d
Parent:
6:a8c83a2e6fa4
Fixed inappropriate include path.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 6:a8c83a2e6fa4 1 /*******************************************************************************
IanBenzMaxim 6:a8c83a2e6fa4 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 6:a8c83a2e6fa4 3 *
IanBenzMaxim 6:a8c83a2e6fa4 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 6:a8c83a2e6fa4 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 6:a8c83a2e6fa4 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 6:a8c83a2e6fa4 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 6:a8c83a2e6fa4 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 6:a8c83a2e6fa4 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 6:a8c83a2e6fa4 10 *
IanBenzMaxim 6:a8c83a2e6fa4 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 6:a8c83a2e6fa4 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 6:a8c83a2e6fa4 13 *
IanBenzMaxim 6:a8c83a2e6fa4 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 6:a8c83a2e6fa4 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 6:a8c83a2e6fa4 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 6:a8c83a2e6fa4 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 6:a8c83a2e6fa4 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 6:a8c83a2e6fa4 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 6:a8c83a2e6fa4 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 6:a8c83a2e6fa4 21 *
IanBenzMaxim 6:a8c83a2e6fa4 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 6:a8c83a2e6fa4 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 6:a8c83a2e6fa4 24 * Products, Inc. Branding Policy.
IanBenzMaxim 6:a8c83a2e6fa4 25 *
IanBenzMaxim 6:a8c83a2e6fa4 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 6:a8c83a2e6fa4 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 6:a8c83a2e6fa4 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 6:a8c83a2e6fa4 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 6:a8c83a2e6fa4 30 * ownership rights.
IanBenzMaxim 6:a8c83a2e6fa4 31 *******************************************************************************/
IanBenzMaxim 6:a8c83a2e6fa4 32
IanBenzMaxim 6:a8c83a2e6fa4 33 #ifndef MaximInterface_RunCommand
IanBenzMaxim 6:a8c83a2e6fa4 34 #define MaximInterface_RunCommand
IanBenzMaxim 6:a8c83a2e6fa4 35
IanBenzMaxim 6:a8c83a2e6fa4 36 #include <MaximInterface/Utilities/Export.h>
IanBenzMaxim 6:a8c83a2e6fa4 37 #include <MaximInterface/Utilities/Function.hpp>
IanBenzMaxim 6:a8c83a2e6fa4 38 #include <MaximInterface/Utilities/span.hpp>
IanBenzMaxim 6:a8c83a2e6fa4 39 #include <MaximInterface/Utilities/system_error.hpp>
IanBenzMaxim 6:a8c83a2e6fa4 40 #include "SelectRom.hpp"
IanBenzMaxim 6:a8c83a2e6fa4 41
IanBenzMaxim 6:a8c83a2e6fa4 42 namespace MaximInterface {
IanBenzMaxim 6:a8c83a2e6fa4 43
IanBenzMaxim 6:a8c83a2e6fa4 44 class I2CMaster;
IanBenzMaxim 6:a8c83a2e6fa4 45 class OneWireMaster;
IanBenzMaxim 6:a8c83a2e6fa4 46 class Sleep;
IanBenzMaxim 6:a8c83a2e6fa4 47
IanBenzMaxim 6:a8c83a2e6fa4 48 typedef Function<error_code(span<const uint_least8_t>, int,
IanBenzMaxim 6:a8c83a2e6fa4 49 span<uint_least8_t> &)>
IanBenzMaxim 6:a8c83a2e6fa4 50 RunCommand;
IanBenzMaxim 6:a8c83a2e6fa4 51
IanBenzMaxim 6:a8c83a2e6fa4 52 class RunCommandWithOneWireMaster {
IanBenzMaxim 6:a8c83a2e6fa4 53 public:
IanBenzMaxim 6:a8c83a2e6fa4 54 typedef RunCommand::result_type result_type;
IanBenzMaxim 6:a8c83a2e6fa4 55
IanBenzMaxim 6:a8c83a2e6fa4 56 enum ErrorValue { CrcError = 1, InvalidResponseError };
IanBenzMaxim 6:a8c83a2e6fa4 57 MaximInterface_EXPORT static const error_category & errorCategory();
IanBenzMaxim 6:a8c83a2e6fa4 58
IanBenzMaxim 6:a8c83a2e6fa4 59 RunCommandWithOneWireMaster(Sleep & sleep, OneWireMaster & master,
IanBenzMaxim 6:a8c83a2e6fa4 60 const SelectRom & selectRom)
IanBenzMaxim 6:a8c83a2e6fa4 61 : selectRom(selectRom), master(&master), sleep(&sleep) {}
IanBenzMaxim 6:a8c83a2e6fa4 62
IanBenzMaxim 6:a8c83a2e6fa4 63 void setSleep(Sleep & sleep) { this->sleep = &sleep; }
IanBenzMaxim 6:a8c83a2e6fa4 64
IanBenzMaxim 6:a8c83a2e6fa4 65 void setMaster(OneWireMaster & master) { this->master = &master; }
IanBenzMaxim 6:a8c83a2e6fa4 66
IanBenzMaxim 6:a8c83a2e6fa4 67 void setSelectRom(const SelectRom & selectRom) {
IanBenzMaxim 6:a8c83a2e6fa4 68 this->selectRom = selectRom;
IanBenzMaxim 6:a8c83a2e6fa4 69 }
IanBenzMaxim 6:a8c83a2e6fa4 70
IanBenzMaxim 6:a8c83a2e6fa4 71 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 72 operator()(span<const uint_least8_t> command, int delayTime,
IanBenzMaxim 6:a8c83a2e6fa4 73 span<uint_least8_t> & response) const;
IanBenzMaxim 6:a8c83a2e6fa4 74
IanBenzMaxim 6:a8c83a2e6fa4 75 private:
IanBenzMaxim 6:a8c83a2e6fa4 76 SelectRom selectRom;
IanBenzMaxim 6:a8c83a2e6fa4 77 OneWireMaster * master;
IanBenzMaxim 6:a8c83a2e6fa4 78 const Sleep * sleep;
IanBenzMaxim 6:a8c83a2e6fa4 79 };
IanBenzMaxim 6:a8c83a2e6fa4 80
IanBenzMaxim 6:a8c83a2e6fa4 81 inline error_code make_error_code(RunCommandWithOneWireMaster::ErrorValue e) {
IanBenzMaxim 6:a8c83a2e6fa4 82 return error_code(e, RunCommandWithOneWireMaster::errorCategory());
IanBenzMaxim 6:a8c83a2e6fa4 83 }
IanBenzMaxim 6:a8c83a2e6fa4 84
IanBenzMaxim 6:a8c83a2e6fa4 85 class RunCommandWithI2CMaster {
IanBenzMaxim 6:a8c83a2e6fa4 86 public:
IanBenzMaxim 6:a8c83a2e6fa4 87 typedef RunCommand::result_type result_type;
IanBenzMaxim 6:a8c83a2e6fa4 88
IanBenzMaxim 6:a8c83a2e6fa4 89 enum ErrorValue { InvalidResponseError = 1 };
IanBenzMaxim 6:a8c83a2e6fa4 90 MaximInterface_EXPORT static const error_category & errorCategory();
IanBenzMaxim 6:a8c83a2e6fa4 91
IanBenzMaxim 6:a8c83a2e6fa4 92 RunCommandWithI2CMaster(Sleep & sleep, I2CMaster & master,
IanBenzMaxim 6:a8c83a2e6fa4 93 uint_least8_t address)
IanBenzMaxim 6:a8c83a2e6fa4 94 : sleep(&sleep), master(&master), address_(address & 0xFE) {}
IanBenzMaxim 6:a8c83a2e6fa4 95
IanBenzMaxim 6:a8c83a2e6fa4 96 void setSleep(Sleep & sleep) { this->sleep = &sleep; }
IanBenzMaxim 6:a8c83a2e6fa4 97
IanBenzMaxim 6:a8c83a2e6fa4 98 void setMaster(I2CMaster & master) { this->master = &master; }
IanBenzMaxim 6:a8c83a2e6fa4 99
IanBenzMaxim 6:a8c83a2e6fa4 100 uint_least8_t address() const { return address_; }
IanBenzMaxim 6:a8c83a2e6fa4 101
IanBenzMaxim 6:a8c83a2e6fa4 102 void setAddress(uint_least8_t address) { address_ = address & 0xFE; }
IanBenzMaxim 6:a8c83a2e6fa4 103
IanBenzMaxim 6:a8c83a2e6fa4 104 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 105 operator()(span<const uint_least8_t> command, int delayTime,
IanBenzMaxim 6:a8c83a2e6fa4 106 span<uint_least8_t> & response) const;
IanBenzMaxim 6:a8c83a2e6fa4 107
IanBenzMaxim 6:a8c83a2e6fa4 108 private:
IanBenzMaxim 6:a8c83a2e6fa4 109 const Sleep * sleep;
IanBenzMaxim 6:a8c83a2e6fa4 110 I2CMaster * master;
IanBenzMaxim 6:a8c83a2e6fa4 111 uint_least8_t address_;
IanBenzMaxim 6:a8c83a2e6fa4 112 };
IanBenzMaxim 6:a8c83a2e6fa4 113
IanBenzMaxim 6:a8c83a2e6fa4 114 inline error_code make_error_code(RunCommandWithI2CMaster::ErrorValue e) {
IanBenzMaxim 6:a8c83a2e6fa4 115 return error_code(e, RunCommandWithI2CMaster::errorCategory());
IanBenzMaxim 6:a8c83a2e6fa4 116 }
IanBenzMaxim 6:a8c83a2e6fa4 117
IanBenzMaxim 6:a8c83a2e6fa4 118 } // namespace MaximInterface
IanBenzMaxim 6:a8c83a2e6fa4 119
IanBenzMaxim 6:a8c83a2e6fa4 120 #endif