For YRL Robot Arm

Committer:
jah128
Date:
Fri Mar 03 13:28:54 2017 +0000
Revision:
0:b14dfd8816da
Updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:b14dfd8816da 1 /* University of York Robotics Laboratory Robot Arm Controller Board
jah128 0:b14dfd8816da 2 *
jah128 0:b14dfd8816da 3
jah128 0:b14dfd8816da 4 * File: display.cpp
jah128 0:b14dfd8816da 5 *
jah128 0:b14dfd8816da 6 * (C) Dept. Electronics & Computer Science, University of York
jah128 0:b14dfd8816da 7 *
jah128 0:b14dfd8816da 8 * James Hilder, Alan Millard, Shuhei Miyashita, Homero Elizondo, Jon Timmis
jah128 0:b14dfd8816da 9 *
jah128 0:b14dfd8816da 10 *
jah128 0:b14dfd8816da 11 * January 2017
jah128 0:b14dfd8816da 12 *
jah128 0:b14dfd8816da 13 * Driver for the Midas 16x2 I2C LCD Display (MCCOG21605x6W) LCD
jah128 0:b14dfd8816da 14 * [Farnell part 2218942 or 2063206]
jah128 0:b14dfd8816da 15 *
jah128 0:b14dfd8816da 16 */
jah128 0:b14dfd8816da 17
jah128 0:b14dfd8816da 18
jah128 0:b14dfd8816da 19 #ifndef DISPLAY_H
jah128 0:b14dfd8816da 20 #define DISPLAY_H
jah128 0:b14dfd8816da 21
jah128 0:b14dfd8816da 22
jah128 0:b14dfd8816da 23 /**
jah128 0:b14dfd8816da 24 * Display class
jah128 0:b14dfd8816da 25 * Functions for use with the Midas 16x2 I2C LCD Display (MCCOG21605x6W) LCD
jah128 0:b14dfd8816da 26 * Farnell part 2218942 or 2063206
jah128 0:b14dfd8816da 27 *
jah128 0:b14dfd8816da 28 * Example:
jah128 0:b14dfd8816da 29 * @code
jah128 0:b14dfd8816da 30 * #include "robotarm.h"
jah128 0:b14dfd8816da 31 *
jah128 0:b14dfd8816da 32 * Robotarm arm;
jah128 0:b14dfd8816da 33 *
jah128 0:b14dfd8816da 34 * int main() {
jah128 0:b14dfd8816da 35 * arm.init();
jah128 0:b14dfd8816da 36 * display.clear_display; //Clears display
jah128 0:b14dfd8816da 37 * display.set_position(0,2); //Set cursor to row 0 column 2
jah128 0:b14dfd8816da 38 * display.write_string("YORK ROBOTICS");
jah128 0:b14dfd8816da 39 * display.set_position(1,3); //Set cursor to row 1 column 3
jah128 0:b14dfd8816da 40 * display.write_string("LABORATORY");
jah128 0:b14dfd8816da 41 * }
jah128 0:b14dfd8816da 42 * @endcode
jah128 0:b14dfd8816da 43 */
jah128 0:b14dfd8816da 44 class Display : public Stream
jah128 0:b14dfd8816da 45 {
jah128 0:b14dfd8816da 46
jah128 0:b14dfd8816da 47 // Public Functions
jah128 0:b14dfd8816da 48
jah128 0:b14dfd8816da 49 public:
jah128 0:b14dfd8816da 50
jah128 0:b14dfd8816da 51 /** Create the LCD Display object connected to the default pins
jah128 0:b14dfd8816da 52 * (sda = p28, scl = p27)
jah128 0:b14dfd8816da 53 */
jah128 0:b14dfd8816da 54 Display();
jah128 0:b14dfd8816da 55
jah128 0:b14dfd8816da 56 /** Create the LCD Display object connected to specific pins
jah128 0:b14dfd8816da 57 *
jah128 0:b14dfd8816da 58 * @param sda pin - default is p28
jah128 0:b14dfd8816da 59 * @param scl pin - default is p27
jah128 0:b14dfd8816da 60 */
jah128 0:b14dfd8816da 61 Display(PinName sda, PinName scl);
jah128 0:b14dfd8816da 62
jah128 0:b14dfd8816da 63 /** Clear the display
jah128 0:b14dfd8816da 64 */
jah128 0:b14dfd8816da 65 void clear_display(void);
jah128 0:b14dfd8816da 66
jah128 0:b14dfd8816da 67 /** Set cursor to home position
jah128 0:b14dfd8816da 68 */
jah128 0:b14dfd8816da 69 void home(void);
jah128 0:b14dfd8816da 70
jah128 0:b14dfd8816da 71 /** Print string message
jah128 0:b14dfd8816da 72 * @param message - The null-terminated message to print
jah128 0:b14dfd8816da 73 */
jah128 0:b14dfd8816da 74 void write_string(char * message);
jah128 0:b14dfd8816da 75
jah128 0:b14dfd8816da 76 /** Print string message of given length
jah128 0:b14dfd8816da 77 * @param message - The message to print
jah128 0:b14dfd8816da 78 * @param length - The number of characters to display
jah128 0:b14dfd8816da 79 */
jah128 0:b14dfd8816da 80 void write_string(char * message, char length);
jah128 0:b14dfd8816da 81
jah128 0:b14dfd8816da 82 /** Set the row and column of cursor position
jah128 0:b14dfd8816da 83 * @param row - The row of the display to set the cursor to (either 0 or 1)
jah128 0:b14dfd8816da 84 * @param column - The column of the display to set the cursor to (range 0 to 15)
jah128 0:b14dfd8816da 85 */
jah128 0:b14dfd8816da 86 void set_position(char row, char column);
jah128 0:b14dfd8816da 87
jah128 0:b14dfd8816da 88 /** Enable or disable cursor
jah128 0:b14dfd8816da 89 * @param enable - Set to 1 to enable the cursor visibility
jah128 0:b14dfd8816da 90 */
jah128 0:b14dfd8816da 91 void set_cursor(char enable);
jah128 0:b14dfd8816da 92
jah128 0:b14dfd8816da 93 /** Enable or disable cursor blink
jah128 0:b14dfd8816da 94 * @param enable - Set to 1 to enable the cursor blinking mode
jah128 0:b14dfd8816da 95 */
jah128 0:b14dfd8816da 96 void set_blink(char enable);
jah128 0:b14dfd8816da 97
jah128 0:b14dfd8816da 98 /** Enable or disable display
jah128 0:b14dfd8816da 99 * @param enable - Set to 1 to enable the display output
jah128 0:b14dfd8816da 100 */
jah128 0:b14dfd8816da 101 void set_display(char enable);
jah128 0:b14dfd8816da 102
jah128 0:b14dfd8816da 103 //Parts of initialisation routine
jah128 0:b14dfd8816da 104 void post_init(void);
jah128 0:b14dfd8816da 105 void post_post_init(void);
jah128 0:b14dfd8816da 106
jah128 0:b14dfd8816da 107 // Send a 1-byte control message to the display
jah128 0:b14dfd8816da 108 int i2c_message(char byte);
jah128 0:b14dfd8816da 109
jah128 0:b14dfd8816da 110 // Default initialisation sequence for the display
jah128 0:b14dfd8816da 111 void init(void);
jah128 0:b14dfd8816da 112
jah128 0:b14dfd8816da 113 int disp_putc(int c);
jah128 0:b14dfd8816da 114
jah128 0:b14dfd8816da 115
jah128 0:b14dfd8816da 116 private :
jah128 0:b14dfd8816da 117
jah128 0:b14dfd8816da 118 I2C _i2c;
jah128 0:b14dfd8816da 119
jah128 0:b14dfd8816da 120 char display_on;
jah128 0:b14dfd8816da 121 char cursor_on;
jah128 0:b14dfd8816da 122 char blink_on;
jah128 0:b14dfd8816da 123
jah128 0:b14dfd8816da 124 void _set_display();
jah128 0:b14dfd8816da 125
jah128 0:b14dfd8816da 126 virtual int _putc(int c);
jah128 0:b14dfd8816da 127 virtual int _getc();
jah128 0:b14dfd8816da 128
jah128 0:b14dfd8816da 129 };
jah128 0:b14dfd8816da 130
jah128 0:b14dfd8816da 131 #endif // DISPLAY_H
jah128 0:b14dfd8816da 132
jah128 0:b14dfd8816da 133 /*
jah128 0:b14dfd8816da 134 * Copyright 2017 University of York
jah128 0:b14dfd8816da 135 *
jah128 0:b14dfd8816da 136 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
jah128 0:b14dfd8816da 137 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
jah128 0:b14dfd8816da 138 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS
jah128 0:b14dfd8816da 139 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jah128 0:b14dfd8816da 140 * See the License for the specific language governing permissions and limitations under the License.
jah128 0:b14dfd8816da 141 */