Skip to content

Commit

Permalink
sck_takeover_edge -> sck_clock_mode to account for all four SPI modes.
Browse files Browse the repository at this point in the history
  • Loading branch information
basilfx committed Jul 25, 2016
1 parent 0213db2 commit 54e3c1a
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 36 deletions.
6 changes: 3 additions & 3 deletions cppsrc/U8x8lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ extern "C" uint8_t u8x8_byte_arduino_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uin
{
uint8_t i, b;
uint8_t *data;
uint8_t takeover_edge = u8x8->display_info->sck_takeover_edge;
uint8_t takeover_edge = u8x8_GetSckTakeoverEdge(u8x8);
uint8_t not_takeover_edge = 1 - takeover_edge;

/* the following static vars are recalculated in U8X8_MSG_BYTE_START_TRANSFER */
Expand Down Expand Up @@ -213,7 +213,7 @@ extern "C" uint8_t u8x8_byte_arduino_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uin
/* no wait required here */

/* for SPI: setup correct level of the clock signal */
u8x8_gpio_SetSPIClock(u8x8, u8x8->display_info->sck_takeover_edge);
u8x8_gpio_SetSPIClock(u8x8, u8x8_GetSckTakeoverEdge(u8x8));
break;
case U8X8_MSG_BYTE_SET_DC:
u8x8_gpio_SetDC(u8x8, arg_int);
Expand Down Expand Up @@ -282,7 +282,7 @@ extern "C" uint8_t u8x8_byte_arduino_hw_spi(u8x8_t *u8g2, uint8_t msg, uint8_t a
/* for SPI: setup correct level of the clock signal */
pinMode(11, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(13, u8g2->display_info->sck_takeover_edge);
digitalWrite(13, u8x8_GetSckTakeoverEdge(u8g2_GetU8x8(u8g2)));
break;

case U8X8_MSG_BYTE_SET_DC:
Expand Down
14 changes: 9 additions & 5 deletions csrc/u8x8.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,13 @@ struct u8x8_display_info_struct
/* AVR: below 70: DIV2, 8 MHz, >= 70 --> 4MHz clock (DIV4) */
uint8_t sck_pulse_width_ns; /* UC1701: 50ns */

/* data takeover edge: 0=falling edge, 1=rising edge*/
/* initial default value for sck is low (0) for falling edge and high for rising edge */
/* this means, default value is identical to sck_takeover_edge */
uint8_t sck_takeover_edge; /* UC1601: rising edge (1) */
/* SPI has four clock modes: */
/* 0: clock active high, data out on falling edge */
/* 1: clock active high, data out on rising edge */
/* 2: clock active low, data out on rising edge */
/* 3: clock active low, data out on falling edge */
/* most displays have clock mode 1 */
uint8_t sck_clock_mode;

/* == I2C == */
uint8_t i2c_bus_clock_100kHz; /* UC1601: 1000000000/275 = 37 *100k */
Expand Down Expand Up @@ -314,7 +317,8 @@ struct u8x8_struct
#define u8x8_GetRows(u8x8) ((u8x8)->display_info->tile_height)
#define u8x8_GetI2CAddress(u8x8) ((u8x8)->i2c_address)
#define u8x8_SetGPIOResult(u8x8, val) ((u8x8)->gpio_result = (val))

#define u8x8_GetSckTakeoverEdge(u8x8) ((u8x8)->display_info->sck_clock_mode & 0x01)
#define u8x8_GetSckPolarity(u8x8) (((u8x8)->display_info->sck_clock_mode & 0x10) >> 1)


#ifdef U8X8_USE_PINS
Expand Down
14 changes: 7 additions & 7 deletions csrc/u8x8_byte.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ uint8_t u8x8_byte_EndTransfer(u8x8_t *u8x8)
Uses:
u8x8->display_info->sda_setup_time_ns
u8x8->display_info->sck_pulse_width_ns
u8x8->display_info->sck_takeover_edge
u8x8->display_info->sck_clock_mode
u8x8->display_info->chip_disable_level
u8x8->display_info->chip_enable_level
u8x8->display_info->post_chip_enable_wait_ns
Expand All @@ -89,7 +89,7 @@ uint8_t u8x8_byte_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
{
uint8_t i, b;
uint8_t *data;
uint8_t takeover_edge = u8x8->display_info->sck_takeover_edge;
uint8_t takeover_edge = u8x8_GetSckTakeoverEdge(u8x8);
uint8_t not_takeover_edge = 1 - takeover_edge;

switch(msg)
Expand Down Expand Up @@ -123,7 +123,7 @@ uint8_t u8x8_byte_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
/* no wait required here */

/* for SPI: setup correct level of the clock signal */
u8x8_gpio_SetSPIClock(u8x8, u8x8->display_info->sck_takeover_edge);
u8x8_gpio_SetSPIClock(u8x8, u8x8_GetSckTakeoverEdge(u8x8));
break;
case U8X8_MSG_BYTE_SET_DC:
u8x8_gpio_SetDC(u8x8, arg_int);
Expand Down Expand Up @@ -250,7 +250,7 @@ uint8_t u8x8_byte_3wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
{
uint8_t i;
uint8_t *data;
uint8_t takeover_edge = u8x8->display_info->sck_takeover_edge;
uint8_t takeover_edge = u8x8_GetSckTakeoverEdge(u8x8);
uint8_t not_takeover_edge = 1 - takeover_edge;
uint16_t b;
static uint8_t last_dc;
Expand Down Expand Up @@ -288,7 +288,7 @@ uint8_t u8x8_byte_3wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
/* no wait required here */

/* for SPI: setup correct level of the clock signal */
u8x8_gpio_SetSPIClock(u8x8, u8x8->display_info->sck_takeover_edge);
u8x8_gpio_SetSPIClock(u8x8, u8x8_GetSckTakeoverEdge(u8x8));
break;
case U8X8_MSG_BYTE_SET_DC:
last_dc = arg_int;
Expand All @@ -314,7 +314,7 @@ uint8_t u8x8_byte_3wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
static void u8x8_byte_st7920_send_byte(u8x8_t *u8x8, uint8_t b) U8X8_NOINLINE;
static void u8x8_byte_st7920_send_byte(u8x8_t *u8x8, uint8_t b)
{
uint8_t takeover_edge = u8x8->display_info->sck_takeover_edge;
uint8_t takeover_edge = u8x8_GetSckTakeoverEdge(u8x8);
uint8_t not_takeover_edge = 1 - takeover_edge;
uint8_t cnt;

Expand Down Expand Up @@ -376,7 +376,7 @@ uint8_t u8x8_byte_st7920_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
/* no wait required here */

/* for SPI: setup correct level of the clock signal */
u8x8_gpio_SetSPIClock(u8x8, u8x8->display_info->sck_takeover_edge);
u8x8_gpio_SetSPIClock(u8x8, u8x8_GetSckTakeoverEdge(u8x8));
break;
case U8X8_MSG_BYTE_SET_DC:
last_dc = arg_int;
Expand Down
2 changes: 1 addition & 1 deletion csrc/u8x8_d_ld7032_60x32.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static const u8x8_display_info_t u8x8_ld7032_60x32_display_info =
/* post_reset_wait_ms = */ 100,
/* sda_setup_time_ns = */ 30, /* 20ns, but cycle time is 60ns, so use 60/2 */
/* sck_pulse_width_ns = */ 30, /* 20ns, but cycle time is 60ns, so use 60/2 */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 20,
/* write_pulse_width_ns = */ 40,
Expand Down
2 changes: 1 addition & 1 deletion csrc/u8x8_d_ls013b7dh03.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static const u8x8_display_info_t u8x8_ls013b7dh03_128x128_display_info =
/* post_reset_wait_ms = */ 6,
/* sda_setup_time_ns = */ 227, /* 227 nsec according to the datasheet */
/* sck_pulse_width_ns = */ 255, /* 450 nsec according to the datasheet */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 100,
/* write_pulse_width_ns = */ 100,
Expand Down
2 changes: 1 addition & 1 deletion csrc/u8x8_d_ssd1306_128x32.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static const u8x8_display_info_t u8x8_ssd1306_128x32_univision_display_info =
/* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
/* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
/* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 40,
/* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
Expand Down
4 changes: 2 additions & 2 deletions csrc/u8x8_d_ssd1306_128x64_noname.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static const u8x8_display_info_t u8x8_ssd1306_128x64_noname_display_info =
/* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
/* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
/* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 40,
/* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
Expand Down Expand Up @@ -222,7 +222,7 @@ static const u8x8_display_info_t u8x8_sh1106_128x64_noname_display_info =
/* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
/* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
/* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 40,
/* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
Expand Down
2 changes: 1 addition & 1 deletion csrc/u8x8_d_ssd1322.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static const u8x8_display_info_t u8x8_ssd1322_256x64_display_info =
/* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
/* sda_setup_time_ns = */ 50, /* SSD1322: 15ns, but cycle time is 100ns, so use 100/2 */
/* sck_pulse_width_ns = */ 50, /* SSD1322: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 10,
/* write_pulse_width_ns = */ 150, /* SSD1322: cycle time is 300ns, so use 300/2 = 150 */
Expand Down
4 changes: 2 additions & 2 deletions csrc/u8x8_d_st7565.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static const u8x8_display_info_t u8x8_st7565_128x64_display_info =
/* post_reset_wait_ms = */ 1,
/* sda_setup_time_ns = */ 50, /* st7565 datasheet, table 26, tsds */
/* sck_pulse_width_ns = */ 120, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 40, /* st7565 datasheet, table 24, tds8 */
/* write_pulse_width_ns = */ 80, /* st7565 datasheet, table 24, tcclw */
Expand All @@ -104,7 +104,7 @@ static const u8x8_display_info_t u8x8_st7565_128x32_display_info =
/* post_reset_wait_ms = */ 1,
/* sda_setup_time_ns = */ 50, /* st7565 datasheet, table 26, tsds */
/* sck_pulse_width_ns = */ 120, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 40, /* st7565 datasheet, table 24, tds8 */
/* write_pulse_width_ns = */ 80, /* st7565 datasheet, table 24, tcclw */
Expand Down
4 changes: 2 additions & 2 deletions csrc/u8x8_d_st7920.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static const u8x8_display_info_t u8x8_st7920_192x32_display_info =
/* post_reset_wait_ms = */ 6,
/* sda_setup_time_ns = */ 20,
/* sck_pulse_width_ns = */ 140, /* datasheet ST7920 */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 30,
/* write_pulse_width_ns = */ 40,
Expand All @@ -179,7 +179,7 @@ static const u8x8_display_info_t u8x8_st7920_128x64_display_info =
/* post_reset_wait_ms = */ 6,
/* sda_setup_time_ns = */ 20,
/* sck_pulse_width_ns = */ 140, /* datasheet ST7920 */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 30,
/* write_pulse_width_ns = */ 40,
Expand Down
6 changes: 3 additions & 3 deletions csrc/u8x8_d_t6963.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static const u8x8_display_info_t u8x8_t6963_240x128_display_info =
/* post_reset_wait_ms = */ 6,
/* sda_setup_time_ns = */ 20,
/* sck_pulse_width_ns = */ 140,
/* sck_takeover_edge = */ 1,
/* sck_clock_mode = */ 1,
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 80,
/* write_pulse_width_ns = */ 80,
Expand Down Expand Up @@ -220,7 +220,7 @@ static const u8x8_display_info_t u8x8_t6963_256x64_display_info =
/* post_reset_wait_ms = */ 6,
/* sda_setup_time_ns = */ 20,
/* sck_pulse_width_ns = */ 140,
/* sck_takeover_edge = */ 1,
/* sck_clock_mode = */ 1,
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 80,
/* write_pulse_width_ns = */ 80,
Expand Down Expand Up @@ -302,7 +302,7 @@ static const u8x8_display_info_t u8x8_t6963_128x64_display_info =
/* post_reset_wait_ms = */ 6,
/* sda_setup_time_ns = */ 20,
/* sck_pulse_width_ns = */ 140,
/* sck_takeover_edge = */ 1,
/* sck_clock_mode = */ 1,
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 80,
/* write_pulse_width_ns = */ 80,
Expand Down
2 changes: 1 addition & 1 deletion csrc/u8x8_d_uc1701_dogs102.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static const u8x8_display_info_t u8x8_uc1701_display_info =
/* post_reset_wait_ms = */ 6,
/* sda_setup_time_ns = */ 12,
/* sck_pulse_width_ns = */ 75, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
/* sck_takeover_edge = */ 1, /* rising edge */
/* sck_clock_mode = */ 1, /* active high, rising edge */
/* i2c_bus_clock_100kHz = */ 4,
/* data_setup_time_ns = */ 30,
/* write_pulse_width_ns = */ 40,
Expand Down
2 changes: 1 addition & 1 deletion sys/arduino/test/test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ uint8_t u8x8_byte_arduino_hw_spi(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, voi
/* no wait required here */

/* for SPI: setup correct level of the clock signal */
digitalWrite(13, u8g2->display_info->sck_takeover_edge);
digitalWrite(13, u8x8_GetSckTakeoverEdge(u8g2_GetU8x8(u8g2)));
break;
case U8X8_MSG_BYTE_SET_DC:
u8x8_gpio_SetDC(u8g2, arg_int);
Expand Down
2 changes: 1 addition & 1 deletion sys/arduino/text/text.ino
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ uint8_t u8x8_byte_arduino_hw_spi(u8x8_t *u8g2, uint8_t msg, uint8_t arg_int, voi
/* no wait required here */

/* for SPI: setup correct level of the clock signal */
digitalWrite(13, u8g2->display_info->sck_takeover_edge);
digitalWrite(13, u8x8_GetSckTakeoverEdge(u8g2_GetU8x8(u8g2)));
break;
case U8X8_MSG_BYTE_SET_DC:
u8x8_gpio_SetDC(u8g2, arg_int);
Expand Down
2 changes: 1 addition & 1 deletion sys/sdl/common/u8x8_d_sdl_128x64.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static const u8x8_display_info_t u8x8_sdl_128x64_info =
/* post_reset_wait_ms = */ 0,
/* sda_setup_time_ns = */ 0,
/* sck_pulse_width_ns = */ 0,
/* sck_takeover_edge = */ 1,
/* sck_clock_mode = */ 1,
/* i2c_bus_clock_100kHz = */ 0,
/* data_setup_time_ns = */ 0,
/* write_pulse_width_ns = */ 0,
Expand Down
4 changes: 2 additions & 2 deletions sys/tga/common/u8x8_d_tga.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static const u8x8_display_info_t u8x8_tga_desc_info =
/* post_reset_wait_ms = */ 0,
/* sda_setup_time_ns = */ 0,
/* sck_pulse_width_ns = */ 0,
/* sck_takeover_edge = */ 1,
/* sck_clock_mode = */ 1,
/* i2c_bus_clock_100kHz = */ 0,
/* data_setup_time_ns = */ 0,
/* write_pulse_width_ns = */ 0,
Expand Down Expand Up @@ -306,7 +306,7 @@ static const u8x8_display_info_t u8x8_tga_lcd_info =
/* post_reset_wait_ms = */ 0,
/* sda_setup_time_ns = */ 0,
/* sck_pulse_width_ns = */ 0,
/* sck_takeover_edge = */ 1,
/* sck_clock_mode = */ 1,
/* i2c_bus_clock_100kHz = */ 0,
/* data_setup_time_ns = */ 0,
/* write_pulse_width_ns = */ 0,
Expand Down
2 changes: 1 addition & 1 deletion sys/utf8/common/u8x8_d_utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static const u8x8_display_info_t u8x8_utf8_info =
/* post_reset_wait_ms = */ 0,
/* sda_setup_time_ns = */ 0,
/* sck_pulse_width_ns = */ 0,
/* sck_takeover_edge = */ 1,
/* sck_clock_mode = */ 1,
/* i2c_bus_clock_100kHz = */ 0,
/* data_setup_time_ns = */ 0,
/* write_pulse_width_ns = */ 0,
Expand Down
2 changes: 1 addition & 1 deletion tools/font/build/u8g2_d_tga.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static const u8x8_display_info_t u8x8_tga_info =
/* post_reset_wait_ms = */ 0,
/* sda_setup_time_ns = */ 0,
/* sck_pulse_width_ns = */ 0,
/* sck_takeover_edge = */ 1,
/* sck_clock_mode = */ 1,
/* i2c_bus_clock_100kHz = */ 0,
/* data_setup_time_ns = */ 0,
/* write_pulse_width_ns = */ 0,
Expand Down

0 comments on commit 54e3c1a

Please sign in to comment.