CDY version that shares functionality with Counter

Dependencies:   SDFileSystem_HelloWorld mbed FATFileSystem

Committer:
Charles David Young
Date:
Sun Nov 04 18:44:51 2018 -0700
Revision:
0:aa13e1c335cd
create new repo for show2me

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_PORTOUT_H
Charles David Young 0:aa13e1c335cd 17 #define MBED_PORTOUT_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_PORTOUT
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 /** A multiple pin digital out
Charles David Young 0:aa13e1c335cd 30 *
Charles David Young 0:aa13e1c335cd 31 * @Note Synchronization level: Interrupt safe
Charles David Young 0:aa13e1c335cd 32 *
Charles David Young 0:aa13e1c335cd 33 * Example:
Charles David Young 0:aa13e1c335cd 34 * @code
Charles David Young 0:aa13e1c335cd 35 * // Toggle all four LEDs
Charles David Young 0:aa13e1c335cd 36 *
Charles David Young 0:aa13e1c335cd 37 * #include "mbed.h"
Charles David Young 0:aa13e1c335cd 38 *
Charles David Young 0:aa13e1c335cd 39 * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
Charles David Young 0:aa13e1c335cd 40 * #define LED_MASK 0x00B40000
Charles David Young 0:aa13e1c335cd 41 *
Charles David Young 0:aa13e1c335cd 42 * PortOut ledport(Port1, LED_MASK);
Charles David Young 0:aa13e1c335cd 43 *
Charles David Young 0:aa13e1c335cd 44 * int main() {
Charles David Young 0:aa13e1c335cd 45 * while(1) {
Charles David Young 0:aa13e1c335cd 46 * ledport = LED_MASK;
Charles David Young 0:aa13e1c335cd 47 * wait(1);
Charles David Young 0:aa13e1c335cd 48 * ledport = 0;
Charles David Young 0:aa13e1c335cd 49 * wait(1);
Charles David Young 0:aa13e1c335cd 50 * }
Charles David Young 0:aa13e1c335cd 51 * }
Charles David Young 0:aa13e1c335cd 52 * @endcode
Charles David Young 0:aa13e1c335cd 53 */
Charles David Young 0:aa13e1c335cd 54 class PortOut {
Charles David Young 0:aa13e1c335cd 55 public:
Charles David Young 0:aa13e1c335cd 56
Charles David Young 0:aa13e1c335cd 57 /** Create an PortOut, connected to the specified port
Charles David Young 0:aa13e1c335cd 58 *
Charles David Young 0:aa13e1c335cd 59 * @param port Port to connect to (Port0-Port5)
Charles David Young 0:aa13e1c335cd 60 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
Charles David Young 0:aa13e1c335cd 61 */
Charles David Young 0:aa13e1c335cd 62 PortOut(PortName port, int mask = 0xFFFFFFFF) {
Charles David Young 0:aa13e1c335cd 63 core_util_critical_section_enter();
Charles David Young 0:aa13e1c335cd 64 port_init(&_port, port, mask, PIN_OUTPUT);
Charles David Young 0:aa13e1c335cd 65 core_util_critical_section_exit();
Charles David Young 0:aa13e1c335cd 66 }
Charles David Young 0:aa13e1c335cd 67
Charles David Young 0:aa13e1c335cd 68 /** Write the value to the output port
Charles David Young 0:aa13e1c335cd 69 *
Charles David Young 0:aa13e1c335cd 70 * @param value An integer specifying a bit to write for every corresponding PortOut pin
Charles David Young 0:aa13e1c335cd 71 */
Charles David Young 0:aa13e1c335cd 72 void write(int value) {
Charles David Young 0:aa13e1c335cd 73 port_write(&_port, value);
Charles David Young 0:aa13e1c335cd 74 }
Charles David Young 0:aa13e1c335cd 75
Charles David Young 0:aa13e1c335cd 76 /** Read the value currently output on the port
Charles David Young 0:aa13e1c335cd 77 *
Charles David Young 0:aa13e1c335cd 78 * @returns
Charles David Young 0:aa13e1c335cd 79 * An integer with each bit corresponding to associated PortOut pin setting
Charles David Young 0:aa13e1c335cd 80 */
Charles David Young 0:aa13e1c335cd 81 int read() {
Charles David Young 0:aa13e1c335cd 82 return port_read(&_port);
Charles David Young 0:aa13e1c335cd 83 }
Charles David Young 0:aa13e1c335cd 84
Charles David Young 0:aa13e1c335cd 85 /** A shorthand for write()
Charles David Young 0:aa13e1c335cd 86 */
Charles David Young 0:aa13e1c335cd 87 PortOut& operator= (int value) {
Charles David Young 0:aa13e1c335cd 88 write(value);
Charles David Young 0:aa13e1c335cd 89 return *this;
Charles David Young 0:aa13e1c335cd 90 }
Charles David Young 0:aa13e1c335cd 91
Charles David Young 0:aa13e1c335cd 92 PortOut& operator= (PortOut& rhs) {
Charles David Young 0:aa13e1c335cd 93 write(rhs.read());
Charles David Young 0:aa13e1c335cd 94 return *this;
Charles David Young 0:aa13e1c335cd 95 }
Charles David Young 0:aa13e1c335cd 96
Charles David Young 0:aa13e1c335cd 97 /** A shorthand for read()
Charles David Young 0:aa13e1c335cd 98 */
Charles David Young 0:aa13e1c335cd 99 operator int() {
Charles David Young 0:aa13e1c335cd 100 return read();
Charles David Young 0:aa13e1c335cd 101 }
Charles David Young 0:aa13e1c335cd 102
Charles David Young 0:aa13e1c335cd 103 private:
Charles David Young 0:aa13e1c335cd 104 port_t _port;
Charles David Young 0:aa13e1c335cd 105 };
Charles David Young 0:aa13e1c335cd 106
Charles David Young 0:aa13e1c335cd 107 } // namespace mbed
Charles David Young 0:aa13e1c335cd 108
Charles David Young 0:aa13e1c335cd 109 #endif
Charles David Young 0:aa13e1c335cd 110
Charles David Young 0:aa13e1c335cd 111 #endif
Charles David Young 0:aa13e1c335cd 112
Charles David Young 0:aa13e1c335cd 113 /** @}*/