UART object

Dependencies:   mbed

Fork of DigoleSerialDisp1 by James Novak

Committer:
jdbunda
Date:
Sun Nov 22 16:01:18 2015 +0000
Revision:
6:fc42c0dc7b7f
Parent:
5:7d3fd21b9ead
New DigoleSerialDisp UART object

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:3cf7c2683c3a 1 /** Digole Serial Display library, I2C
shimniok 0:3cf7c2683c3a 2 *
shimniok 4:c4b2a8f0d056 3 * @Author: Digole Digital Solutions : www.digole.com ported from Arduino to mbed by Michael Shimniok www.bot-thoughts.com
shimniok 0:3cf7c2683c3a 4 */
shimniok 0:3cf7c2683c3a 5 #ifndef DigoleSerialDisp_h
shimniok 0:3cf7c2683c3a 6 #define DigoleSerialDisp_h
shimniok 0:3cf7c2683c3a 7
shimniok 0:3cf7c2683c3a 8 #include "mbed.h"
jdbunda 6:fc42c0dc7b7f 9 #include "Serial.h"
shimniok 0:3cf7c2683c3a 10 #include <inttypes.h>
shimniok 0:3cf7c2683c3a 11
shimniok 0:3cf7c2683c3a 12 #define DEC 10
shimniok 0:3cf7c2683c3a 13 #define HEX 16
shimniok 0:3cf7c2683c3a 14 #define OCT 8
shimniok 0:3cf7c2683c3a 15 #define BIN 2
shimniok 0:3cf7c2683c3a 16
shimniok 0:3cf7c2683c3a 17 #define delay(x) wait_ms(x)
shimniok 0:3cf7c2683c3a 18
shimniok 0:3cf7c2683c3a 19 // Communication set up command
shimniok 0:3cf7c2683c3a 20 // Text function command
shimniok 0:3cf7c2683c3a 21 // Graph function command
shimniok 0:3cf7c2683c3a 22
shimniok 0:3cf7c2683c3a 23 #define Serial_UART 0;
shimniok 0:3cf7c2683c3a 24 #define Serial_I2C 1;
shimniok 0:3cf7c2683c3a 25 #define Serial_SPI 2;
shimniok 0:3cf7c2683c3a 26 #define _TEXT_ 0
shimniok 0:3cf7c2683c3a 27 #define _GRAPH_ 1
shimniok 0:3cf7c2683c3a 28
jdbunda 6:fc42c0dc7b7f 29
jdbunda 6:fc42c0dc7b7f 30 class DigoleSerialDisp : Serial
jdbunda 6:fc42c0dc7b7f 31 {
shimniok 0:3cf7c2683c3a 32 public:
jdbunda 6:fc42c0dc7b7f 33 DigoleSerialDisp(PinName, PinName);
jdbunda 6:fc42c0dc7b7f 34
jdbunda 6:fc42c0dc7b7f 35 // Simple write methods.
shimniok 0:3cf7c2683c3a 36 size_t write(const char x);
shimniok 0:3cf7c2683c3a 37
shimniok 0:3cf7c2683c3a 38
shimniok 0:3cf7c2683c3a 39 /** Write out raw data from a buffer
shimniok 1:959715b1d042 40 * @param buffer is the char array to write
shimniok 1:959715b1d042 41 * @param size is the the number of bytes to write
shimniok 0:3cf7c2683c3a 42 * @returns size
shimniok 0:3cf7c2683c3a 43 */
shimniok 0:3cf7c2683c3a 44 size_t write(const char *buffer, size_t size);
shimniok 0:3cf7c2683c3a 45
shimniok 0:3cf7c2683c3a 46
shimniok 0:3cf7c2683c3a 47 /** Write out raw string
shimniok 1:959715b1d042 48 * @param str is the string to write
shimniok 0:3cf7c2683c3a 49 * @returns number of bytes written
shimniok 0:3cf7c2683c3a 50 */
shimniok 0:3cf7c2683c3a 51 size_t write(const char *str);
shimniok 0:3cf7c2683c3a 52
shimniok 0:3cf7c2683c3a 53
shimniok 0:3cf7c2683c3a 54 /** Prints a char to the display in a single I2C transmission using "TTb\0"
shimniok 0:3cf7c2683c3a 55 *
shimniok 1:959715b1d042 56 * @param c is the character to print
shimniok 0:3cf7c2683c3a 57 * @returns 1
shimniok 0:3cf7c2683c3a 58 */
shimniok 0:3cf7c2683c3a 59 size_t print(const char c);
shimniok 0:3cf7c2683c3a 60
shimniok 0:3cf7c2683c3a 61
shimniok 0:3cf7c2683c3a 62 /** Prints a string of data to the display in a single I2C transmission using "TTbbb...\0"
shimniok 0:3cf7c2683c3a 63 *
shimniok 1:959715b1d042 64 * @param s is the null-terminated char array to print
shimniok 0:3cf7c2683c3a 65 * @returns length of s
shimniok 0:3cf7c2683c3a 66 */
shimniok 0:3cf7c2683c3a 67 size_t print(const char s[]);
shimniok 0:3cf7c2683c3a 68
shimniok 0:3cf7c2683c3a 69
shimniok 0:3cf7c2683c3a 70 /** Print out an unsigned char as a number
shimniok 1:959715b1d042 71 * @param u is the integer to print
shimniok 1:959715b1d042 72 * @param base is the base to print, either DEC (default), HEX, BIN
shimniok 1:959715b1d042 73 * @returns number of chars written
shimniok 0:3cf7c2683c3a 74 */
shimniok 0:3cf7c2683c3a 75 size_t print(unsigned char u, int base = DEC);
shimniok 0:3cf7c2683c3a 76
shimniok 0:3cf7c2683c3a 77
shimniok 0:3cf7c2683c3a 78 /** Print out an integer
shimniok 1:959715b1d042 79 * @param i is the integer to print
shimniok 1:959715b1d042 80 * @param base is the base to print, either DEC (default), HEX, BIN
shimniok 1:959715b1d042 81 * @returns number of chars written
shimniok 0:3cf7c2683c3a 82 */
shimniok 0:3cf7c2683c3a 83 size_t print(int i, int base = DEC);
shimniok 0:3cf7c2683c3a 84
shimniok 0:3cf7c2683c3a 85
shimniok 0:3cf7c2683c3a 86 /** Print out an unsigned integer
shimniok 1:959715b1d042 87 * @param u is the integer to print
shimniok 1:959715b1d042 88 * @param base is the base to print, either DEC (default), HEX, BIN
shimniok 1:959715b1d042 89 * @returns number of chars written
shimniok 0:3cf7c2683c3a 90 */
shimniok 0:3cf7c2683c3a 91 size_t print(unsigned int u, int base = DEC);
shimniok 0:3cf7c2683c3a 92
shimniok 0:3cf7c2683c3a 93
shimniok 0:3cf7c2683c3a 94 /** Print out a long as a number
shimniok 1:959715b1d042 95 * @param l is the integer to print
shimniok 1:959715b1d042 96 * @param base is the base to print, either DEC (default), HEX, BIN
shimniok 1:959715b1d042 97 * @returns number of chars written
shimniok 0:3cf7c2683c3a 98 */
shimniok 0:3cf7c2683c3a 99 size_t print(long l, int base = DEC);
shimniok 0:3cf7c2683c3a 100
shimniok 0:3cf7c2683c3a 101
shimniok 0:3cf7c2683c3a 102 /** Print out an unsigned long
shimniok 1:959715b1d042 103 * @param l is the integer to print
shimniok 1:959715b1d042 104 * @param base is the base to print, either DEC (default), HEX, BIN
shimniok 1:959715b1d042 105 * @returns number of chars written
shimniok 0:3cf7c2683c3a 106 */
shimniok 0:3cf7c2683c3a 107 size_t print(unsigned long l, int base = DEC);
shimniok 0:3cf7c2683c3a 108
shimniok 0:3cf7c2683c3a 109
shimniok 0:3cf7c2683c3a 110 /** Print out a double
shimniok 1:959715b1d042 111 * @param f is the integer to print
shimniok 1:959715b1d042 112 * @param digits is the number of digits after the decimal
shimniok 0:3cf7c2683c3a 113 */
shimniok 0:3cf7c2683c3a 114 size_t print(double f, int digits = 2);
shimniok 0:3cf7c2683c3a 115
shimniok 0:3cf7c2683c3a 116
shimniok 0:3cf7c2683c3a 117 /** Prints a string of data to the display in a single I2C transmission using "TTbbb...\0"
shimniok 0:3cf7c2683c3a 118 *
shimniok 1:959715b1d042 119 * @param s is the null-terminated char array to print
shimniok 0:3cf7c2683c3a 120 * @returns length of s
shimniok 0:3cf7c2683c3a 121 */
shimniok 0:3cf7c2683c3a 122 size_t println(const char s[]);
shimniok 0:3cf7c2683c3a 123
shimniok 0:3cf7c2683c3a 124
shimniok 0:3cf7c2683c3a 125 /** Prints a char the display in a single I2C transmission using "TTb\0"
shimniok 0:3cf7c2683c3a 126 *
shimniok 1:959715b1d042 127 * @param c is the character to print
shimniok 0:3cf7c2683c3a 128 * @returns 1
shimniok 0:3cf7c2683c3a 129 */
shimniok 0:3cf7c2683c3a 130 size_t println(char c);
shimniok 0:3cf7c2683c3a 131
shimniok 0:3cf7c2683c3a 132
shimniok 0:3cf7c2683c3a 133 /** Prints an unsigned char as a number
shimniok 0:3cf7c2683c3a 134 *
shimniok 1:959715b1d042 135 * @param u is the unsigned char number
shimniok 0:3cf7c2683c3a 136 * @returns 1
shimniok 0:3cf7c2683c3a 137 */
shimniok 0:3cf7c2683c3a 138 size_t println(unsigned char u, int base = DEC);
shimniok 0:3cf7c2683c3a 139
shimniok 0:3cf7c2683c3a 140
shimniok 0:3cf7c2683c3a 141 /** Print out an integer
shimniok 1:959715b1d042 142 * @param i is the integer to print
shimniok 1:959715b1d042 143 * @param base is the base to print, either DEC (default), HEX, BIN
shimniok 1:959715b1d042 144 * @returns number of chars written
shimniok 0:3cf7c2683c3a 145 */
shimniok 0:3cf7c2683c3a 146 size_t println(int i, int base = DEC);
shimniok 0:3cf7c2683c3a 147
shimniok 0:3cf7c2683c3a 148
shimniok 0:3cf7c2683c3a 149 /** Print out an unsigned char as a number
shimniok 1:959715b1d042 150 * @param u is the integer to print
shimniok 1:959715b1d042 151 * @param base is the base to print, either DEC (default), HEX, BIN
shimniok 1:959715b1d042 152 * @returns number of chars written
shimniok 0:3cf7c2683c3a 153 */
shimniok 0:3cf7c2683c3a 154 size_t println(unsigned int u, int base = DEC);
shimniok 0:3cf7c2683c3a 155
shimniok 0:3cf7c2683c3a 156
shimniok 0:3cf7c2683c3a 157 /** Print out a long as a number
shimniok 1:959715b1d042 158 * @param l is the integer to print
shimniok 1:959715b1d042 159 * @param base is the base to print, either DEC (default), HEX, BIN
shimniok 1:959715b1d042 160 * @returns number of chars written
shimniok 0:3cf7c2683c3a 161 */
shimniok 0:3cf7c2683c3a 162 size_t println(long l, int base = DEC);
shimniok 0:3cf7c2683c3a 163
shimniok 0:3cf7c2683c3a 164
shimniok 0:3cf7c2683c3a 165 /** Print out an unsigned long
shimniok 1:959715b1d042 166 * @param l is the integer to print
shimniok 1:959715b1d042 167 * @param base is the base to print, either DEC (default), HEX, BIN
shimniok 1:959715b1d042 168 * @returns number of chars written
shimniok 0:3cf7c2683c3a 169 */
shimniok 0:3cf7c2683c3a 170 size_t println(unsigned long l, int base = DEC);
shimniok 0:3cf7c2683c3a 171
shimniok 0:3cf7c2683c3a 172
shimniok 0:3cf7c2683c3a 173 /** Print out a double
shimniok 1:959715b1d042 174 * @param f is the integer to print
shimniok 1:959715b1d042 175 * @param digits is the number of digits after the decimal
shimniok 1:959715b1d042 176 * @returns number of chars written
shimniok 0:3cf7c2683c3a 177 */
shimniok 0:3cf7c2683c3a 178 size_t println(double f, int digits = 2);
shimniok 0:3cf7c2683c3a 179
shimniok 0:3cf7c2683c3a 180
shimniok 3:e5615f0cb6ee 181 /** prints, well, nothing in this case, but pretend we printed a newline
shimniok 0:3cf7c2683c3a 182 * @returns 1
shimniok 0:3cf7c2683c3a 183 */
shimniok 0:3cf7c2683c3a 184 size_t println(void);
shimniok 0:3cf7c2683c3a 185
shimniok 0:3cf7c2683c3a 186
shimniok 0:3cf7c2683c3a 187 /*---------functions for Text and Graphic LCD adapters---------*/
shimniok 0:3cf7c2683c3a 188
shimniok 0:3cf7c2683c3a 189 /** Turns off the cursor */
shimniok 0:3cf7c2683c3a 190 void disableCursor(void);
shimniok 0:3cf7c2683c3a 191
shimniok 0:3cf7c2683c3a 192 /** Turns on the cursor */
shimniok 0:3cf7c2683c3a 193 void enableCursor(void);
shimniok 0:3cf7c2683c3a 194
shimniok 0:3cf7c2683c3a 195 /** Displays a string at specified coordinates
shimniok 1:959715b1d042 196 * @param x is the x coordinate to display the string
shimniok 1:959715b1d042 197 * @param y is the y coordinate to display the string
shimniok 1:959715b1d042 198 * @param s is the string to display
shimniok 0:3cf7c2683c3a 199 */
shimniok 0:3cf7c2683c3a 200 void drawStr(uint8_t x, uint8_t y, const char *s);
shimniok 0:3cf7c2683c3a 201
shimniok 0:3cf7c2683c3a 202 /** Sets the print position for graphics or text
shimniok 1:959715b1d042 203 * @param x is the x coordinate to display the string
shimniok 1:959715b1d042 204 * @param y is the y coordinate to display the string
shimniok 1:959715b1d042 205 * @param graph if set to _TEXT_ affects subsequent text position, otherwise, affects graphics position
shimniok 0:3cf7c2683c3a 206 */
shimniok 0:3cf7c2683c3a 207 void setPrintPos(uint8_t x, uint8_t y, uint8_t graph = _TEXT_);
shimniok 0:3cf7c2683c3a 208
shimniok 0:3cf7c2683c3a 209 /** Clears the display screen */
shimniok 0:3cf7c2683c3a 210 void clearScreen(void);
shimniok 0:3cf7c2683c3a 211
shimniok 0:3cf7c2683c3a 212 /** Configure your LCD if other than 1602 and the chip is other than KS0066U/F / HD44780
shimniok 1:959715b1d042 213 * @param col is the number of columns
shimniok 1:959715b1d042 214 * @param row is the number of rows
shimniok 0:3cf7c2683c3a 215 */
shimniok 0:3cf7c2683c3a 216 void setLCDColRow(uint8_t col, uint8_t row);
shimniok 0:3cf7c2683c3a 217
shimniok 0:3cf7c2683c3a 218 /** Sets a new I2C address for the display (default is 0x27), the adapter will store the new address in memory
shimniok 1:959715b1d042 219 * @param address is the the new address
shimniok 0:3cf7c2683c3a 220 */
shimniok 0:3cf7c2683c3a 221 void setI2CAddress(uint8_t add);
shimniok 0:3cf7c2683c3a 222
shimniok 0:3cf7c2683c3a 223 /** Display Config on/off, the factory default set is on,
shimniok 0:3cf7c2683c3a 224 * so, when the module is powered up, it will display
shimniok 0:3cf7c2683c3a 225 * current communication mode on LCD, after you
shimniok 0:3cf7c2683c3a 226 * design finished, you can turn it off
shimniok 1:959715b1d042 227 * @param v is the 1 is on, 0 is off
shimniok 0:3cf7c2683c3a 228 */
shimniok 0:3cf7c2683c3a 229 void displayConfig(uint8_t v);
shimniok 0:3cf7c2683c3a 230
shimniok 0:3cf7c2683c3a 231 /** Holdover from Arduino library; not needed */
shimniok 0:3cf7c2683c3a 232 void preprint(void);
shimniok 0:3cf7c2683c3a 233
shimniok 0:3cf7c2683c3a 234 /*----------Functions for Graphic LCD/OLED adapters only---------*/
shimniok 0:3cf7c2683c3a 235 //the functions in this section compatible with u8glib
shimniok 0:3cf7c2683c3a 236 void drawBitmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *bitmap);
shimniok 0:3cf7c2683c3a 237 void setRot90(void);
shimniok 0:3cf7c2683c3a 238 void setRot180(void);
shimniok 0:3cf7c2683c3a 239 void setRot270(void);
shimniok 0:3cf7c2683c3a 240 void undoRotation(void);
shimniok 0:3cf7c2683c3a 241 void setRotation(uint8_t);
shimniok 0:3cf7c2683c3a 242 void setContrast(uint8_t);
shimniok 0:3cf7c2683c3a 243 void drawBox(uint8_t x, uint8_t y, uint8_t w, uint8_t h);
shimniok 0:3cf7c2683c3a 244 void drawCircle(uint8_t x, uint8_t y, uint8_t r, uint8_t = 0);
shimniok 0:3cf7c2683c3a 245 void drawDisc(uint8_t x, uint8_t y, uint8_t r);
shimniok 0:3cf7c2683c3a 246 void drawFrame(uint8_t x, uint8_t y, uint8_t w, uint8_t h);
shimniok 0:3cf7c2683c3a 247 void drawPixel(uint8_t x, uint8_t y, uint8_t = 1);
shimniok 0:3cf7c2683c3a 248 void drawLine(uint8_t x, uint8_t y, uint8_t x1, uint8_t y1);
shimniok 0:3cf7c2683c3a 249 void drawLineTo(uint8_t x, uint8_t y);
shimniok 0:3cf7c2683c3a 250 void drawHLine(uint8_t x, uint8_t y, uint8_t w);
shimniok 0:3cf7c2683c3a 251 void drawVLine(uint8_t x, uint8_t y, uint8_t h);
shimniok 0:3cf7c2683c3a 252 //-------------------------------
shimniok 0:3cf7c2683c3a 253 //special functions for our adapters
shimniok 0:3cf7c2683c3a 254
shimniok 0:3cf7c2683c3a 255 /** Sets the font
shimniok 0:3cf7c2683c3a 256 *
shimniok 0:3cf7c2683c3a 257 * @parameter font - available fonts: 6,10,18,51,120,123, user font 200-203
shimniok 0:3cf7c2683c3a 258 */
shimniok 0:3cf7c2683c3a 259 void setFont(uint8_t font);
shimniok 0:3cf7c2683c3a 260
shimniok 0:3cf7c2683c3a 261 /** go to next text line, depending on the font size */
shimniok 0:3cf7c2683c3a 262 void nextTextLine(void);
shimniok 0:3cf7c2683c3a 263
shimniok 0:3cf7c2683c3a 264 /** set color for graphic function */
shimniok 0:3cf7c2683c3a 265 void setColor(uint8_t);
shimniok 0:3cf7c2683c3a 266
shimniok 0:3cf7c2683c3a 267 /** Turn on back light */
shimniok 0:3cf7c2683c3a 268 void backLightOn(void);
shimniok 0:3cf7c2683c3a 269
shimniok 0:3cf7c2683c3a 270 /** Turn off back light */
shimniok 0:3cf7c2683c3a 271 void backLightOff(void);
shimniok 0:3cf7c2683c3a 272
shimniok 0:3cf7c2683c3a 273 /** send command to LCD drectly
shimniok 0:3cf7c2683c3a 274 * @param d - command
shimniok 0:3cf7c2683c3a 275 */
shimniok 0:3cf7c2683c3a 276 void directCommand(uint8_t d);
shimniok 0:3cf7c2683c3a 277
shimniok 0:3cf7c2683c3a 278 /** send data to LCD drectly
shimniok 1:959715b1d042 279 * @param d is the data
shimniok 0:3cf7c2683c3a 280 */
shimniok 0:3cf7c2683c3a 281 void directData(uint8_t d);
shimniok 0:3cf7c2683c3a 282
shimniok 0:3cf7c2683c3a 283 /** Move rectangle area on screen to another place
shimniok 1:959715b1d042 284 * @param x0, y1 is the top left of the area to move
shimniok 1:959715b1d042 285 * @param x1, y1 is the bottom right of the area to move
shimniok 1:959715b1d042 286 * @param xoffset, yoffset is the the distance to move
shimniok 0:3cf7c2683c3a 287 */
shimniok 0:3cf7c2683c3a 288 void moveArea(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, char xoffset, char yoffset);
shimniok 0:3cf7c2683c3a 289
shimniok 0:3cf7c2683c3a 290 /** Display startup screen */
shimniok 0:3cf7c2683c3a 291 void displayStartScreen(uint8_t m);
shimniok 0:3cf7c2683c3a 292
shimniok 0:3cf7c2683c3a 293 /** Set display mode */
shimniok 0:3cf7c2683c3a 294 void setMode(uint8_t m);
shimniok 0:3cf7c2683c3a 295
shimniok 0:3cf7c2683c3a 296 /** set text position back to previous, only one back allowed */
shimniok 0:3cf7c2683c3a 297 void setTextPosBack(void);
shimniok 0:3cf7c2683c3a 298
shimniok 0:3cf7c2683c3a 299 void setTextPosOffset(char xoffset, char yoffset);
shimniok 0:3cf7c2683c3a 300 void setTextPosAbs(uint8_t x, uint8_t y);
shimniok 0:3cf7c2683c3a 301 void setLinePattern(uint8_t pattern);
shimniok 0:3cf7c2683c3a 302 /** Only for universal serial adapter */
shimniok 0:3cf7c2683c3a 303 void setLCDChip(uint8_t chip);
shimniok 0:3cf7c2683c3a 304
shimniok 0:3cf7c2683c3a 305
shimniok 0:3cf7c2683c3a 306 /** Set Start Screen, 1st B is the lower byte of data length.
shimniok 0:3cf7c2683c3a 307 * Convert images to C array here: <a href="http://www.digole.com/tools/PicturetoC_Hex_converter.php">http://www.digole.com/tools/PicturetoC_Hex_converter.php</a>
shimniok 1:959715b1d042 308 * @param lon is the length of data
shimniok 1:959715b1d042 309 * @param data is the binary data
shimniok 0:3cf7c2683c3a 310 */
shimniok 0:3cf7c2683c3a 311 void uploadStartScreen(int lon, const unsigned char *data); //upload start screen
shimniok 0:3cf7c2683c3a 312
shimniok 0:3cf7c2683c3a 313 /** Upload a user font
shimniok 1:959715b1d042 314 * @param lon is the length of data
shimniok 1:959715b1d042 315 * @param data is the user font data
shimniok 1:959715b1d042 316 * @param sect is the section of memory you want to upload to
shimniok 0:3cf7c2683c3a 317 */
shimniok 0:3cf7c2683c3a 318 void uploadUserFont(int lon, const unsigned char *data, uint8_t sect); //upload user font
shimniok 0:3cf7c2683c3a 319
shimniok 0:3cf7c2683c3a 320 /** Send a Byte to output head on board
shimniok 1:959715b1d042 321 * @param x is the byte to output
shimniok 0:3cf7c2683c3a 322 */
shimniok 0:3cf7c2683c3a 323 void digitalOutput(uint8_t x);
shimniok 0:3cf7c2683c3a 324
shimniok 0:3cf7c2683c3a 325 private:
jdbunda 6:fc42c0dc7b7f 326 // I2C _device;
jdbunda 6:fc42c0dc7b7f 327 // uint8_t _address;
shimniok 0:3cf7c2683c3a 328 uint8_t _Comdelay;
shimniok 0:3cf7c2683c3a 329
shimniok 0:3cf7c2683c3a 330 size_t printNumber(unsigned long n, uint8_t base);
shimniok 0:3cf7c2683c3a 331 size_t printFloat(double number, uint8_t digits);
shimniok 0:3cf7c2683c3a 332 };
shimniok 0:3cf7c2683c3a 333
shimniok 0:3cf7c2683c3a 334 #endif