st7920 SPI

This commit is contained in:
olikraus 2016-02-26 21:58:40 +01:00
parent 93bdfc5902
commit ecbcf8ceea
5 changed files with 143 additions and 1 deletions

View File

@ -275,6 +275,12 @@ class U8G2_ST7920_192X32_1_8080 : public U8G2 {
u8x8_SetPin_8Bit_8080(getU8x8(), d0, d1, d2, d3, d4, d5, d6, d7, enable, cs, dc, reset);
}
};
class U8G2_ST7920_192X32_1_ST7920_SW_SPI : public U8G2 {
public: U8G2_ST7920_192X32_1_ST7920_SW_SPI(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t cs, uint8_t reset = U8X8_PIN_NONE) : U8G2() {
u8g2_Setup_st7920_192x32_1(&u8g2, rotation, u8x8_byte_st7920_sw_spi, u8x8_gpio_and_delay_arduino);
u8x8_SetPin_3Wire_SW_SPI(getU8x8(), clock, data, cs, reset);
}
};
class U8G2_ST7920_192X32_2_6800 : public U8G2 {
public: U8G2_ST7920_192X32_2_6800(const u8g2_cb_t *rotation, 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 = U8X8_PIN_NONE) : U8G2() {
u8g2_Setup_st7920_192x32_2(&u8g2, rotation, u8x8_byte_8bit_6800mode, u8x8_gpio_and_delay_arduino);
@ -287,6 +293,12 @@ class U8G2_ST7920_192X32_2_8080 : public U8G2 {
u8x8_SetPin_8Bit_8080(getU8x8(), d0, d1, d2, d3, d4, d5, d6, d7, enable, cs, dc, reset);
}
};
class U8G2_ST7920_192X32_2_ST7920_SW_SPI : public U8G2 {
public: U8G2_ST7920_192X32_2_ST7920_SW_SPI(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t cs, uint8_t reset = U8X8_PIN_NONE) : U8G2() {
u8g2_Setup_st7920_192x32_2(&u8g2, rotation, u8x8_byte_st7920_sw_spi, u8x8_gpio_and_delay_arduino);
u8x8_SetPin_3Wire_SW_SPI(getU8x8(), clock, data, cs, reset);
}
};
class U8G2_ST7920_192X32_F_6800 : public U8G2 {
public: U8G2_ST7920_192X32_F_6800(const u8g2_cb_t *rotation, 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 = U8X8_PIN_NONE) : U8G2() {
u8g2_Setup_st7920_192x32_f(&u8g2, rotation, u8x8_byte_8bit_6800mode, u8x8_gpio_and_delay_arduino);
@ -299,6 +311,12 @@ class U8G2_ST7920_192X32_F_8080 : public U8G2 {
u8x8_SetPin_8Bit_8080(getU8x8(), d0, d1, d2, d3, d4, d5, d6, d7, enable, cs, dc, reset);
}
};
class U8G2_ST7920_192X32_F_ST7920_SW_SPI : public U8G2 {
public: U8G2_ST7920_192X32_F_ST7920_SW_SPI(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t cs, uint8_t reset = U8X8_PIN_NONE) : U8G2() {
u8g2_Setup_st7920_192x32_f(&u8g2, rotation, u8x8_byte_st7920_sw_spi, u8x8_gpio_and_delay_arduino);
u8x8_SetPin_3Wire_SW_SPI(getU8x8(), clock, data, cs, reset);
}
};
class U8G2_UC1701_DOGS102_1_4W_SW_SPI : public U8G2 {
public: U8G2_UC1701_DOGS102_1_4W_SW_SPI(const u8g2_cb_t *rotation, uint8_t clock, uint8_t data, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() {
u8g2_Setup_uc1701_dogs102_1(&u8g2, rotation, u8x8_byte_4wire_sw_spi, u8x8_gpio_and_delay_arduino);

View File

@ -202,6 +202,12 @@ class U8X8_ST7920_192X32_8080 : public U8X8 {
u8x8_SetPin_8Bit_8080(getU8x8(), d0, d1, d2, d3, d4, d5, d6, d7, enable, cs, dc, reset);
}
};
class U8X8_ST7920_192X32_ST7920_SW_SPI : public U8X8 {
public: U8X8_ST7920_192X32_ST7920_SW_SPI(uint8_t clock, uint8_t data, uint8_t cs, uint8_t reset = U8X8_PIN_NONE) : U8X8() {
u8x8_Setup(getU8x8(), u8x8_d_st7920_192x32, u8x8_cad_001, u8x8_byte_st7920_sw_spi, u8x8_gpio_and_delay_arduino);
u8x8_SetPin_3Wire_SW_SPI(getU8x8(), clock, data, cs, reset);
}
};
class U8X8_UC1701_DOGS102_4W_SW_SPI : public U8X8 {
public: U8X8_UC1701_DOGS102_4W_SW_SPI(uint8_t clock, uint8_t data, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8X8() {
u8x8_Setup(getU8x8(), u8x8_d_uc1701_dogs102, u8x8_cad_001, u8x8_byte_4wire_sw_spi, u8x8_gpio_and_delay_arduino);

View File

@ -494,6 +494,7 @@ uint8_t u8x8_byte_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
uint8_t u8x8_byte_8bit_6800mode(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8x8_byte_8bit_8080mode(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8x8_byte_3wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8x8_byte_st7920_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8x8_byte_ssd13xx_sw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);

View File

@ -316,6 +316,94 @@ uint8_t u8x8_byte_3wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
return 1;
}
/*=========================================*/
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 not_takeover_edge = 1 - takeover_edge;
uint8_t cnt;
cnt = 8;
do
{
if ( b & 128 )
u8x8_gpio_SetSPIData(u8x8, 1);
else
u8x8_gpio_SetSPIData(u8x8, 0);
u8x8_gpio_SetSPIClock(u8x8, not_takeover_edge);
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sda_setup_time_ns);
u8x8_gpio_SetSPIClock(u8x8, takeover_edge);
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sck_pulse_width_ns);
cnt--;
} while( cnt != 0 );
}
uint8_t u8x8_byte_st7920_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
uint8_t *data;
uint16_t b;
static uint8_t last_dc;
switch(msg)
{
case U8X8_MSG_BYTE_SEND:
if ( last_dc == 0 )
{
/* command */
u8x8_byte_st7920_send_byte(u8x8, 0x0f8);
}
else
{
/* data */
u8x8_byte_st7920_send_byte(u8x8, 0x0fa);
}
data = (uint8_t *)arg_ptr;
while( arg_int > 0 )
{
b = *data;
u8x8_byte_st7920_send_byte(u8x8, b);
data++;
arg_int--;
}
break;
case U8X8_MSG_BYTE_INIT:
/* disable chipselect */
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
/* no wait required here */
/* for SPI: setup correct level of the clock signal */
u8x8_gpio_SetSPIClock(u8x8, u8x8->display_info->sck_takeover_edge);
break;
case U8X8_MSG_BYTE_SET_DC:
last_dc = arg_int;
break;
case U8X8_MSG_BYTE_START_TRANSFER:
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
break;
case U8X8_MSG_BYTE_END_TRANSFER:
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
break;
case U8X8_MSG_BYTE_SET_I2C_ADR:
break;
case U8X8_MSG_BYTE_SET_DEVICE:
break;
default:
return 0;
}
return 1;
}
/*=========================================*/

View File

@ -19,6 +19,7 @@
#define COM_6800 0x0004
#define COM_8080 0x0008
#define COM_SSDI2C 0x0010
#define COM_ST7920SPI 0x0020
struct interface
{
@ -59,7 +60,7 @@ struct controller controller_list[] =
}
},
{
"st7920", 24, 4, "u8g2_ll_hvline_horizontal_right_lsb", "u8x8_cad_001", COM_6800|COM_8080,
"st7920", 24, 4, "u8g2_ll_hvline_horizontal_right_lsb", "u8x8_cad_001", COM_6800|COM_8080|COM_ST7920SPI,
{
{ "192x32" },
{ NULL }
@ -164,6 +165,28 @@ struct interface interface_list[] =
"[reset]",
"uC specific"
},
/* 8 */
{
"ST7920_SW_SPI",
"u8x8_SetPin_3Wire_SW_SPI",
"u8x8_byte_st7920_sw_spi",
"u8x8_gpio_and_delay_arduino",
"uint8_t clock, uint8_t data, uint8_t cs, uint8_t reset = U8X8_PIN_NONE",
"clock, data, cs, reset",
"clock, data, cs [, reset]",
"u8x8_byte_st7920_sw_spi"
},
/* 9 */
{
"ST7920_HW_SPI",
"",
"",
"",
"uint8_t cs, uint8_t reset = U8X8_PIN_NONE",
"cs, reset",
"cs [, reset]",
"uC specific"
},
};
@ -439,6 +462,12 @@ void do_display(int controller_idx, int display_idx, const char *postfix)
do_display_interface(controller_idx, display_idx, postfix, 6); /* SW SPI */
//do_display_interface(controller_idx, display_idx, postfix, 7); /* HW SPI (not yet implemented) */
}
if ( controller_list[controller_idx].com & COM_ST7920SPI )
{
do_display_interface(controller_idx, display_idx, postfix, 8); /* SW SPI */
//do_display_interface(controller_idx, display_idx, postfix, 9); /* HW SPI (not yet implemented) */
}
}