hellomqttt to thingspeak mqtt and ifttt

Dependencies:   Servo MQTTPacket FP

Committer:
jasonberry
Date:
Wed May 05 14:48:01 2021 +0000
Revision:
25:ca1b1098c77f
TEST

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jasonberry 25:ca1b1098c77f 1 /* mbed library for the mbed Lab Board 128*32 pixel LCD
jasonberry 25:ca1b1098c77f 2 * use C12832 controller
jasonberry 25:ca1b1098c77f 3 * Copyright (c) 2012 Peter Drescher - DC2PD
jasonberry 25:ca1b1098c77f 4 * Released under the MIT License: http://mbed.org/license/mit
jasonberry 25:ca1b1098c77f 5 *
jasonberry 25:ca1b1098c77f 6 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jasonberry 25:ca1b1098c77f 7 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jasonberry 25:ca1b1098c77f 8 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jasonberry 25:ca1b1098c77f 9 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jasonberry 25:ca1b1098c77f 10 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jasonberry 25:ca1b1098c77f 11 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jasonberry 25:ca1b1098c77f 12 * THE SOFTWARE.
jasonberry 25:ca1b1098c77f 13 */
jasonberry 25:ca1b1098c77f 14
jasonberry 25:ca1b1098c77f 15 #ifndef C12832_H
jasonberry 25:ca1b1098c77f 16 #define C12832_H
jasonberry 25:ca1b1098c77f 17
jasonberry 25:ca1b1098c77f 18 #include "mbed.h"
jasonberry 25:ca1b1098c77f 19 #include "GraphicsDisplay.h"
jasonberry 25:ca1b1098c77f 20
jasonberry 25:ca1b1098c77f 21
jasonberry 25:ca1b1098c77f 22 /**
jasonberry 25:ca1b1098c77f 23 * Optional Defines:
jasonberry 25:ca1b1098c77f 24 * #define debug_lcd 1 enable infos to PC_USB
jasonberry 25:ca1b1098c77f 25 */
jasonberry 25:ca1b1098c77f 26
jasonberry 25:ca1b1098c77f 27 // some defines for the DMA use
jasonberry 25:ca1b1098c77f 28 #define DMA_CHANNEL_ENABLE 1
jasonberry 25:ca1b1098c77f 29 #define DMA_TRANSFER_TYPE_M2P (1UL << 11)
jasonberry 25:ca1b1098c77f 30 #define DMA_CHANNEL_TCIE (1UL << 31)
jasonberry 25:ca1b1098c77f 31 #define DMA_CHANNEL_SRC_INC (1UL << 26)
jasonberry 25:ca1b1098c77f 32 #define DMA_MASK_IE (1UL << 14)
jasonberry 25:ca1b1098c77f 33 #define DMA_MASK_ITC (1UL << 15)
jasonberry 25:ca1b1098c77f 34 #define DMA_SSP1_TX (1UL << 2)
jasonberry 25:ca1b1098c77f 35 #define DMA_SSP0_TX (0)
jasonberry 25:ca1b1098c77f 36 #define DMA_DEST_SSP1_TX (2UL << 6)
jasonberry 25:ca1b1098c77f 37 #define DMA_DEST_SSP0_TX (0UL << 6)
jasonberry 25:ca1b1098c77f 38
jasonberry 25:ca1b1098c77f 39 /**
jasonberry 25:ca1b1098c77f 40 * Draw mode
jasonberry 25:ca1b1098c77f 41 * NORMAL
jasonberry 25:ca1b1098c77f 42 * XOR set pixel by xor the screen
jasonberry 25:ca1b1098c77f 43 */
jasonberry 25:ca1b1098c77f 44 enum {NORMAL,XOR};
jasonberry 25:ca1b1098c77f 45
jasonberry 25:ca1b1098c77f 46 /**
jasonberry 25:ca1b1098c77f 47 * Bitmap
jasonberry 25:ca1b1098c77f 48 */
jasonberry 25:ca1b1098c77f 49 struct Bitmap{
jasonberry 25:ca1b1098c77f 50 int xSize;
jasonberry 25:ca1b1098c77f 51 int ySize;
jasonberry 25:ca1b1098c77f 52 int Byte_in_Line;
jasonberry 25:ca1b1098c77f 53 char* data;
jasonberry 25:ca1b1098c77f 54 };
jasonberry 25:ca1b1098c77f 55
jasonberry 25:ca1b1098c77f 56 /**
jasonberry 25:ca1b1098c77f 57 * The C12832 class
jasonberry 25:ca1b1098c77f 58 */
jasonberry 25:ca1b1098c77f 59 class C12832 : public GraphicsDisplay
jasonberry 25:ca1b1098c77f 60 {
jasonberry 25:ca1b1098c77f 61 public:
jasonberry 25:ca1b1098c77f 62 /**
jasonberry 25:ca1b1098c77f 63 * Create a C12832 object connected to SPI1
jasonberry 25:ca1b1098c77f 64 */
jasonberry 25:ca1b1098c77f 65 C12832(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs, const char* name = "LCD");
jasonberry 25:ca1b1098c77f 66
jasonberry 25:ca1b1098c77f 67 /**
jasonberry 25:ca1b1098c77f 68 * Get the width of the screen in pixel
jasonberry 25:ca1b1098c77f 69 *
jasonberry 25:ca1b1098c77f 70 * @returns width of screen in pixel
jasonberry 25:ca1b1098c77f 71 *
jasonberry 25:ca1b1098c77f 72 */
jasonberry 25:ca1b1098c77f 73 virtual int width();
jasonberry 25:ca1b1098c77f 74
jasonberry 25:ca1b1098c77f 75 /**
jasonberry 25:ca1b1098c77f 76 * Get the height of the screen in pixel
jasonberry 25:ca1b1098c77f 77 *
jasonberry 25:ca1b1098c77f 78 * @returns height of screen in pixel
jasonberry 25:ca1b1098c77f 79 */
jasonberry 25:ca1b1098c77f 80 virtual int height();
jasonberry 25:ca1b1098c77f 81
jasonberry 25:ca1b1098c77f 82 /**
jasonberry 25:ca1b1098c77f 83 * Draw a pixel at x,y black or white
jasonberry 25:ca1b1098c77f 84 *
jasonberry 25:ca1b1098c77f 85 * @param x horizontal position
jasonberry 25:ca1b1098c77f 86 * @param y vertical position
jasonberry 25:ca1b1098c77f 87 * @param color - 1 set pixel, 0 erase pixel
jasonberry 25:ca1b1098c77f 88 */
jasonberry 25:ca1b1098c77f 89 virtual void pixel(int x, int y,int colour);
jasonberry 25:ca1b1098c77f 90
jasonberry 25:ca1b1098c77f 91 /**
jasonberry 25:ca1b1098c77f 92 * Draw a circle
jasonberry 25:ca1b1098c77f 93 *
jasonberry 25:ca1b1098c77f 94 * @param x0,y0 center
jasonberry 25:ca1b1098c77f 95 * @param r radius
jasonberry 25:ca1b1098c77f 96 * @param color - 1 set pixel, 0 erase pixel
jasonberry 25:ca1b1098c77f 97 */
jasonberry 25:ca1b1098c77f 98 void circle(int x, int y, int r, int colour);
jasonberry 25:ca1b1098c77f 99
jasonberry 25:ca1b1098c77f 100 /**
jasonberry 25:ca1b1098c77f 101 * Draw a filled circle
jasonberry 25:ca1b1098c77f 102 *
jasonberry 25:ca1b1098c77f 103 * @param x0,y0 center
jasonberry 25:ca1b1098c77f 104 * @param r radius
jasonberry 25:ca1b1098c77f 105 * @param color - 1 set pixel, 0 erase pixel
jasonberry 25:ca1b1098c77f 106 *
jasonberry 25:ca1b1098c77f 107 * Use circle with different radius,
jasonberry 25:ca1b1098c77f 108 * Can miss some pixels
jasonberry 25:ca1b1098c77f 109 */
jasonberry 25:ca1b1098c77f 110 void fillcircle(int x, int y, int r, int colour);
jasonberry 25:ca1b1098c77f 111
jasonberry 25:ca1b1098c77f 112 /**
jasonberry 25:ca1b1098c77f 113 * Draw a 1 pixel line
jasonberry 25:ca1b1098c77f 114 *
jasonberry 25:ca1b1098c77f 115 * @param x0,y0 start point
jasonberry 25:ca1b1098c77f 116 * @param x1,y1 stop point
jasonberry 25:ca1b1098c77f 117 * @param color - 1 set pixel, 0 erase pixel
jasonberry 25:ca1b1098c77f 118 */
jasonberry 25:ca1b1098c77f 119 void line(int x0, int y0, int x1, int y1, int colour);
jasonberry 25:ca1b1098c77f 120
jasonberry 25:ca1b1098c77f 121 /**
jasonberry 25:ca1b1098c77f 122 * Draw a rect
jasonberry 25:ca1b1098c77f 123 *
jasonberry 25:ca1b1098c77f 124 * @param x0,y0 top left corner
jasonberry 25:ca1b1098c77f 125 * @param x1,y1 down right corner
jasonberry 25:ca1b1098c77f 126 * @param color - 1 set pixel, 0 erase pixel
jasonberry 25:ca1b1098c77f 127 */
jasonberry 25:ca1b1098c77f 128 void rect(int x0, int y0, int x1, int y1, int colour);
jasonberry 25:ca1b1098c77f 129
jasonberry 25:ca1b1098c77f 130 /**
jasonberry 25:ca1b1098c77f 131 * Draw a filled rect
jasonberry 25:ca1b1098c77f 132 *
jasonberry 25:ca1b1098c77f 133 * @param x0,y0 top left corner
jasonberry 25:ca1b1098c77f 134 * @param x1,y1 down right corner
jasonberry 25:ca1b1098c77f 135 * @param color - 1 set pixel, 0 erase pixel
jasonberry 25:ca1b1098c77f 136 */
jasonberry 25:ca1b1098c77f 137 void fillrect(int x0, int y0, int x1, int y1, int colour);
jasonberry 25:ca1b1098c77f 138
jasonberry 25:ca1b1098c77f 139 /**
jasonberry 25:ca1b1098c77f 140 * Copy display buffer to LCD
jasonberry 25:ca1b1098c77f 141 */
jasonberry 25:ca1b1098c77f 142 void copy_to_lcd(void);
jasonberry 25:ca1b1098c77f 143
jasonberry 25:ca1b1098c77f 144 /**
jasonberry 25:ca1b1098c77f 145 * Set the orienation of the screen
jasonberry 25:ca1b1098c77f 146 */
jasonberry 25:ca1b1098c77f 147
jasonberry 25:ca1b1098c77f 148 void set_contrast(unsigned int o);
jasonberry 25:ca1b1098c77f 149
jasonberry 25:ca1b1098c77f 150 /**
jasonberry 25:ca1b1098c77f 151 * Read the contrast level
jasonberry 25:ca1b1098c77f 152 */
jasonberry 25:ca1b1098c77f 153 unsigned int get_contrast(void);
jasonberry 25:ca1b1098c77f 154
jasonberry 25:ca1b1098c77f 155 /**
jasonberry 25:ca1b1098c77f 156 * Invert the screen
jasonberry 25:ca1b1098c77f 157 *
jasonberry 25:ca1b1098c77f 158 * @param o = 0 normal, 1 invert
jasonberry 25:ca1b1098c77f 159 */
jasonberry 25:ca1b1098c77f 160 void invert(unsigned int o);
jasonberry 25:ca1b1098c77f 161
jasonberry 25:ca1b1098c77f 162 /**
jasonberry 25:ca1b1098c77f 163 * Clear the screen
jasonberry 25:ca1b1098c77f 164 */
jasonberry 25:ca1b1098c77f 165 virtual void cls(void);
jasonberry 25:ca1b1098c77f 166
jasonberry 25:ca1b1098c77f 167 /**
jasonberry 25:ca1b1098c77f 168 * Set the drawing mode
jasonberry 25:ca1b1098c77f 169 *
jasonberry 25:ca1b1098c77f 170 * @param mode NORMAl or XOR
jasonberry 25:ca1b1098c77f 171 */
jasonberry 25:ca1b1098c77f 172 void setmode(int mode);
jasonberry 25:ca1b1098c77f 173
jasonberry 25:ca1b1098c77f 174 virtual int columns(void);
jasonberry 25:ca1b1098c77f 175
jasonberry 25:ca1b1098c77f 176 /**
jasonberry 25:ca1b1098c77f 177 * Calculate the max number of columns.
jasonberry 25:ca1b1098c77f 178 * Depends on actual font size
jasonberry 25:ca1b1098c77f 179 *
jasonberry 25:ca1b1098c77f 180 * @returns max column
jasonberry 25:ca1b1098c77f 181 */
jasonberry 25:ca1b1098c77f 182 virtual int rows(void);
jasonberry 25:ca1b1098c77f 183
jasonberry 25:ca1b1098c77f 184 /**
jasonberry 25:ca1b1098c77f 185 * Put a char on the screen
jasonberry 25:ca1b1098c77f 186 *
jasonberry 25:ca1b1098c77f 187 * @param value char to print
jasonberry 25:ca1b1098c77f 188 * @returns printed char
jasonberry 25:ca1b1098c77f 189 */
jasonberry 25:ca1b1098c77f 190 virtual int _putc(int value);
jasonberry 25:ca1b1098c77f 191
jasonberry 25:ca1b1098c77f 192 /**
jasonberry 25:ca1b1098c77f 193 * Draw a character on given position out of the active font to the LCD
jasonberry 25:ca1b1098c77f 194 *
jasonberry 25:ca1b1098c77f 195 * @param x x-position of char (top left)
jasonberry 25:ca1b1098c77f 196 * @param y y-position
jasonberry 25:ca1b1098c77f 197 * @param c char to print
jasonberry 25:ca1b1098c77f 198 */
jasonberry 25:ca1b1098c77f 199 virtual void character(int x, int y, int c);
jasonberry 25:ca1b1098c77f 200
jasonberry 25:ca1b1098c77f 201 /**
jasonberry 25:ca1b1098c77f 202 * Setup cursor position
jasonberry 25:ca1b1098c77f 203 *
jasonberry 25:ca1b1098c77f 204 * @param x x-position (top left)
jasonberry 25:ca1b1098c77f 205 * @param y y-position
jasonberry 25:ca1b1098c77f 206 */
jasonberry 25:ca1b1098c77f 207 virtual void locate(int x, int y);
jasonberry 25:ca1b1098c77f 208
jasonberry 25:ca1b1098c77f 209 /**
jasonberry 25:ca1b1098c77f 210 * Setup auto update of screen
jasonberry 25:ca1b1098c77f 211 *
jasonberry 25:ca1b1098c77f 212 * @param up 1 = on , 0 = off
jasonberry 25:ca1b1098c77f 213 *
jasonberry 25:ca1b1098c77f 214 * if switched off the program has to call copy_to_lcd()
jasonberry 25:ca1b1098c77f 215 * to update screen from framebuffer
jasonberry 25:ca1b1098c77f 216 */
jasonberry 25:ca1b1098c77f 217 void set_auto_up(unsigned int up);
jasonberry 25:ca1b1098c77f 218
jasonberry 25:ca1b1098c77f 219 /**
jasonberry 25:ca1b1098c77f 220 * Get status of the auto update function
jasonberry 25:ca1b1098c77f 221 *
jasonberry 25:ca1b1098c77f 222 * @returns if auto update is on
jasonberry 25:ca1b1098c77f 223 */
jasonberry 25:ca1b1098c77f 224 unsigned int get_auto_up(void);
jasonberry 25:ca1b1098c77f 225
jasonberry 25:ca1b1098c77f 226 /** Vars */
jasonberry 25:ca1b1098c77f 227 SPI _spi;
jasonberry 25:ca1b1098c77f 228 DigitalOut _reset;
jasonberry 25:ca1b1098c77f 229 DigitalOut _A0;
jasonberry 25:ca1b1098c77f 230 DigitalOut _CS;
jasonberry 25:ca1b1098c77f 231 unsigned char* font;
jasonberry 25:ca1b1098c77f 232 unsigned int draw_mode;
jasonberry 25:ca1b1098c77f 233
jasonberry 25:ca1b1098c77f 234
jasonberry 25:ca1b1098c77f 235 /**
jasonberry 25:ca1b1098c77f 236 * Select the font to use
jasonberry 25:ca1b1098c77f 237 *
jasonberry 25:ca1b1098c77f 238 * @param f pointer to font array
jasonberry 25:ca1b1098c77f 239 *
jasonberry 25:ca1b1098c77f 240 * font array can created with GLCD Font Creator from http://www.mikroe.com
jasonberry 25:ca1b1098c77f 241 * you have to add 4 parameter at the beginning of the font array to use:
jasonberry 25:ca1b1098c77f 242 * - the number of byte / char
jasonberry 25:ca1b1098c77f 243 * - the vertial size in pixel
jasonberry 25:ca1b1098c77f 244 * - the horizontal size in pixel
jasonberry 25:ca1b1098c77f 245 * - the number of byte per vertical line
jasonberry 25:ca1b1098c77f 246 * you also have to change the array to char[]
jasonberry 25:ca1b1098c77f 247 */
jasonberry 25:ca1b1098c77f 248 void set_font(unsigned char* f);
jasonberry 25:ca1b1098c77f 249
jasonberry 25:ca1b1098c77f 250 /**
jasonberry 25:ca1b1098c77f 251 * Print bitmap to buffer
jasonberry 25:ca1b1098c77f 252 *
jasonberry 25:ca1b1098c77f 253 * @param bm Bitmap in flash
jasonberry 25:ca1b1098c77f 254 * @param x x start
jasonberry 25:ca1b1098c77f 255 * @param y y start
jasonberry 25:ca1b1098c77f 256 */
jasonberry 25:ca1b1098c77f 257 void print_bm(Bitmap bm, int x, int y);
jasonberry 25:ca1b1098c77f 258
jasonberry 25:ca1b1098c77f 259 protected:
jasonberry 25:ca1b1098c77f 260
jasonberry 25:ca1b1098c77f 261 /**
jasonberry 25:ca1b1098c77f 262 * Draw a horizontal line
jasonberry 25:ca1b1098c77f 263 *
jasonberry 25:ca1b1098c77f 264 * @param x0 horizontal start
jasonberry 25:ca1b1098c77f 265 * @param x1 horizontal stop
jasonberry 25:ca1b1098c77f 266 * @param y vertical position
jasonberry 25:ca1b1098c77f 267 * @param color - 1 set pixel, 0 erase pixel
jasonberry 25:ca1b1098c77f 268 */
jasonberry 25:ca1b1098c77f 269 void hline(int x0, int x1, int y, int colour);
jasonberry 25:ca1b1098c77f 270
jasonberry 25:ca1b1098c77f 271 /**
jasonberry 25:ca1b1098c77f 272 * Draw a vertical line
jasonberry 25:ca1b1098c77f 273 *
jasonberry 25:ca1b1098c77f 274 * @param x horizontal position
jasonberry 25:ca1b1098c77f 275 * @param y0 vertical start
jasonberry 25:ca1b1098c77f 276 * @param y1 vertical stop
jasonberry 25:ca1b1098c77f 277 * @param color - 1 set pixel, 0 erase pixel
jasonberry 25:ca1b1098c77f 278 */
jasonberry 25:ca1b1098c77f 279 void vline(int y0, int y1, int x, int colour);
jasonberry 25:ca1b1098c77f 280
jasonberry 25:ca1b1098c77f 281 /**
jasonberry 25:ca1b1098c77f 282 * Init the C12832 LCD controller
jasonberry 25:ca1b1098c77f 283 */
jasonberry 25:ca1b1098c77f 284 void lcd_reset();
jasonberry 25:ca1b1098c77f 285
jasonberry 25:ca1b1098c77f 286 /**
jasonberry 25:ca1b1098c77f 287 * Write data to the LCD controller
jasonberry 25:ca1b1098c77f 288 *
jasonberry 25:ca1b1098c77f 289 * @param dat data written to LCD controller
jasonberry 25:ca1b1098c77f 290 */
jasonberry 25:ca1b1098c77f 291 void wr_dat(unsigned char value);
jasonberry 25:ca1b1098c77f 292
jasonberry 25:ca1b1098c77f 293 /**
jasonberry 25:ca1b1098c77f 294 * Write a command the LCD controller
jasonberry 25:ca1b1098c77f 295 *
jasonberry 25:ca1b1098c77f 296 * @param cmd: command to be written
jasonberry 25:ca1b1098c77f 297 */
jasonberry 25:ca1b1098c77f 298 void wr_cmd(unsigned char value);
jasonberry 25:ca1b1098c77f 299
jasonberry 25:ca1b1098c77f 300 void wr_cnt(unsigned char cmd);
jasonberry 25:ca1b1098c77f 301
jasonberry 25:ca1b1098c77f 302 unsigned int orientation;
jasonberry 25:ca1b1098c77f 303 unsigned int char_x;
jasonberry 25:ca1b1098c77f 304 unsigned int char_y;
jasonberry 25:ca1b1098c77f 305 unsigned char buffer[512];
jasonberry 25:ca1b1098c77f 306 unsigned int contrast;
jasonberry 25:ca1b1098c77f 307 unsigned int auto_up;
jasonberry 25:ca1b1098c77f 308
jasonberry 25:ca1b1098c77f 309 };
jasonberry 25:ca1b1098c77f 310
jasonberry 25:ca1b1098c77f 311
jasonberry 25:ca1b1098c77f 312
jasonberry 25:ca1b1098c77f 313
jasonberry 25:ca1b1098c77f 314 #endif