CDY version that shares functionality with Counter

Dependencies:   SDFileSystem_HelloWorld mbed FATFileSystem

Committer:
Charles David Young
Date:
Mon Nov 05 09:52:17 2018 -0700
Revision:
3:c547dba5d39b
Parent:
0:aa13e1c335cd
debug

Who changed what in which revision?

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