Skip to content

Commit ad76362

Browse files
author
Wu Han
committed
Added 8080 Support
1 parent 7df33e5 commit ad76362

File tree

7 files changed

+141
-19
lines changed

7 files changed

+141
-19
lines changed

SConscript

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ src = Glob('src/*.c')
99
src += Glob('port/*.c')
1010

1111
if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
12-
src += Glob('examples/ssd1306_sw_i2c_example.c')
12+
src += Glob('examples/ssd1306_12864_sw_i2c_example.c')
1313

1414
if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
15-
src += Glob('examples/ssd1306_hw_i2c_example.c')
15+
src += Glob('examples/ssd1306_12864_hw_i2c_example.c')
1616

1717
if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
18-
src += Glob('examples/ssd1306_4wire_sw_spi_example.c')
18+
src += Glob('examples/ssd1306_12864_4wire_sw_spi_example.c')
1919

2020
if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
21-
src += Glob('examples/ssd1306_4wire_hw_spi_example.c')
21+
src += Glob('examples/ssd1306_12864_4wire_hw_spi_example.c')
22+
23+
if GetDepend('U8G2_USING_8080_ST7920'):
24+
src += Glob('examples/st7920_12864_8080_example.c')
2225

2326
if GetDepend('U8G2_USING_I2C_YL40'):
2427
src += Glob('examples/yl_40_example.c')

examples/ssd1306_4wire_hw_spi_example.c renamed to examples/ssd1306_12864_4wire_hw_spi_example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define OLED_SPI_PIN_DC 15 // PA1
1111
#define OLED_SPI_PIN_CS 14 // PA0
1212

13-
static void ssd1306_example_4wire_hw_spi(int argc,char *argv[])
13+
static void ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[])
1414
{
1515
u8g2_t u8g2;
1616

@@ -34,4 +34,4 @@ static void ssd1306_example_4wire_hw_spi(int argc,char *argv[])
3434
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
3535
u8g2_SendBuffer(&u8g2);
3636
}
37-
MSH_CMD_EXPORT(ssd1306_example_4wire_hw_spi, sw 4wire spi ssd1306 sample);
37+
MSH_CMD_EXPORT(ssd1306_12864_4wire_hw_spi_example, sw 4wire spi ssd1306 sample);

examples/ssd1306_4wire_sw_spi_example.c renamed to examples/ssd1306_12864_4wire_sw_spi_example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define OLED_SPI_PIN_DC 15 // PA1
1313
#define OLED_SPI_PIN_CS 14 // PA0
1414

15-
static void ssd1306_example_4wire_sw_spi(int argc,char *argv[])
15+
static void ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[])
1616
{
1717
u8g2_t u8g2;
1818

@@ -38,4 +38,4 @@ static void ssd1306_example_4wire_sw_spi(int argc,char *argv[])
3838
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
3939
u8g2_SendBuffer(&u8g2);
4040
}
41-
MSH_CMD_EXPORT(ssd1306_example_4wire_sw_spi, sw 4wire spi ssd1306 sample);
41+
MSH_CMD_EXPORT(ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <rtdevice.h>
44
#include <u8g2_port.h>
55

6-
static void ssd1306_example_hw_i2c(int argc,char *argv[])
6+
static void ssd1306_12864_hw_i2c_example(int argc,char *argv[])
77
{
88
u8g2_t u8g2;
99

@@ -23,4 +23,4 @@ static void ssd1306_example_hw_i2c(int argc,char *argv[])
2323
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
2424
u8g2_SendBuffer(&u8g2);
2525
}
26-
MSH_CMD_EXPORT(ssd1306_example_hw_i2c, i2c ssd1306 sample);
26+
MSH_CMD_EXPORT(ssd1306_12864_hw_i2c_example, i2c ssd1306 sample);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define OLED_I2C_PIN_SCL 58 // PB6
77
#define OLED_I2C_PIN_SDA 59 // PB7
88

9-
static void ssd1306_example_sw_i2c(int argc,char *argv[])
9+
static void ssd1306_12864_sw_i2c_example(int argc,char *argv[])
1010
{
1111
u8g2_t u8g2;
1212

@@ -29,4 +29,4 @@ static void ssd1306_example_sw_i2c(int argc,char *argv[])
2929
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
3030
u8g2_SendBuffer(&u8g2);
3131
}
32-
MSH_CMD_EXPORT(ssd1306_example_sw_i2c, i2c ssd1306 software i2c sample);
32+
MSH_CMD_EXPORT(ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <rthw.h>
2+
#include <rtthread.h>
3+
#include <rtdevice.h>
4+
#include <u8g2_port.h>
5+
6+
// You may reference Drivers/drv_gpio.c for pinout
7+
// In u8x8.h #define U8X8_USE_PINS
8+
9+
#define ST7920_8080_PIN_D0 36 // PB15
10+
#define ST7920_8080_PIN_D1 35 // PB14
11+
#define ST7920_8080_PIN_D2 34 // PB13
12+
#define ST7920_8080_PIN_D3 33 // PB12
13+
#define ST7920_8080_PIN_D4 37 // PC6
14+
#define ST7920_8080_PIN_D5 38 // PC7
15+
#define ST7920_8080_PIN_D6 39 // PC8
16+
#define ST7920_8080_PIN_D7 40 // PC9
17+
#define ST7920_8080_PIN_EN 50 // PA15
18+
#define ST7920_8080_PIN_CS U8X8_PIN_NONE
19+
#define ST7920_8080_PIN_DC 44 // PA11
20+
#define ST7920_8080_PIN_RST 45 // PA12
21+
22+
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)
23+
{
24+
u8x8_SetPin(u8x8, U8X8_PIN_D0, d0);
25+
u8x8_SetPin(u8x8, U8X8_PIN_D1, d1);
26+
u8x8_SetPin(u8x8, U8X8_PIN_D2, d2);
27+
u8x8_SetPin(u8x8, U8X8_PIN_D3, d3);
28+
u8x8_SetPin(u8x8, U8X8_PIN_D4, d4);
29+
u8x8_SetPin(u8x8, U8X8_PIN_D5, d5);
30+
u8x8_SetPin(u8x8, U8X8_PIN_D6, d6);
31+
u8x8_SetPin(u8x8, U8X8_PIN_D7, d7);
32+
u8x8_SetPin(u8x8, U8X8_PIN_E, wr);
33+
u8x8_SetPin(u8x8, U8X8_PIN_CS, cs);
34+
u8x8_SetPin(u8x8, U8X8_PIN_DC, dc);
35+
u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset);
36+
}
37+
38+
static void st7920_12864_8080_example(int argc,char *argv[])
39+
{
40+
u8g2_t u8g2;
41+
42+
// Initialization
43+
u8g2_Setup_st7920_p_128x64_f(&u8g2, U8G2_R0, u8x8_byte_8bit_8080mode, u8x8_rt_gpio_and_delay);
44+
u8x8_SetPin_8Bit_8080(u8g2_GetU8x8(&u8g2),
45+
ST7920_8080_PIN_D0, ST7920_8080_PIN_D1,
46+
ST7920_8080_PIN_D2, ST7920_8080_PIN_D3,
47+
ST7920_8080_PIN_D4, ST7920_8080_PIN_D5,
48+
ST7920_8080_PIN_D6, ST7920_8080_PIN_D7,
49+
ST7920_8080_PIN_EN, ST7920_8080_PIN_CS,
50+
ST7920_8080_PIN_DC, ST7920_8080_PIN_RST);
51+
52+
u8g2_InitDisplay(&u8g2);
53+
u8g2_SetPowerSave(&u8g2, 0);
54+
55+
// Draw Graphics
56+
/* full buffer example, setup procedure ends in _f */
57+
u8g2_ClearBuffer(&u8g2);
58+
u8g2_SetFont(&u8g2, u8g2_font_baby_tf);
59+
u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread");
60+
u8g2_SendBuffer(&u8g2);
61+
62+
u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
63+
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
64+
u8g2_SendBuffer(&u8g2);
65+
}
66+
MSH_CMD_EXPORT(st7920_12864_8080_example, st7920 12864 LCD sample);

port/u8g2_port.c

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,30 @@ uint8_t u8x8_rt_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
6666
break;
6767

6868
case U8X8_MSG_GPIO_AND_DELAY_INIT:
69-
//Function which implements a delay, arg_int contains the amount of ms
70-
//set mode
69+
// Function which implements a delay, arg_int contains the amount of ms
70+
// set spi pin mode
7171
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
7272
rt_pin_mode(u8x8->pins[U8X8_PIN_SPI_DATA],PIN_MODE_OUTPUT);
7373
rt_pin_mode(u8x8->pins[U8X8_PIN_RESET],PIN_MODE_OUTPUT);
7474
rt_pin_mode(u8x8->pins[U8X8_PIN_DC],PIN_MODE_OUTPUT);
7575
rt_pin_mode(u8x8->pins[U8X8_PIN_CS],PIN_MODE_OUTPUT);
76-
76+
// set i2c pin mode
7777
rt_pin_mode(u8x8->pins[U8X8_PIN_I2C_DATA],PIN_MODE_OUTPUT);
7878
rt_pin_mode(u8x8->pins[U8X8_PIN_I2C_CLOCK],PIN_MODE_OUTPUT);
79-
80-
//set value
79+
// set 8080 pin mode
80+
rt_pin_mode(u8x8->pins[U8X8_PIN_D0],PIN_MODE_OUTPUT);
81+
rt_pin_mode(u8x8->pins[U8X8_PIN_D1],PIN_MODE_OUTPUT);
82+
rt_pin_mode(u8x8->pins[U8X8_PIN_D2],PIN_MODE_OUTPUT);
83+
rt_pin_mode(u8x8->pins[U8X8_PIN_D3],PIN_MODE_OUTPUT);
84+
rt_pin_mode(u8x8->pins[U8X8_PIN_D4],PIN_MODE_OUTPUT);
85+
rt_pin_mode(u8x8->pins[U8X8_PIN_D5],PIN_MODE_OUTPUT);
86+
rt_pin_mode(u8x8->pins[U8X8_PIN_D6],PIN_MODE_OUTPUT);
87+
rt_pin_mode(u8x8->pins[U8X8_PIN_D7],PIN_MODE_OUTPUT);
88+
rt_pin_mode(u8x8->pins[U8X8_PIN_E],PIN_MODE_OUTPUT);
89+
rt_pin_mode(u8x8->pins[U8X8_PIN_DC],PIN_MODE_OUTPUT);
90+
rt_pin_mode(u8x8->pins[U8X8_PIN_RESET],PIN_MODE_OUTPUT);
91+
92+
// set value
8193
rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK],1);
8294
rt_pin_write(u8x8->pins[U8X8_PIN_SPI_DATA],1);
8395
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
91103
__asm__ volatile("nop");
92104
}
93105
break; // arg_int=1: delay by 5us, arg_int = 4: delay by 1.25us
94-
106+
107+
//case U8X8_MSG_GPIO_D0: // D0 or SPI clock pin: Output level in arg_int
108+
//case U8X8_MSG_GPIO_SPI_CLOCK:
109+
110+
//case U8X8_MSG_GPIO_D1: // D1 or SPI data pin: Output level in arg_int
111+
//case U8X8_MSG_GPIO_SPI_DATA:
112+
113+
case U8X8_MSG_GPIO_D2: // D2 pin: Output level in arg_int
114+
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D2],1);
115+
else rt_pin_write(u8x8->pins[U8X8_PIN_D2],0);
116+
break;
117+
118+
case U8X8_MSG_GPIO_D3: // D3 pin: Output level in arg_int
119+
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D3],1);
120+
else rt_pin_write(u8x8->pins[U8X8_PIN_D3],0);
121+
break;
122+
123+
case U8X8_MSG_GPIO_D4: // D4 pin: Output level in arg_int
124+
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D4],1);
125+
else rt_pin_write(u8x8->pins[U8X8_PIN_D4],0);
126+
break;
127+
128+
case U8X8_MSG_GPIO_D5: // D5 pin: Output level in arg_int
129+
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D5],1);
130+
else rt_pin_write(u8x8->pins[U8X8_PIN_D5],0);
131+
break;
132+
133+
case U8X8_MSG_GPIO_D6: // D6 pin: Output level in arg_int
134+
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D6],1);
135+
else rt_pin_write(u8x8->pins[U8X8_PIN_D6],0);
136+
break;
137+
138+
case U8X8_MSG_GPIO_D7: // D7 pin: Output level in arg_int
139+
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_D7],1);
140+
else rt_pin_write(u8x8->pins[U8X8_PIN_D7],0);
141+
break;
142+
143+
case U8X8_MSG_GPIO_E: // E/WR pin: Output level in arg_int
144+
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_E],1);
145+
else rt_pin_write(u8x8->pins[U8X8_PIN_E],0);
146+
break;
147+
95148
case U8X8_MSG_GPIO_I2C_CLOCK: // arg_int=0: Output low at I2C clock pin
96149
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_I2C_CLOCK],1);
97150
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
107160
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK],1);
108161
else rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK],0);
109162
break;
110-
163+
111164
case U8X8_MSG_GPIO_SPI_DATA:
112165
//Function to define the logic level of the data line to the display
113166
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_SPI_DATA],1);

0 commit comments

Comments
 (0)