dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
cyberjoey
Date:
Sat Oct 22 01:31:58 2016 +0000
Revision:
9:6bb35cef007d
Parent:
1:55a6170b404f
WORKING

Who changed what in which revision?

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