SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 21:37:21 2019 +0000
Revision:
0:8ede47d38d10
SPKT

Who changed what in which revision?

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