TINF_MittelwerteUeberwachung

Dependencies:   mbed

Committer:
martwerl
Date:
Thu Nov 15 18:24:11 2018 +0000
Revision:
0:fb8791842ef8
TINF_MittelwerteUeberwachung

Who changed what in which revision?

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