test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Committer:
ommpy
Date:
Mon Jul 06 17:18:59 2020 +0530
Revision:
0:d383e2dee0f7
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ommpy 0:d383e2dee0f7 1 /* mbed Microcontroller Library
ommpy 0:d383e2dee0f7 2 * Copyright (c) 2006-2013 ARM Limited
ommpy 0:d383e2dee0f7 3 *
ommpy 0:d383e2dee0f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
ommpy 0:d383e2dee0f7 5 * you may not use this file except in compliance with the License.
ommpy 0:d383e2dee0f7 6 * You may obtain a copy of the License at
ommpy 0:d383e2dee0f7 7 *
ommpy 0:d383e2dee0f7 8 * http://www.apache.org/licenses/LICENSE-2.0
ommpy 0:d383e2dee0f7 9 *
ommpy 0:d383e2dee0f7 10 * Unless required by applicable law or agreed to in writing, software
ommpy 0:d383e2dee0f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
ommpy 0:d383e2dee0f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ommpy 0:d383e2dee0f7 13 * See the License for the specific language governing permissions and
ommpy 0:d383e2dee0f7 14 * limitations under the License.
ommpy 0:d383e2dee0f7 15 */
ommpy 0:d383e2dee0f7 16 #ifndef MBED_PORTINOUT_H
ommpy 0:d383e2dee0f7 17 #define MBED_PORTINOUT_H
ommpy 0:d383e2dee0f7 18
ommpy 0:d383e2dee0f7 19 #include "platform.h"
ommpy 0:d383e2dee0f7 20
ommpy 0:d383e2dee0f7 21 #if DEVICE_PORTINOUT
ommpy 0:d383e2dee0f7 22
ommpy 0:d383e2dee0f7 23 #include "port_api.h"
ommpy 0:d383e2dee0f7 24
ommpy 0:d383e2dee0f7 25 namespace mbed {
ommpy 0:d383e2dee0f7 26
ommpy 0:d383e2dee0f7 27 /** A multiple pin digital in/out used to set/read multiple bi-directional pins
ommpy 0:d383e2dee0f7 28 */
ommpy 0:d383e2dee0f7 29 class PortInOut {
ommpy 0:d383e2dee0f7 30 public:
ommpy 0:d383e2dee0f7 31
ommpy 0:d383e2dee0f7 32 /** Create an PortInOut, connected to the specified port
ommpy 0:d383e2dee0f7 33 *
ommpy 0:d383e2dee0f7 34 * @param port Port to connect to (Port0-Port5)
ommpy 0:d383e2dee0f7 35 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
ommpy 0:d383e2dee0f7 36 */
ommpy 0:d383e2dee0f7 37 PortInOut(PortName port, int mask = 0xFFFFFFFF) {
ommpy 0:d383e2dee0f7 38 port_init(&_port, port, mask, PIN_INPUT);
ommpy 0:d383e2dee0f7 39 }
ommpy 0:d383e2dee0f7 40
ommpy 0:d383e2dee0f7 41 /** Write the value to the output port
ommpy 0:d383e2dee0f7 42 *
ommpy 0:d383e2dee0f7 43 * @param value An integer specifying a bit to write for every corresponding port pin
ommpy 0:d383e2dee0f7 44 */
ommpy 0:d383e2dee0f7 45 void write(int value) {
ommpy 0:d383e2dee0f7 46 port_write(&_port, value);
ommpy 0:d383e2dee0f7 47 }
ommpy 0:d383e2dee0f7 48
ommpy 0:d383e2dee0f7 49 /** Read the value currently output on the port
ommpy 0:d383e2dee0f7 50 *
ommpy 0:d383e2dee0f7 51 * @returns
ommpy 0:d383e2dee0f7 52 * An integer with each bit corresponding to associated port pin setting
ommpy 0:d383e2dee0f7 53 */
ommpy 0:d383e2dee0f7 54 int read() {
ommpy 0:d383e2dee0f7 55 return port_read(&_port);
ommpy 0:d383e2dee0f7 56 }
ommpy 0:d383e2dee0f7 57
ommpy 0:d383e2dee0f7 58 /** Set as an output
ommpy 0:d383e2dee0f7 59 */
ommpy 0:d383e2dee0f7 60 void output() {
ommpy 0:d383e2dee0f7 61 port_dir(&_port, PIN_OUTPUT);
ommpy 0:d383e2dee0f7 62 }
ommpy 0:d383e2dee0f7 63
ommpy 0:d383e2dee0f7 64 /** Set as an input
ommpy 0:d383e2dee0f7 65 */
ommpy 0:d383e2dee0f7 66 void input() {
ommpy 0:d383e2dee0f7 67 port_dir(&_port, PIN_INPUT);
ommpy 0:d383e2dee0f7 68 }
ommpy 0:d383e2dee0f7 69
ommpy 0:d383e2dee0f7 70 /** Set the input pin mode
ommpy 0:d383e2dee0f7 71 *
ommpy 0:d383e2dee0f7 72 * @param mode PullUp, PullDown, PullNone, OpenDrain
ommpy 0:d383e2dee0f7 73 */
ommpy 0:d383e2dee0f7 74 void mode(PinMode mode) {
ommpy 0:d383e2dee0f7 75 port_mode(&_port, mode);
ommpy 0:d383e2dee0f7 76 }
ommpy 0:d383e2dee0f7 77
ommpy 0:d383e2dee0f7 78 /** A shorthand for write()
ommpy 0:d383e2dee0f7 79 */
ommpy 0:d383e2dee0f7 80 PortInOut& operator= (int value) {
ommpy 0:d383e2dee0f7 81 write(value);
ommpy 0:d383e2dee0f7 82 return *this;
ommpy 0:d383e2dee0f7 83 }
ommpy 0:d383e2dee0f7 84
ommpy 0:d383e2dee0f7 85 PortInOut& operator= (PortInOut& rhs) {
ommpy 0:d383e2dee0f7 86 write(rhs.read());
ommpy 0:d383e2dee0f7 87 return *this;
ommpy 0:d383e2dee0f7 88 }
ommpy 0:d383e2dee0f7 89
ommpy 0:d383e2dee0f7 90 /** A shorthand for read()
ommpy 0:d383e2dee0f7 91 */
ommpy 0:d383e2dee0f7 92 operator int() {
ommpy 0:d383e2dee0f7 93 return read();
ommpy 0:d383e2dee0f7 94 }
ommpy 0:d383e2dee0f7 95
ommpy 0:d383e2dee0f7 96 private:
ommpy 0:d383e2dee0f7 97 port_t _port;
ommpy 0:d383e2dee0f7 98 };
ommpy 0:d383e2dee0f7 99
ommpy 0:d383e2dee0f7 100 } // namespace mbed
ommpy 0:d383e2dee0f7 101
ommpy 0:d383e2dee0f7 102 #endif
ommpy 0:d383e2dee0f7 103
ommpy 0:d383e2dee0f7 104 #endif