From a802f8fb17ad0f4c98b0fa9f12880759a9710804 Mon Sep 17 00:00:00 2001 From: olikraus Date: Tue, 8 Dec 2015 21:30:14 +0100 Subject: [PATCH] towards arduino support --- cppsrc/U8x8lib.cpp | 149 ++++++++++++++++++++++++++++++ csrc/u8x8.h | 29 +++++- doc/device_matrix.txt | 18 ++++ doc/u8g2.txt | 1 + sys/arduino/ssd1306_test/test.ino | 87 ++++++++--------- 5 files changed, 236 insertions(+), 48 deletions(-) create mode 100644 doc/device_matrix.txt diff --git a/cppsrc/U8x8lib.cpp b/cppsrc/U8x8lib.cpp index 139597f9..b1ccbca0 100644 --- a/cppsrc/U8x8lib.cpp +++ b/cppsrc/U8x8lib.cpp @@ -1,2 +1,151 @@ + +/* + use U8X8_PIN_NONE as value for "reset", if there is no reset line +*/ +void u8x8_Setup_4Wire_SW_SPI(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clock, uint8_t data, uint8_t cs, uint8_t dc, uint8_t reset) +{ + /* setup defaults and reset pins to U8X8_PIN_NONE */ + u8x8_SetupDefaults(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_SPI_CLOCK, clock); + u8x8_SetPin(u8x8, U8X8_PIN_SPI_DATA, data); + u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); + u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); + + /* setup specific callbacks */ + u8x8->display_cb = display_cb; + u8x8->cad_cb = u8x8_cad_001; + u8x8->byte_cb = u8x8_byte_4wire_sw_spi; + u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; + + /* setup display info */ + u8x8_SetupMemory(u8x8); +} + + +void u8x8_Setup_3Wire_SW_SPI(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clock, uint8_t data, uint8_t cs, uint8_t reset) +{ + /* setup defaults and reset pins to U8X8_PIN_NONE */ + u8x8_SetupDefaults(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_SPI_CLOCK, clock); + u8x8_SetPin(u8x8, U8X8_PIN_SPI_DATA, data); + u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); + + /* setup specific callbacks */ + u8x8->display_cb = display_cb; + u8x8->cad_cb = u8x8_cad_001; + u8x8->byte_cb = u8x8_byte_3wire_sw_spi; + u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; + + /* setup display info */ + u8x8_SetupMemory(u8x8); +} + +/* + use U8X8_PIN_NONE as value for "reset", if there is no reset line +*/ +void u8x8_Setup_4Wire_HW_SPI(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t cs, uint8_t dc, uint8_t reset) +{ + /* setup defaults and reset pins to U8X8_PIN_NONE */ + u8x8_SetupDefaults(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); + u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); + + /* setup specific callbacks */ + u8x8->display_cb = display_cb; + u8x8->cad_cb = u8x8_cad_001; + u8x8->byte_cb = u8x8_byte_arduino_hw_spi; + u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; + + /* setup display info */ + u8x8_SetupMemory(u8x8); +} + +void u8x8_Setup_SSD13xx_SW_I2C(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clock, uint8_t data, uint8_t reset) +{ + /* setup defaults and reset pins to U8X8_PIN_NONE */ + u8x8_SetupDefaults(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_I2C_CLOCK, clock); + u8x8_SetPin(u8x8, U8X8_PIN_I2C_DATA, data); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); + + /* setup specific callbacks */ + u8x8->display_cb = display_cb; + u8x8->cad_cb = u8x8_cad_001; + u8x8->byte_cb = u8x8_byte_ssd13xx_sw_i2c; + u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; + + /* setup display info */ + u8x8_SetupMemory(u8x8); +} + +void u8x8_Setup_8Bit_6800(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t enable, uint8_t cs, uint8_t dc, uint8_t reset) +{ + /* setup defaults and reset pins to U8X8_PIN_NONE */ + u8x8_SetupDefaults(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_D0, d0); + u8x8_SetPin(u8x8, U8X8_PIN_D1, d1); + u8x8_SetPin(u8x8, U8X8_PIN_D2, d2); + u8x8_SetPin(u8x8, U8X8_PIN_D3, d3); + u8x8_SetPin(u8x8, U8X8_PIN_D4, d4); + u8x8_SetPin(u8x8, U8X8_PIN_D5, d5); + u8x8_SetPin(u8x8, U8X8_PIN_D6, d6); + u8x8_SetPin(u8x8, U8X8_PIN_D7, d7); + u8x8_SetPin(u8x8, U8X8_PIN_E, enable); + u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); + u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); + + /* setup specific callbacks */ + u8x8->display_cb = display_cb; + u8x8->cad_cb = u8x8_cad_001; + u8x8->byte_cb = u8x8_byte_8bit_6800mode; + u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; + + /* setup display info */ + u8x8_SetupMemory(u8x8); +} + +void u8x8_Setup_8Bit_8080(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t wr, uint8_t cs, uint8_t dc, uint8_t reset) +{ + /* setup defaults and reset pins to U8X8_PIN_NONE */ + u8x8_SetupDefaults(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_D0, d0); + u8x8_SetPin(u8x8, U8X8_PIN_D1, d1); + u8x8_SetPin(u8x8, U8X8_PIN_D2, d2); + u8x8_SetPin(u8x8, U8X8_PIN_D3, d3); + u8x8_SetPin(u8x8, U8X8_PIN_D4, d4); + u8x8_SetPin(u8x8, U8X8_PIN_D5, d5); + u8x8_SetPin(u8x8, U8X8_PIN_D6, d6); + u8x8_SetPin(u8x8, U8X8_PIN_D7, d7); + u8x8_SetPin(u8x8, U8X8_PIN_E, wr); + u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); + u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); + + /* setup specific callbacks */ + u8x8->display_cb = display_cb; + u8x8->cad_cb = u8x8_cad_001; + u8x8->byte_cb = u8x8_byte_8bit_8080mode; + u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; + + /* setup display info */ + u8x8_SetupMemory(u8x8); +} + diff --git a/csrc/u8x8.h b/csrc/u8x8.h index 05777a45..3e34f40c 100644 --- a/csrc/u8x8.h +++ b/csrc/u8x8.h @@ -327,12 +327,34 @@ void u8x8_d_helper_display_init(u8x8_t *u8g2); /* arg_ptr: layout struct */ //#define U8X8_MSG_DISPLAY_GET_LAYOUT 16 + +/*==========================================*/ +/* u8x8_setup.c */ + +/* + Setup u8x8 object itself. This should be the very first function + called on the new u8x8 object. After this call, assign the callback + functions. Optional: Set the pins +*/ + +void u8x8_SetupDefaults(u8x8_t *u8x8); + +/*==========================================*/ /* u8x8_display.c */ uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr); -/* setup u8x8 memory structures */ +/* + After a call to u8x8_SetupDefaults, + setup u8x8 memory structures & inform callbacks +*/ void u8x8_SetupMemory(u8x8_t *u8x8); -/* Init display, but keep display in power save mode. Usually this command must be followed by u8x8_SetPowerSave() */ + +/* + After calling u8x8_SetupMemory(), init the display hardware itself. + This will will the first time, u8x8 talks to the display. + It will init the display, but keep display in power save mode. + Usually this command must be followed by u8x8_SetPowerSave() +*/ void u8x8_InitDisplay(u8x8_t *u8x8); /* wake up display from power save mode */ void u8x8_SetPowerSave(u8x8_t *u8x8, uint8_t is_enable); @@ -499,9 +521,6 @@ void u8x8_gpio_call(u8x8_t *u8x8, uint8_t msg, uint8_t arg) U8X8_NOINLINE; //void u8x8_gpio_Delay(u8x8_t *u8x8, uint8_t msg, uint8_t dly) U8X8_NOINLINE; -/*==========================================*/ -/* u8x8_setup.c */ -void u8x8_SetupDefaults(u8x8_t *u8x8); /*==========================================*/ diff --git a/doc/device_matrix.txt b/doc/device_matrix.txt new file mode 100644 index 00000000..320a01bd --- /dev/null +++ b/doc/device_matrix.txt @@ -0,0 +1,18 @@ +3=3 wire SPI +4=4 wire SPI +2=I2C +6=6800 8 bit parallel +8=8080 8 bit parallel + +s=Arduino Standard Software Communication + pinMode and digitalWrite are used for communication +o=Arduino Optimized Software Communication + uC Specific low level functions for digital write and read +h=Hardware Communication with Standard Libs + TWI and SPI library +H=uC specific hardware communication + + +SSD1306 128x64 + Arduino with ATMega328 (e.g. Uno) s2s3s4s6s8 h2h4 + Arduino with AT91SAM3X8E (Due) s2s3s4s6s8 h2h4 \ No newline at end of file diff --git a/doc/u8g2.txt b/doc/u8g2.txt index bf7b6519..2e013da0 100644 --- a/doc/u8g2.txt +++ b/doc/u8g2.txt @@ -3,6 +3,7 @@ U8glib V2: Features and Limitations - Arduino Standard Libs - Full Memory Buffer +- 3-wire-SPI - Unicode Support Unicode plane 0 (Basic Multilingual Plane, BMP, glyphs with 0x0000-0xffff) diff --git a/sys/arduino/ssd1306_test/test.ino b/sys/arduino/ssd1306_test/test.ino index 9030934d..4e702bb2 100644 --- a/sys/arduino/ssd1306_test/test.ino +++ b/sys/arduino/ssd1306_test/test.ino @@ -155,13 +155,6 @@ void u8x8_Setup_4Wire_SW_SPI(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clock { /* setup defaults and reset pins to U8X8_PIN_NONE */ u8x8_SetupDefaults(u8x8); - - /* assign individual pin values (only for ARDUINO, if pin_list is available) */ - u8x8_SetPin(u8x8, U8X8_PIN_SPI_CLOCK, clock); - u8x8_SetPin(u8x8, U8X8_PIN_SPI_DATA, data); - u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); - u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); - u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); /* setup specific callbacks */ u8x8->display_cb = display_cb; @@ -171,6 +164,13 @@ void u8x8_Setup_4Wire_SW_SPI(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clock /* setup display info */ u8x8_SetupMemory(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_SPI_CLOCK, clock); + u8x8_SetPin(u8x8, U8X8_PIN_SPI_DATA, data); + u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); + u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); } @@ -179,12 +179,6 @@ void u8x8_Setup_3Wire_SW_SPI(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clock /* setup defaults and reset pins to U8X8_PIN_NONE */ u8x8_SetupDefaults(u8x8); - /* assign individual pin values (only for ARDUINO, if pin_list is available) */ - u8x8_SetPin(u8x8, U8X8_PIN_SPI_CLOCK, clock); - u8x8_SetPin(u8x8, U8X8_PIN_SPI_DATA, data); - u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); - u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); - /* setup specific callbacks */ u8x8->display_cb = display_cb; u8x8->cad_cb = u8x8_cad_001; @@ -193,6 +187,12 @@ void u8x8_Setup_3Wire_SW_SPI(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clock /* setup display info */ u8x8_SetupMemory(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_SPI_CLOCK, clock); + u8x8_SetPin(u8x8, U8X8_PIN_SPI_DATA, data); + u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); } /* @@ -202,11 +202,6 @@ void u8x8_Setup_4Wire_HW_SPI(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t cs, u { /* setup defaults and reset pins to U8X8_PIN_NONE */ u8x8_SetupDefaults(u8x8); - - /* assign individual pin values (only for ARDUINO, if pin_list is available) */ - u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); - u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); - u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); /* setup specific callbacks */ u8x8->display_cb = display_cb; @@ -216,6 +211,11 @@ void u8x8_Setup_4Wire_HW_SPI(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t cs, u /* setup display info */ u8x8_SetupMemory(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); + u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); } void u8x8_Setup_SSD13xx_SW_I2C(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clock, uint8_t data, uint8_t reset) @@ -223,11 +223,6 @@ void u8x8_Setup_SSD13xx_SW_I2C(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clo /* setup defaults and reset pins to U8X8_PIN_NONE */ u8x8_SetupDefaults(u8x8); - /* assign individual pin values (only for ARDUINO, if pin_list is available) */ - u8x8_SetPin(u8x8, U8X8_PIN_I2C_CLOCK, clock); - u8x8_SetPin(u8x8, U8X8_PIN_I2C_DATA, data); - u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); - /* setup specific callbacks */ u8x8->display_cb = display_cb; u8x8->cad_cb = u8x8_cad_001; @@ -236,12 +231,27 @@ void u8x8_Setup_SSD13xx_SW_I2C(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t clo /* setup display info */ u8x8_SetupMemory(u8x8); + + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ + u8x8_SetPin(u8x8, U8X8_PIN_I2C_CLOCK, clock); + u8x8_SetPin(u8x8, U8X8_PIN_I2C_DATA, data); + u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); + } void u8x8_Setup_8Bit_6800(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t enable, uint8_t cs, uint8_t dc, uint8_t reset) { /* setup defaults and reset pins to U8X8_PIN_NONE */ u8x8_SetupDefaults(u8x8); + + /* setup specific callbacks */ + u8x8->display_cb = display_cb; + u8x8->cad_cb = u8x8_cad_001; + u8x8->byte_cb = u8x8_byte_8bit_6800mode; + u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; + + /* setup display info */ + u8x8_SetupMemory(u8x8); /* assign individual pin values (only for ARDUINO, if pin_list is available) */ u8x8_SetPin(u8x8, U8X8_PIN_D0, d0); @@ -256,15 +266,6 @@ void u8x8_Setup_8Bit_6800(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t d0, uint u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); - - /* setup specific callbacks */ - u8x8->display_cb = display_cb; - u8x8->cad_cb = u8x8_cad_001; - u8x8->byte_cb = u8x8_byte_8bit_6800mode; - u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; - - /* setup display info */ - u8x8_SetupMemory(u8x8); } void u8x8_Setup_8Bit_8080(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t wr, uint8_t cs, uint8_t dc, uint8_t reset) @@ -272,6 +273,15 @@ void u8x8_Setup_8Bit_8080(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t d0, uint /* setup defaults and reset pins to U8X8_PIN_NONE */ u8x8_SetupDefaults(u8x8); + /* setup specific callbacks */ + u8x8->display_cb = display_cb; + u8x8->cad_cb = u8x8_cad_001; + u8x8->byte_cb = u8x8_byte_8bit_8080mode; + u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; + + /* setup display info */ + u8x8_SetupMemory(u8x8); + /* assign individual pin values (only for ARDUINO, if pin_list is available) */ u8x8_SetPin(u8x8, U8X8_PIN_D0, d0); u8x8_SetPin(u8x8, U8X8_PIN_D1, d1); @@ -285,15 +295,6 @@ void u8x8_Setup_8Bit_8080(u8x8_t *u8x8, u8x8_msg_cb display_cb, uint8_t d0, uint u8x8_SetPin(u8x8, U8X8_PIN_CS, cs); u8x8_SetPin(u8x8, U8X8_PIN_DC, dc); u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset); - - /* setup specific callbacks */ - u8x8->display_cb = display_cb; - u8x8->cad_cb = u8x8_cad_001; - u8x8->byte_cb = u8x8_byte_8bit_8080mode; - u8x8->gpio_and_delay_cb = u8x8_gpio_and_delay_arduino; - - /* setup display info */ - u8x8_SetupMemory(u8x8); } @@ -318,8 +319,8 @@ void setup(void) //u8x8_Setup_4Wire_HW_SPI(&u8x8, u8x8_d_ssd1306_128x64_noname, 10, 9, 8); //u8x8_Setup_SSD13xx_SW_I2C(&u8x8, u8x8_d_ssd1306_128x64_noname, 13, 11, 8); - //u8x8_Setup_8Bit_6800(&u8x8, u8x8_d_ssd1306_128x64_noname, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); - u8x8_Setup_8Bit_8080(&u8x8, u8x8_d_ssd1306_128x64_noname, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); + u8x8_Setup_8Bit_6800(&u8x8, u8x8_d_ssd1306_128x64_noname, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); + //u8x8_Setup_8Bit_8080(&u8x8, u8x8_d_ssd1306_128x64_noname, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //u8x8_Setup_SW_4Wire_SPI(&u8x8, u8x8_d_uc1701_dogs102, 13, 11, 10, 9, 8); //u8x8_Setup_HW_4Wire_SPI(&u8x8, u8x8_d_uc1701_dogs102, 10, 9, 8);