pro vyuku PSS v Jecne

Committer:
vladvana
Date:
Sun Sep 24 12:31:52 2017 +0000
Revision:
0:23d1f73bf130
podklady pro cviceni z PSS

Who changed what in which revision?

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