Skip to content

Commit 5ea7a59

Browse files
author
Wu Han
committed
C++ RT-Thread wrapper
1 parent 9cb076d commit 5ea7a59

17 files changed

+14266
-43
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ modules.order
5050
Module.symvers
5151
Mkfile.old
5252
dkms.conf
53+
.vscode/

SConscript

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,44 @@ cwd = GetCurrentDir()
77
src = Glob('inc/*.h')
88
src = Glob('src/*.c')
99
src += Glob('port/*.c')
10+
src += Glob('port/*.cpp')
1011

11-
if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
12-
src += Glob('examples/ssd1306_12864_sw_i2c_example.c')
12+
if(GetDepend('PKG_USING_U8G2_V100') or GetDepend('PKG_USING_U8G2_V110') or GetDepend('PKG_USING_U8G2_V120')):
13+
if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
14+
src += Glob('examples/legacy/ssd1306_12864_sw_i2c_example.c')
1315

14-
if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
15-
src += Glob('examples/ssd1306_12864_hw_i2c_example.c')
16+
if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
17+
src += Glob('examples/legacy/ssd1306_12864_hw_i2c_example.c')
1618

17-
if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
18-
src += Glob('examples/ssd1306_12864_4wire_sw_spi_example.c')
19+
if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
20+
src += Glob('examples/legacy/ssd1306_12864_4wire_sw_spi_example.c')
1921

20-
if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
21-
src += Glob('examples/ssd1306_12864_4wire_hw_spi_example.c')
22+
if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
23+
src += Glob('examples/legacy/ssd1306_12864_4wire_hw_spi_example.c')
2224

23-
if GetDepend('U8G2_USING_8080_ST7920'):
24-
src += Glob('examples/st7920_12864_8080_example.c')
25+
if GetDepend('U8G2_USING_8080_ST7920'):
26+
src += Glob('examples/legacy/st7920_12864_8080_example.c')
2527

26-
if GetDepend('U8G2_USING_I2C_YL40'):
27-
src += Glob('examples/yl_40_example.c')
28+
if GetDepend('U8G2_USING_I2C_YL40'):
29+
src += Glob('examples/yl_40_example.c')
30+
else:
31+
if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
32+
src += Glob('examples/ssd1306_12864_sw_i2c_example.cpp')
33+
34+
if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
35+
src += Glob('examples/ssd1306_12864_hw_i2c_example.cpp')
36+
37+
if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
38+
src += Glob('examples/ssd1306_12864_4wire_sw_spi_example.cpp')
39+
40+
if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
41+
src += Glob('examples/ssd1306_12864_4wire_hw_spi_example.cpp')
42+
43+
if GetDepend('U8G2_USING_8080_ST7920'):
44+
src += Glob('examples/st7920_12864_8080_example.cpp')
45+
46+
if GetDepend('U8G2_USING_I2C_YL40'):
47+
src += Glob('examples/yl_40_example.c')
2848

2949
path = [cwd + '/']
3050
path += [cwd + '/port']
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <rthw.h>
2+
#include <rtthread.h>
3+
#include <rtdevice.h>
4+
#include <U8g2lib.h>
5+
6+
// You may reference Drivers/drv_gpio.c for pinout
7+
// In u8x8.h #define U8X8_USE_PINS
8+
9+
#define OLED_SPI_PIN_RES 16 // PA2
10+
#define OLED_SPI_PIN_DC 15 // PA1
11+
#define OLED_SPI_PIN_CS 14 // PA0
12+
13+
// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
14+
static U8G2_SSD1306_128X64_ALT0_F_4W_HW_SPI u8g2(U8G2_R0,
15+
/* cs=*/ OLED_SPI_PIN_CS,
16+
/* dc=*/ OLED_SPI_PIN_DC,
17+
/* reset=*/ OLED_SPI_PIN_RES);
18+
// same as the NONAME variant, but may solve the "every 2nd line skipped" problem
19+
20+
static void ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[])
21+
{
22+
u8g2.begin();
23+
u8g2.clearBuffer(); // clear the internal memory
24+
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
25+
u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
26+
u8g2.sendBuffer(); // transfer internal memory to the display
27+
u8g2.setFont(u8g2_font_unifont_t_symbols);
28+
u8g2.drawGlyph(112, 56, 0x2603 );
29+
u8g2.sendBuffer();
30+
}
31+
MSH_CMD_EXPORT(ssd1306_12864_4wire_hw_spi_example, sw 4wire spi ssd1306 sample);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <rthw.h>
2+
#include <rtthread.h>
3+
#include <rtdevice.h>
4+
#include <U8g2lib.h>
5+
6+
// You may reference Drivers/drv_gpio.c for pinout
7+
// In u8x8.h #define U8X8_USE_PINS
8+
9+
#define OLED_SPI_PIN_CLK 21 // PA5
10+
#define OLED_SPI_PIN_MOSI 23 // PA7
11+
#define OLED_SPI_PIN_RES 16 // PA2
12+
#define OLED_SPI_PIN_DC 15 // PA1
13+
#define OLED_SPI_PIN_CS 14 // PA0
14+
15+
// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
16+
static U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0,
17+
/* clock=*/ OLED_SPI_PIN_CLK,
18+
/* data=*/ OLED_SPI_PIN_MOSI,
19+
/* cs=*/ OLED_SPI_PIN_CS,
20+
/* dc=*/ OLED_SPI_PIN_DC,
21+
/* reset=*/ OLED_SPI_PIN_RES);
22+
23+
static void ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[])
24+
{
25+
u8g2.begin();
26+
u8g2.clearBuffer(); // clear the internal memory
27+
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
28+
u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
29+
u8g2.sendBuffer(); // transfer internal memory to the display
30+
u8g2.setFont(u8g2_font_unifont_t_symbols);
31+
u8g2.drawGlyph(112, 56, 0x2603 );
32+
u8g2.sendBuffer();
33+
}
34+
MSH_CMD_EXPORT(ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <rthw.h>
2+
#include <rtthread.h>
3+
#include <rtdevice.h>
4+
#include <U8g2lib.h>
5+
6+
// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
7+
static U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
8+
9+
static void ssd1306_12864_hw_i2c_example(int argc,char *argv[])
10+
{
11+
u8g2.begin();
12+
u8g2.clearBuffer(); // clear the internal memory
13+
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
14+
u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
15+
u8g2.sendBuffer(); // transfer internal memory to the display
16+
u8g2.setFont(u8g2_font_unifont_t_symbols);
17+
u8g2.drawGlyph(112, 56, 0x2603 );
18+
u8g2.sendBuffer();
19+
}
20+
MSH_CMD_EXPORT(ssd1306_12864_hw_i2c_example, i2c ssd1306 sample);

0 commit comments

Comments
 (0)