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_FILEHANDLE_H
tushki7 0:60d829a0353a 17 #define MBED_FILEHANDLE_H
tushki7 0:60d829a0353a 18
tushki7 0:60d829a0353a 19 typedef int FILEHANDLE;
tushki7 0:60d829a0353a 20
tushki7 0:60d829a0353a 21 #include <stdio.h>
tushki7 0:60d829a0353a 22
tushki7 0:60d829a0353a 23 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
tushki7 0:60d829a0353a 24 typedef int ssize_t;
tushki7 0:60d829a0353a 25 typedef long off_t;
tushki7 0:60d829a0353a 26
tushki7 0:60d829a0353a 27 #else
tushki7 0:60d829a0353a 28 # include <sys/types.h>
tushki7 0:60d829a0353a 29 #endif
tushki7 0:60d829a0353a 30
tushki7 0:60d829a0353a 31 namespace mbed {
tushki7 0:60d829a0353a 32
tushki7 0:60d829a0353a 33 /** An OO equivalent of the internal FILEHANDLE variable
tushki7 0:60d829a0353a 34 * and associated _sys_* functions.
tushki7 0:60d829a0353a 35 *
tushki7 0:60d829a0353a 36 * FileHandle is an abstract class, needing at least sys_write and
tushki7 0:60d829a0353a 37 * sys_read to be implmented for a simple interactive device.
tushki7 0:60d829a0353a 38 *
tushki7 0:60d829a0353a 39 * No one ever directly tals to/instanciates a FileHandle - it gets
tushki7 0:60d829a0353a 40 * created by FileSystem, and wrapped up by stdio.
tushki7 0:60d829a0353a 41 */
tushki7 0:60d829a0353a 42 class FileHandle {
tushki7 0:60d829a0353a 43
tushki7 0:60d829a0353a 44 public:
tushki7 0:60d829a0353a 45 /** Write the contents of a buffer to the file
tushki7 0:60d829a0353a 46 *
tushki7 0:60d829a0353a 47 * @param buffer the buffer to write from
tushki7 0:60d829a0353a 48 * @param length the number of characters to write
tushki7 0:60d829a0353a 49 *
tushki7 0:60d829a0353a 50 * @returns
tushki7 0:60d829a0353a 51 * The number of characters written (possibly 0) on success, -1 on error.
tushki7 0:60d829a0353a 52 */
tushki7 0:60d829a0353a 53 virtual ssize_t write(const void* buffer, size_t length) = 0;
tushki7 0:60d829a0353a 54
tushki7 0:60d829a0353a 55 /** Close the file
tushki7 0:60d829a0353a 56 *
tushki7 0:60d829a0353a 57 * @returns
tushki7 0:60d829a0353a 58 * Zero on success, -1 on error.
tushki7 0:60d829a0353a 59 */
tushki7 0:60d829a0353a 60 virtual int close() = 0;
tushki7 0:60d829a0353a 61
tushki7 0:60d829a0353a 62 /** Function read
tushki7 0:60d829a0353a 63 * Reads the contents of the file into a buffer
tushki7 0:60d829a0353a 64 *
tushki7 0:60d829a0353a 65 * @param buffer the buffer to read in to
tushki7 0:60d829a0353a 66 * @param length the number of characters to read
tushki7 0:60d829a0353a 67 *
tushki7 0:60d829a0353a 68 * @returns
tushki7 0:60d829a0353a 69 * The number of characters read (zero at end of file) on success, -1 on error.
tushki7 0:60d829a0353a 70 */
tushki7 0:60d829a0353a 71 virtual ssize_t read(void* buffer, size_t length) = 0;
tushki7 0:60d829a0353a 72
tushki7 0:60d829a0353a 73 /** Check if the handle is for a interactive terminal device.
tushki7 0:60d829a0353a 74 * If so, line buffered behaviour is used by default
tushki7 0:60d829a0353a 75 *
tushki7 0:60d829a0353a 76 * @returns
tushki7 0:60d829a0353a 77 * 1 if it is a terminal,
tushki7 0:60d829a0353a 78 * 0 otherwise
tushki7 0:60d829a0353a 79 */
tushki7 0:60d829a0353a 80 virtual int isatty() = 0;
tushki7 0:60d829a0353a 81
tushki7 0:60d829a0353a 82 /** Move the file position to a given offset from a given location.
tushki7 0:60d829a0353a 83 *
tushki7 0:60d829a0353a 84 * @param offset The offset from whence to move to
tushki7 0:60d829a0353a 85 * @param whence SEEK_SET for the start of the file, SEEK_CUR for the
tushki7 0:60d829a0353a 86 * current file position, or SEEK_END for the end of the file.
tushki7 0:60d829a0353a 87 *
tushki7 0:60d829a0353a 88 * @returns
tushki7 0:60d829a0353a 89 * new file position on success,
tushki7 0:60d829a0353a 90 * -1 on failure or unsupported
tushki7 0:60d829a0353a 91 */
tushki7 0:60d829a0353a 92 virtual off_t lseek(off_t offset, int whence) = 0;
tushki7 0:60d829a0353a 93
tushki7 0:60d829a0353a 94 /** Flush any buffers associated with the FileHandle, ensuring it
tushki7 0:60d829a0353a 95 * is up to date on disk
tushki7 0:60d829a0353a 96 *
tushki7 0:60d829a0353a 97 * @returns
tushki7 0:60d829a0353a 98 * 0 on success or un-needed,
tushki7 0:60d829a0353a 99 * -1 on error
tushki7 0:60d829a0353a 100 */
tushki7 0:60d829a0353a 101 virtual int fsync() = 0;
tushki7 0:60d829a0353a 102
tushki7 0:60d829a0353a 103 virtual off_t flen() {
tushki7 0:60d829a0353a 104 /* remember our current position */
tushki7 0:60d829a0353a 105 off_t pos = lseek(0, SEEK_CUR);
tushki7 0:60d829a0353a 106 if(pos == -1) return -1;
tushki7 0:60d829a0353a 107 /* seek to the end to get the file length */
tushki7 0:60d829a0353a 108 off_t res = lseek(0, SEEK_END);
tushki7 0:60d829a0353a 109 /* return to our old position */
tushki7 0:60d829a0353a 110 lseek(pos, SEEK_SET);
tushki7 0:60d829a0353a 111 return res;
tushki7 0:60d829a0353a 112 }
tushki7 0:60d829a0353a 113
tushki7 0:60d829a0353a 114 virtual ~FileHandle();
tushki7 0:60d829a0353a 115 };
tushki7 0:60d829a0353a 116
tushki7 0:60d829a0353a 117 } // namespace mbed
tushki7 0:60d829a0353a 118
tushki7 0:60d829a0353a 119 #endif