parent
deea00dde3
commit
7592bb1f2f
@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
A2Printer.pde
|
||||||
|
|
||||||
|
Special example code for the A2 Mciro Printer (https://www.sparkfun.com/products/10438)
|
||||||
|
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library, http://code.google.com/p/u8glib/
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "U8glib.h"
|
||||||
|
|
||||||
|
// use this serial interface
|
||||||
|
#define PRINTER_SERIAL Serial
|
||||||
|
// #define PRINTER_SERIAL Serial1
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_com_uart(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
|
||||||
|
switch(msg) {
|
||||||
|
case U8G_COM_MSG_WRITE_BYTE:
|
||||||
|
PRINTER_SERIAL.write(arg_val);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup u8g object, please remove comment from one of the following constructor calls
|
||||||
|
|
||||||
|
// half resolution
|
||||||
|
//U8GLIB u8g(&u8g_dev_a2_micro_printer_192x120_ds, (u8g_com_fnptr)u8g_com_uart);
|
||||||
|
|
||||||
|
// full resolution, requires to uncomment U8G_16BIT in u8g.h
|
||||||
|
//U8GLIB u8g(&u8g_dev_a2_micro_printer_384x240, (u8g_com_fnptr)u8g_com_uart);
|
||||||
|
|
||||||
|
// half resolution, extra log, requires to uncomment U8G_16BIT in u8g.h
|
||||||
|
//U8GLIB u8g(&u8g_dev_a2_micro_printer_192x360_ds, (u8g_com_fnptr)u8g_com_uart);
|
||||||
|
U8GLIB u8g(&u8g_dev_a2_micro_printer_192x720_ds, (u8g_com_fnptr)u8g_com_uart);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void drawLogo(uint8_t d) {
|
||||||
|
u8g.setFont(u8g_font_gdr25r);
|
||||||
|
u8g.drawStr(0+d, 30+d, "U");
|
||||||
|
u8g.setFont(u8g_font_gdr30n);
|
||||||
|
u8g.drawStr90(23+d,10+d,"8");
|
||||||
|
u8g.setFont(u8g_font_gdr25r);
|
||||||
|
u8g.drawStr(53+d,30+d,"g");
|
||||||
|
|
||||||
|
u8g.drawHLine(2+d, 35+d, 47);
|
||||||
|
u8g.drawVLine(45+d, 32+d, 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawURL(void) {
|
||||||
|
u8g.setFont(u8g_font_4x6);
|
||||||
|
if ( u8g.getHeight() < 59 ) {
|
||||||
|
u8g.drawStr(53,9,"code.google.com");
|
||||||
|
u8g.drawStr(77,18,"/p/u8glib");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
u8g.drawStr(1,54,"code.google.com/p/u8glib");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw(void) {
|
||||||
|
// graphic commands to redraw the complete screen should be placed here
|
||||||
|
|
||||||
|
drawLogo(0);
|
||||||
|
drawURL();
|
||||||
|
u8g.drawFrame(0,0,u8g.getWidth(), u8g.getHeight());
|
||||||
|
|
||||||
|
u8g.setFont(u8g_font_helvR24r);
|
||||||
|
u8g.setPrintPos(0, 100);
|
||||||
|
u8g.print(u8g.getWidth(), DEC);
|
||||||
|
u8g.print("x");
|
||||||
|
u8g.print(u8g.getHeight(), DEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(void) {
|
||||||
|
PRINTER_SERIAL.begin(19200);
|
||||||
|
|
||||||
|
// flip screen, if required
|
||||||
|
// u8g.setRot180();
|
||||||
|
|
||||||
|
// assign default color value
|
||||||
|
u8g.setColorIndex(1); // pixel on
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(void) {
|
||||||
|
|
||||||
|
// picture loop: This will print the picture
|
||||||
|
u8g.firstPage();
|
||||||
|
do {
|
||||||
|
draw();
|
||||||
|
} while( u8g.nextPage() );
|
||||||
|
|
||||||
|
// send manual CR to the printer
|
||||||
|
PRINTER_SERIAL.write('\n');
|
||||||
|
|
||||||
|
// reprint the picture after 10 seconds
|
||||||
|
delay(10000);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Color.pde
|
||||||
|
|
||||||
|
"Hello World!" example code with color.
|
||||||
|
|
||||||
|
>>> Before compiling: Please remove comment from the constructor of the
|
||||||
|
>>> connected graphics display (see below).
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library, http://code.google.com/p/u8glib/
|
||||||
|
|
||||||
|
Copyright (c) 2012, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "U8glib.h"
|
||||||
|
|
||||||
|
// setup u8g object, please remove comment from one of the following constructor calls
|
||||||
|
// IMPORTANT NOTE: The following list is incomplete. The complete list of supported
|
||||||
|
// devices with all constructor calls is here: http://code.google.com/p/u8glib/wiki/device
|
||||||
|
//U8GLIB_NHD27OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGS102 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM132 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM128 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM128_2X u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_ST7920_128X64_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_128X64_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_128X64_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(13, 11, 10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10, HW SPI
|
||||||
|
//U8GLIB_ST7920_202X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_202X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_202X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_202X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_LM6059 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_LM6063 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_BW u8g(10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
||||||
|
//U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
||||||
|
//U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16
|
||||||
|
//U8GLIB_LC7981_160X80 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_LC7981_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_LC7981_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_ILI9325D_320x240 u8g(18,17,19,U8G_PIN_NONE,16 ); // 8Bit Com: D0..D7: 0,1,2,3,4,5,6,7 en=wr=18, cs=17, rs=19, rd=U8G_PIN_NONE, reset = 16
|
||||||
|
//U8GLIB_SBN1661_122X32 u8g(8,9,10,11,4,5,6,7,14,15, 17, U8G_PIN_NONE, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 cs1=14, cs2=15,di=17,rw=16,reset = 16
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new white HalTec OLED)
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send AC
|
||||||
|
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new blue HalTec OLED)
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST); // Dev 0, Fast I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send ACK
|
||||||
|
//U8GLIB_SSD1309_128X64 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1327_96X96_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_SSD1327_96X96_2X_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_NHD_C12832 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_LD7032_60x32 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_LD7032_60x32 u8g(11, 12, 9, 10, 8); // SPI Com: SCK = 11, MOSI = 12, CS = 9, A0 = 10, RST = 8 (SW SPI Nano Board)
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_T6963_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_128X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_HT1632_24X16 u8g(3, 2, 4); // WR = 3, DATA = 2, CS = 4
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(13, 11, 8, 9, 7); // Arduino UNO: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(76, 75, 8, 9, 7); // Arduino DUE: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(8, 9, 7); // Arduino: HW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_HICOLOR u8g(76, 75, 8, 9, 7); // Arduino DUE, SW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128GH_332 u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
|
||||||
|
//U8GLIB_SSD1351_128X128GH_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
|
||||||
|
|
||||||
|
|
||||||
|
void draw(void) {
|
||||||
|
|
||||||
|
if ( u8g.getMode() == U8G_MODE_HICOLOR || u8g.getMode() == U8G_MODE_R3G3B2) {
|
||||||
|
/* draw background (area is 128x128) */
|
||||||
|
u8g_uint_t r, g, b;
|
||||||
|
for( b = 0; b < 4; b++ )
|
||||||
|
{
|
||||||
|
for( g = 0; g < 32; g++ )
|
||||||
|
{
|
||||||
|
for( r = 0; r < 32; r++ )
|
||||||
|
{
|
||||||
|
u8g.setRGB(r<<3, g<<3, b<<4 );
|
||||||
|
u8g.drawPixel(g + b*32, r);
|
||||||
|
u8g.setRGB(r<<3, g<<3, (b<<4)+64 );
|
||||||
|
u8g.drawPixel(g + b*32, r+32);
|
||||||
|
u8g.setRGB(r<<3, g<<3, (b<<4)+128 );
|
||||||
|
u8g.drawPixel(g + b*32, r+32+32);
|
||||||
|
u8g.setRGB(r<<3, g<<3, (b<<4)+128+64 );
|
||||||
|
u8g.drawPixel(g + b*32, r+32+32+32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// assign default color value
|
||||||
|
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
|
||||||
|
u8g.setColorIndex(255); // white
|
||||||
|
}
|
||||||
|
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
|
||||||
|
u8g.setColorIndex(3); // max intensity
|
||||||
|
}
|
||||||
|
else if ( u8g.getMode() == U8G_MODE_BW ) {
|
||||||
|
u8g.setColorIndex(1); // pixel on
|
||||||
|
}
|
||||||
|
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
|
||||||
|
u8g.setHiColorByRGB(255,255,255);
|
||||||
|
}
|
||||||
|
u8g.setFont(u8g_font_unifont);
|
||||||
|
u8g.drawStr( 0, 22, "Hello World!");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(void) {
|
||||||
|
|
||||||
|
// flip screen, if required
|
||||||
|
// u8g.setRot180();
|
||||||
|
|
||||||
|
// set SPI backup if required
|
||||||
|
//u8g.setHardwareBackup(u8g_backup_avr_spi);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(void) {
|
||||||
|
// picture loop
|
||||||
|
u8g.firstPage();
|
||||||
|
do {
|
||||||
|
draw();
|
||||||
|
} while( u8g.nextPage() );
|
||||||
|
|
||||||
|
// rebuild the picture after some delay
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,398 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
FPS.pde
|
||||||
|
|
||||||
|
>>> Before compiling: Please remove comment from the constructor of the
|
||||||
|
>>> connected graphics display (see below).
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library, http://code.google.com/p/u8glib/
|
||||||
|
|
||||||
|
Copyright (c) 2012, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
ST7920_192X32, SPI: FPS: Box=7.6 @=9.8 iFPS: Box=11.4 @=14.7
|
||||||
|
ST7920_192X32, 8Bit: FPS: Box=6.2 @=7.5 iFPS: Box=9.3 @=11.2
|
||||||
|
DOGM128 SW SPI: FPS: Box=5.1 @=5.9 Pix=2.6 iFPS: Box=10.2 @=11.8 Pix=5.2
|
||||||
|
DOGM128 HW SPI: FPS: Box=5.5 @=6.3 iFPS: Box=11.0 @=12.6
|
||||||
|
DOGXL160 SW SPI: FPS: Box=1.7 @=1.9 iFPS: Box=6.9 @=7.7
|
||||||
|
DOGXL160 HW SPI: FPS: Box=1.8 @=2.1
|
||||||
|
|
||||||
|
NHD27OLED_BW, SW SPI: FPS: Box=3.0 @=3.7
|
||||||
|
NHD27OLED_BW, HW SPI: FPS: Box=3.5 @=4.5
|
||||||
|
NHD27OLED_2X_BW, SW SPI: FPS: Box=3.8 @=4.9
|
||||||
|
NHD27OLED_2X_BW, HW SPI: FPS: Box=4.6 @=6.4
|
||||||
|
|
||||||
|
30 Sep 2012
|
||||||
|
NHD27OLED_BW, SW SPI: FPS: Clip=9.2 Box=3.9 @=4.4 NEW_CODE
|
||||||
|
NHD27OLED_BW, SW SPI: FPS: Clip=9.2 Box=3.6 @=4.5
|
||||||
|
NHD27OLED_BW, HW SPI: FPS: Clip=16.3 Box=4.7 @=5.6
|
||||||
|
NHD27OLED_2X_BW, SW SPI: FPS: Clip=9.7 Box=4.5 @=5.8
|
||||||
|
NHD27OLED_2X_BW, SW SPI: FPS: Clip=18.0 Box=5.8 @=7.9
|
||||||
|
|
||||||
|
1 Oct 2012
|
||||||
|
ST7920_192X32, 8Bit: FPS: Box=7.2 @=10.0
|
||||||
|
DOGM128 SW SPI: FPS: Box=5.2 @=6.6 Pix=2.6
|
||||||
|
DOGM128 HW SPI: FPS: Clip=33.2 Box=5.5 @=7.1
|
||||||
|
DOGXL160 SW SPI: FPS: Box=1.7 @=2.0
|
||||||
|
DOGXL160 HW SPI: FPS: Box=1.8 @=2.2
|
||||||
|
|
||||||
|
DOGXL160 GR SW SPI: FPS: Box=1.1 @=1.3
|
||||||
|
|
||||||
|
1 Mar 2013
|
||||||
|
ST7920_192X32_1X, SPI: FPS: Clip=10.3 Box=5.5 @=7.2 Pix=3.9
|
||||||
|
ST7920_192X32_4X, SPI: FPS: Clip=10.9 Box=6.7 @=8.8 Pix=7.4
|
||||||
|
ST7920_192X32_1X, 8Bit: FPS: Clip=14.2 Box=6.1 @=8.4 Pix=4.2
|
||||||
|
ST7920_192X32_4X, 8Bit: FPS: Clip=14.2 Box=7.8 @=10.7 Pix=8.7
|
||||||
|
ST7920_192X32_1X, HW SPI: FPS: Clip=14.2 Box=6.3 @=8.7 Pix=4.3
|
||||||
|
ST7920_192X32_4X, HW SPI: FPS: Clip=15.3 Box=8.0 @=11.2 Pix=9.0
|
||||||
|
|
||||||
|
2 Jun 2013
|
||||||
|
U8GLIB_DOGM128 SW SPI: FPS: Clip=23.9 Box=4.5 @=6.6 Pix=2.1
|
||||||
|
U8GLIB_DOGM128_2X SW SPI: FPS: Clip=28.5 Box=6.6 @=9.7 Pix=3.9
|
||||||
|
U8GLIB_DOGM128_2X HW SPI: FPS: Clip=40.8 Box=7.1 @=10.8 Pix=4.1
|
||||||
|
|
||||||
|
3 Jun 2013
|
||||||
|
U8GLIB_ST7920_192X32_1X -Os SW SPI FPS: Clip=11.0 Box=5.4 @=7.1 Pix=3.9 Size=11828
|
||||||
|
U8GLIB_ST7920_192X32_1X -O3 SW SPI FPS: Clip=10.9 Box=5.6 @=7.5 Pix=4.0 Size=13800
|
||||||
|
U8GLIB_ST7920_192X32_1X -Os SW SPI FPS: Clip=16.8 Box=6.7 @=9.6 Pix=4.5 Size=11858 (new seq data output)
|
||||||
|
U8GLIB_ST7920_192X32_1X -Os HW SPI FPS: Clip=25.7 Box=7.5 @=11.3 Pix=4.8 (new seq data output)
|
||||||
|
|
||||||
|
6 Jun 2013
|
||||||
|
U8GLIB_DOGS102 u8g(13, 11, 10, 9); STD SW SPI FPS: Clip=9.5 Box=7.6 @=8.2 Pix=6.2 Size=15652
|
||||||
|
U8GLIB_DOGS102 u8g(13, 11, 10, 9); SW SPI FPS: Clip=19.1 Box=12.8 @=14.0 Pix=9.2 Size=15532
|
||||||
|
|
||||||
|
|
||||||
|
12 Jun 2013
|
||||||
|
SSD1351_128X128_332 SW SPI Clip=1.3 Box=0.7 @=0.9 Pix=0.4
|
||||||
|
SSD1351_128X128_332 HW SPI Clip=3.6 Box=1.1 @=1.5 Pix=0.5
|
||||||
|
|
||||||
|
24 Jun 2013
|
||||||
|
Uno SSD1351_128X128_332 SW SPI Clip=1.4 Box=0.8 @=0.9 Pix=0.4
|
||||||
|
|
||||||
|
Uno SSD1351_128X128_332 HW SPI Clip=4.4 Box=1.2 @=1.6 Pix=0.5
|
||||||
|
Uno SSD1351_128X128_HICOLOR HW SPI Clip=3.7 Box=0.8 @=1.0 Pix=0.3
|
||||||
|
|
||||||
|
Mega2560 SSD1351_128X128_332 HW SPI Clip=4.4 Box=1.2 @=1.6 Pix=0.5
|
||||||
|
Mega2560 SSD1351_128X128_4X_332 HW SPI Clip=4.6 Box=2.3 @=2.8 Pix=1.5
|
||||||
|
Mega2560 SSD1351_128X128_HICOLOR HW SPI Clip=3.6 Box=0.8 @=1.0 Pix=0.3
|
||||||
|
Mega2560 SSD1351_128X128_4X_HICOLOR HW SPI Clip=4.2 Box=1.7 @=2.1 Pix=1.0
|
||||||
|
|
||||||
|
Due SSD1351_128X128_332 HW SPI Clip=24.6 Box=6.3 @=7.8 Pix=2.8
|
||||||
|
Due SSD1351_128X128_4X_332 HW SPI Clip=28.1 Box=13.0 @=15.1 Pix=8.5
|
||||||
|
Due SSD1351_128X128_HICOLOR HW SPI Clip=20.8 Box=3.4 @=4.5 Pix=1.4
|
||||||
|
Due SSD1351_128X128_4X_HICOLOR HW SPI Clip=26.3 Box=8.9 @=11.1 Pix=4.8
|
||||||
|
|
||||||
|
Due SSD1351_128X128_4X_HICOLOR SW SPI Clip=0.4 Box=0.4 @=0.4 Pix=0.4
|
||||||
|
|
||||||
|
Due DOGS102 u8g(13, 11, 10, 9); SW SPI FPS: Clip=19.1 Box=13.1 @=14.3 Pix=9.4
|
||||||
|
Due DOGS102 u8g(10, 9); HW SPI FPS: Clip=128.9 Box=30.7 @=40.6 Pix=15.4
|
||||||
|
|
||||||
|
Due NHD27OLED_BW u8g(10, 9) HW SPI FPS: Clip=53.0 Box=19.6 @=23.8 Pix=10.6
|
||||||
|
Due NHD27OLED_2X_BW u8g(10, 9) HW SPI FPS: Clip=57.0 Box=25.3 @=31.7 Pix=18.1
|
||||||
|
Due NHD27OLED_GR u8g(10, 9) HW SPI FPS: Clip=34.1 Box=11.7 @=13.7 Pix=5.6
|
||||||
|
Due NHD27OLED_2X_GR u8g(10, 9) HW SPI FPS: Clip=38.1 Box=15.5 @=20.0 Pix=8.8
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "U8glib.h"
|
||||||
|
|
||||||
|
// setup u8g object, please remove comment from one of the following constructor calls
|
||||||
|
// IMPORTANT NOTE: The following list is incomplete. The complete list of supported
|
||||||
|
// devices with all constructor calls is here: http://code.google.com/p/u8glib/wiki/device
|
||||||
|
//U8GLIB_NHD27OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGS102 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM132 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM128 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM128_2X u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_ST7920_128X64_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_128X64_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_128X64_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(13, 11, 10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10, HW SPI
|
||||||
|
//U8GLIB_ST7920_202X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_202X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_202X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_202X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_LM6059 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_LM6063 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_BW u8g(10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
||||||
|
//U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
||||||
|
//U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16
|
||||||
|
//U8GLIB_LC7981_160X80 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_LC7981_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_LC7981_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_ILI9325D_320x240 u8g(18,17,19,U8G_PIN_NONE,16 ); // 8Bit Com: D0..D7: 0,1,2,3,4,5,6,7 en=wr=18, cs=17, rs=19, rd=U8G_PIN_NONE, reset = 16
|
||||||
|
//U8GLIB_SBN1661_122X32 u8g(8,9,10,11,4,5,6,7,14,15, 17, U8G_PIN_NONE, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 cs1=14, cs2=15,di=17,rw=16,reset = 16
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new white HalTec OLED)
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send AC
|
||||||
|
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new blue HalTec OLED)
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST); // Dev 0, Fast I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send ACK
|
||||||
|
//U8GLIB_SSD1309_128X64 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1327_96X96_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_SSD1327_96X96_2X_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_NHD_C12832 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_LD7032_60x32 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_LD7032_60x32 u8g(11, 12, 9, 10, 8); // SPI Com: SCK = 11, MOSI = 12, CS = 9, A0 = 10, RST = 8 (SW SPI Nano Board)
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_T6963_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_128X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_HT1632_24X16 u8g(3, 2, 4); // WR = 3, DATA = 2, CS = 4
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(13, 11, 8, 9, 7); // Arduino UNO: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(76, 75, 8, 9, 7); // Arduino DUE: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(8, 9, 7); // Arduino: HW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_HICOLOR u8g(76, 75, 8, 9, 7); // Arduino DUE, SW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128GH_332 u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
|
||||||
|
//U8GLIB_SSD1351_128X128GH_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
|
||||||
|
|
||||||
|
#define SECONDS 10
|
||||||
|
uint8_t flip_color = 0;
|
||||||
|
uint8_t draw_color = 1;
|
||||||
|
|
||||||
|
void draw_set_screen(void) {
|
||||||
|
// graphic commands to redraw the complete screen should be placed here
|
||||||
|
if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
|
||||||
|
if ( flip_color == 0 )
|
||||||
|
u8g.setHiColorByRGB(0,0,0);
|
||||||
|
else
|
||||||
|
u8g.setHiColorByRGB(255,255,255);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
u8g.setColorIndex(flip_color);
|
||||||
|
}
|
||||||
|
u8g.drawBox( 0, 0, u8g.getWidth(), u8g.getHeight() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_clip_test(void) {
|
||||||
|
u8g_uint_t i, j, k;
|
||||||
|
char buf[3] = "AB";
|
||||||
|
k = 0;
|
||||||
|
if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
|
||||||
|
u8g.setHiColorByRGB(255,255,255);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
u8g.setColorIndex(draw_color);
|
||||||
|
}
|
||||||
|
u8g.setFont(u8g_font_6x10);
|
||||||
|
|
||||||
|
for( i = 0; i < 6; i++ ) {
|
||||||
|
for( j = 1; j < 8; j++ ) {
|
||||||
|
u8g.drawHLine(i-3, k, j);
|
||||||
|
u8g.drawHLine(i-3+10, k, j);
|
||||||
|
|
||||||
|
u8g.drawVLine(k+20, i-3, j);
|
||||||
|
u8g.drawVLine(k+20, i-3+10, j);
|
||||||
|
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
u8g.drawStr(0-3, 50, buf);
|
||||||
|
u8g.drawStr180(0+3, 50, buf);
|
||||||
|
|
||||||
|
u8g.drawStr(u8g.getWidth()-3, 40, buf);
|
||||||
|
u8g.drawStr180(u8g.getWidth()+3, 40, buf);
|
||||||
|
|
||||||
|
u8g.drawStr90(u8g.getWidth()-10, 0-3, buf);
|
||||||
|
u8g.drawStr270(u8g.getWidth()-10, 3, buf);
|
||||||
|
|
||||||
|
u8g.drawStr90(u8g.getWidth()-20, u8g.getHeight()-3, buf);
|
||||||
|
u8g.drawStr270(u8g.getWidth()-20, u8g.getHeight()+3, buf);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_char(void) {
|
||||||
|
char buf[2] = "@";
|
||||||
|
u8g_uint_t i, j;
|
||||||
|
// graphic commands to redraw the complete screen should be placed here
|
||||||
|
if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
|
||||||
|
u8g.setHiColorByRGB(255,255,255);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
u8g.setColorIndex(draw_color);
|
||||||
|
}
|
||||||
|
u8g.setFont(u8g_font_6x10);
|
||||||
|
j = 8;
|
||||||
|
for(;;) {
|
||||||
|
i = 0;
|
||||||
|
for(;;) {
|
||||||
|
u8g.drawStr( i, j, buf);
|
||||||
|
i += 8;
|
||||||
|
if ( i > u8g.getWidth() )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
j += 8;
|
||||||
|
if ( j > u8g.getHeight() )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_pixel(void) {
|
||||||
|
u8g_uint_t x, y, w2, h2;
|
||||||
|
if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
|
||||||
|
u8g.setHiColorByRGB(255,255,255);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
u8g.setColorIndex(draw_color);
|
||||||
|
}
|
||||||
|
w2 = u8g.getWidth();
|
||||||
|
h2 = u8g.getHeight();
|
||||||
|
w2 /= 2;
|
||||||
|
h2 /= 2;
|
||||||
|
for( y = 0; y < h2; y++ ) {
|
||||||
|
for( x = 0; x < w2; x++ ) {
|
||||||
|
if ( (x + y) & 1 ) {
|
||||||
|
u8g.drawPixel(x,y);
|
||||||
|
u8g.drawPixel(x,y+h2);
|
||||||
|
u8g.drawPixel(x+w2,y);
|
||||||
|
u8g.drawPixel(x+w2,y+h2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns unadjusted FPS
|
||||||
|
uint16_t picture_loop_with_fps(void (*draw_fn)(void)) {
|
||||||
|
uint16_t FPS10 = 0;
|
||||||
|
uint32_t time;
|
||||||
|
|
||||||
|
time = millis() + SECONDS*1000;
|
||||||
|
|
||||||
|
// picture loop
|
||||||
|
do {
|
||||||
|
u8g.firstPage();
|
||||||
|
do {
|
||||||
|
draw_fn();
|
||||||
|
} while( u8g.nextPage() );
|
||||||
|
FPS10++;
|
||||||
|
flip_color = flip_color ^ 1;
|
||||||
|
} while( millis() < time );
|
||||||
|
return FPS10;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *convert_FPS(uint16_t fps) {
|
||||||
|
static char buf[6];
|
||||||
|
strcpy(buf, u8g_u8toa( (uint8_t)(fps/10), 3));
|
||||||
|
buf[3] = '.';
|
||||||
|
buf[4] = (fps % 10) + '0';
|
||||||
|
buf[5] = '\0';
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_result(const char *s, uint16_t fps) {
|
||||||
|
// assign default color value
|
||||||
|
if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
|
||||||
|
u8g.setHiColorByRGB(255,255,255);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
u8g.setColorIndex(draw_color);
|
||||||
|
}
|
||||||
|
u8g.setFont(u8g_font_8x13B);
|
||||||
|
u8g.firstPage();
|
||||||
|
do {
|
||||||
|
u8g.drawStr(0,12, s);
|
||||||
|
u8g.drawStr(0,24, convert_FPS(fps));
|
||||||
|
} while( u8g.nextPage() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(void) {
|
||||||
|
// flip screen, if required
|
||||||
|
// u8g.setRot180();
|
||||||
|
|
||||||
|
// assign default color value
|
||||||
|
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
|
||||||
|
draw_color = 255; // white
|
||||||
|
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
|
||||||
|
draw_color = 3; // max intensity
|
||||||
|
else if ( u8g.getMode() == U8G_MODE_BW )
|
||||||
|
draw_color = 1; // pixel on
|
||||||
|
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
|
||||||
|
u8g.setHiColorByRGB(255,255,255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(void) {
|
||||||
|
uint16_t fps;
|
||||||
|
fps = picture_loop_with_fps(draw_clip_test);
|
||||||
|
show_result("draw clip test", fps);
|
||||||
|
delay(5000);
|
||||||
|
fps = picture_loop_with_fps(draw_set_screen);
|
||||||
|
show_result("clear screen", fps);
|
||||||
|
delay(5000);
|
||||||
|
fps = picture_loop_with_fps(draw_char);
|
||||||
|
show_result("draw @", fps);
|
||||||
|
delay(5000);
|
||||||
|
fps = picture_loop_with_fps(draw_pixel);
|
||||||
|
show_result("draw pixel", fps);
|
||||||
|
delay(5000);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,348 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Touch4WSetup.pde
|
||||||
|
|
||||||
|
Use this example to figure out the ranges for of the active area of a 4-wire resistive
|
||||||
|
touch panel.
|
||||||
|
|
||||||
|
>>> Before compiling: Please remove comment from the constructor of the
|
||||||
|
>>> connected graphics display (see below).
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library, http://code.google.com/p/u8glib/
|
||||||
|
|
||||||
|
Copyright (c) 2012, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "U8glib.h"
|
||||||
|
|
||||||
|
// setup u8g object, please remove comment from one of the following constructor calls
|
||||||
|
// IMPORTANT NOTE: The following list is incomplete. The complete list of supported
|
||||||
|
// devices with all constructor calls is here: http://code.google.com/p/u8glib/wiki/device
|
||||||
|
//U8GLIB_NHD27OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGS102 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM132 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM128 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM128_2X u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_ST7920_128X64_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_128X64_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_128X64_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(13, 11, 10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10, HW SPI
|
||||||
|
//U8GLIB_ST7920_202X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_202X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_202X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_202X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_LM6059 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_LM6063 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_BW u8g(10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
||||||
|
//U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
||||||
|
//U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16
|
||||||
|
//U8GLIB_LC7981_160X80 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_LC7981_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_LC7981_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_ILI9325D_320x240 u8g(18,17,19,U8G_PIN_NONE,16 ); // 8Bit Com: D0..D7: 0,1,2,3,4,5,6,7 en=wr=18, cs=17, rs=19, rd=U8G_PIN_NONE, reset = 16
|
||||||
|
//U8GLIB_SBN1661_122X32 u8g(8,9,10,11,4,5,6,7,14,15, 17, U8G_PIN_NONE, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 cs1=14, cs2=15,di=17,rw=16,reset = 16
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new white HalTec OLED)
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send AC
|
||||||
|
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new blue HalTec OLED)
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST); // Dev 0, Fast I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send ACK
|
||||||
|
//U8GLIB_SSD1309_128X64 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1327_96X96_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_SSD1327_96X96_2X_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_NHD_C12832 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_LD7032_60x32 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_LD7032_60x32 u8g(11, 12, 9, 10, 8); // SPI Com: SCK = 11, MOSI = 12, CS = 9, A0 = 10, RST = 8 (SW SPI Nano Board)
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_T6963_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_128X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_HT1632_24X16 u8g(3, 2, 4); // WR = 3, DATA = 2, CS = 4
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(13, 11, 8, 9, 7); // Arduino UNO: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(76, 75, 8, 9, 7); // Arduino DUE: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(8, 9, 7); // Arduino: HW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_HICOLOR u8g(76, 75, 8, 9, 7); // Arduino DUE, SW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128GH_332 u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
|
||||||
|
//U8GLIB_SSD1351_128X128GH_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// Setup 4-Wire Resistive Touch Panel
|
||||||
|
|
||||||
|
uint8_t tp_left = A3;
|
||||||
|
uint8_t tp_right = A5;
|
||||||
|
uint8_t tp_top = A4;
|
||||||
|
uint8_t tp_bottom = A2;
|
||||||
|
|
||||||
|
#define X_START 120
|
||||||
|
#define X_END 140
|
||||||
|
#define Y_START 120
|
||||||
|
#define Y_END 140
|
||||||
|
|
||||||
|
#define PULLUP_THRESHOLD 235
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// Touch Panel Code
|
||||||
|
|
||||||
|
/* touch panel dimension */
|
||||||
|
struct tpd_struct
|
||||||
|
{
|
||||||
|
/* raw value */
|
||||||
|
uint8_t raw;
|
||||||
|
|
||||||
|
/* calibration values */
|
||||||
|
uint8_t start;
|
||||||
|
uint8_t end;
|
||||||
|
|
||||||
|
/* user values */
|
||||||
|
uint8_t range; /* result will have range fron 0..range (including the value of range) */
|
||||||
|
|
||||||
|
uint8_t result; /* output value: position [0...range] */
|
||||||
|
uint8_t is_pressed; /* output value: pressed (=1) or not pressed (=0) */
|
||||||
|
uint8_t is_update; /* will be set to 1 if result or is_pressed has been updated */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tp_struct
|
||||||
|
{
|
||||||
|
struct tpd_struct x;
|
||||||
|
struct tpd_struct y;
|
||||||
|
uint8_t is_pressed; /* combination of x.is_pressed && y.is_pressed */
|
||||||
|
uint8_t is_update;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tp_struct tp;
|
||||||
|
|
||||||
|
/* map raw value to 0...range (result) */
|
||||||
|
void tpd_map_touch_position(struct tpd_struct *d, uint8_t raw)
|
||||||
|
{
|
||||||
|
uint8_t is_pressed;
|
||||||
|
uint16_t p;
|
||||||
|
uint8_t start, end;
|
||||||
|
|
||||||
|
d->raw = raw;
|
||||||
|
|
||||||
|
start = d->start;
|
||||||
|
end = d->end;
|
||||||
|
|
||||||
|
/* check if position is within active area; store result in "is_pressed" */
|
||||||
|
is_pressed = 1;
|
||||||
|
if ( raw >= PULLUP_THRESHOLD )
|
||||||
|
{
|
||||||
|
d->result = 0;
|
||||||
|
is_pressed = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* update start and end */
|
||||||
|
if ( raw < start )
|
||||||
|
{
|
||||||
|
start = raw;
|
||||||
|
d->start = raw;
|
||||||
|
}
|
||||||
|
if ( raw > end )
|
||||||
|
{
|
||||||
|
end = raw;
|
||||||
|
d->end = raw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* store "is_pressed" in the global structure, set update flag */
|
||||||
|
if ( d->is_pressed != is_pressed )
|
||||||
|
d->is_update = 1;
|
||||||
|
d->is_pressed = is_pressed;
|
||||||
|
|
||||||
|
/* map "raw" value into target range */
|
||||||
|
if ( is_pressed != 0 )
|
||||||
|
{
|
||||||
|
p = raw;
|
||||||
|
p -= start;
|
||||||
|
p *= d->range;
|
||||||
|
end -= start;
|
||||||
|
p /= end;
|
||||||
|
|
||||||
|
if ( d->result != p )
|
||||||
|
d->is_update = 1;
|
||||||
|
d->result = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tp_Init(uint8_t width, uint8_t height)
|
||||||
|
{
|
||||||
|
tp.x.start = X_START;
|
||||||
|
tp.x.end = X_END;
|
||||||
|
tp.x.range = width-1;
|
||||||
|
|
||||||
|
tp.y.start = Y_START;
|
||||||
|
tp.y.end = Y_END;
|
||||||
|
tp.y.range = height-1;
|
||||||
|
|
||||||
|
tp.is_update = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTouchRawValues(uint8_t x, uint8_t y)
|
||||||
|
{
|
||||||
|
tpd_map_touch_position(&(tp.x), x);
|
||||||
|
tpd_map_touch_position(&(tp.y), y);
|
||||||
|
|
||||||
|
tp.is_pressed = tp.x.is_pressed && tp.y.is_pressed;
|
||||||
|
if ( tp.x.is_update || tp.y.is_update )
|
||||||
|
tp.is_update = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t getTouchPos(uint8_t hiPin, uint8_t lowPin, uint8_t sensePin, uint8_t dcPin)
|
||||||
|
{
|
||||||
|
uint8_t val;
|
||||||
|
pinMode(dcPin, INPUT);
|
||||||
|
pinMode(sensePin, INPUT_PULLUP);
|
||||||
|
pinMode(hiPin, OUTPUT);
|
||||||
|
pinMode(lowPin, OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(hiPin, HIGH);
|
||||||
|
digitalWrite(lowPin, LOW);
|
||||||
|
delay(10);
|
||||||
|
val = analogRead(sensePin) >> 2;
|
||||||
|
pinMode(hiPin, INPUT);
|
||||||
|
pinMode(lowPin, INPUT);
|
||||||
|
delay(10);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateTouchPanel(void)
|
||||||
|
{
|
||||||
|
uint8_t tp_raw_x;
|
||||||
|
uint8_t tp_raw_y;
|
||||||
|
|
||||||
|
tp_raw_x = getTouchPos(tp_right, tp_left, tp_bottom, tp_top);
|
||||||
|
tp_raw_y = getTouchPos(tp_top, tp_bottom, tp_left, tp_right);
|
||||||
|
|
||||||
|
setTouchRawValues(tp_raw_x, tp_raw_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// graphics output and picture loop
|
||||||
|
|
||||||
|
void center(u8g_uint_t y, const char *str)
|
||||||
|
{
|
||||||
|
u8g_uint_t x;
|
||||||
|
x = u8g.getWidth();
|
||||||
|
x -= u8g.getStrWidth(str);
|
||||||
|
x /= 2;
|
||||||
|
u8g.drawStr(x, y, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void draw(void) {
|
||||||
|
u8g.setFont(u8g_font_6x10);
|
||||||
|
center( 10, "Touch Panel Setup");
|
||||||
|
u8g.setPrintPos(0, 20); u8g.print("x_start=");u8g.print((int)tp.x.start);u8g.print(" x_end=");u8g.print((int)tp.x.end);
|
||||||
|
u8g.setPrintPos(0, 30); u8g.print("y_start=");u8g.print((int)tp.y.start);u8g.print(" y_end=");u8g.print((int)tp.y.end);
|
||||||
|
u8g.setPrintPos(0, 40); u8g.print("x=");u8g.print((int)tp.x.raw);
|
||||||
|
u8g.setPrintPos(0, 50); u8g.print("y=");u8g.print((int)tp.y.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(void) {
|
||||||
|
|
||||||
|
// flip screen, if required
|
||||||
|
// u8g.setRot180();
|
||||||
|
u8g.setCursorFont(u8g_font_cursor);
|
||||||
|
u8g.setCursorStyle(32);
|
||||||
|
|
||||||
|
tp_Init(u8g.getWidth(), u8g.getHeight());
|
||||||
|
|
||||||
|
tp.is_update = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(void) {
|
||||||
|
|
||||||
|
// update touch panel and handle return values
|
||||||
|
updateTouchPanel();
|
||||||
|
|
||||||
|
if ( tp.is_pressed != 0 )
|
||||||
|
u8g.enableCursor();
|
||||||
|
else
|
||||||
|
u8g.disableCursor();
|
||||||
|
|
||||||
|
u8g.setCursorPos(tp.x.result, u8g.getHeight()-tp.y.result-1);
|
||||||
|
|
||||||
|
// picture loop
|
||||||
|
if ( tp.is_update != 0 )
|
||||||
|
{
|
||||||
|
tp.is_update = 0;
|
||||||
|
u8g.firstPage();
|
||||||
|
do {
|
||||||
|
draw();
|
||||||
|
} while( u8g.nextPage() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,335 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Touch4WTest.pde
|
||||||
|
|
||||||
|
>>> Before compiling: Please remove comment from the constructor of the
|
||||||
|
>>> connected graphics display (see below).
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library, http://code.google.com/p/u8glib/
|
||||||
|
|
||||||
|
Copyright (c) 2012, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "U8glib.h"
|
||||||
|
|
||||||
|
// setup u8g object, please remove comment from one of the following constructor calls
|
||||||
|
// IMPORTANT NOTE: The following list is incomplete. The complete list of supported
|
||||||
|
// devices with all constructor calls is here: http://code.google.com/p/u8glib/wiki/device
|
||||||
|
//U8GLIB_NHD27OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD27OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_NHD31OLED_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGS102 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM132 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM128 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGM128_2X u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_ST7920_128X64_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_128X64_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_128X64_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_128X64_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_192X32_1X u8g(13, 11, 10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10
|
||||||
|
//U8GLIB_ST7920_192X32_4X u8g(10); // SPI Com: SCK = en = 13, MOSI = rw = 11, CS = di = 10, HW SPI
|
||||||
|
//U8GLIB_ST7920_202X32_1X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_202X32_4X u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, di=17,rw=16
|
||||||
|
//U8GLIB_ST7920_202X32_1X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_ST7920_202X32_4X u8g(18, 16, 17); // SPI Com: SCK = en = 18, MOSI = rw = 16, CS = di = 17
|
||||||
|
//U8GLIB_LM6059 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_LM6063 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_BW u8g(10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_2X_BW u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_DOGXL160_2X_GR u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
||||||
|
//U8GLIB_PCF8812 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
|
||||||
|
//U8GLIB_KS0108_128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16
|
||||||
|
//U8GLIB_LC7981_160X80 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_LC7981_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_LC7981_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs=14 ,di=15,rw=17, reset = 16
|
||||||
|
//U8GLIB_ILI9325D_320x240 u8g(18,17,19,U8G_PIN_NONE,16 ); // 8Bit Com: D0..D7: 0,1,2,3,4,5,6,7 en=wr=18, cs=17, rs=19, rd=U8G_PIN_NONE, reset = 16
|
||||||
|
//U8GLIB_SBN1661_122X32 u8g(8,9,10,11,4,5,6,7,14,15, 17, U8G_PIN_NONE, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 cs1=14, cs2=15,di=17,rw=16,reset = 16
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new white HalTec OLED)
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST); // Fast I2C / TWI
|
||||||
|
//U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send AC
|
||||||
|
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(4, 5, 6, 7); // SW SPI Com: SCK = 4, MOSI = 5, CS = 6, A0 = 7 (new blue HalTec OLED)
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST); // Dev 0, Fast I2C / TWI
|
||||||
|
//U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send ACK
|
||||||
|
//U8GLIB_SSD1309_128X64 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_SSD1327_96X96_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_SSD1327_96X96_2X_GR u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_UC1611_DOGM240 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(U8G_I2C_OPT_NONE); // I2C
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(13, 11, 10, 9); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
|
||||||
|
//U8GLIB_UC1611_DOGXL240 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
|
||||||
|
//U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_NHD_C12832 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_LD7032_60x32 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_LD7032_60x32 u8g(11, 12, 9, 10, 8); // SPI Com: SCK = 11, MOSI = 12, CS = 9, A0 = 10, RST = 8 (SW SPI Nano Board)
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(13, 11, 10, 9, 8); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64 u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_UC1608_240X64_2X u8g(10, 9, 8); // HW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
|
||||||
|
//U8GLIB_T6963_240X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_128X128 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_240X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_T6963_128X64 u8g(8, 9, 10, 11, 4, 5, 6, 7, 14, 15, 17, 18, 16); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7, cs=14, a0=15, wr=17, rd=18, reset=16
|
||||||
|
//U8GLIB_HT1632_24X16 u8g(3, 2, 4); // WR = 3, DATA = 2, CS = 4
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(13, 11, 8, 9, 7); // Arduino UNO: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(76, 75, 8, 9, 7); // Arduino DUE: SW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_332 u8g(8, 9, 7); // Arduino: HW SPI Com: SCK = 13, MOSI = 11, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_HICOLOR u8g(76, 75, 8, 9, 7); // Arduino DUE, SW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
|
||||||
|
//U8GLIB_SSD1351_128X128GH_332 u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
|
||||||
|
//U8GLIB_SSD1351_128X128GH_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// Setup 4-Wire Resistive Touch Panel
|
||||||
|
|
||||||
|
uint8_t tp_left = A3;
|
||||||
|
uint8_t tp_right = A5;
|
||||||
|
uint8_t tp_top = A4;
|
||||||
|
uint8_t tp_bottom = A2;
|
||||||
|
|
||||||
|
/* Run "Touch4WSetup" and enter values here */
|
||||||
|
#define X_START 64
|
||||||
|
#define X_END 200
|
||||||
|
#define Y_START 105
|
||||||
|
#define Y_END 160
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// Touch Panel Code
|
||||||
|
|
||||||
|
/* touch panel dimension */
|
||||||
|
struct tpd_struct
|
||||||
|
{
|
||||||
|
/* raw value */
|
||||||
|
uint8_t raw;
|
||||||
|
|
||||||
|
/* calibration values */
|
||||||
|
uint8_t start;
|
||||||
|
uint8_t end;
|
||||||
|
|
||||||
|
/* user values */
|
||||||
|
uint8_t range; /* result will have range fron 0..range (including the value of range) */
|
||||||
|
|
||||||
|
uint8_t result; /* output value: position [0...range] */
|
||||||
|
uint8_t is_pressed; /* output value: pressed (=1) or not pressed (=0) */
|
||||||
|
uint8_t is_update; /* will be set to 1 if result or is_pressed has been updated */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tp_struct
|
||||||
|
{
|
||||||
|
struct tpd_struct x;
|
||||||
|
struct tpd_struct y;
|
||||||
|
uint8_t is_pressed; /* combination of x.is_pressed && y.is_pressed */
|
||||||
|
uint8_t is_update;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct tp_struct tp;
|
||||||
|
|
||||||
|
/* map raw value to 0...range (result) */
|
||||||
|
void tpd_map_touch_position(struct tpd_struct *d, uint8_t raw)
|
||||||
|
{
|
||||||
|
uint8_t is_pressed;
|
||||||
|
uint16_t p;
|
||||||
|
uint8_t start, end;
|
||||||
|
|
||||||
|
d->raw = raw;
|
||||||
|
|
||||||
|
start = d->start;
|
||||||
|
end = d->end;
|
||||||
|
|
||||||
|
/* check if position is within active area; store result in "is_pressed" */
|
||||||
|
is_pressed = 1;
|
||||||
|
if ( raw < start )
|
||||||
|
{
|
||||||
|
d->result = 0;
|
||||||
|
is_pressed = 0;
|
||||||
|
}
|
||||||
|
if ( raw >= end )
|
||||||
|
{
|
||||||
|
d->result = d->range;
|
||||||
|
is_pressed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* store "is_pressed" in the global structure, set update flag */
|
||||||
|
if ( d->is_pressed != is_pressed )
|
||||||
|
d->is_update = 1;
|
||||||
|
d->is_pressed = is_pressed;
|
||||||
|
|
||||||
|
/* map "raw" value into target range */
|
||||||
|
if ( is_pressed != 0 )
|
||||||
|
{
|
||||||
|
p = raw;
|
||||||
|
p -= start;
|
||||||
|
p *= d->range;
|
||||||
|
end -= start;
|
||||||
|
p /= end;
|
||||||
|
|
||||||
|
if ( d->result != p )
|
||||||
|
d->is_update = 1;
|
||||||
|
d->result = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tp_Init(uint8_t width, uint8_t height)
|
||||||
|
{
|
||||||
|
tp.x.start = X_START;
|
||||||
|
tp.x.end = X_END;
|
||||||
|
tp.x.range = width-1;
|
||||||
|
|
||||||
|
tp.y.start = Y_START;
|
||||||
|
tp.y.end = Y_END;
|
||||||
|
tp.y.range = height-1;
|
||||||
|
|
||||||
|
tp.is_update = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTouchRawValues(uint8_t x, uint8_t y)
|
||||||
|
{
|
||||||
|
tpd_map_touch_position(&(tp.x), x);
|
||||||
|
tpd_map_touch_position(&(tp.y), y);
|
||||||
|
|
||||||
|
tp.is_pressed = tp.x.is_pressed && tp.y.is_pressed;
|
||||||
|
if ( tp.x.is_update || tp.y.is_update )
|
||||||
|
tp.is_update = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t getTouchPos(uint8_t hiPin, uint8_t lowPin, uint8_t sensePin, uint8_t dcPin)
|
||||||
|
{
|
||||||
|
uint8_t val;
|
||||||
|
pinMode(dcPin, INPUT);
|
||||||
|
pinMode(sensePin, INPUT_PULLUP);
|
||||||
|
pinMode(hiPin, OUTPUT);
|
||||||
|
pinMode(lowPin, OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(hiPin, HIGH);
|
||||||
|
digitalWrite(lowPin, LOW);
|
||||||
|
delay(10);
|
||||||
|
val = analogRead(sensePin) >> 2;
|
||||||
|
pinMode(hiPin, INPUT);
|
||||||
|
pinMode(lowPin, INPUT);
|
||||||
|
delay(10);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateTouchPanel(void)
|
||||||
|
{
|
||||||
|
uint8_t tp_raw_x;
|
||||||
|
uint8_t tp_raw_y;
|
||||||
|
|
||||||
|
tp_raw_x = getTouchPos(tp_right, tp_left, tp_bottom, tp_top);
|
||||||
|
tp_raw_y = getTouchPos(tp_top, tp_bottom, tp_left, tp_right);
|
||||||
|
|
||||||
|
setTouchRawValues(tp_raw_x, tp_raw_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
//================================================================
|
||||||
|
// graphics output and picture loop
|
||||||
|
|
||||||
|
void center(u8g_uint_t y, const char *str)
|
||||||
|
{
|
||||||
|
u8g_uint_t x;
|
||||||
|
x = u8g.getWidth();
|
||||||
|
x -= u8g.getStrWidth(str);
|
||||||
|
x /= 2;
|
||||||
|
u8g.drawStr(x, y, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void draw(void) {
|
||||||
|
u8g.setFont(u8g_font_6x10);
|
||||||
|
center( 10, "Touch Panel Test");
|
||||||
|
if ( tp.is_pressed != 0 )
|
||||||
|
{
|
||||||
|
u8g.setPrintPos(0, 20); u8g.print("x=");u8g.print((int)tp.x.result);
|
||||||
|
u8g.setPrintPos(0, 30); u8g.print("y=");u8g.print((int)(u8g.getHeight()-tp.y.result-1));
|
||||||
|
//u8g.setPrintPos(0, 40); u8g.print("x: ");u8g.print((int)tp.x.start);u8g.print("..");u8g.print((int)tp.x.end);
|
||||||
|
//u8g.setPrintPos(0, 50); u8g.print("y: ");u8g.print((int)tp.y.start);u8g.print("..");u8g.print((int)tp.y.end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(void) {
|
||||||
|
|
||||||
|
// flip screen, if required
|
||||||
|
// u8g.setRot180();
|
||||||
|
u8g.setCursorFont(u8g_font_cursor);
|
||||||
|
u8g.setCursorStyle(32);
|
||||||
|
|
||||||
|
tp_Init(u8g.getWidth(), u8g.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(void) {
|
||||||
|
|
||||||
|
// update touch panel and handle return values
|
||||||
|
updateTouchPanel();
|
||||||
|
|
||||||
|
if ( tp.is_pressed != 0 )
|
||||||
|
u8g.enableCursor();
|
||||||
|
else
|
||||||
|
u8g.disableCursor();
|
||||||
|
|
||||||
|
u8g.setCursorPos(tp.x.result, u8g.getHeight()-tp.y.result-1);
|
||||||
|
|
||||||
|
// picture loop
|
||||||
|
if ( tp.is_update != 0 ) {
|
||||||
|
tp.is_update = 0;
|
||||||
|
u8g.firstPage();
|
||||||
|
do {
|
||||||
|
draw();
|
||||||
|
} while( u8g.nextPage() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_arduino_ATtiny85_std_hw_spi.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2011, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Uses code from tinySPI Written by Nick Gammon
|
||||||
|
// March 2013
|
||||||
|
|
||||||
|
// ATMEL ATTINY45 / ARDUINO pin mappings
|
||||||
|
//
|
||||||
|
// +-\/-+
|
||||||
|
// RESET Ain0 (D 5) PB5 1| |8 Vcc
|
||||||
|
// CLK1 Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 SCK / USCK / SCL
|
||||||
|
// CLK0 Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 MISO / DO
|
||||||
|
// GND 4| |5 PB0 (D 0) pwm0 MOSI / DI / SDA
|
||||||
|
// +----+
|
||||||
|
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(ARDUINO) && defined(__AVR_ATtiny85__)
|
||||||
|
|
||||||
|
#if ARDUINO < 100
|
||||||
|
#include <WProgram.h>
|
||||||
|
#else
|
||||||
|
#include <Arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const byte DI = 0; // D0, pin 5 Data In
|
||||||
|
const byte DO = 1; // D1, pin 6 Data Out (this is *not* MOSI)
|
||||||
|
const byte USCK = 2; // D2, pin 7 Universal Serial Interface clock
|
||||||
|
|
||||||
|
uint8_t u8g_arduino_ATtiny85_spi_out(uint8_t val)
|
||||||
|
{
|
||||||
|
USIDR = val; // byte to output
|
||||||
|
USISR = _BV (USIOIF); // clear Counter Overflow Interrupt Flag, set count to zero
|
||||||
|
do
|
||||||
|
{
|
||||||
|
USICR = _BV (USIWM0) // 3-wire mode
|
||||||
|
| _BV (USICS1) | _BV (USICLK) // Software clock strobe
|
||||||
|
| _BV (USITC); // Toggle Clock Port Pin
|
||||||
|
}
|
||||||
|
while ((USISR & _BV (USIOIF)) == 0); // until Counter Overflow Interrupt Flag set
|
||||||
|
|
||||||
|
return USIDR; // return read data
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_COM_MSG_INIT:
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); // ensure SS stays high until needed
|
||||||
|
pinMode (USCK, OUTPUT);
|
||||||
|
pinMode (DO, OUTPUT);
|
||||||
|
pinMode (u8g->pin_list[U8G_PI_CS], OUTPUT);
|
||||||
|
pinMode (u8g->pin_list[U8G_PI_A0], OUTPUT);
|
||||||
|
USICR = _BV (USIWM0); // 3-wire mode
|
||||||
|
u8g_MicroDelay();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_STOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_RESET:
|
||||||
|
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_CHIP_SELECT:
|
||||||
|
if ( arg_val == 0 )
|
||||||
|
{
|
||||||
|
/* disable */
|
||||||
|
u8g_MicroDelay();
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* enable */
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_BYTE:
|
||||||
|
u8g_arduino_ATtiny85_spi_out(arg_val);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ:
|
||||||
|
{
|
||||||
|
register uint8_t *ptr = arg_ptr;
|
||||||
|
while( arg_val > 0 )
|
||||||
|
{
|
||||||
|
u8g_arduino_ATtiny85_spi_out(*ptr++);
|
||||||
|
arg_val--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||||
|
{
|
||||||
|
register uint8_t *ptr = arg_ptr;
|
||||||
|
while( arg_val > 0 )
|
||||||
|
{
|
||||||
|
u8g_arduino_ATtiny85_spi_out(u8g_pgm_read(ptr));
|
||||||
|
ptr++;
|
||||||
|
arg_val--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* ARDUINO */
|
||||||
|
|
||||||
|
uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ARDUINO */
|
@ -0,0 +1,159 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_com_arduino_hw_usart_spi.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2011, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
SPI Clock Cycle Type
|
||||||
|
|
||||||
|
SSD1351 50ns 20 MHz
|
||||||
|
SSD1322 300ns 3.3 MHz
|
||||||
|
SSD1327 300ns
|
||||||
|
SSD1306 300ns
|
||||||
|
ST7565 400ns 2.5 MHz
|
||||||
|
ST7920 400ns
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#if defined(ARDUINO)
|
||||||
|
|
||||||
|
#if defined(__AVR_ATmega32U4__ )
|
||||||
|
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
#if ARDUINO < 100
|
||||||
|
#include <WProgram.h>
|
||||||
|
#else
|
||||||
|
#include <Arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static uint8_t u8g_usart_spi_out(uint8_t data)
|
||||||
|
{
|
||||||
|
/* send data */
|
||||||
|
UDR1 = data;
|
||||||
|
/* wait for empty transmit buffer */
|
||||||
|
while(!(UCSR1A & (1 << UDRE1)));
|
||||||
|
|
||||||
|
return UDR1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_COM_MSG_STOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_INIT:
|
||||||
|
/* SCK is already an output as we overwrite TXLED */
|
||||||
|
u8g_com_arduino_assign_pin_output_high(u8g);
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||||
|
|
||||||
|
// Init interface at 2MHz
|
||||||
|
UBRR1 = 0x00;
|
||||||
|
UCSR1C = (1 << UMSEL11) | (1 << UMSEL10);
|
||||||
|
UCSR1B = (1 << TXEN1);
|
||||||
|
UBRR1 = 3;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_CHIP_SELECT:
|
||||||
|
if ( arg_val == 0 )
|
||||||
|
{
|
||||||
|
/* disable */
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* enable */
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_RESET:
|
||||||
|
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_BYTE:
|
||||||
|
u8g_usart_spi_out(arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ:
|
||||||
|
{
|
||||||
|
register uint8_t *ptr = arg_ptr;
|
||||||
|
while( arg_val > 0 )
|
||||||
|
{
|
||||||
|
u8g_usart_spi_out(*ptr++);
|
||||||
|
arg_val--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||||
|
{
|
||||||
|
register uint8_t *ptr = arg_ptr;
|
||||||
|
while( arg_val > 0 )
|
||||||
|
{
|
||||||
|
u8g_usart_spi_out(u8g_pgm_read(ptr));
|
||||||
|
ptr++;
|
||||||
|
arg_val--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* #elif defined(__18CXX) || defined(__PIC32MX) */
|
||||||
|
/* #elif defined(__arm__) // Arduino Due, maybe we should better check for __SAM3X8E__ */
|
||||||
|
|
||||||
|
#else /* __AVR_ATmega32U4__ */
|
||||||
|
|
||||||
|
#endif /* __AVR_ATmega32U4__ */
|
||||||
|
|
||||||
|
#else /* ARDUINO */
|
||||||
|
|
||||||
|
uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ARDUINO */
|
||||||
|
|
@ -0,0 +1,330 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_com_arduino_st7920_custom.c
|
||||||
|
|
||||||
|
Additional COM device, initially introduced for 3D Printer community
|
||||||
|
Implements a fast SW SPI com subsystem
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2011, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
A special SPI interface for ST7920 controller
|
||||||
|
|
||||||
|
Update for ATOMIC operation done (01 Jun 2013)
|
||||||
|
U8G_ATOMIC_OR(ptr, val)
|
||||||
|
U8G_ATOMIC_AND(ptr, val)
|
||||||
|
U8G_ATOMIC_START();
|
||||||
|
U8G_ATOMIC_END();
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#if defined(ARDUINO)
|
||||||
|
|
||||||
|
#if ARDUINO < 100
|
||||||
|
#include <WProgram.h>
|
||||||
|
#include "wiring_private.h"
|
||||||
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
|
#else
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "wiring_private.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__AVR__)
|
||||||
|
|
||||||
|
static uint8_t u8g_bitData, u8g_bitNotData;
|
||||||
|
static uint8_t u8g_bitClock, u8g_bitNotClock;
|
||||||
|
static volatile uint8_t *u8g_outData;
|
||||||
|
static volatile uint8_t *u8g_outClock;
|
||||||
|
|
||||||
|
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||||
|
{
|
||||||
|
u8g_outData = portOutputRegister(digitalPinToPort(dataPin));
|
||||||
|
u8g_outClock = portOutputRegister(digitalPinToPort(clockPin));
|
||||||
|
u8g_bitData = digitalPinToBitMask(dataPin);
|
||||||
|
u8g_bitClock = digitalPinToBitMask(clockPin);
|
||||||
|
|
||||||
|
u8g_bitNotClock = u8g_bitClock;
|
||||||
|
u8g_bitNotClock ^= 0x0ff;
|
||||||
|
|
||||||
|
u8g_bitNotData = u8g_bitData;
|
||||||
|
u8g_bitNotData ^= 0x0ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val) U8G_NOINLINE;
|
||||||
|
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||||
|
{
|
||||||
|
uint8_t cnt = 8;
|
||||||
|
uint8_t bitData = u8g_bitData;
|
||||||
|
uint8_t bitNotData = u8g_bitNotData;
|
||||||
|
uint8_t bitClock = u8g_bitClock;
|
||||||
|
uint8_t bitNotClock = u8g_bitNotClock;
|
||||||
|
volatile uint8_t *outData = u8g_outData;
|
||||||
|
volatile uint8_t *outClock = u8g_outClock;
|
||||||
|
|
||||||
|
|
||||||
|
U8G_ATOMIC_START();
|
||||||
|
bitData |= *outData;
|
||||||
|
bitNotData &= *outData;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ( val & 128 )
|
||||||
|
*outData = bitData;
|
||||||
|
else
|
||||||
|
*outData = bitNotData;
|
||||||
|
|
||||||
|
/*
|
||||||
|
*outClock |= bitClock;
|
||||||
|
val <<= 1;
|
||||||
|
cnt--;
|
||||||
|
*outClock &= bitNotClock;
|
||||||
|
*/
|
||||||
|
|
||||||
|
val <<= 1;
|
||||||
|
*outClock &= bitNotClock;
|
||||||
|
cnt--;
|
||||||
|
// removed micro delays, because AVRs are too slow and the delay is not required
|
||||||
|
//u8g_MicroDelay();
|
||||||
|
*outClock |= bitClock;
|
||||||
|
//u8g_MicroDelay();
|
||||||
|
} while( cnt != 0 );
|
||||||
|
U8G_ATOMIC_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(__18CXX) || defined(__PIC32MX)
|
||||||
|
|
||||||
|
uint16_t dog_bitData, dog_bitNotData;
|
||||||
|
uint16_t dog_bitClock, dog_bitNotClock;
|
||||||
|
volatile uint32_t *dog_outData;
|
||||||
|
volatile uint32_t *dog_outClock;
|
||||||
|
volatile uint32_t dog_pic32_spi_tmp;
|
||||||
|
|
||||||
|
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||||
|
{
|
||||||
|
dog_outData = portOutputRegister(digitalPinToPort(dataPin));
|
||||||
|
dog_outClock = portOutputRegister(digitalPinToPort(clockPin));
|
||||||
|
dog_bitData = digitalPinToBitMask(dataPin);
|
||||||
|
dog_bitClock = digitalPinToBitMask(clockPin);
|
||||||
|
|
||||||
|
dog_bitNotClock = dog_bitClock;
|
||||||
|
dog_bitNotClock ^= 0x0ffff;
|
||||||
|
|
||||||
|
dog_bitNotData = dog_bitData;
|
||||||
|
dog_bitNotData ^= 0x0ffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||||
|
{
|
||||||
|
uint8_t cnt = 8;
|
||||||
|
U8G_ATOMIC_START();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ( val & 128 )
|
||||||
|
*dog_outData |= dog_bitData;
|
||||||
|
else
|
||||||
|
*dog_outData &= dog_bitNotData;
|
||||||
|
val <<= 1;
|
||||||
|
//u8g_MicroDelay();
|
||||||
|
//*dog_outClock |= dog_bitClock;
|
||||||
|
*dog_outClock &= dog_bitNotClock;
|
||||||
|
cnt--;
|
||||||
|
u8g_MicroDelay();
|
||||||
|
//*dog_outClock &= dog_bitNotClock;
|
||||||
|
*dog_outClock |= dog_bitClock;
|
||||||
|
u8g_MicroDelay();
|
||||||
|
|
||||||
|
} while( cnt != 0 );
|
||||||
|
U8G_ATOMIC_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* default interface, Arduino DUE (__arm__) */
|
||||||
|
|
||||||
|
uint8_t u8g_data_custom_pin;
|
||||||
|
uint8_t u8g_clock_custom_pin;
|
||||||
|
|
||||||
|
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin)
|
||||||
|
{
|
||||||
|
u8g_data_custom_pin = dataPin;
|
||||||
|
u8g_clock_custom_pin = clockPin;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void u8g_com_arduino_do_shift_out_msb_first(uint8_t val)
|
||||||
|
{
|
||||||
|
uint8_t cnt = 8;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ( val & 128 )
|
||||||
|
digitalWrite(u8g_data_custom_pin, HIGH);
|
||||||
|
else
|
||||||
|
digitalWrite(u8g_data_custom_pin, LOW);
|
||||||
|
val <<= 1;
|
||||||
|
//u8g_MicroDelay();
|
||||||
|
digitalWrite(u8g_clock_custom_pin, LOW);
|
||||||
|
cnt--;
|
||||||
|
u8g_MicroDelay();
|
||||||
|
digitalWrite(u8g_clock_custom_pin, HIGH);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
} while( cnt != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static void u8g_com_arduino_st7920_write_byte_seq(uint8_t rs, uint8_t *ptr, uint8_t len)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
|
if ( rs == 0 )
|
||||||
|
{
|
||||||
|
/* command */
|
||||||
|
u8g_com_arduino_do_shift_out_msb_first(0x0f8);
|
||||||
|
}
|
||||||
|
else if ( rs == 1 )
|
||||||
|
{
|
||||||
|
/* data */
|
||||||
|
u8g_com_arduino_do_shift_out_msb_first(0x0fa);
|
||||||
|
}
|
||||||
|
|
||||||
|
while( len > 0 )
|
||||||
|
{
|
||||||
|
u8g_com_arduino_do_shift_out_msb_first(*ptr & 0x0f0);
|
||||||
|
u8g_com_arduino_do_shift_out_msb_first(*ptr << 4);
|
||||||
|
ptr++;
|
||||||
|
len--;
|
||||||
|
u8g_10MicroDelay();
|
||||||
|
}
|
||||||
|
|
||||||
|
for( i = 0; i < 4; i++ )
|
||||||
|
u8g_10MicroDelay();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void u8g_com_arduino_st7920_write_byte(uint8_t rs, uint8_t val)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
|
if ( rs == 0 )
|
||||||
|
{
|
||||||
|
/* command */
|
||||||
|
u8g_com_arduino_do_shift_out_msb_first(0x0f8);
|
||||||
|
}
|
||||||
|
else if ( rs == 1 )
|
||||||
|
{
|
||||||
|
/* data */
|
||||||
|
u8g_com_arduino_do_shift_out_msb_first(0x0fa);
|
||||||
|
}
|
||||||
|
|
||||||
|
u8g_com_arduino_do_shift_out_msb_first(val & 0x0f0);
|
||||||
|
u8g_com_arduino_do_shift_out_msb_first(val << 4);
|
||||||
|
|
||||||
|
for( i = 0; i < 4; i++ )
|
||||||
|
u8g_10MicroDelay();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_COM_MSG_INIT:
|
||||||
|
u8g_com_arduino_assign_pin_output_high(u8g);
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||||
|
// u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW);
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH);
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW);
|
||||||
|
u8g_com_arduino_init_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK]);
|
||||||
|
u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_STOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_RESET:
|
||||||
|
if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE )
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_CHIP_SELECT:
|
||||||
|
if ( arg_val == 0 )
|
||||||
|
{
|
||||||
|
/* disable, note: the st7920 has an active high chip select */
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* enable */
|
||||||
|
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, HIGH);
|
||||||
|
u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_BYTE:
|
||||||
|
u8g_com_arduino_st7920_write_byte( u8g->pin_list[U8G_PI_A0_STATE], arg_val);
|
||||||
|
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
|
||||||
|
//u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ:
|
||||||
|
u8g_com_arduino_st7920_write_byte_seq(u8g->pin_list[U8G_PI_A0_STATE], (uint8_t *)arg_ptr, arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||||
|
{
|
||||||
|
register uint8_t *ptr = arg_ptr;
|
||||||
|
while( arg_val > 0 )
|
||||||
|
{
|
||||||
|
u8g_com_arduino_st7920_write_byte(u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr) );
|
||||||
|
//u8g->pin_list[U8G_PI_A0_STATE] = 2;
|
||||||
|
ptr++;
|
||||||
|
arg_val--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||||
|
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* ARDUINO */
|
||||||
|
|
||||||
|
uint8_t u8g_com_arduino_st7920_custom_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ARDUINO */
|
||||||
|
|
@ -0,0 +1,206 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_com_arduino_uc_i2c.c
|
||||||
|
|
||||||
|
com interface for arduino (AND atmega) and the SSDxxxx chip (SOLOMON) variant
|
||||||
|
I2C protocol
|
||||||
|
|
||||||
|
ToDo: Rename this to u8g_com_avr_ssd_i2c.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2012, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
Special pin usage:
|
||||||
|
U8G_PI_I2C_OPTION additional options
|
||||||
|
U8G_PI_A0_STATE used to store the last value of the command/data register selection
|
||||||
|
U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
|
||||||
|
U8G_PI_SCL clock line (NOT USED)
|
||||||
|
U8G_PI_SDA data line (NOT USED)
|
||||||
|
|
||||||
|
U8G_PI_RESET reset line (currently disabled, see below)
|
||||||
|
|
||||||
|
Protocol:
|
||||||
|
SLA, Cmd/Data Selection, Arguments
|
||||||
|
The command/data register is selected by a special instruction byte, which is sent after SLA
|
||||||
|
|
||||||
|
The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#if defined(U8G_WITH_PINLIST)
|
||||||
|
|
||||||
|
#define DOGM240_SLA_CMD (0x38*2)
|
||||||
|
#define DOGM240_SLA_DATA (0x39*2)
|
||||||
|
|
||||||
|
uint8_t u8g_com_arduino_uc_start_sequence(u8g_t *u8g)
|
||||||
|
{
|
||||||
|
/* are we requested to set the a0 state? */
|
||||||
|
if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
|
||||||
|
{
|
||||||
|
if ( u8g_i2c_start(DOGM240_SLA_CMD) == 0 )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( u8g_i2c_start(DOGM240_SLA_DATA) == 0 )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8g->pin_list[U8G_PI_SET_A0] = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_com_arduino_uc_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_COM_MSG_INIT:
|
||||||
|
//u8g_com_arduino_digital_write(u8g, U8G_PI_SCL, HIGH);
|
||||||
|
//u8g_com_arduino_digital_write(u8g, U8G_PI_SDA, HIGH);
|
||||||
|
//u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: unknown mode */
|
||||||
|
|
||||||
|
u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_STOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_RESET:
|
||||||
|
/* Currently disabled, but it could be enable. Previous restrictions have been removed */
|
||||||
|
/* u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_CHIP_SELECT:
|
||||||
|
u8g->pin_list[U8G_PI_A0_STATE] = 0;
|
||||||
|
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */
|
||||||
|
if ( arg_val == 0 )
|
||||||
|
{
|
||||||
|
/* disable chip, send stop condition */
|
||||||
|
u8g_i2c_stop();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* enable, do nothing: any byte writing will trigger the i2c start */
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_BYTE:
|
||||||
|
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||||
|
if ( u8g_com_arduino_uc_start_sequence(u8g) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
if ( u8g_i2c_send_byte(arg_val) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
// u8g_i2c_stop();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ:
|
||||||
|
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||||
|
if ( u8g_com_arduino_uc_start_sequence(u8g) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
{
|
||||||
|
register uint8_t *ptr = arg_ptr;
|
||||||
|
while( arg_val > 0 )
|
||||||
|
{
|
||||||
|
if ( u8g_i2c_send_byte(*ptr++) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
arg_val--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// u8g_i2c_stop();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||||
|
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||||
|
if ( u8g_com_arduino_uc_start_sequence(u8g) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
{
|
||||||
|
register uint8_t *ptr = arg_ptr;
|
||||||
|
while( arg_val > 0 )
|
||||||
|
{
|
||||||
|
if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
|
||||||
|
return 0;
|
||||||
|
ptr++;
|
||||||
|
arg_val--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// u8g_i2c_stop();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||||
|
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
|
||||||
|
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */
|
||||||
|
|
||||||
|
#ifdef OLD_CODE
|
||||||
|
if ( i2c_state != 0 )
|
||||||
|
{
|
||||||
|
u8g_i2c_stop();
|
||||||
|
i2c_state = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( u8g_com_arduino_uc_start_sequence(arg_val) == 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* setup bus, might be a repeated start */
|
||||||
|
/*
|
||||||
|
if ( u8g_i2c_start(I2C_SLA) == 0 )
|
||||||
|
return 0;
|
||||||
|
if ( arg_val == 0 )
|
||||||
|
{
|
||||||
|
i2c_state = 1;
|
||||||
|
|
||||||
|
if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i2c_state = 2;
|
||||||
|
if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* defined(U8G_WITH_PINLIST) */
|
||||||
|
|
||||||
|
uint8_t u8g_com_arduino_uc_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined(U8G_WITH_PINLIST) */
|
||||||
|
|
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_com_raspberrypi_hw_spi.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2012, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
Assumes, that
|
||||||
|
MOSI is at PORTB, Pin 3
|
||||||
|
and
|
||||||
|
SCK is at PORTB, Pin 5
|
||||||
|
|
||||||
|
Update for ATOMIC operation done (01 Jun 2013)
|
||||||
|
U8G_ATOMIC_OR(ptr, val)
|
||||||
|
U8G_ATOMIC_AND(ptr, val)
|
||||||
|
U8G_ATOMIC_START()
|
||||||
|
U8G_ATOMIC_END()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(U8G_RASPBERRY_PI)
|
||||||
|
|
||||||
|
#include <wiringPiSPI.h>
|
||||||
|
#include <wiringPi.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_COM_MSG_STOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_INIT:
|
||||||
|
// check wiringPi setup
|
||||||
|
if (wiringPiSetup() == -1)
|
||||||
|
{
|
||||||
|
printf("wiringPi-Error\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wiringPiSPISetup (0, 100000) < 0)
|
||||||
|
{
|
||||||
|
printf ("Unable to open SPI device 0: %s\n", strerror (errno)) ;
|
||||||
|
exit (1) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8g_SetPIOutput(u8g, U8G_PI_RESET);
|
||||||
|
u8g_SetPIOutput(u8g, U8G_PI_A0);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||||
|
u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_CHIP_SELECT:
|
||||||
|
/* Done by the SPI hardware */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_RESET:
|
||||||
|
u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_BYTE:
|
||||||
|
wiringPiSPIDataRW (0, &arg_val, 1) ;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ:
|
||||||
|
wiringPiSPIDataRW (0, arg_ptr, arg_val);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||||
|
wiringPiSPIDataRW (0, arg_ptr, arg_val);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
Special pin usage:
|
||||||
|
U8G_PI_I2C_OPTION additional options
|
||||||
|
U8G_PI_A0_STATE used to store the last value of the command/data register selection
|
||||||
|
U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device
|
||||||
|
U8G_PI_SCL clock line (NOT USED)
|
||||||
|
U8G_PI_SDA data line (NOT USED)
|
||||||
|
|
||||||
|
U8G_PI_RESET reset line (currently disabled, see below)
|
||||||
|
|
||||||
|
Protocol:
|
||||||
|
SLA, Cmd/Data Selection, Arguments
|
||||||
|
The command/data register is selected by a special instruction byte, which is sent after SLA
|
||||||
|
|
||||||
|
The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#if defined(U8G_RASPBERRY_PI)
|
||||||
|
|
||||||
|
#include <wiringPi.h>
|
||||||
|
#include <wiringPiI2C.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#define I2C_SLA 0x3c
|
||||||
|
#define I2C_CMD_MODE 0x000
|
||||||
|
#define I2C_DATA_MODE 0x040
|
||||||
|
|
||||||
|
#if defined(U8G_WITH_PINLIST)
|
||||||
|
|
||||||
|
uint8_t u8g_com_raspberrypi_ssd_start_sequence(u8g_t *u8g)
|
||||||
|
{
|
||||||
|
/* are we requested to set the a0 state? */
|
||||||
|
if ( u8g->pin_list[U8G_PI_SET_A0] == 0 )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
/* setup bus, might be a repeated start */
|
||||||
|
if ( u8g_i2c_start(I2C_SLA) == 0 )
|
||||||
|
return 0;
|
||||||
|
if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 )
|
||||||
|
{
|
||||||
|
if ( u8g_i2c_send_mode(I2C_CMD_MODE) == 0 )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( u8g_i2c_send_mode(I2C_DATA_MODE) == 0 )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
u8g->pin_list[U8G_PI_SET_A0] = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_COM_MSG_INIT:
|
||||||
|
u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]);
|
||||||
|
u8g_SetPIOutput(u8g, U8G_PI_RESET);
|
||||||
|
u8g_SetPIOutput(u8g, U8G_PI_A0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_STOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_RESET:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_CHIP_SELECT:
|
||||||
|
u8g->pin_list[U8G_PI_A0_STATE] = 0;
|
||||||
|
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */
|
||||||
|
if ( arg_val == 0 )
|
||||||
|
{
|
||||||
|
/* disable chip, send stop condition */
|
||||||
|
u8g_i2c_stop();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* enable, do nothing: any byte writing will trigger the i2c start */
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_BYTE:
|
||||||
|
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||||
|
if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
if ( u8g_i2c_send_byte(arg_val) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
// u8g_i2c_stop();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ:
|
||||||
|
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||||
|
if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
{
|
||||||
|
register uint8_t *ptr = (uint8_t *)arg_ptr;
|
||||||
|
while( arg_val > 0 )
|
||||||
|
{
|
||||||
|
if ( u8g_i2c_send_byte(*ptr++) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
arg_val--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// u8g_i2c_stop();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_WRITE_SEQ_P:
|
||||||
|
//u8g->pin_list[U8G_PI_SET_A0] = 1;
|
||||||
|
if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 )
|
||||||
|
return u8g_i2c_stop(), 0;
|
||||||
|
{
|
||||||
|
register uint8_t *ptr = (uint8_t *)arg_ptr;
|
||||||
|
while( arg_val > 0 )
|
||||||
|
{
|
||||||
|
if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 )
|
||||||
|
return 0;
|
||||||
|
ptr++;
|
||||||
|
arg_val--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// u8g_i2c_stop();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||||
|
u8g->pin_list[U8G_PI_A0_STATE] = arg_val;
|
||||||
|
u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */
|
||||||
|
|
||||||
|
#ifdef OLD_CODE
|
||||||
|
if ( i2c_state != 0 )
|
||||||
|
{
|
||||||
|
u8g_i2c_stop();
|
||||||
|
i2c_state = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( u8g_com_raspberrypi_ssd_start_sequence(arg_val) == 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* setup bus, might be a repeated start */
|
||||||
|
/*
|
||||||
|
if ( u8g_i2c_start(I2C_SLA) == 0 )
|
||||||
|
return 0;
|
||||||
|
if ( arg_val == 0 )
|
||||||
|
{
|
||||||
|
i2c_state = 1;
|
||||||
|
|
||||||
|
if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i2c_state = 2;
|
||||||
|
if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* defined(U8G_WITH_PINLIST) */
|
||||||
|
|
||||||
|
uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined(U8G_WITH_PINLIST) */
|
||||||
|
#endif
|
@ -0,0 +1,199 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_dev_a2_micro_printer_ds.c
|
||||||
|
|
||||||
|
Use DC2 bitmap command of the A2 Micro panel termal printer
|
||||||
|
double stroke
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#define LINE_DELAY 40
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_dev_a2_micro_printer_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
uint8_t y, i, j;
|
||||||
|
uint8_t *ptr;
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
y = pb->p.page_y0;
|
||||||
|
ptr = pb->buf;
|
||||||
|
|
||||||
|
u8g_WriteByte(u8g, dev, 27); /* ESC */
|
||||||
|
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
|
||||||
|
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
|
||||||
|
u8g_WriteByte(u8g, dev, 160); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
|
||||||
|
u8g_WriteByte(u8g, dev, 20); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
|
||||||
|
|
||||||
|
u8g_WriteByte(u8g, dev, 18); /* DC2 */
|
||||||
|
u8g_WriteByte(u8g, dev, 42 ); /* * */
|
||||||
|
u8g_WriteByte(u8g, dev, pb->p.page_height );
|
||||||
|
u8g_WriteByte(u8g, dev, pb->width/8 );
|
||||||
|
|
||||||
|
for( i = 0; i < pb->p.page_height; i ++ )
|
||||||
|
{
|
||||||
|
for( j = 0; j < pb->width/8; j++ )
|
||||||
|
{
|
||||||
|
u8g_WriteByte(u8g, dev, *ptr);
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
u8g_Delay(LINE_DELAY);
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set parameters back to their default values */
|
||||||
|
u8g_WriteByte(u8g, dev, 27); /* ESC */
|
||||||
|
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
|
||||||
|
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
|
||||||
|
u8g_WriteByte(u8g, dev, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
|
||||||
|
u8g_WriteByte(u8g, dev, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t u8g_dev_expand4(uint8_t val)
|
||||||
|
{
|
||||||
|
uint8_t a,b,c,d;
|
||||||
|
a = val&1;
|
||||||
|
b = (val&2)<<1;
|
||||||
|
c = (val&4)<<2;
|
||||||
|
d = (val&8)<<3;
|
||||||
|
a |=b;
|
||||||
|
a |=c;
|
||||||
|
a |=d;
|
||||||
|
a |= a<<1;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_dev_a2_micro_printer_double_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_FIRST:
|
||||||
|
{
|
||||||
|
//u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
//u8g_WriteByte(u8g, dev, 18); /* DC2 */
|
||||||
|
//u8g_WriteByte(u8g, dev, 42 ); /* * */
|
||||||
|
//u8g_WriteByte(u8g, dev, pb->p.total_height*2 );
|
||||||
|
//u8g_WriteByte(u8g, dev, pb->width/8*2 );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
uint8_t y, i, j;
|
||||||
|
uint8_t *ptr;
|
||||||
|
uint8_t *p2;
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
y = pb->p.page_y0;
|
||||||
|
ptr = pb->buf;
|
||||||
|
//u8g_WriteByte(u8g, dev, 18); /* DC2 */
|
||||||
|
//u8g_WriteByte(u8g, dev, 35 ); /* # */
|
||||||
|
//u8g_WriteByte(u8g, dev, 0x0ff ); /* max */
|
||||||
|
|
||||||
|
u8g_WriteByte(u8g, dev, 27); /* ESC */
|
||||||
|
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
|
||||||
|
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
|
||||||
|
u8g_WriteByte(u8g, dev, 160); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
|
||||||
|
u8g_WriteByte(u8g, dev, 20); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
|
||||||
|
|
||||||
|
u8g_WriteByte(u8g, dev, 18); /* DC2 */
|
||||||
|
u8g_WriteByte(u8g, dev, 42 ); /* * */
|
||||||
|
u8g_WriteByte(u8g, dev, pb->p.page_height*2 );
|
||||||
|
u8g_WriteByte(u8g, dev, pb->width/8*2 );
|
||||||
|
|
||||||
|
for( i = 0; i < pb->p.page_height; i ++ )
|
||||||
|
{
|
||||||
|
p2 = ptr;
|
||||||
|
for( j = 0; j < pb->width/8; j++ )
|
||||||
|
{
|
||||||
|
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4));
|
||||||
|
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15));
|
||||||
|
p2++;
|
||||||
|
}
|
||||||
|
u8g_Delay(LINE_DELAY);
|
||||||
|
p2 = ptr;
|
||||||
|
for( j = 0; j < pb->width/8; j++ )
|
||||||
|
{
|
||||||
|
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 >> 4));
|
||||||
|
u8g_WriteByte(u8g, dev, u8g_dev_expand4(*p2 & 15));
|
||||||
|
p2++;
|
||||||
|
}
|
||||||
|
u8g_Delay(LINE_DELAY);
|
||||||
|
ptr += pb->width/8;
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set parameters back to their default values */
|
||||||
|
u8g_WriteByte(u8g, dev, 27); /* ESC */
|
||||||
|
u8g_WriteByte(u8g, dev, 55 ); /* parameter command */
|
||||||
|
u8g_WriteByte(u8g, dev, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
|
||||||
|
u8g_WriteByte(u8g, dev, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
|
||||||
|
u8g_WriteByte(u8g, dev, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(U8G_16BIT)
|
||||||
|
U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 384, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn);
|
||||||
|
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x360_ds, 192, 360, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
||||||
|
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x720_ds, 192, 720, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
||||||
|
#else
|
||||||
|
U8G_PB_DEV(u8g_dev_a2_micro_printer_384x240, 240, 240, 8, u8g_dev_a2_micro_printer_fn, u8g_com_null_fn);
|
||||||
|
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x360_ds, 192, 240, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
||||||
|
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x720_ds, 192, 240, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
U8G_PB_DEV(u8g_dev_a2_micro_printer_192x120_ds, 192, 120, 8, u8g_dev_a2_micro_printer_double_fn, u8g_com_null_fn);
|
@ -0,0 +1,281 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_dev_ht1632.c
|
||||||
|
|
||||||
|
1-Bit (BW) Driver for HT1632 controller
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
U8G_PIN_NONE can be used as argument
|
||||||
|
|
||||||
|
uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
u8g->pin_list[U8G_PI_SCK] = sck;
|
||||||
|
u8g->pin_list[U8G_PI_MOSI] = mosi;
|
||||||
|
u8g->pin_list[U8G_PI_CS] = cs;
|
||||||
|
u8g->pin_list[U8G_PI_A0] = a0;
|
||||||
|
u8g->pin_list[U8G_PI_RESET] = reset;
|
||||||
|
|
||||||
|
mapping
|
||||||
|
|
||||||
|
#define DATA_PIN --> U8G_PI_MOSI
|
||||||
|
#define WR_PIN --> U8G_PI_SCK
|
||||||
|
#define CS_PIN --> U8G_PI_CS
|
||||||
|
U8G_PI_A0 --> not used
|
||||||
|
U8G_PI_RESET --> not used
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
u8g_InitSPI(&u8g, &u8g_dev_ht1632_24x16, WR_PIN, DATA_IN, CS_PIN, U8G_PIN_NONE, U8G_PIN_NONE)
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#define WIDTH 24
|
||||||
|
#define HEIGHT 16
|
||||||
|
#define PAGE_HEIGHT 16
|
||||||
|
|
||||||
|
/* http://forum.arduino.cc/index.php?topic=168537.0 */
|
||||||
|
|
||||||
|
#define HT1632_CMD_SYSDIS 0x00 // CMD= 0000-0000-x Turn off oscil
|
||||||
|
#define HT1632_CMD_SYSON 0x01 // CMD= 0000-0001-x Enable system oscil
|
||||||
|
#define HT1632_CMD_LEDOFF 0x02 // CMD= 0000-0010-x LED duty cycle gen off
|
||||||
|
#define HT1632_CMD_LEDON 0x03 // CMD= 0000-0011-x LEDs ON
|
||||||
|
#define HT1632_CMD_BLOFF 0x08 // CMD= 0000-1000-x Blink OFF
|
||||||
|
#define HT1632_CMD_BLON 0x09 // CMD= 0000-1001-x Blink On
|
||||||
|
#define HT1632_CMD_SLVMD 0x10 // CMD= 0001-00xx-x Slave Mode
|
||||||
|
#define HT1632_CMD_MSTMD 0x14 // CMD= 0001-01xx-x Master Mode
|
||||||
|
#define HT1632_CMD_RCCLK 0x18 // CMD= 0001-10xx-x Use on-chip clock
|
||||||
|
#define HT1632_CMD_EXTCLK 0x1C // CMD= 0001-11xx-x Use external clock
|
||||||
|
#define HT1632_CMD_COMS00 0x20 // CMD= 0010-ABxx-x commons options
|
||||||
|
#define HT1632_CMD_COMS01 0x24 // CMD= 0010-ABxx-x commons options
|
||||||
|
#define HT1632_CMD_COMS10 0x28 // CMD= 0010-ABxx-x commons options
|
||||||
|
#define HT1632_CMD_COMS11 0x2C // P-MOS OUTPUT AND 16COMMON OPTION
|
||||||
|
#define HT1632_CMD_PWM 0xA0 // CMD= 101x-PPPP-x PWM duty cycle
|
||||||
|
|
||||||
|
#define HT1632_ID_CMD 4 /* ID = 100 - Commands */
|
||||||
|
#define HT1632_ID_RD 6 /* ID = 110 - Read RAM */
|
||||||
|
#define HT1632_ID_WR 5 /* ID = 101 - Write RAM */
|
||||||
|
|
||||||
|
#define HT1632_ID_LEN 3 // IDs are 3 bits
|
||||||
|
#define HT1632_CMD_LEN 8 // CMDs are 8 bits
|
||||||
|
#define HT1632_DATA_LEN 8 // Data are 4*2 bits
|
||||||
|
#define HT1632_ADDR_LEN 7 // Address are 7 bits
|
||||||
|
|
||||||
|
#if defined(ARDUINO)
|
||||||
|
|
||||||
|
#if ARDUINO < 100
|
||||||
|
#include <WProgram.h>
|
||||||
|
#else
|
||||||
|
#include <Arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//#define WR_PIN 3
|
||||||
|
//#define DATA_PIN 2
|
||||||
|
//#define CS_PIN 4
|
||||||
|
|
||||||
|
void ht1632_write_data_MSB(u8g_t *u8g, uint8_t cnt, uint8_t data, uint8_t extra)
|
||||||
|
{
|
||||||
|
int8_t i;
|
||||||
|
uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
|
||||||
|
uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
|
||||||
|
|
||||||
|
for(i = cnt - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if ((data >> i) & 1)
|
||||||
|
{
|
||||||
|
digitalWrite(data_pin, HIGH);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
digitalWrite(data_pin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite(wr_pin, LOW);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
digitalWrite(wr_pin, HIGH);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send an extra bit
|
||||||
|
if (extra)
|
||||||
|
{
|
||||||
|
digitalWrite(data_pin, HIGH);
|
||||||
|
digitalWrite(wr_pin, LOW);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
digitalWrite(wr_pin, HIGH);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ht1632_write_data(u8g_t *u8g, uint8_t cnt, uint8_t data)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
|
||||||
|
uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
|
||||||
|
for (i = 0; i < cnt; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ((data >> i) & 1) {
|
||||||
|
digitalWrite(data_pin, HIGH);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
digitalWrite(data_pin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite(wr_pin, LOW);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
digitalWrite(wr_pin, HIGH);
|
||||||
|
u8g_MicroDelay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ht1632_init(u8g_t *u8g)
|
||||||
|
{
|
||||||
|
//uint8_t i;
|
||||||
|
uint8_t data_pin = u8g->pin_list[U8G_PI_MOSI];
|
||||||
|
uint8_t wr_pin = u8g->pin_list[U8G_PI_SCK];
|
||||||
|
uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
|
||||||
|
pinMode(data_pin, OUTPUT);
|
||||||
|
pinMode(wr_pin, OUTPUT);
|
||||||
|
pinMode(cs_pin, OUTPUT);
|
||||||
|
|
||||||
|
digitalWrite(data_pin, HIGH);
|
||||||
|
digitalWrite(wr_pin, HIGH);
|
||||||
|
digitalWrite(cs_pin, HIGH);
|
||||||
|
|
||||||
|
digitalWrite(cs_pin, LOW);
|
||||||
|
/* init display once after startup */
|
||||||
|
ht1632_write_data_MSB(u8g, 3, HT1632_ID_CMD, false); // IDs are 3 bits
|
||||||
|
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_SYSDIS, true); // 8 bits
|
||||||
|
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_SYSON, true); // 8 bits
|
||||||
|
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_COMS11, true); // 8 bits
|
||||||
|
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_LEDON, true); // 8 bits
|
||||||
|
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_BLOFF, true); // 8 bits
|
||||||
|
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_PWM+15, true); // 8 bits
|
||||||
|
digitalWrite(cs_pin, HIGH);
|
||||||
|
|
||||||
|
/* removed following (debug) code */
|
||||||
|
/*
|
||||||
|
digitalWrite(cs_pin, LOW);
|
||||||
|
ht1632_write_data_MSB(u8g, 3, HT1632_ID_WR, false); // Send "write to display" command
|
||||||
|
ht1632_write_data_MSB(u8g, 7, 0, false);
|
||||||
|
for(i = 0; i<48; ++i)
|
||||||
|
{
|
||||||
|
ht1632_write_data(u8g, 8, 0xFF);
|
||||||
|
}
|
||||||
|
digitalWrite(cs_pin, HIGH);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
page: 0=data contain lines 0..16, 1=data contain lines 16..32 (a 24x16 display will only have page 0)
|
||||||
|
cnt: width of the display
|
||||||
|
data: pointer to a buffer with 2*cnt bytes.
|
||||||
|
*/
|
||||||
|
void ht1632_transfer_data(u8g_t *u8g, uint8_t page, uint8_t cnt, uint8_t *data)
|
||||||
|
{
|
||||||
|
uint8_t addr;
|
||||||
|
uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
|
||||||
|
/* send data to the ht1632 */
|
||||||
|
digitalWrite(cs_pin, LOW);
|
||||||
|
ht1632_write_data_MSB(u8g, 3, HT1632_ID_WR, false); // Send "write to display" command
|
||||||
|
ht1632_write_data_MSB(u8g, 7, page*2*cnt, false);
|
||||||
|
|
||||||
|
// Operating in progressive addressing mode
|
||||||
|
for (addr = 0; addr < cnt; addr++)
|
||||||
|
{
|
||||||
|
ht1632_write_data(u8g, 8, data[addr]);
|
||||||
|
ht1632_write_data(u8g, 8, data[addr+cnt]);
|
||||||
|
}
|
||||||
|
digitalWrite(cs_pin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* value is between 0...15 */
|
||||||
|
void ht1632_set_contrast(u8g_t *u8g, uint8_t value)
|
||||||
|
{
|
||||||
|
uint8_t cs_pin = u8g->pin_list[U8G_PI_CS];
|
||||||
|
digitalWrite(cs_pin, LOW);
|
||||||
|
ht1632_write_data_MSB(u8g, 3, HT1632_ID_CMD, false);
|
||||||
|
ht1632_write_data_MSB(u8g, 8, HT1632_CMD_PWM + value, false);
|
||||||
|
digitalWrite(cs_pin, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
void ht1632_init(u8g_t *u8g)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ht1632_transfer_data(u8g_t *u8g, uint8_t page, uint8_t cnt, uint8_t *data)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ht1632_set_contrast(u8g_t *u8g, uint8_t value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ARDUINO */
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ht1632_24x16_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
ht1632_init(u8g);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
/* current page: pb->p.page */
|
||||||
|
/* ptr to the buffer: pb->buf */
|
||||||
|
ht1632_transfer_data(u8g, pb->p.page, WIDTH, pb->buf);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
/* values passed to SetContrast() are between 0 and 255, scale down to 0...15 */
|
||||||
|
ht1632_set_contrast(u8g, (*(uint8_t *)arg) >> 4);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ht1632_24x16_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||||
|
u8g_pb_t u8g_dev_ht1632_24x16_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ht1632_24x16_buf};
|
||||||
|
u8g_dev_t u8g_dev_ht1632_24x16 = { u8g_dev_ht1632_24x16_fn, &u8g_dev_ht1632_24x16_pb, u8g_com_null_fn };
|
||||||
|
|
@ -0,0 +1,232 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_dev_ld7032_60x32.c
|
||||||
|
|
||||||
|
60x32 OLED display
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2011, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
/* define width as 64, so that it is a multiple of 8 */
|
||||||
|
#define WIDTH 64
|
||||||
|
#define HEIGHT 32
|
||||||
|
#define PAGE_HEIGHT 8
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_ld7032_60x32_init_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_DLY(1), /* delay 1 ms */
|
||||||
|
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x002, /* Dot Matrix Display ON/OFF */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x001, /* ON */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x014, /* Dot Matrix Display Stand-by ON/OFF */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x000, /* ON */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x01a, /* Dot Matrix Frame Rate */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x004, /* special value for this OLED from manual */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x01d, /* Graphics Memory Writing Direction */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x000, /* reset default (right down, horizontal) */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x009, /* Display Direction */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x000, /* reset default (x,y: min --> max) */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x030, /* Display Size X */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x000, /* Column Start Output */
|
||||||
|
0x03b, /* Column End Output */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x032, /* Display Size Y */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x000, /* Row Start Output */
|
||||||
|
0x01f, /* Row End Output */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x010, /* Peak Pulse Width Set */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x000, /* 0 SCLK */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x016, /* Peak Pulse Delay Set */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x000, /* 0 SCLK */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x012, /* Dot Matrix Current Level Set */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x050, /* 0x050 * 1 uA = 80 uA */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x018, /* Pre-Charge Pulse Width */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x003, /* 3 SCLK */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x044, /* Pre-Charge Mode */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x002, /* Every Time */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x048, /* Row overlap timing */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x003, /* Pre-Charge + Peak Delay + Peak boot Timing */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x03f, /* VCC_R_SEL */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x011, /* ??? */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x03d, /* VSS selection */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x000, /* 2.8V */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x002, /* Dot Matrix Display ON/OFF */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x001, /* ON */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x008, /* write data */
|
||||||
|
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* use box commands to set start adr */
|
||||||
|
static const uint8_t u8g_dev_ld7032_60x32_data_start[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x034, /* box x start */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x000, /* 0 */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x035, /* box x end */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x007, /* */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x037, /* box y end */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
0x01f, /* */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x036, /* box y start */
|
||||||
|
U8G_ESC_ADR(1), /* data mode */
|
||||||
|
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_ld7032_60x32_sleep_on[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
/* ... */
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_ld7032_60x32_sleep_off[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
/* ... */
|
||||||
|
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ld7032_60x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, pb->p.page_y0); /* y start */
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x008);
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||||
|
return 0;
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x081);
|
||||||
|
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
return 1;
|
||||||
|
case U8G_DEV_MSG_SLEEP_ON:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_sleep_on);
|
||||||
|
return 1;
|
||||||
|
case U8G_DEV_MSG_SLEEP_OFF:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ld7032_60x32_sleep_off);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb8h1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
U8G_PB_DEV(u8g_dev_ld7032_60x32_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_SW_SPI);
|
||||||
|
U8G_PB_DEV(u8g_dev_ld7032_60x32_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_HW_SPI);
|
||||||
|
U8G_PB_DEV(u8g_dev_ld7032_60x32_parallel, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_PARALLEL);
|
||||||
|
U8G_PB_DEV(u8g_dev_ld7032_60x32_hw_usart_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ld7032_60x32_fn, U8G_COM_HW_USART_SPI);
|
||||||
|
|
@ -0,0 +1,787 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_dev_ssd1351_128x128.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, jamjardavies@gmail.com
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
History:
|
||||||
|
Initial version 20 May 2013 jamjardavies@gmail.com
|
||||||
|
indexed device 22 May 2013 olikraus@gmail.com
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#define WIDTH 128
|
||||||
|
#define HEIGHT 128
|
||||||
|
#define PAGE_HEIGHT 8
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_ssd1351_128x128_init_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_DLY(50),
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
U8G_ESC_DLY(50),
|
||||||
|
|
||||||
|
0xfd, /* Command Lock */
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x12,
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xfd,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xb1, /* Command Lock */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xae, /* Set Display Off */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb3,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xf1, /* Front Clock Div */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xca,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x7f, /* Set Multiplex Ratio */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xa0,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xb4, /* Set Colour Depth */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x15,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x00, 0x7f, /* Set Column Address */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x75,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x00, 0x7f, /* Set Row Address */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xa1,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x00, /* Set Display Start Line */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xa2,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x00, /* Set Display Offset */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb5,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x00, /* Set GPIO */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xab,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x01, /* Set Function Selection */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb1,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x32, /* Set Phase Length */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb4,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xa0, 0xb5, 0x55, /* Set Segment Low Voltage */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xbb,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x17, /* Set Precharge Voltage */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xbe,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x05, /* Set VComH Voltage */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xc1,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xc8, 0x80, 0xc8, /* Set Contrast */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xc7,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x0f, /* Set Master Contrast */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb6,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x01, /* Set Second Precharge Period */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xa6, /* Set Display Mode Reset */
|
||||||
|
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb8, /* Set CMD Grayscale Lookup */
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x05,
|
||||||
|
0x06,
|
||||||
|
0x07,
|
||||||
|
0x08,
|
||||||
|
0x09,
|
||||||
|
0x0a,
|
||||||
|
0x0b,
|
||||||
|
0x0c,
|
||||||
|
0x0D,
|
||||||
|
0x0E,
|
||||||
|
0x0F,
|
||||||
|
0x10,
|
||||||
|
0x11,
|
||||||
|
0x12,
|
||||||
|
0x13,
|
||||||
|
0x14,
|
||||||
|
0x15,
|
||||||
|
0x16,
|
||||||
|
0x18,
|
||||||
|
0x1a,
|
||||||
|
0x1b,
|
||||||
|
0x1C,
|
||||||
|
0x1D,
|
||||||
|
0x1F,
|
||||||
|
0x21,
|
||||||
|
0x23,
|
||||||
|
0x25,
|
||||||
|
0x27,
|
||||||
|
0x2A,
|
||||||
|
0x2D,
|
||||||
|
0x30,
|
||||||
|
0x33,
|
||||||
|
0x36,
|
||||||
|
0x39,
|
||||||
|
0x3C,
|
||||||
|
0x3F,
|
||||||
|
0x42,
|
||||||
|
0x45,
|
||||||
|
0x48,
|
||||||
|
0x4C,
|
||||||
|
0x50,
|
||||||
|
0x54,
|
||||||
|
0x58,
|
||||||
|
0x5C,
|
||||||
|
0x60,
|
||||||
|
0x64,
|
||||||
|
0x68,
|
||||||
|
0x6C,
|
||||||
|
0x70,
|
||||||
|
0x74,
|
||||||
|
0x78,
|
||||||
|
0x7D,
|
||||||
|
0x82,
|
||||||
|
0x87,
|
||||||
|
0x8C,
|
||||||
|
0x91,
|
||||||
|
0x96,
|
||||||
|
0x9B,
|
||||||
|
0xA0,
|
||||||
|
0xA5,
|
||||||
|
0xAA,
|
||||||
|
0xAF,
|
||||||
|
0xB4,
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0),
|
||||||
|
0xaf, /* Set Display On */
|
||||||
|
0x5c,
|
||||||
|
U8G_ESC_DLY(50),
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* set gpio to high */
|
||||||
|
static const uint8_t u8g_dev_ssd1351_128x128gh_init_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_DLY(50),
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
U8G_ESC_DLY(50),
|
||||||
|
|
||||||
|
0xfd, /* Command Lock */
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x12,
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xfd,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xb1, /* Command Lock */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xae, /* Set Display Off */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb3,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xf1, /* Front Clock Div */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xca,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x7f, /* Set Multiplex Ratio */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xa0,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xb4, /* Set Colour Depth */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x15,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x00, 0x7f, /* Set Column Address */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0x75,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x00, 0x7f, /* Set Row Address */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xa1,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x00, /* Set Display Start Line */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xa2,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x00, /* Set Display Offset */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb5,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x03, /* Set GPIO to High Level */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xab,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x01, /* Set Function Selection */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb1,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x32, /* Set Phase Length */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb4,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xa0, 0xb5, 0x55, /* Set Segment Low Voltage */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xbb,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x17, /* Set Precharge Voltage */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xbe,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x05, /* Set VComH Voltage */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xc1,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0xc8, 0x80, 0xc8, /* Set Contrast */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xc7,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x0f, /* Set Master Contrast */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb6,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x01, /* Set Second Precharge Period */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xa6, /* Set Display Mode Reset */
|
||||||
|
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
0xb8, /* Set CMD Grayscale Lookup */
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
0x05,
|
||||||
|
0x06,
|
||||||
|
0x07,
|
||||||
|
0x08,
|
||||||
|
0x09,
|
||||||
|
0x0a,
|
||||||
|
0x0b,
|
||||||
|
0x0c,
|
||||||
|
0x0D,
|
||||||
|
0x0E,
|
||||||
|
0x0F,
|
||||||
|
0x10,
|
||||||
|
0x11,
|
||||||
|
0x12,
|
||||||
|
0x13,
|
||||||
|
0x14,
|
||||||
|
0x15,
|
||||||
|
0x16,
|
||||||
|
0x18,
|
||||||
|
0x1a,
|
||||||
|
0x1b,
|
||||||
|
0x1C,
|
||||||
|
0x1D,
|
||||||
|
0x1F,
|
||||||
|
0x21,
|
||||||
|
0x23,
|
||||||
|
0x25,
|
||||||
|
0x27,
|
||||||
|
0x2A,
|
||||||
|
0x2D,
|
||||||
|
0x30,
|
||||||
|
0x33,
|
||||||
|
0x36,
|
||||||
|
0x39,
|
||||||
|
0x3C,
|
||||||
|
0x3F,
|
||||||
|
0x42,
|
||||||
|
0x45,
|
||||||
|
0x48,
|
||||||
|
0x4C,
|
||||||
|
0x50,
|
||||||
|
0x54,
|
||||||
|
0x58,
|
||||||
|
0x5C,
|
||||||
|
0x60,
|
||||||
|
0x64,
|
||||||
|
0x68,
|
||||||
|
0x6C,
|
||||||
|
0x70,
|
||||||
|
0x74,
|
||||||
|
0x78,
|
||||||
|
0x7D,
|
||||||
|
0x82,
|
||||||
|
0x87,
|
||||||
|
0x8C,
|
||||||
|
0x91,
|
||||||
|
0x96,
|
||||||
|
0x9B,
|
||||||
|
0xA0,
|
||||||
|
0xA5,
|
||||||
|
0xAA,
|
||||||
|
0xAF,
|
||||||
|
0xB4,
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0),
|
||||||
|
0xaf, /* Set Display On */
|
||||||
|
0x5c,
|
||||||
|
U8G_ESC_DLY(50),
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define u8g_dev_ssd1351_128x128_init_seq u8g_dev_ssd1351_128x128_init_seq
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_ssd1351_128x128_column_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(1),
|
||||||
|
U8G_ESC_ADR(0), 0x15,
|
||||||
|
U8G_ESC_ADR(1), 0x00, 0x7f,
|
||||||
|
U8G_ESC_ADR(0), 0x75,
|
||||||
|
U8G_ESC_ADR(1), 0x00, 0x7f,
|
||||||
|
U8G_ESC_ADR(0), 0x5c,
|
||||||
|
U8G_ESC_ADR(1),
|
||||||
|
U8G_ESC_CS(0),
|
||||||
|
U8G_ESC_END
|
||||||
|
};
|
||||||
|
|
||||||
|
#define RGB332_STREAM_BYTES 8
|
||||||
|
static uint8_t u8g_ssd1351_stream_bytes[RGB332_STREAM_BYTES*3];
|
||||||
|
|
||||||
|
void u8g_ssd1351_to_stream(uint8_t *ptr)
|
||||||
|
{
|
||||||
|
uint8_t cnt = RGB332_STREAM_BYTES;
|
||||||
|
uint8_t val;
|
||||||
|
uint8_t *dest = u8g_ssd1351_stream_bytes;
|
||||||
|
for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
|
||||||
|
{
|
||||||
|
val = *ptr++;
|
||||||
|
*dest++ = ((val & 0xe0) >> 2);
|
||||||
|
*dest++ = ((val & 0x1c) << 1);
|
||||||
|
*dest++ = ((val & 0x03) << 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef OBSOLETE
|
||||||
|
// Convert the internal RGB 332 to R
|
||||||
|
static uint8_t u8g_ssd1351_get_r(uint8_t colour)
|
||||||
|
{
|
||||||
|
//return ((colour & 0xe0) >> 5) * 9;
|
||||||
|
//return ((colour & 0xe0) >> 5) * 8;
|
||||||
|
return ((colour & 0xe0) >> 2) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the internal RGB 332 to G
|
||||||
|
static uint8_t u8g_ssd1351_get_g(uint8_t colour)
|
||||||
|
{
|
||||||
|
//return ((colour & 0x1c) >> 2) * 9;
|
||||||
|
//return ((colour & 0x1c) >> 2) * 8;
|
||||||
|
return ((colour & 0x1c) << 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the internal RGB 332 to B
|
||||||
|
static uint8_t u8g_ssd1351_get_b(uint8_t colour)
|
||||||
|
{
|
||||||
|
//return (colour & 0x03) * 21;
|
||||||
|
return (colour & 0x03) * 16;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ssd1351_128x128_332_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_PAGE_FIRST:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_uint_t x;
|
||||||
|
uint8_t page_height;
|
||||||
|
uint8_t i;
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
uint8_t *ptr = pb->buf;
|
||||||
|
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
|
||||||
|
page_height = pb->p.page_y1;
|
||||||
|
page_height -= pb->p.page_y0;
|
||||||
|
page_height++;
|
||||||
|
for( i = 0; i < page_height; i++ )
|
||||||
|
{
|
||||||
|
|
||||||
|
for (x = 0; x < pb->width; x+=RGB332_STREAM_BYTES)
|
||||||
|
{
|
||||||
|
u8g_ssd1351_to_stream(ptr);
|
||||||
|
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
|
||||||
|
ptr += RGB332_STREAM_BYTES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_GET_MODE:
|
||||||
|
return U8G_MODE_R3G3B2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ssd1351_128x128gh_332_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128gh_init_seq);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_PAGE_FIRST:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_uint_t x;
|
||||||
|
uint8_t page_height;
|
||||||
|
uint8_t i;
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
uint8_t *ptr = pb->buf;
|
||||||
|
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
|
||||||
|
page_height = pb->p.page_y1;
|
||||||
|
page_height -= pb->p.page_y0;
|
||||||
|
page_height++;
|
||||||
|
for( i = 0; i < page_height; i++ )
|
||||||
|
{
|
||||||
|
|
||||||
|
for (x = 0; x < pb->width; x+=RGB332_STREAM_BYTES)
|
||||||
|
{
|
||||||
|
u8g_ssd1351_to_stream(ptr);
|
||||||
|
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
|
||||||
|
ptr += RGB332_STREAM_BYTES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_GET_MODE:
|
||||||
|
return U8G_MODE_R3G3B2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t u8g_dev_ssd1351_128x128_r[256];
|
||||||
|
static uint8_t u8g_dev_ssd1351_128x128_g[256];
|
||||||
|
static uint8_t u8g_dev_ssd1351_128x128_b[256];
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ssd1351_128x128_idx_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
// u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||||
|
u8g_dev_ssd1351_128x128_r[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->r;
|
||||||
|
u8g_dev_ssd1351_128x128_g[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->g;
|
||||||
|
u8g_dev_ssd1351_128x128_b[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->b;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_PAGE_FIRST:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
uint8_t *ptr = pb->buf;
|
||||||
|
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
|
||||||
|
for (x = 0; x < pb->width; x++)
|
||||||
|
{
|
||||||
|
u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_r[(*ptr)>>2]);
|
||||||
|
u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_g[(*ptr)>>2]);
|
||||||
|
u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_b[(*ptr)>>2]);
|
||||||
|
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_GET_MODE:
|
||||||
|
return U8G_MODE_INDEX;
|
||||||
|
}
|
||||||
|
|
||||||
|
return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void u8g_ssd1351_hicolor_to_stream(uint8_t *ptr)
|
||||||
|
{
|
||||||
|
register uint8_t cnt = RGB332_STREAM_BYTES;
|
||||||
|
register uint8_t low, high, r, g, b;
|
||||||
|
uint8_t *dest = u8g_ssd1351_stream_bytes;
|
||||||
|
for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
|
||||||
|
{
|
||||||
|
low = *ptr++;
|
||||||
|
high = *ptr++;
|
||||||
|
|
||||||
|
r = high & ~7;
|
||||||
|
r >>= 2;
|
||||||
|
b = low & 31;
|
||||||
|
b <<= 1;
|
||||||
|
g = high & 7;
|
||||||
|
g <<= 3;
|
||||||
|
g |= (low>>5)&7;
|
||||||
|
|
||||||
|
*dest++ = r;
|
||||||
|
*dest++ = g;
|
||||||
|
*dest++ = b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ssd1351_128x128_hicolor_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_FIRST:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
uint8_t i, j;
|
||||||
|
uint8_t page_height;
|
||||||
|
uint8_t *ptr = pb->buf;
|
||||||
|
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
|
||||||
|
page_height = pb->p.page_y1;
|
||||||
|
page_height -= pb->p.page_y0;
|
||||||
|
page_height++;
|
||||||
|
for( j = 0; j < page_height; j++ )
|
||||||
|
{
|
||||||
|
for (i = 0; i < pb->width; i+=RGB332_STREAM_BYTES)
|
||||||
|
{
|
||||||
|
u8g_ssd1351_hicolor_to_stream(ptr);
|
||||||
|
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
|
||||||
|
ptr += RGB332_STREAM_BYTES*2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
break; /* continue to base fn */
|
||||||
|
case U8G_DEV_MSG_GET_MODE:
|
||||||
|
return U8G_MODE_HICOLOR;
|
||||||
|
}
|
||||||
|
return u8g_dev_pbxh16_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ssd1351_128x128gh_hicolor_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128gh_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_FIRST:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
uint8_t i, j;
|
||||||
|
uint8_t page_height;
|
||||||
|
uint8_t *ptr = pb->buf;
|
||||||
|
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
|
||||||
|
page_height = pb->p.page_y1;
|
||||||
|
page_height -= pb->p.page_y0;
|
||||||
|
page_height++;
|
||||||
|
for( j = 0; j < page_height; j++ )
|
||||||
|
{
|
||||||
|
for (i = 0; i < pb->width; i+=RGB332_STREAM_BYTES)
|
||||||
|
{
|
||||||
|
u8g_ssd1351_hicolor_to_stream(ptr);
|
||||||
|
u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
|
||||||
|
ptr += RGB332_STREAM_BYTES*2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
break; /* continue to base fn */
|
||||||
|
case U8G_DEV_MSG_GET_MODE:
|
||||||
|
return U8G_MODE_HICOLOR;
|
||||||
|
}
|
||||||
|
return u8g_dev_pbxh16_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ssd1351_128x128_byte_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
|
||||||
|
|
||||||
|
u8g_pb_t u8g_dev_ssd1351_128x128_byte_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_byte_buf};
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128_332_sw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128_332_hw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128gh_332_sw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128gh_332_hw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
|
||||||
|
|
||||||
|
//u8g_dev_t u8g_dev_ssd1351_128x128_idx_sw_spi = { u8g_dev_ssd1351_128x128_idx_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
|
||||||
|
//u8g_dev_t u8g_dev_ssd1351_128x128_idx_hw_spi = { u8g_dev_ssd1351_128x128_idx_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
|
||||||
|
|
||||||
|
|
||||||
|
/* only half of the height, because two bytes are needed for one pixel */
|
||||||
|
u8g_pb_t u8g_dev_ssd1351_128x128_hicolor_byte_pb = { {PAGE_HEIGHT/2, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_byte_buf};
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_sw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_hw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_HW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_sw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_hw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_HW_SPI };
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_dev_ssd1351_128x128_4x_byte_buf[WIDTH*PAGE_HEIGHT*4] U8G_NOCOMMON ;
|
||||||
|
|
||||||
|
u8g_pb_t u8g_dev_ssd1351_128x128_4x_332_byte_pb = { {PAGE_HEIGHT*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_4x_byte_buf};
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_sw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_hw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_HW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_sw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_hw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_HW_SPI };
|
||||||
|
|
||||||
|
u8g_pb_t u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb = { {PAGE_HEIGHT/2*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_4x_byte_buf};
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_sw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_hw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_HW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_sw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_hw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_HW_SPI };
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
U8G_PB_DEV(u8g_dev_ssd1351_128x128_332_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_332_fn, U8G_COM_SW_SPI);
|
||||||
|
U8G_PB_DEV(u8g_dev_ssd1351_128x128_332_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_332_fn, U8G_COM_HW_SPI);
|
||||||
|
|
||||||
|
U8G_PB_DEV(u8g_dev_ssd1351_128x128_idx_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_idx_fn, U8G_COM_SW_SPI);
|
||||||
|
U8G_PB_DEV(u8g_dev_ssd1351_128x128_idx_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_idx_fn, U8G_COM_HW_SPI);
|
||||||
|
*/
|
||||||
|
|
@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_dev_t6963_128x128.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
Application Notes for the MGLS 128x128
|
||||||
|
www.baso.no/content/pdf/T6963C_Application.pdf
|
||||||
|
|
||||||
|
Hitachi App Notes:
|
||||||
|
https://www.sparkfun.com/datasheets/LCD/Monochrome/AN-029-Toshiba_T6963C.pdf
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
The font selection pins should generate the 8x8 font.
|
||||||
|
For the MGLS240128TZ only FS1 is available on pin 18.
|
||||||
|
FS1 must be low to generate the 8x8 font.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#define WIDTH 128
|
||||||
|
#define HEIGHT 128
|
||||||
|
#define PAGE_HEIGHT 16
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
http://www.mark-products.com/graphics.htm#240x64%20Pixel%20Format
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* text is not used, so settings are not relevant */
|
||||||
|
static const uint8_t u8g_dev_t6963_128x128_init_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_ADR(0), /* data mode */
|
||||||
|
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
|
||||||
|
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* data mode */
|
||||||
|
0x000, /* low byte */
|
||||||
|
0x000, /* height byte */
|
||||||
|
U8G_ESC_ADR(1), /* instruction mode */
|
||||||
|
0x021, /* set cursor position */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* data mode */
|
||||||
|
0x000, /* low byte */
|
||||||
|
0x000, /* height byte */
|
||||||
|
U8G_ESC_ADR(1), /* instruction mode */
|
||||||
|
0x022, /* set offset */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* data mode */
|
||||||
|
0x000, /* low byte */
|
||||||
|
0x000, /* height byte */
|
||||||
|
U8G_ESC_ADR(1), /* instruction mode */
|
||||||
|
0x040, /* text home */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* data mode */
|
||||||
|
WIDTH/8, /* low byte */
|
||||||
|
0x000, /* height byte */
|
||||||
|
U8G_ESC_ADR(1), /* instruction mode */
|
||||||
|
0x041, /* text columns */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* data mode */
|
||||||
|
0x000, /* low byte */
|
||||||
|
0x000, /* height byte */
|
||||||
|
U8G_ESC_ADR(1), /* instruction mode */
|
||||||
|
0x042, /* graphics home */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* data mode */
|
||||||
|
WIDTH/8, /* low byte */
|
||||||
|
0x000, /* height byte */
|
||||||
|
U8G_ESC_ADR(1), /* instruction mode */
|
||||||
|
0x043, /* graphics columns */
|
||||||
|
|
||||||
|
// mode set
|
||||||
|
// 0x080: Internal CG, OR Mode
|
||||||
|
// 0x081: Internal CG, EXOR Mode
|
||||||
|
// 0x083: Internal CG, AND Mode
|
||||||
|
// 0x088: External CG, OR Mode
|
||||||
|
// 0x089: External CG, EXOR Mode
|
||||||
|
// 0x08B: External CG, AND Mode
|
||||||
|
U8G_ESC_ADR(1), /* instruction mode */
|
||||||
|
0x080, /* mode register: OR Mode, Internal Character Mode */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(1), /* instruction mode */
|
||||||
|
// display mode
|
||||||
|
// 0x090: Display off
|
||||||
|
// 0x094: Graphic off, text on, cursor off, blink off
|
||||||
|
// 0x096: Graphic off, text on, cursor on, blink off
|
||||||
|
// 0x097: Graphic off, text on, cursor on, blink on
|
||||||
|
// 0x098: Graphic on, text off, cursor off, blink off
|
||||||
|
// 0x09a: Graphic on, text off, cursor on, blink off
|
||||||
|
// ...
|
||||||
|
// 0x09c: Graphic on, text on, cursor off, blink off
|
||||||
|
// 0x09f: Graphic on, text on, cursor on, blink on
|
||||||
|
0x098, /* mode register: Display Mode, Graphics on, Text off, Cursor off */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* data mode */
|
||||||
|
0x000, /* low byte */
|
||||||
|
0x000, /* height byte */
|
||||||
|
U8G_ESC_ADR(1), /* instruction mode */
|
||||||
|
0x024, /* set adr pointer */
|
||||||
|
|
||||||
|
|
||||||
|
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||||
|
|
||||||
|
U8G_ESC_ADR(0), /* data mode */
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t u8g_dev_t6963_128x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_t6963_128x128_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
uint8_t y, i;
|
||||||
|
uint16_t disp_ram_adr;
|
||||||
|
uint8_t *ptr;
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* data mode */
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
y = pb->p.page_y0;
|
||||||
|
ptr = pb->buf;
|
||||||
|
disp_ram_adr = WIDTH/8;
|
||||||
|
disp_ram_adr *= y;
|
||||||
|
for( i = 0; i < PAGE_HEIGHT; i ++ )
|
||||||
|
{
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* data mode */
|
||||||
|
u8g_WriteByte(u8g, dev, disp_ram_adr&255 ); /* address low byte */
|
||||||
|
u8g_WriteByte(u8g, dev, disp_ram_adr>>8 ); /* address hight byte */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* cmd mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x024 ); /* set adr ptr */
|
||||||
|
|
||||||
|
u8g_WriteSequence(u8g, dev, WIDTH/8, ptr);
|
||||||
|
|
||||||
|
ptr += WIDTH/8;
|
||||||
|
disp_ram_adr += WIDTH/8;
|
||||||
|
}
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* data mode */
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb16h1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// U8G_PB_DEV(u8g_dev_t6963_128x128_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_t6963_128x128_fn, U8G_COM_T6963);
|
||||||
|
|
||||||
|
uint8_t u8g_dev_t6963_128x128_2x_bw_buf[WIDTH/8*PAGE_HEIGHT] U8G_NOCOMMON ;
|
||||||
|
u8g_pb_t u8g_dev_t6963_128x128_2x_bw_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_t6963_128x128_2x_bw_buf};
|
||||||
|
u8g_dev_t u8g_dev_t6963_128x128_8bit = { u8g_dev_t6963_128x128_fn, &u8g_dev_t6963_128x128_2x_bw_pb, U8G_COM_T6963 };
|
||||||
|
|
||||||
|
|
@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_dev_uc1601_c128032.c
|
||||||
|
|
||||||
|
LCD-AG-C128032R-DIW W/KK E6 PBF from http://www.artronic.pl/o_produkcie.php?id=1343
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#define WIDTH 128
|
||||||
|
#define HEIGHT 32
|
||||||
|
#define PAGE_HEIGHT 8
|
||||||
|
|
||||||
|
/* init sequence */
|
||||||
|
static const uint8_t u8g_dev_uc1601_c128032_init_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
|
||||||
|
|
||||||
|
0x0a3, /* 0x0a3: LCD bias 1/7 , 0x0a2: LCD bias 1/9 */
|
||||||
|
0x0a0, /* 0x0a0: ADC set to normal, 0x0a1 ADC set to inverted */
|
||||||
|
0x0c8, /* common output mode: set scan direction normal operation/SHL Select, 0x0c0 --> SHL = 0, normal, 0x0c8 --> SHL = 1 */
|
||||||
|
0x0c2, /* 22 May 2013: mirror x */
|
||||||
|
|
||||||
|
0x040, /* set display start line */
|
||||||
|
|
||||||
|
0x028 | 0x04, /* power control: turn on voltage converter */
|
||||||
|
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||||
|
|
||||||
|
0x028 | 0x06, /* power control: turn on voltage regulator */
|
||||||
|
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||||
|
|
||||||
|
0x028 | 0x07, /* power control: turn on voltage follower */
|
||||||
|
U8G_ESC_DLY(10), /* delay 10 ms */
|
||||||
|
|
||||||
|
0x020| 0x06, /* set V0 voltage resistor ratio to 6 */
|
||||||
|
|
||||||
|
0x0af, /* display on */
|
||||||
|
|
||||||
|
//0x081, /* set contrast */
|
||||||
|
//0x018, /* contrast value*/
|
||||||
|
|
||||||
|
0x0a6, /* display normal, bit val 0: LCD pixel off. */
|
||||||
|
|
||||||
|
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||||
|
U8G_ESC_CS(0), /* disable chip */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_uc1601_c128032_data_start[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
0x010, /* set upper 4 bit of the col adr to 0 */
|
||||||
|
0x004, /* set lower 4 bit of the col adr */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_uc1601_c128032_sleep_on[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
0x0ac, /* static indicator off */
|
||||||
|
0x000, /* indicator register set (not sure if this is required) */
|
||||||
|
0x0ae, /* display off */
|
||||||
|
0x0a5, /* all points on */
|
||||||
|
U8G_ESC_CS(1), /* disable chip */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_uc1601_c128032_sleep_off[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
0x0a4, /* all points off */
|
||||||
|
0x0af, /* display on */
|
||||||
|
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||||
|
U8G_ESC_CS(1), /* disable chip */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1601_c128032_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (UC1601) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||||
|
return 0;
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x081);
|
||||||
|
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
return 1;
|
||||||
|
case U8G_DEV_MSG_SLEEP_ON:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_on);
|
||||||
|
return 1;
|
||||||
|
case U8G_DEV_MSG_SLEEP_OFF:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_off);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1601_c128032_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (UC1601) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (UC1601) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x081);
|
||||||
|
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
return 1;
|
||||||
|
case U8G_DEV_MSG_SLEEP_ON:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_on);
|
||||||
|
return 1;
|
||||||
|
case U8G_DEV_MSG_SLEEP_OFF:
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1601_c128032_sleep_off);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1601_c128032_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1601_c128032_fn, U8G_COM_SW_SPI);
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1601_c128032_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1601_c128032_fn, U8G_COM_HW_SPI);
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1601_c128032_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||||
|
u8g_pb_t u8g_dev_uc1601_c128032_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1601_c128032_2x_buf};
|
||||||
|
u8g_dev_t u8g_dev_uc1601_c128032_2x_sw_spi = { u8g_dev_uc1601_c128032_2x_fn, &u8g_dev_uc1601_c128032_2x_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_uc1601_c128032_2x_hw_spi = { u8g_dev_uc1601_c128032_2x_fn, &u8g_dev_uc1601_c128032_2x_pb, U8G_COM_HW_SPI };
|
||||||
|
|
@ -0,0 +1,200 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
u8g_dev_uc1608_240x128.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com (original 240x64 library)
|
||||||
|
Modified by thieringpeti@gmail.com for Raystar rx240128 family displays
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Display: http://www.tme.eu/en/details/rx240128a-ghw/lcd-graphic-displays/raystar-optronics/
|
||||||
|
Connection: HW / SW SPI.
|
||||||
|
To get this display working, You need some extra capacitors:
|
||||||
|
|
||||||
|
connect 4.7uF caps between:
|
||||||
|
PIN1 & PIN2 VB1 +-
|
||||||
|
PIN3 & PIN4 VB0 -+
|
||||||
|
connect 0.1uF caps between:
|
||||||
|
VLCD and VSS
|
||||||
|
VBIAS and VSS
|
||||||
|
You can find some schematics with a 10M resistor parallellized with the VLCD capacitor.
|
||||||
|
|
||||||
|
Select 4-bit SPI mode.
|
||||||
|
|
||||||
|
Connect D7 (PIN9) To VDD (+3.3V)
|
||||||
|
Connect D1, D2, D4, D5, D6 to GND (PINS 10,11,12,14,15)
|
||||||
|
Connect WR0, WR1, BM0, BM1 to GND (PINS 17,18,22,23)
|
||||||
|
|
||||||
|
D0: (PIN16) AVR's SCK pin (HW SPI)
|
||||||
|
D3: (PIN13) AVR's MOSI pin (HW SPI)
|
||||||
|
CD: (PIN19) used as A0 in the library
|
||||||
|
CS: (PIN21) Connect to the defined CS pin, and You can re-use the HW SPI in different routines.
|
||||||
|
RST: (PIN20) optional reset, can be defined in the function, resets on initialization.
|
||||||
|
|
||||||
|
Adjust contrast if necessary. Default: 0x072.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#define WIDTH 240
|
||||||
|
#define HEIGHT 128
|
||||||
|
#define PAGE_HEIGHT 8
|
||||||
|
|
||||||
|
/* see also ERC24064-1 for init sequence example */
|
||||||
|
static const uint8_t u8g_dev_uc1608_240x128_init_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(1), /* disable chip (UC1608 has positive logic for CS) */
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_RST(1), /* do reset low pulse with (15*16)+2 milliseconds */
|
||||||
|
|
||||||
|
|
||||||
|
U8G_ESC_CS(0), /* enable chip */
|
||||||
|
0x0e2, /* soft reset */
|
||||||
|
|
||||||
|
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||||
|
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||||
|
0x026, /* MUX rate and temperature compensation */
|
||||||
|
|
||||||
|
0x0c8, /* Map control, Bit 3: MY=1, Bit 2: MX=0, Bit 0: MSF =0 */
|
||||||
|
|
||||||
|
0x0eb, /* LCD bias Bits 0/1: 00=10.7 01=10.3, 10=12.0, 11=12.7*/
|
||||||
|
/* default 0x0ea for 240x128 */
|
||||||
|
0x081, /* set contrast (bits 0..5) and gain (bits 6/7) */
|
||||||
|
0x072, /* default for 240x128 displays: 0x072*/
|
||||||
|
|
||||||
|
0x02f, /* power on, Bit 2 PC2=1 (internal charge pump), Bits 0/1: cap of panel */
|
||||||
|
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||||
|
|
||||||
|
0x040, /* set display start line to 0 */
|
||||||
|
0x090, /* no fixed lines */
|
||||||
|
0x089, /* RAM access control */
|
||||||
|
|
||||||
|
0x0af, /* disable sleep mode */
|
||||||
|
0x0a4, /* normal display */
|
||||||
|
0x0a5, /* display all points, ST7565, UC1610 */
|
||||||
|
// 0x0a7, /* inverse display */
|
||||||
|
0x0a6, /* normal display */
|
||||||
|
|
||||||
|
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||||
|
0x0a4, /* normal display */
|
||||||
|
U8G_ESC_CS(1), /* disable chip */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_uc1608_240x128_data_start[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(0), /* enable chip */
|
||||||
|
0x010, /* set upper 4 bit of the col adr to 0 (UC1608) */
|
||||||
|
0x000, /* set lower 4 bit of the col adr to 0 */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1608_240x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (UC1608) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||||
|
return 0;
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x081);
|
||||||
|
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1608_240x128_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x128_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x081);
|
||||||
|
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1608_240x128_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x128_fn, U8G_COM_SW_SPI);
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1608_240x128_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x128_fn, U8G_COM_HW_SPI);
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1608_240x128_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||||
|
u8g_pb_t u8g_dev_uc1608_240x128_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1608_240x128_2x_buf};
|
||||||
|
u8g_dev_t u8g_dev_uc1608_240x128_2x_sw_spi = { u8g_dev_uc1608_240x128_2x_fn, &u8g_dev_uc1608_240x128_2x_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_uc1608_240x128_2x_hw_spi = { u8g_dev_uc1608_240x128_2x_fn, &u8g_dev_uc1608_240x128_2x_pb, U8G_COM_HW_SPI };
|
||||||
|
|
@ -0,0 +1,168 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_dev_uc1608_240x64.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
#define WIDTH 240
|
||||||
|
#define HEIGHT 64
|
||||||
|
#define PAGE_HEIGHT 8
|
||||||
|
|
||||||
|
/* see also ERC24064-1 for init sequence example */
|
||||||
|
static const uint8_t u8g_dev_uc1608_240x64_init_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(1), /* disable chip (UC1608 has positive logic for CS) */
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_RST(1), /* do reset low pulse with (15*16)+2 milliseconds */
|
||||||
|
|
||||||
|
|
||||||
|
U8G_ESC_CS(0), /* enable chip */
|
||||||
|
0x0e2, /* soft reset */
|
||||||
|
|
||||||
|
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||||
|
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||||
|
#if HEIGHT <= 96
|
||||||
|
0x023, /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */
|
||||||
|
#else
|
||||||
|
/* 30 Nov 2013: not tested */
|
||||||
|
0x027, /* Bit 0/1: Temp compenstation, Bit 2: Multiplex Rate 0=96, 1=128 */
|
||||||
|
#endif
|
||||||
|
0x0c8, /* Map control, Bit 3: MY=1, Bit 2: MX=0, Bit 0: MSF =0 */
|
||||||
|
0x0e8, /* LCD bias Bits 0/1: 00=10.7 01=10.3, 10=12.0, 11=12.7*/
|
||||||
|
|
||||||
|
0x081, /* set contrast (bits 0..5) and gain (bits 6/7) */
|
||||||
|
0x014, /* ECR24064-1 default: 0x040*/
|
||||||
|
|
||||||
|
0x02f, /* power on, Bit 2 PC2=1 (internal charge pump), Bits 0/1: cap of panel */
|
||||||
|
U8G_ESC_DLY(50), /* delay 50 ms */
|
||||||
|
|
||||||
|
0x040, /* set display start line to 0 */
|
||||||
|
0x090, /* no fixed lines */
|
||||||
|
0x089, /* RAM access control */
|
||||||
|
|
||||||
|
0x0af, /* disable sleep mode */
|
||||||
|
0x0a4, /* normal display */
|
||||||
|
0x0a5, /* display all points, ST7565, UC1610 */
|
||||||
|
U8G_ESC_DLY(100), /* delay 100 ms */
|
||||||
|
0x0a4, /* normal display */
|
||||||
|
U8G_ESC_CS(1), /* disable chip */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_uc1608_240x64_data_start[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(0), /* enable chip */
|
||||||
|
0x010, /* set upper 4 bit of the col adr to 0 (UC1608) */
|
||||||
|
0x000, /* set lower 4 bit of the col adr to 0 */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1608_240x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (UC1608) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||||
|
return 0;
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x081);
|
||||||
|
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1608_240x64_2x_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page)); /* select current page (ST7565R) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
u8g_WriteSequence(u8g, dev, pb->width, pb->buf);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1608_240x64_data_start);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x0b0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
u8g_WriteSequence(u8g, dev, pb->width, (uint8_t *)(pb->buf)+pb->width);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x081);
|
||||||
|
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2);
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1608_240x64_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x64_fn, U8G_COM_SW_SPI);
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1608_240x64_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1608_240x64_fn, U8G_COM_HW_SPI);
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1608_240x64_2x_buf[WIDTH*2] U8G_NOCOMMON ;
|
||||||
|
u8g_pb_t u8g_dev_uc1608_240x64_2x_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_uc1608_240x64_2x_buf};
|
||||||
|
u8g_dev_t u8g_dev_uc1608_240x64_2x_sw_spi = { u8g_dev_uc1608_240x64_2x_fn, &u8g_dev_uc1608_240x64_2x_pb, U8G_COM_SW_SPI };
|
||||||
|
u8g_dev_t u8g_dev_uc1608_240x64_2x_hw_spi = { u8g_dev_uc1608_240x64_2x_fn, &u8g_dev_uc1608_240x64_2x_pb, U8G_COM_HW_SPI };
|
||||||
|
|
@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_dev_uc1611_dogm240.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2014, dev.menges.jonas@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define WIDTH 240
|
||||||
|
#define HEIGHT 64
|
||||||
|
#define PAGE_HEIGHT 8
|
||||||
|
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_uc1611_dogm240_init_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(1), // enable chip
|
||||||
|
U8G_ESC_ADR(0), // instruction mode
|
||||||
|
0xF1, // set last COM electrode
|
||||||
|
0x3F, // 64-1=63
|
||||||
|
0xF2, // set display start line
|
||||||
|
0x00, // 0
|
||||||
|
0xF3, // set display end line
|
||||||
|
0x3F, // 64-1=63
|
||||||
|
0x81, // set contrast (0-255)
|
||||||
|
0xB7, // 183
|
||||||
|
0xC0, // set view
|
||||||
|
//0x04, // topview
|
||||||
|
0x02, // bottomview
|
||||||
|
0xA3, // set line rate (9.4k)
|
||||||
|
0xE9, // set bias ratio (10)
|
||||||
|
0xA9, // enable display
|
||||||
|
0xD1, // set black and white mode
|
||||||
|
U8G_ESC_CS(0), // disable chip
|
||||||
|
U8G_ESC_END // end of sequence
|
||||||
|
};
|
||||||
|
|
||||||
|
static void setPage(u8g_t *u8g, u8g_dev_t *dev, unsigned char page)
|
||||||
|
{
|
||||||
|
u8g_WriteByte(u8g, dev, 0x70);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F));
|
||||||
|
}
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_uc1611_dogm240_data_start[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
0x10, /* set upper 4 bit of the col adr to 0 */
|
||||||
|
0x00, /* set lower 4 bit of the col adr to 0 */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t u8g_dev_uc1611_dogm240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_data_start);
|
||||||
|
setPage(u8g, dev, pb->p.page); /* select current page (uc1611) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||||
|
return 0;
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x81);
|
||||||
|
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1611_dogm240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_UC_I2C);
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1611_dogm240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_SW_SPI);
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1611_dogm240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_HW_SPI);
|
||||||
|
|
@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_dev_uc1611_dogxl240.c
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2014, dev.menges.jonas@gmail.com, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define WIDTH 240
|
||||||
|
#define HEIGHT 128
|
||||||
|
#define PAGE_HEIGHT 8
|
||||||
|
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_uc1611_dogxl240_init_seq[] PROGMEM = {
|
||||||
|
U8G_ESC_CS(1), // enable chip
|
||||||
|
U8G_ESC_ADR(0), // instruction mode
|
||||||
|
0xF1, // set last COM electrode
|
||||||
|
0x7F, // DOGXL240
|
||||||
|
0xF2, // set display start line
|
||||||
|
0x00, // 0
|
||||||
|
0xF3, // set display end line
|
||||||
|
0x7F, // DOGXL240
|
||||||
|
0x81, // set contrast (0-255)
|
||||||
|
0xAA, // DOGXL240
|
||||||
|
0xC0, // set view
|
||||||
|
//0x04, // topview
|
||||||
|
0x02, // bottomview
|
||||||
|
0xA3, // set line rate (9.4k)
|
||||||
|
0xE9, // set bias ratio (10)
|
||||||
|
0xA9, // enable display
|
||||||
|
0xD1, // set black and white mode
|
||||||
|
U8G_ESC_CS(0), // disable chip
|
||||||
|
U8G_ESC_END // end of sequence
|
||||||
|
};
|
||||||
|
|
||||||
|
static void u8g_dev_dogxl240_set_page(u8g_t *u8g, u8g_dev_t *dev, unsigned char page)
|
||||||
|
{
|
||||||
|
u8g_WriteByte(u8g, dev, 0x70);
|
||||||
|
u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F));
|
||||||
|
}
|
||||||
|
|
||||||
|
static const uint8_t u8g_dev_uc1611_dogxl240_data_start[] PROGMEM = {
|
||||||
|
U8G_ESC_ADR(0), /* instruction mode */
|
||||||
|
U8G_ESC_CS(1), /* enable chip */
|
||||||
|
0x10, /* set upper 4 bit of the col adr to 0 */
|
||||||
|
0x00, /* set lower 4 bit of the col adr to 0 */
|
||||||
|
U8G_ESC_END /* end of sequence */
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint8_t u8g_dev_uc1611_dogxl240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_init_seq);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_data_start);
|
||||||
|
u8g_dev_dogxl240_set_page(u8g, dev, pb->p.page); /* select current page (uc1611) */
|
||||||
|
u8g_SetAddress(u8g, dev, 1); /* data mode */
|
||||||
|
if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 )
|
||||||
|
return 0;
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_CONTRAST:
|
||||||
|
u8g_SetChipSelect(u8g, dev, 0);
|
||||||
|
u8g_SetAddress(u8g, dev, 0); /* instruction mode */
|
||||||
|
u8g_WriteByte(u8g, dev, 0x81);
|
||||||
|
u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */
|
||||||
|
u8g_SetChipSelect(u8g, dev, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1611_dogxl240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_UC_I2C);
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1611_dogxl240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_SW_SPI);
|
||||||
|
U8G_PB_DEV(u8g_dev_uc1611_dogxl240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_HW_SPI);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,184 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_pbxh16.c
|
||||||
|
|
||||||
|
x lines per page, horizontal, 16 bits per pixel (hi color modes)
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
struct _u8g_pb_t
|
||||||
|
{
|
||||||
|
u8g_page_t p;
|
||||||
|
u8g_uint_t width;
|
||||||
|
void *buf;
|
||||||
|
};
|
||||||
|
typedef struct _u8g_pb_t u8g_pb_t;
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
|
||||||
|
u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf};
|
||||||
|
u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn }
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define WIDTH_BITS 7
|
||||||
|
#define WIDTH (1<<WIDTH_BITS)
|
||||||
|
#define PAGE_HEIGHT_BITS 3
|
||||||
|
#define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
|
||||||
|
*/
|
||||||
|
|
||||||
|
void u8g_pbxh16_Clear(u8g_pb_t *b)
|
||||||
|
{
|
||||||
|
uint8_t *ptr = (uint8_t *)b->buf;
|
||||||
|
uint8_t *end_ptr = ptr;
|
||||||
|
uint8_t cnt = b->p.page_height;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
end_ptr += b->width*2;
|
||||||
|
cnt--;
|
||||||
|
} while( cnt > 0 );
|
||||||
|
do
|
||||||
|
{
|
||||||
|
*ptr++ = 0;
|
||||||
|
} while( ptr != end_ptr );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void u8g_pbxh16_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
|
||||||
|
{
|
||||||
|
b->buf = buf;
|
||||||
|
b->width = width;
|
||||||
|
u8g_pbxh16_Clear(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void u8g_pbxh16_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t low, uint8_t high)
|
||||||
|
{
|
||||||
|
uint16_t tmp;
|
||||||
|
uint8_t *ptr = b->buf;
|
||||||
|
y -= b->p.page_y0;
|
||||||
|
tmp = y;
|
||||||
|
tmp *= b->width;
|
||||||
|
tmp += x;
|
||||||
|
tmp <<= 1;
|
||||||
|
ptr += tmp;
|
||||||
|
*ptr = low;
|
||||||
|
ptr++;
|
||||||
|
*ptr = high;
|
||||||
|
}
|
||||||
|
|
||||||
|
void u8g_pbxh16_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
|
||||||
|
{
|
||||||
|
if ( arg_pixel->y < b->p.page_y0 )
|
||||||
|
return;
|
||||||
|
if ( arg_pixel->y > b->p.page_y1 )
|
||||||
|
return;
|
||||||
|
if ( arg_pixel->x >= b->width )
|
||||||
|
return;
|
||||||
|
u8g_pbxh16_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void u8g_pbxh16_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
|
||||||
|
{
|
||||||
|
register uint8_t pixel = arg_pixel->pixel;
|
||||||
|
u8g_uint_t dx = 0;
|
||||||
|
u8g_uint_t dy = 0;
|
||||||
|
|
||||||
|
switch( arg_pixel->dir )
|
||||||
|
{
|
||||||
|
case 0: dx++; break;
|
||||||
|
case 1: dy++; break;
|
||||||
|
case 2: dx--; break;
|
||||||
|
case 3: dy--; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ( pixel & 128 )
|
||||||
|
u8g_pbxh16_SetPixel(b, arg_pixel);
|
||||||
|
arg_pixel->x += dx;
|
||||||
|
arg_pixel->y += dy;
|
||||||
|
pixel <<= 1;
|
||||||
|
} while( pixel != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_SET_8PIXEL:
|
||||||
|
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
|
||||||
|
u8g_pbxh16_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_SET_PIXEL:
|
||||||
|
u8g_pbxh16_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_FIRST:
|
||||||
|
u8g_pbxh16_Clear(pb);
|
||||||
|
u8g_page_First(&(pb->p));
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
if ( u8g_page_Next(&(pb->p)) == 0 )
|
||||||
|
return 0;
|
||||||
|
u8g_pbxh16_Clear(pb);
|
||||||
|
break;
|
||||||
|
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
|
||||||
|
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
|
||||||
|
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
|
||||||
|
#endif
|
||||||
|
case U8G_DEV_MSG_GET_PAGE_BOX:
|
||||||
|
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_GET_WIDTH:
|
||||||
|
*((u8g_uint_t *)arg) = pb->width;
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_GET_HEIGHT:
|
||||||
|
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_SET_XY_CB:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_GET_MODE:
|
||||||
|
return U8G_MODE_HICOLOR;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,287 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_pbxh24.c
|
||||||
|
|
||||||
|
x lines per page, horizontal, 24 bits per pixel (true color modes)
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
struct _u8g_pb_t
|
||||||
|
{
|
||||||
|
u8g_page_t p;
|
||||||
|
u8g_uint_t width;
|
||||||
|
void *buf;
|
||||||
|
};
|
||||||
|
typedef struct _u8g_pb_t u8g_pb_t;
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
|
||||||
|
u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf};
|
||||||
|
u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn }
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
#define WIDTH_BITS 7
|
||||||
|
#define WIDTH (1<<WIDTH_BITS)
|
||||||
|
#define PAGE_HEIGHT_BITS 3
|
||||||
|
#define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
|
||||||
|
*/
|
||||||
|
|
||||||
|
void u8g_pbxh24_Clear(u8g_pb_t *b)
|
||||||
|
{
|
||||||
|
uint8_t *ptr = (uint8_t *)b->buf;
|
||||||
|
uint8_t *end_ptr = ptr;
|
||||||
|
uint8_t cnt = b->p.page_height;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
end_ptr += b->width*3;
|
||||||
|
cnt--;
|
||||||
|
} while( cnt > 0 );
|
||||||
|
do
|
||||||
|
{
|
||||||
|
*ptr++ = 0;
|
||||||
|
} while( ptr != end_ptr );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void u8g_pbxh24_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
|
||||||
|
{
|
||||||
|
b->buf = buf;
|
||||||
|
b->width = width;
|
||||||
|
u8g_pbxh24_Clear(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef OBSOLETE
|
||||||
|
static void u8g_pbxh24_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
uint16_t tmp;
|
||||||
|
uint8_t *ptr = b->buf;
|
||||||
|
y -= b->p.page_y0;
|
||||||
|
tmp = y;
|
||||||
|
tmp *= b->width;
|
||||||
|
tmp += x;
|
||||||
|
tmp *= 3;
|
||||||
|
ptr += tmp;
|
||||||
|
*ptr = r;
|
||||||
|
ptr++;
|
||||||
|
*ptr = g;
|
||||||
|
ptr++;
|
||||||
|
*ptr = b;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
intensity
|
||||||
|
0..3 intensity value
|
||||||
|
4 replace color
|
||||||
|
*/
|
||||||
|
static void u8g_pbxh24_set_tpixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t red, uint8_t green, uint8_t blue, uint8_t intensity)
|
||||||
|
{
|
||||||
|
uint16_t tmp;
|
||||||
|
uint8_t *ptr = b->buf;
|
||||||
|
|
||||||
|
if ( intensity == 0 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
y -= b->p.page_y0;
|
||||||
|
tmp = y;
|
||||||
|
tmp *= b->width;
|
||||||
|
tmp += x;
|
||||||
|
tmp *= 3;
|
||||||
|
ptr += tmp;
|
||||||
|
|
||||||
|
if ( intensity == 4 )
|
||||||
|
{
|
||||||
|
*ptr = red;
|
||||||
|
ptr++;
|
||||||
|
*ptr = green;
|
||||||
|
ptr++;
|
||||||
|
*ptr = blue;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( intensity == 2 )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
red = red/4 + red/2;
|
||||||
|
green = green/4 + green/2;
|
||||||
|
blue = blue/4 + blue/2;
|
||||||
|
*/
|
||||||
|
red >>= 1;
|
||||||
|
green >>= 1;
|
||||||
|
blue >>= 1;
|
||||||
|
}
|
||||||
|
else if ( intensity == 1 )
|
||||||
|
{
|
||||||
|
red >>= 2;
|
||||||
|
green >>= 2;
|
||||||
|
blue >>= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( *ptr >= 255-red ) *ptr = 255;
|
||||||
|
else *ptr += red;
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
if ( *ptr >= 255-green ) *ptr = 255;
|
||||||
|
else *ptr += green;
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
if ( *ptr >= 255-blue ) *ptr = 255;
|
||||||
|
else *ptr += blue;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if ( *ptr < red ) *ptr = red;
|
||||||
|
ptr++;
|
||||||
|
if ( *ptr < green ) *ptr = green;
|
||||||
|
ptr++;
|
||||||
|
if ( *ptr < blue ) *ptr = blue;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void u8g_pbxh24_SetTPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel, uint8_t intensity)
|
||||||
|
{
|
||||||
|
if ( arg_pixel->y < b->p.page_y0 )
|
||||||
|
return;
|
||||||
|
if ( arg_pixel->y > b->p.page_y1 )
|
||||||
|
return;
|
||||||
|
if ( arg_pixel->x >= b->width )
|
||||||
|
return;
|
||||||
|
u8g_pbxh24_set_tpixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color, arg_pixel->blue, intensity);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void u8g_pbxh24_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
|
||||||
|
{
|
||||||
|
register uint8_t pixel = arg_pixel->pixel;
|
||||||
|
u8g_uint_t dx = 0;
|
||||||
|
u8g_uint_t dy = 0;
|
||||||
|
|
||||||
|
switch( arg_pixel->dir )
|
||||||
|
{
|
||||||
|
case 0: dx++; break;
|
||||||
|
case 1: dy++; break;
|
||||||
|
case 2: dx--; break;
|
||||||
|
case 3: dy--; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if ( pixel & 128 )
|
||||||
|
u8g_pbxh24_SetTPixel(b, arg_pixel, 4);
|
||||||
|
arg_pixel->x += dx;
|
||||||
|
arg_pixel->y += dy;
|
||||||
|
pixel <<= 1;
|
||||||
|
} while( pixel != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void u8g_pbxh24_Set4TPixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
|
||||||
|
{
|
||||||
|
register uint8_t pixel = arg_pixel->pixel;
|
||||||
|
u8g_uint_t dx = 0;
|
||||||
|
u8g_uint_t dy = 0;
|
||||||
|
|
||||||
|
switch( arg_pixel->dir )
|
||||||
|
{
|
||||||
|
case 0: dx++; break;
|
||||||
|
case 1: dy++; break;
|
||||||
|
case 2: dx--; break;
|
||||||
|
case 3: dy--; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
u8g_pbxh24_SetTPixel(b, arg_pixel, pixel >> 6);
|
||||||
|
arg_pixel->x += dx;
|
||||||
|
arg_pixel->y += dy;
|
||||||
|
pixel <<= 2;
|
||||||
|
} while( pixel != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t u8g_dev_pbxh24_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
|
||||||
|
{
|
||||||
|
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
|
||||||
|
switch(msg)
|
||||||
|
{
|
||||||
|
case U8G_DEV_MSG_SET_8PIXEL:
|
||||||
|
if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
|
||||||
|
u8g_pbxh24_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_SET_PIXEL:
|
||||||
|
u8g_pbxh24_SetTPixel(pb, (u8g_dev_arg_pixel_t *)arg, 4);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_SET_4TPIXEL:
|
||||||
|
u8g_pbxh24_Set4TPixel(pb, (u8g_dev_arg_pixel_t *)arg);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_SET_TPIXEL:
|
||||||
|
u8g_pbxh24_SetTPixel(pb, (u8g_dev_arg_pixel_t *)arg, ((u8g_dev_arg_pixel_t *)arg)->pixel&3);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_INIT:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_STOP:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_FIRST:
|
||||||
|
u8g_pbxh24_Clear(pb);
|
||||||
|
u8g_page_First(&(pb->p));
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_PAGE_NEXT:
|
||||||
|
if ( u8g_page_Next(&(pb->p)) == 0 )
|
||||||
|
return 0;
|
||||||
|
u8g_pbxh24_Clear(pb);
|
||||||
|
break;
|
||||||
|
#ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
|
||||||
|
case U8G_DEV_MSG_IS_BBX_INTERSECTION:
|
||||||
|
return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
|
||||||
|
#endif
|
||||||
|
case U8G_DEV_MSG_GET_PAGE_BOX:
|
||||||
|
u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_GET_WIDTH:
|
||||||
|
*((u8g_uint_t *)arg) = pb->width;
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_GET_HEIGHT:
|
||||||
|
*((u8g_uint_t *)arg) = pb->p.total_height;
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_SET_COLOR_ENTRY:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_SET_XY_CB:
|
||||||
|
break;
|
||||||
|
case U8G_DEV_MSG_GET_MODE:
|
||||||
|
return U8G_MODE_TRUECOLOR;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,334 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
u8g_polygon.c
|
||||||
|
|
||||||
|
Implementation of a polygon draw algorithm for "convex" polygons.
|
||||||
|
|
||||||
|
Universal 8bit Graphics Library
|
||||||
|
|
||||||
|
Copyright (c) 2013, olikraus@gmail.com
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
See also:
|
||||||
|
http://www.angelfire.com/linux/myp/ConvexPolRas/ConvexPolRas.html
|
||||||
|
Computer Graphics, Principles and Practice, Foley, van Dam, Feiner, Hughes (pp 92)
|
||||||
|
Michael Abrash's Graphics Programming Black Book, Special Edition (Chapter 38 and 39)
|
||||||
|
|
||||||
|
Optimized for embedded systems
|
||||||
|
- static memory usage only
|
||||||
|
- consistent data types
|
||||||
|
- low flash ROM consumption
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "u8g.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*===========================================*/
|
||||||
|
/* procedures, which should not be inlined (save as much flash ROM as possible */
|
||||||
|
|
||||||
|
static uint8_t pge_Next(struct pg_edge_struct *pge) PG_NOINLINE;
|
||||||
|
static uint8_t pg_inc(pg_struct *pg, uint8_t i) PG_NOINLINE;
|
||||||
|
static uint8_t pg_dec(pg_struct *pg, uint8_t i) PG_NOINLINE;
|
||||||
|
static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx) PG_NOINLINE;
|
||||||
|
static void pg_line_init(pg_struct * const pg, uint8_t pge_index) PG_NOINLINE;
|
||||||
|
|
||||||
|
/*===========================================*/
|
||||||
|
/* line draw algorithm */
|
||||||
|
|
||||||
|
static uint8_t pge_Next(struct pg_edge_struct *pge)
|
||||||
|
{
|
||||||
|
if ( pge->current_y >= pge->max_y )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
pge->current_x += pge->current_x_offset;
|
||||||
|
pge->error += pge->error_offset;
|
||||||
|
if ( pge->error > 0 )
|
||||||
|
{
|
||||||
|
pge->current_x += pge->x_direction;
|
||||||
|
pge->error -= pge->height;
|
||||||
|
}
|
||||||
|
|
||||||
|
pge->current_y++;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* assumes y2 > y1 */
|
||||||
|
static void pge_Init(struct pg_edge_struct *pge, pg_word_t x1, pg_word_t y1, pg_word_t x2, pg_word_t y2)
|
||||||
|
{
|
||||||
|
pg_word_t dx = x2 - x1;
|
||||||
|
pg_word_t width;
|
||||||
|
|
||||||
|
pge->height = y2 - y1;
|
||||||
|
pge->max_y = y2;
|
||||||
|
pge->current_y = y1;
|
||||||
|
pge->current_x = x1;
|
||||||
|
|
||||||
|
if ( dx >= 0 )
|
||||||
|
{
|
||||||
|
pge->x_direction = 1;
|
||||||
|
width = dx;
|
||||||
|
pge->error = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pge->x_direction = -1;
|
||||||
|
width = -dx;
|
||||||
|
pge->error = 1 - pge->height;
|
||||||
|
}
|
||||||
|
|
||||||
|
pge->current_x_offset = dx / pge->height;
|
||||||
|
pge->error_offset = width % pge->height;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*===========================================*/
|
||||||
|
/* convex polygon algorithm */
|
||||||
|
|
||||||
|
static uint8_t pg_inc(pg_struct *pg, uint8_t i)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
if ( i >= pg->cnt )
|
||||||
|
i = 0;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t pg_dec(pg_struct *pg, uint8_t i)
|
||||||
|
{
|
||||||
|
i--;
|
||||||
|
if ( i >= pg->cnt )
|
||||||
|
i = pg->cnt-1;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx)
|
||||||
|
{
|
||||||
|
uint8_t i = pg->pge[pge_idx].curr_idx;
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
i = pg->pge[pge_idx].next_idx_fn(pg, i);
|
||||||
|
if ( pg->list[i].y != min_y )
|
||||||
|
break;
|
||||||
|
pg->pge[pge_idx].curr_idx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t pg_prepare(pg_struct *pg)
|
||||||
|
{
|
||||||
|
pg_word_t max_y;
|
||||||
|
pg_word_t min_y;
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
|
/* setup the next index procedures */
|
||||||
|
pg->pge[PG_RIGHT].next_idx_fn = pg_inc;
|
||||||
|
pg->pge[PG_LEFT].next_idx_fn = pg_dec;
|
||||||
|
|
||||||
|
/* search for highest and lowest point */
|
||||||
|
max_y = pg->list[0].y;
|
||||||
|
min_y = pg->list[0].y;
|
||||||
|
pg->pge[PG_LEFT].curr_idx = 0;
|
||||||
|
for( i = 1; i < pg->cnt; i++ )
|
||||||
|
{
|
||||||
|
if ( max_y < pg->list[i].y )
|
||||||
|
{
|
||||||
|
max_y = pg->list[i].y;
|
||||||
|
}
|
||||||
|
if ( min_y > pg->list[i].y )
|
||||||
|
{
|
||||||
|
pg->pge[PG_LEFT].curr_idx = i;
|
||||||
|
min_y = pg->list[i].y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* calculate total number of scan lines */
|
||||||
|
pg->total_scan_line_cnt = max_y;
|
||||||
|
pg->total_scan_line_cnt -= min_y;
|
||||||
|
|
||||||
|
/* exit if polygon height is zero */
|
||||||
|
if ( pg->total_scan_line_cnt == 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* if the minimum y side is flat, try to find the lowest and highest x points */
|
||||||
|
pg->pge[PG_RIGHT].curr_idx = pg->pge[PG_LEFT].curr_idx;
|
||||||
|
pg_expand_min_y(pg, min_y, PG_RIGHT);
|
||||||
|
pg_expand_min_y(pg, min_y, PG_LEFT);
|
||||||
|
|
||||||
|
/* check if the min side is really flat (depends on the x values) */
|
||||||
|
pg->is_min_y_not_flat = 1;
|
||||||
|
if ( pg->list[pg->pge[PG_LEFT].curr_idx].x != pg->list[pg->pge[PG_RIGHT].curr_idx].x )
|
||||||
|
{
|
||||||
|
pg->is_min_y_not_flat = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pg->total_scan_line_cnt--;
|
||||||
|
if ( pg->total_scan_line_cnt == 0 )
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pg_hline(pg_struct *pg, u8g_t *u8g)
|
||||||
|
{
|
||||||
|
pg_word_t x1, x2, y;
|
||||||
|
x1 = pg->pge[PG_LEFT].current_x;
|
||||||
|
x2 = pg->pge[PG_RIGHT].current_x;
|
||||||
|
y = pg->pge[PG_RIGHT].current_y;
|
||||||
|
|
||||||
|
if ( y < 0 )
|
||||||
|
return;
|
||||||
|
if ( y >= u8g_GetHeight(u8g) )
|
||||||
|
return;
|
||||||
|
if ( x1 < x2 )
|
||||||
|
{
|
||||||
|
if ( x2 < 0 )
|
||||||
|
return;
|
||||||
|
if ( x1 >= u8g_GetWidth(u8g) )
|
||||||
|
return;
|
||||||
|
if ( x1 < 0 )
|
||||||
|
x1 = 0;
|
||||||
|
if ( x2 >= u8g_GetWidth(u8g) )
|
||||||
|
x2 = u8g_GetWidth(u8g);
|
||||||
|
u8g_DrawHLine(u8g, x1, y, x2 - x1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( x1 < 0 )
|
||||||
|
return;
|
||||||
|
if ( x2 >= u8g_GetWidth(u8g) )
|
||||||
|
return;
|
||||||
|
if ( x2 < 0 )
|
||||||
|
x1 = 0;
|
||||||
|
if ( x1 >= u8g_GetWidth(u8g) )
|
||||||
|
x1 = u8g_GetWidth(u8g);
|
||||||
|
u8g_DrawHLine(u8g, x2, y, x1 - x2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pg_line_init(pg_struct * pg, uint8_t pge_index)
|
||||||
|
{
|
||||||
|
struct pg_edge_struct *pge = pg->pge+pge_index;
|
||||||
|
uint8_t idx;
|
||||||
|
pg_word_t x1;
|
||||||
|
pg_word_t y1;
|
||||||
|
pg_word_t x2;
|
||||||
|
pg_word_t y2;
|
||||||
|
|
||||||
|
idx = pge->curr_idx;
|
||||||
|
y1 = pg->list[idx].y;
|
||||||
|
x1 = pg->list[idx].x;
|
||||||
|
idx = pge->next_idx_fn(pg, idx);
|
||||||
|
y2 = pg->list[idx].y;
|
||||||
|
x2 = pg->list[idx].x;
|
||||||
|
pge->curr_idx = idx;
|
||||||
|
|
||||||
|
pge_Init(pge, x1, y1, x2, y2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pg_exec(pg_struct *pg, u8g_t *u8g)
|
||||||
|
{
|
||||||
|
pg_word_t i = pg->total_scan_line_cnt;
|
||||||
|
|
||||||
|
/* first line is skipped if the min y line is not flat */
|
||||||
|
pg_line_init(pg, PG_LEFT);
|
||||||
|
pg_line_init(pg, PG_RIGHT);
|
||||||
|
|
||||||
|
if ( pg->is_min_y_not_flat != 0 )
|
||||||
|
{
|
||||||
|
pge_Next(&(pg->pge[PG_LEFT]));
|
||||||
|
pge_Next(&(pg->pge[PG_RIGHT]));
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
pg_hline(pg, u8g);
|
||||||
|
while ( pge_Next(&(pg->pge[PG_LEFT])) == 0 )
|
||||||
|
{
|
||||||
|
pg_line_init(pg, PG_LEFT);
|
||||||
|
}
|
||||||
|
while ( pge_Next(&(pg->pge[PG_RIGHT])) == 0 )
|
||||||
|
{
|
||||||
|
pg_line_init(pg, PG_RIGHT);
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
} while( i > 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*===========================================*/
|
||||||
|
/* API procedures */
|
||||||
|
|
||||||
|
void pg_ClearPolygonXY(pg_struct *pg)
|
||||||
|
{
|
||||||
|
pg->cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pg_AddPolygonXY(pg_struct *pg, u8g_t *u8g, int16_t x, int16_t y)
|
||||||
|
{
|
||||||
|
if ( pg->cnt < PG_MAX_POINTS )
|
||||||
|
{
|
||||||
|
pg->list[pg->cnt].x = x;
|
||||||
|
pg->list[pg->cnt].y = y;
|
||||||
|
pg->cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pg_DrawPolygon(pg_struct *pg, u8g_t *u8g)
|
||||||
|
{
|
||||||
|
if ( pg_prepare(pg) == 0 )
|
||||||
|
return;
|
||||||
|
pg_exec(pg, u8g);
|
||||||
|
}
|
||||||
|
|
||||||
|
pg_struct u8g_pg;
|
||||||
|
|
||||||
|
void u8g_ClearPolygonXY(void)
|
||||||
|
{
|
||||||
|
pg_ClearPolygonXY(&u8g_pg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void u8g_AddPolygonXY(u8g_t *u8g, int16_t x, int16_t y)
|
||||||
|
{
|
||||||
|
pg_AddPolygonXY(&u8g_pg, u8g, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void u8g_DrawPolygon(u8g_t *u8g)
|
||||||
|
{
|
||||||
|
pg_DrawPolygon(&u8g_pg, u8g);
|
||||||
|
}
|
||||||
|
|
||||||
|
void u8g_DrawTriangle(u8g_t *u8g, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2)
|
||||||
|
{
|
||||||
|
u8g_ClearPolygonXY();
|
||||||
|
u8g_AddPolygonXY(u8g, x0, y0);
|
||||||
|
u8g_AddPolygonXY(u8g, x1, y1);
|
||||||
|
u8g_AddPolygonXY(u8g, x2, y2);
|
||||||
|
u8g_DrawPolygon(u8g);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue