diff --git a/SConscript b/SConscript index d0bccba9..073a4732 100644 --- a/SConscript +++ b/SConscript @@ -9,16 +9,19 @@ src = Glob('src/*.c') src += Glob('port/*.c') if GetDepend('U8G2_USING_SW_I2C_SSD1306'): - src += Glob('examples/ssd1306_sw_i2c_example.c') + src += Glob('examples/ssd1306_12864_sw_i2c_example.c') if GetDepend('U8G2_USING_HW_I2C_SSD1306'): - src += Glob('examples/ssd1306_hw_i2c_example.c') + src += Glob('examples/ssd1306_12864_hw_i2c_example.c') if GetDepend('U8G2_USING_SW_SPI_SSD1306'): - src += Glob('examples/ssd1306_4wire_sw_spi_example.c') + src += Glob('examples/ssd1306_12864_4wire_sw_spi_example.c') if GetDepend('U8G2_USING_HW_SPI_SSD1306'): - src += Glob('examples/ssd1306_4wire_hw_spi_example.c') + src += Glob('examples/ssd1306_12864_4wire_hw_spi_example.c') + +if GetDepend('U8G2_USING_8080_ST7920'): + src += Glob('examples/st7920_12864_8080_example.c') if GetDepend('U8G2_USING_I2C_YL40'): src += Glob('examples/yl_40_example.c') diff --git a/examples/ssd1306_4wire_hw_spi_example.c b/examples/ssd1306_12864_4wire_hw_spi_example.c similarity index 87% rename from examples/ssd1306_4wire_hw_spi_example.c rename to examples/ssd1306_12864_4wire_hw_spi_example.c index 92831668..9a1e704f 100644 --- a/examples/ssd1306_4wire_hw_spi_example.c +++ b/examples/ssd1306_12864_4wire_hw_spi_example.c @@ -10,7 +10,7 @@ #define OLED_SPI_PIN_DC 15 // PA1 #define OLED_SPI_PIN_CS 14 // PA0 -static void ssd1306_example_4wire_hw_spi(int argc,char *argv[]) +static void ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[]) { u8g2_t u8g2; @@ -34,4 +34,4 @@ static void ssd1306_example_4wire_hw_spi(int argc,char *argv[]) u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); u8g2_SendBuffer(&u8g2); } -MSH_CMD_EXPORT(ssd1306_example_4wire_hw_spi, sw 4wire spi ssd1306 sample); +MSH_CMD_EXPORT(ssd1306_12864_4wire_hw_spi_example, sw 4wire spi ssd1306 sample); diff --git a/examples/ssd1306_4wire_sw_spi_example.c b/examples/ssd1306_12864_4wire_sw_spi_example.c similarity index 89% rename from examples/ssd1306_4wire_sw_spi_example.c rename to examples/ssd1306_12864_4wire_sw_spi_example.c index f3d2f75e..f9446133 100644 --- a/examples/ssd1306_4wire_sw_spi_example.c +++ b/examples/ssd1306_12864_4wire_sw_spi_example.c @@ -12,7 +12,7 @@ #define OLED_SPI_PIN_DC 15 // PA1 #define OLED_SPI_PIN_CS 14 // PA0 -static void ssd1306_example_4wire_sw_spi(int argc,char *argv[]) +static void ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[]) { u8g2_t u8g2; @@ -38,4 +38,4 @@ static void ssd1306_example_4wire_sw_spi(int argc,char *argv[]) u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); u8g2_SendBuffer(&u8g2); } -MSH_CMD_EXPORT(ssd1306_example_4wire_sw_spi, sw 4wire spi ssd1306 sample); +MSH_CMD_EXPORT(ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample); diff --git a/examples/ssd1306_hw_i2c_example.c b/examples/ssd1306_12864_hw_i2c_example.c similarity index 82% rename from examples/ssd1306_hw_i2c_example.c rename to examples/ssd1306_12864_hw_i2c_example.c index 94521149..0f05611f 100644 --- a/examples/ssd1306_hw_i2c_example.c +++ b/examples/ssd1306_12864_hw_i2c_example.c @@ -3,7 +3,7 @@ #include #include -static void ssd1306_example_hw_i2c(int argc,char *argv[]) +static void ssd1306_12864_hw_i2c_example(int argc,char *argv[]) { u8g2_t u8g2; @@ -23,4 +23,4 @@ static void ssd1306_example_hw_i2c(int argc,char *argv[]) u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); u8g2_SendBuffer(&u8g2); } -MSH_CMD_EXPORT(ssd1306_example_hw_i2c, i2c ssd1306 sample); +MSH_CMD_EXPORT(ssd1306_12864_hw_i2c_example, i2c ssd1306 sample); diff --git a/examples/ssd1306_sw_i2c_example.c b/examples/ssd1306_12864_sw_i2c_example.c similarity index 85% rename from examples/ssd1306_sw_i2c_example.c rename to examples/ssd1306_12864_sw_i2c_example.c index 8f895dc9..49755f2a 100644 --- a/examples/ssd1306_sw_i2c_example.c +++ b/examples/ssd1306_12864_sw_i2c_example.c @@ -6,7 +6,7 @@ #define OLED_I2C_PIN_SCL 58 // PB6 #define OLED_I2C_PIN_SDA 59 // PB7 -static void ssd1306_example_sw_i2c(int argc,char *argv[]) +static void ssd1306_12864_sw_i2c_example(int argc,char *argv[]) { u8g2_t u8g2; @@ -29,4 +29,4 @@ static void ssd1306_example_sw_i2c(int argc,char *argv[]) u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); u8g2_SendBuffer(&u8g2); } -MSH_CMD_EXPORT(ssd1306_example_sw_i2c, i2c ssd1306 software i2c sample); +MSH_CMD_EXPORT(ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample); diff --git a/examples/st7920_12864_8080_example.c b/examples/st7920_12864_8080_example.c new file mode 100644 index 00000000..a347f666 --- /dev/null +++ b/examples/st7920_12864_8080_example.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +// You may reference Drivers/drv_gpio.c for pinout +// In u8x8.h #define U8X8_USE_PINS + +#define ST7920_8080_PIN_D0 36 // PB15 +#define ST7920_8080_PIN_D1 35 // PB14 +#define ST7920_8080_PIN_D2 34 // PB13 +#define ST7920_8080_PIN_D3 33 // PB12 +#define ST7920_8080_PIN_D4 37 // PC6 +#define ST7920_8080_PIN_D5 38 // PC7 +#define ST7920_8080_PIN_D6 39 // PC8 +#define ST7920_8080_PIN_D7 40 // PC9 +#define ST7920_8080_PIN_EN 50 // PA15 +#define ST7920_8080_PIN_CS U8X8_PIN_NONE +#define ST7920_8080_PIN_DC 44 // PA11 +#define ST7920_8080_PIN_RST 45 // PA12 + +void u8x8_SetPin_8Bit_8080(u8x8_t *u8x8, 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) +{ + 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); +} + +static void st7920_12864_8080_example(int argc,char *argv[]) +{ + u8g2_t u8g2; + + // Initialization + u8g2_Setup_st7920_p_128x64_f(&u8g2, U8G2_R0, u8x8_byte_8bit_8080mode, u8x8_rt_gpio_and_delay); + u8x8_SetPin_8Bit_8080(u8g2_GetU8x8(&u8g2), + ST7920_8080_PIN_D0, ST7920_8080_PIN_D1, + ST7920_8080_PIN_D2, ST7920_8080_PIN_D3, + ST7920_8080_PIN_D4, ST7920_8080_PIN_D5, + ST7920_8080_PIN_D6, ST7920_8080_PIN_D7, + ST7920_8080_PIN_EN, ST7920_8080_PIN_CS, + ST7920_8080_PIN_DC, ST7920_8080_PIN_RST); + + u8g2_InitDisplay(&u8g2); + u8g2_SetPowerSave(&u8g2, 0); + + // Draw Graphics + /* full buffer example, setup procedure ends in _f */ + u8g2_ClearBuffer(&u8g2); + u8g2_SetFont(&u8g2, u8g2_font_baby_tf); + u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread"); + u8g2_SendBuffer(&u8g2); + + u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols); + u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 ); + u8g2_SendBuffer(&u8g2); +} +MSH_CMD_EXPORT(st7920_12864_8080_example, st7920 12864 LCD sample); diff --git a/port/u8g2_port.c b/port/u8g2_port.c index aa37d261..397ff7b8 100644 --- a/port/u8g2_port.c +++ b/port/u8g2_port.c @@ -66,18 +66,30 @@ uint8_t u8x8_rt_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void break; case U8X8_MSG_GPIO_AND_DELAY_INIT: - //Function which implements a delay, arg_int contains the amount of ms - //set mode + // Function which implements a delay, arg_int contains the amount of ms + // set spi pin mode rt_pin_mode(u8x8->pins[U8X8_PIN_SPI_CLOCK],PIN_MODE_OUTPUT);//d0 a5 15 d1 a7 17 res b0 18 dc b1 19 cs a4 14 rt_pin_mode(u8x8->pins[U8X8_PIN_SPI_DATA],PIN_MODE_OUTPUT); rt_pin_mode(u8x8->pins[U8X8_PIN_RESET],PIN_MODE_OUTPUT); rt_pin_mode(u8x8->pins[U8X8_PIN_DC],PIN_MODE_OUTPUT); rt_pin_mode(u8x8->pins[U8X8_PIN_CS],PIN_MODE_OUTPUT); - + // set i2c pin mode rt_pin_mode(u8x8->pins[U8X8_PIN_I2C_DATA],PIN_MODE_OUTPUT); rt_pin_mode(u8x8->pins[U8X8_PIN_I2C_CLOCK],PIN_MODE_OUTPUT); - - //set value + // set 8080 pin mode + rt_pin_mode(u8x8->pins[U8X8_PIN_D0],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_D1],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_D2],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_D3],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_D4],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_D5],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_D6],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_D7],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_E],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_DC],PIN_MODE_OUTPUT); + rt_pin_mode(u8x8->pins[U8X8_PIN_RESET],PIN_MODE_OUTPUT); + + // set value rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK],1); rt_pin_write(u8x8->pins[U8X8_PIN_SPI_DATA],1); rt_pin_write(u8x8->pins[U8X8_PIN_RESET],1); @@ -91,7 +103,48 @@ uint8_t u8x8_rt_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void __asm__ volatile("nop"); } break; // arg_int=1: delay by 5us, arg_int = 4: delay by 1.25us - + + //case U8X8_MSG_GPIO_D0: // D0 or SPI clock pin: Output level in arg_int + //case U8X8_MSG_GPIO_SPI_CLOCK: + + //case U8X8_MSG_GPIO_D1: // D1 or SPI data pin: Output level in arg_int + //case U8X8_MSG_GPIO_SPI_DATA: + + case U8X8_MSG_GPIO_D2: // D2 pin: Output level in arg_int + if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D2],1); + else rt_pin_write(u8x8->pins[U8X8_PIN_D2],0); + break; + + case U8X8_MSG_GPIO_D3: // D3 pin: Output level in arg_int + if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D3],1); + else rt_pin_write(u8x8->pins[U8X8_PIN_D3],0); + break; + + case U8X8_MSG_GPIO_D4: // D4 pin: Output level in arg_int + if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D4],1); + else rt_pin_write(u8x8->pins[U8X8_PIN_D4],0); + break; + + case U8X8_MSG_GPIO_D5: // D5 pin: Output level in arg_int + if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D5],1); + else rt_pin_write(u8x8->pins[U8X8_PIN_D5],0); + break; + + case U8X8_MSG_GPIO_D6: // D6 pin: Output level in arg_int + if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D6],1); + else rt_pin_write(u8x8->pins[U8X8_PIN_D6],0); + break; + + case U8X8_MSG_GPIO_D7: // D7 pin: Output level in arg_int + if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D7],1); + else rt_pin_write(u8x8->pins[U8X8_PIN_D7],0); + break; + + case U8X8_MSG_GPIO_E: // E/WR pin: Output level in arg_int + if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_E],1); + else rt_pin_write(u8x8->pins[U8X8_PIN_E],0); + break; + case U8X8_MSG_GPIO_I2C_CLOCK: // arg_int=0: Output low at I2C clock pin if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_I2C_CLOCK],1); else rt_pin_write(u8x8->pins[U8X8_PIN_I2C_CLOCK],0); @@ -107,7 +160,7 @@ uint8_t u8x8_rt_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK],1); else rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK],0); break; - + case U8X8_MSG_GPIO_SPI_DATA: //Function to define the logic level of the data line to the display if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_SPI_DATA],1);