A simple 128x32 graphical LCD program to quickstart with LCD on ARM mbed IoT Starter Kit. This requires mbed Applciation Shield with FRDM-K64F platform.

Dependencies:   C12832

Committer:
tushki7
Date:
Sun Apr 12 15:45:52 2015 +0000
Revision:
1:eb68c94a8ee5
Parent:
0:60d829a0353a
A simple 128x32 LCD program with ARM mbed IoT Starter Kit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tushki7 0:60d829a0353a 1 /* mbed Microcontroller Library
tushki7 0:60d829a0353a 2 * Copyright (c) 2006-2013 ARM Limited
tushki7 0:60d829a0353a 3 *
tushki7 0:60d829a0353a 4 * Licensed under the Apache License, Version 2.0 (the "License");
tushki7 0:60d829a0353a 5 * you may not use this file except in compliance with the License.
tushki7 0:60d829a0353a 6 * You may obtain a copy of the License at
tushki7 0:60d829a0353a 7 *
tushki7 0:60d829a0353a 8 * http://www.apache.org/licenses/LICENSE-2.0
tushki7 0:60d829a0353a 9 *
tushki7 0:60d829a0353a 10 * Unless required by applicable law or agreed to in writing, software
tushki7 0:60d829a0353a 11 * distributed under the License is distributed on an "AS IS" BASIS,
tushki7 0:60d829a0353a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tushki7 0:60d829a0353a 13 * See the License for the specific language governing permissions and
tushki7 0:60d829a0353a 14 * limitations under the License.
tushki7 0:60d829a0353a 15 */
tushki7 0:60d829a0353a 16 #ifndef MBED_DIGITALINOUT_H
tushki7 0:60d829a0353a 17 #define MBED_DIGITALINOUT_H
tushki7 0:60d829a0353a 18
tushki7 0:60d829a0353a 19 #include "platform.h"
tushki7 0:60d829a0353a 20
tushki7 0:60d829a0353a 21 #include "gpio_api.h"
tushki7 0:60d829a0353a 22
tushki7 0:60d829a0353a 23 namespace mbed {
tushki7 0:60d829a0353a 24
tushki7 0:60d829a0353a 25 /** A digital input/output, used for setting or reading a bi-directional pin
tushki7 0:60d829a0353a 26 */
tushki7 0:60d829a0353a 27 class DigitalInOut {
tushki7 0:60d829a0353a 28
tushki7 0:60d829a0353a 29 public:
tushki7 0:60d829a0353a 30 /** Create a DigitalInOut connected to the specified pin
tushki7 0:60d829a0353a 31 *
tushki7 0:60d829a0353a 32 * @param pin DigitalInOut pin to connect to
tushki7 0:60d829a0353a 33 */
tushki7 0:60d829a0353a 34 DigitalInOut(PinName pin) : gpio() {
tushki7 0:60d829a0353a 35 gpio_init_in(&gpio, pin);
tushki7 0:60d829a0353a 36 }
tushki7 0:60d829a0353a 37
tushki7 0:60d829a0353a 38 /** Create a DigitalInOut connected to the specified pin
tushki7 0:60d829a0353a 39 *
tushki7 0:60d829a0353a 40 * @param pin DigitalInOut pin to connect to
tushki7 0:60d829a0353a 41 * @param direction the initial direction of the pin
tushki7 0:60d829a0353a 42 * @param mode the initial mode of the pin
tushki7 0:60d829a0353a 43 * @param value the initial value of the pin if is an output
tushki7 0:60d829a0353a 44 */
tushki7 0:60d829a0353a 45 DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() {
tushki7 0:60d829a0353a 46 gpio_init_inout(&gpio, pin, direction, mode, value);
tushki7 0:60d829a0353a 47 }
tushki7 0:60d829a0353a 48
tushki7 0:60d829a0353a 49 /** Set the output, specified as 0 or 1 (int)
tushki7 0:60d829a0353a 50 *
tushki7 0:60d829a0353a 51 * @param value An integer specifying the pin output value,
tushki7 0:60d829a0353a 52 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
tushki7 0:60d829a0353a 53 */
tushki7 0:60d829a0353a 54 void write(int value) {
tushki7 0:60d829a0353a 55 gpio_write(&gpio, value);
tushki7 0:60d829a0353a 56 }
tushki7 0:60d829a0353a 57
tushki7 0:60d829a0353a 58 /** Return the output setting, represented as 0 or 1 (int)
tushki7 0:60d829a0353a 59 *
tushki7 0:60d829a0353a 60 * @returns
tushki7 0:60d829a0353a 61 * an integer representing the output setting of the pin if it is an output,
tushki7 0:60d829a0353a 62 * or read the input if set as an input
tushki7 0:60d829a0353a 63 */
tushki7 0:60d829a0353a 64 int read() {
tushki7 0:60d829a0353a 65 return gpio_read(&gpio);
tushki7 0:60d829a0353a 66 }
tushki7 0:60d829a0353a 67
tushki7 0:60d829a0353a 68 /** Set as an output
tushki7 0:60d829a0353a 69 */
tushki7 0:60d829a0353a 70 void output() {
tushki7 0:60d829a0353a 71 gpio_dir(&gpio, PIN_OUTPUT);
tushki7 0:60d829a0353a 72 }
tushki7 0:60d829a0353a 73
tushki7 0:60d829a0353a 74 /** Set as an input
tushki7 0:60d829a0353a 75 */
tushki7 0:60d829a0353a 76 void input() {
tushki7 0:60d829a0353a 77 gpio_dir(&gpio, PIN_INPUT);
tushki7 0:60d829a0353a 78 }
tushki7 0:60d829a0353a 79
tushki7 0:60d829a0353a 80 /** Set the input pin mode
tushki7 0:60d829a0353a 81 *
tushki7 0:60d829a0353a 82 * @param mode PullUp, PullDown, PullNone, OpenDrain
tushki7 0:60d829a0353a 83 */
tushki7 0:60d829a0353a 84 void mode(PinMode pull) {
tushki7 0:60d829a0353a 85 gpio_mode(&gpio, pull);
tushki7 0:60d829a0353a 86 }
tushki7 0:60d829a0353a 87
tushki7 0:60d829a0353a 88 /** Return the output setting, represented as 0 or 1 (int)
tushki7 0:60d829a0353a 89 *
tushki7 0:60d829a0353a 90 * @returns
tushki7 0:60d829a0353a 91 * Non zero value if pin is connected to uc GPIO
tushki7 0:60d829a0353a 92 * 0 if gpio object was initialized with NC
tushki7 0:60d829a0353a 93 */
tushki7 0:60d829a0353a 94 int is_connected() {
tushki7 0:60d829a0353a 95 return gpio_is_connected(&gpio);
tushki7 0:60d829a0353a 96 }
tushki7 0:60d829a0353a 97
tushki7 0:60d829a0353a 98 #ifdef MBED_OPERATORS
tushki7 0:60d829a0353a 99 /** A shorthand for write()
tushki7 0:60d829a0353a 100 */
tushki7 0:60d829a0353a 101 DigitalInOut& operator= (int value) {
tushki7 0:60d829a0353a 102 write(value);
tushki7 0:60d829a0353a 103 return *this;
tushki7 0:60d829a0353a 104 }
tushki7 0:60d829a0353a 105
tushki7 0:60d829a0353a 106 DigitalInOut& operator= (DigitalInOut& rhs) {
tushki7 0:60d829a0353a 107 write(rhs.read());
tushki7 0:60d829a0353a 108 return *this;
tushki7 0:60d829a0353a 109 }
tushki7 0:60d829a0353a 110
tushki7 0:60d829a0353a 111 /** A shorthand for read()
tushki7 0:60d829a0353a 112 */
tushki7 0:60d829a0353a 113 operator int() {
tushki7 0:60d829a0353a 114 return read();
tushki7 0:60d829a0353a 115 }
tushki7 0:60d829a0353a 116 #endif
tushki7 0:60d829a0353a 117
tushki7 0:60d829a0353a 118 protected:
tushki7 0:60d829a0353a 119 gpio_t gpio;
tushki7 0:60d829a0353a 120 };
tushki7 0:60d829a0353a 121
tushki7 0:60d829a0353a 122 } // namespace mbed
tushki7 0:60d829a0353a 123
tushki7 0:60d829a0353a 124 #endif