Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 0:f77ad7f72d04 1 /*******************************************************************************
IanBenzMaxim 0:f77ad7f72d04 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 0:f77ad7f72d04 3 *
IanBenzMaxim 0:f77ad7f72d04 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 0:f77ad7f72d04 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 0:f77ad7f72d04 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 0:f77ad7f72d04 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 0:f77ad7f72d04 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 0:f77ad7f72d04 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 0:f77ad7f72d04 10 *
IanBenzMaxim 0:f77ad7f72d04 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 0:f77ad7f72d04 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 0:f77ad7f72d04 13 *
IanBenzMaxim 0:f77ad7f72d04 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 0:f77ad7f72d04 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 0:f77ad7f72d04 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 0:f77ad7f72d04 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 0:f77ad7f72d04 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 0:f77ad7f72d04 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 0:f77ad7f72d04 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 0:f77ad7f72d04 21 *
IanBenzMaxim 0:f77ad7f72d04 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 24 * Products, Inc. Branding Policy.
IanBenzMaxim 0:f77ad7f72d04 25 *
IanBenzMaxim 0:f77ad7f72d04 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 0:f77ad7f72d04 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 0:f77ad7f72d04 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 0:f77ad7f72d04 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 0:f77ad7f72d04 30 * ownership rights.
IanBenzMaxim 0:f77ad7f72d04 31 *******************************************************************************/
IanBenzMaxim 0:f77ad7f72d04 32
IanBenzMaxim 0:f77ad7f72d04 33 #ifndef MaximInterface_Uart
IanBenzMaxim 0:f77ad7f72d04 34 #define MaximInterface_Uart
IanBenzMaxim 0:f77ad7f72d04 35
IanBenzMaxim 0:f77ad7f72d04 36 #include <stdint.h>
IanBenzMaxim 0:f77ad7f72d04 37 #include <MaximInterface/Utilities/Export.h>
IanBenzMaxim 6:a8c83a2e6fa4 38 #include <MaximInterface/Utilities/span.hpp>
IanBenzMaxim 0:f77ad7f72d04 39 #include <MaximInterface/Utilities/system_error.hpp>
IanBenzMaxim 0:f77ad7f72d04 40
IanBenzMaxim 0:f77ad7f72d04 41 namespace MaximInterface {
IanBenzMaxim 0:f77ad7f72d04 42
IanBenzMaxim 3:f818ea5172ed 43 /// Universal asynchronous receiver-transmitter interface.
IanBenzMaxim 0:f77ad7f72d04 44 class Uart {
IanBenzMaxim 0:f77ad7f72d04 45 public:
IanBenzMaxim 0:f77ad7f72d04 46 enum ErrorValue {
IanBenzMaxim 0:f77ad7f72d04 47 TimeoutError = 1, ///< Read operation aborted due to timeout.
IanBenzMaxim 0:f77ad7f72d04 48 OverrunError ///< Received data lost due to read buffer overrun.
IanBenzMaxim 0:f77ad7f72d04 49 };
IanBenzMaxim 0:f77ad7f72d04 50
IanBenzMaxim 0:f77ad7f72d04 51 virtual ~Uart() {}
IanBenzMaxim 0:f77ad7f72d04 52
IanBenzMaxim 3:f818ea5172ed 53 /// Set the baud rate of the port in Hz.
IanBenzMaxim 3:f818ea5172ed 54 virtual error_code setBaudRate(int_least32_t baudRate) = 0;
IanBenzMaxim 3:f818ea5172ed 55
IanBenzMaxim 3:f818ea5172ed 56 /// Generate a break condition on the port for a small amount of time.
IanBenzMaxim 0:f77ad7f72d04 57 virtual error_code sendBreak() = 0;
IanBenzMaxim 3:f818ea5172ed 58
IanBenzMaxim 3:f818ea5172ed 59 /// Clear all received data that was buffered.
IanBenzMaxim 0:f77ad7f72d04 60 virtual error_code clearReadBuffer() = 0;
IanBenzMaxim 3:f818ea5172ed 61
IanBenzMaxim 3:f818ea5172ed 62 /// Writes a byte of data to the port.
IanBenzMaxim 0:f77ad7f72d04 63 virtual error_code writeByte(uint_least8_t data) = 0;
IanBenzMaxim 3:f818ea5172ed 64
IanBenzMaxim 3:f818ea5172ed 65 /// Writes a block of data to the port.
IanBenzMaxim 0:f77ad7f72d04 66 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 6:a8c83a2e6fa4 67 writeBlock(span<const uint_least8_t> data);
IanBenzMaxim 3:f818ea5172ed 68
IanBenzMaxim 7:471901a04573 69 /// @brief
IanBenzMaxim 3:f818ea5172ed 70 /// Reads a byte of data from the port. Block until data is received or a
IanBenzMaxim 3:f818ea5172ed 71 /// timeout is reached.
IanBenzMaxim 3:f818ea5172ed 72 /// @param[out] data Data read from the port if successful.
IanBenzMaxim 0:f77ad7f72d04 73 virtual error_code readByte(uint_least8_t & data) = 0;
IanBenzMaxim 3:f818ea5172ed 74
IanBenzMaxim 7:471901a04573 75 /// @brief
IanBenzMaxim 3:f818ea5172ed 76 /// Read a block of data from the port. Block until data is received or a
IanBenzMaxim 3:f818ea5172ed 77 /// timeout is reached.
IanBenzMaxim 3:f818ea5172ed 78 /// @param[out] data Data read from the port if successful.
IanBenzMaxim 6:a8c83a2e6fa4 79 MaximInterface_EXPORT virtual error_code readBlock(span<uint_least8_t> data);
IanBenzMaxim 0:f77ad7f72d04 80
IanBenzMaxim 0:f77ad7f72d04 81 MaximInterface_EXPORT static const error_category & errorCategory();
IanBenzMaxim 0:f77ad7f72d04 82 };
IanBenzMaxim 0:f77ad7f72d04 83
IanBenzMaxim 0:f77ad7f72d04 84 inline error_code make_error_code(Uart::ErrorValue e) {
IanBenzMaxim 0:f77ad7f72d04 85 return error_code(e, Uart::errorCategory());
IanBenzMaxim 0:f77ad7f72d04 86 }
IanBenzMaxim 6:a8c83a2e6fa4 87
IanBenzMaxim 0:f77ad7f72d04 88 inline error_condition make_error_condition(Uart::ErrorValue e) {
IanBenzMaxim 0:f77ad7f72d04 89 return error_condition(e, Uart::errorCategory());
IanBenzMaxim 0:f77ad7f72d04 90 }
IanBenzMaxim 0:f77ad7f72d04 91
IanBenzMaxim 0:f77ad7f72d04 92 } // namespace MaximInterface
IanBenzMaxim 0:f77ad7f72d04 93
IanBenzMaxim 6:a8c83a2e6fa4 94 #endif