add st7565 support
[clinton/Smoothieware.git] / src / modules / utils / panel / panels / ST7565.h
1 /*
2 * ST7565.h
3 *
4 * Created on: 21-06-2013
5 * Author: Wulfnor
6 */
7
8 #ifndef ST7565_H_
9 #define ST7565_H_
10 #include "LcdBase.h"
11 #include "libs/Kernel.h"
12 #include "mbed.h"
13 #include "libs/Pin.h"
14 #include "Panel.h"
15
16 using namespace std;
17 #include <vector>
18 #include <string>
19 #include <cstdio>
20 #include <cstdarg>
21
22 //definitions for lcd
23 #define LCDWIDTH 128
24 #define LCDHEIGHT 64
25 #define LCDPAGES (LCDHEIGHT+7)/8
26 #define FB_SIZE LCDWIDTH*LCDPAGES
27 #define FONT_SIZE_X 6
28 #define FONT_SIZE_Y 8
29 #define ALL_BUTTON_BITS (BUTTON_UP|BUTTON_DOWN|BUTTON_LEFT|BUTTON_RIGHT|BUTTON_SELECT)
30
31 #define spi_frequency_checksum CHECKSUM("spi_frequency")
32 #define click_button_pin_checksum CHECKSUM("click_button_pin")
33 #define up_button_pin_checksum CHECKSUM("up_button_pin")
34 #define down_button_pin_checksum CHECKSUM("down_button_pin")
35 class Panel;
36
37 class ST7565: public LcdBase {
38 public:
39 ST7565();
40 virtual ~ST7565();
41 void home();
42 void clear();
43 void display();
44 void setCursor(uint8_t col, uint8_t row);
45 void init();
46 void write_char(char value);
47 void write(const char* line, int len);
48
49 void on_refresh(bool now=false);
50 //encoder which dosent exist :/
51 uint8_t readButtons();
52 int readEncoderDelta();
53 int getEncoderResolution() { return 2; }
54 uint16_t get_screen_lines() { return 8; }
55 bool hasGraphics() { return true; }
56
57 //added ST7565 commands
58 void send_commands(const unsigned char* buf, size_t size);
59 void send_data(const unsigned char* buf, size_t size);
60 // set column and page number
61 void set_xy(int x, int y);
62 //send pic to whole screen
63 void send_pic(const unsigned char* data);
64 //drawing char
65 int drawChar(int x, int y, unsigned char c, int color);
66 // blit a glyph of w pixels wide and h pixels high to x, y. offset pixel position in glyph by x_offset, y_offset.
67 // span is the width in bytes of the src bitmap
68 // The glyph bytes will be 8 bits of X pixels, msbit->lsbit from top left to bottom right
69 void bltGlyph(int x, int y, int w, int h, const uint8_t *glyph, int span= 0, int x_offset=0, int y_offset=0);
70 void renderGlyph(int x, int y, const uint8_t *g, int pixelWidth, int pixelHeight);
71 void pixel(int x, int y, int colour);
72
73 private:
74 //buffer
75 unsigned char *framebuffer;
76 mbed::SPI* spi;
77 Pin cs;
78 Pin rst;
79 Pin a0;
80 Pin click_pin;
81 Pin up_pin;
82 Pin down_pin;
83 // text cursor position
84 uint8_t tx, ty;
85 };
86
87 #endif /* ST7565_H_ */