Skip to content

Commit

Permalink
C++ RT-Thread wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Wu Han committed Apr 21, 2019
1 parent 9cb076d commit 5ea7a59
Show file tree
Hide file tree
Showing 17 changed files with 14,266 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf
.vscode/
44 changes: 32 additions & 12 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,44 @@ cwd = GetCurrentDir()
src = Glob('inc/*.h')
src = Glob('src/*.c')
src += Glob('port/*.c')
src += Glob('port/*.cpp')

if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
src += Glob('examples/ssd1306_12864_sw_i2c_example.c')
if(GetDepend('PKG_USING_U8G2_V100') or GetDepend('PKG_USING_U8G2_V110') or GetDepend('PKG_USING_U8G2_V120')):
if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
src += Glob('examples/legacy/ssd1306_12864_sw_i2c_example.c')

if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
src += Glob('examples/ssd1306_12864_hw_i2c_example.c')
if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
src += Glob('examples/legacy/ssd1306_12864_hw_i2c_example.c')

if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
src += Glob('examples/ssd1306_12864_4wire_sw_spi_example.c')
if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
src += Glob('examples/legacy/ssd1306_12864_4wire_sw_spi_example.c')

if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
src += Glob('examples/ssd1306_12864_4wire_hw_spi_example.c')
if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
src += Glob('examples/legacy/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_8080_ST7920'):
src += Glob('examples/legacy/st7920_12864_8080_example.c')

if GetDepend('U8G2_USING_I2C_YL40'):
src += Glob('examples/yl_40_example.c')
if GetDepend('U8G2_USING_I2C_YL40'):
src += Glob('examples/yl_40_example.c')
else:
if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
src += Glob('examples/ssd1306_12864_sw_i2c_example.cpp')

if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
src += Glob('examples/ssd1306_12864_hw_i2c_example.cpp')

if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
src += Glob('examples/ssd1306_12864_4wire_sw_spi_example.cpp')

if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
src += Glob('examples/ssd1306_12864_4wire_hw_spi_example.cpp')

if GetDepend('U8G2_USING_8080_ST7920'):
src += Glob('examples/st7920_12864_8080_example.cpp')

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

path = [cwd + '/']
path += [cwd + '/port']
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions examples/ssd1306_12864_4wire_hw_spi_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <U8g2lib.h>

// You may reference Drivers/drv_gpio.c for pinout
// In u8x8.h #define U8X8_USE_PINS

#define OLED_SPI_PIN_RES 16 // PA2
#define OLED_SPI_PIN_DC 15 // PA1
#define OLED_SPI_PIN_CS 14 // PA0

// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_SSD1306_128X64_ALT0_F_4W_HW_SPI u8g2(U8G2_R0,
/* cs=*/ OLED_SPI_PIN_CS,
/* dc=*/ OLED_SPI_PIN_DC,
/* reset=*/ OLED_SPI_PIN_RES);
// same as the NONAME variant, but may solve the "every 2nd line skipped" problem

static void ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[])
{
u8g2.begin();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603 );
u8g2.sendBuffer();
}
MSH_CMD_EXPORT(ssd1306_12864_4wire_hw_spi_example, sw 4wire spi ssd1306 sample);
34 changes: 34 additions & 0 deletions examples/ssd1306_12864_4wire_sw_spi_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <U8g2lib.h>

// You may reference Drivers/drv_gpio.c for pinout
// In u8x8.h #define U8X8_USE_PINS

#define OLED_SPI_PIN_CLK 21 // PA5
#define OLED_SPI_PIN_MOSI 23 // PA7
#define OLED_SPI_PIN_RES 16 // PA2
#define OLED_SPI_PIN_DC 15 // PA1
#define OLED_SPI_PIN_CS 14 // PA0

// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0,
/* clock=*/ OLED_SPI_PIN_CLK,
/* data=*/ OLED_SPI_PIN_MOSI,
/* cs=*/ OLED_SPI_PIN_CS,
/* dc=*/ OLED_SPI_PIN_DC,
/* reset=*/ OLED_SPI_PIN_RES);

static void ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[])
{
u8g2.begin();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603 );
u8g2.sendBuffer();
}
MSH_CMD_EXPORT(ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample);
20 changes: 20 additions & 0 deletions examples/ssd1306_12864_hw_i2c_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <U8g2lib.h>

// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

static void ssd1306_12864_hw_i2c_example(int argc,char *argv[])
{
u8g2.begin();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603 );
u8g2.sendBuffer();
}
MSH_CMD_EXPORT(ssd1306_12864_hw_i2c_example, i2c ssd1306 sample);
29 changes: 29 additions & 0 deletions examples/ssd1306_12864_sw_i2c_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <U8g2lib.h>

// You may reference Drivers/drv_gpio.c for pinout
// In u8x8.h #define U8X8_USE_PINS
#define OLED_I2C_PIN_SCL 58 // PB6
#define OLED_I2C_PIN_SDA 59 // PB7

// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,
/* clock=*/ OLED_I2C_PIN_SCL,
/* data=*/ OLED_I2C_PIN_SDA,
/* reset=*/ U8X8_PIN_NONE);
// All Boards without Reset of the Display

static void ssd1306_12864_sw_i2c_example(int argc,char *argv[])
{
u8g2.begin();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603 );
u8g2.sendBuffer();
}
MSH_CMD_EXPORT(ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);
48 changes: 48 additions & 0 deletions examples/st7920_12864_8080_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <U8g2lib.h>

// 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

// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_ST7920_128X64_F_8080 u8g2(U8G2_R0,
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,
/*enable=*/ ST7920_8080_PIN_EN,
/*cs=*/ ST7920_8080_PIN_CS,
/*dc=*/ ST7920_8080_PIN_DC,
/*reset=*/ ST7920_8080_PIN_RST);

static void st7920_12864_8080_example(int argc,char *argv[])
{
u8g2.begin();
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
u8g2.setFont(u8g2_font_unifont_t_symbols);
u8g2.drawGlyph(112, 56, 0x2603 );
u8g2.sendBuffer();
}
MSH_CMD_EXPORT(st7920_12864_8080_example, st7920 12864 LCD sample);
1 change: 0 additions & 1 deletion examples/yl_40_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <rtthread.h>
#include <rtdevice.h>
#include <stdlib.h>
#include <u8g2_port.h>

static void yl_40_example(int argc, char *argv[])
{
Expand Down
Loading

0 comments on commit 5ea7a59

Please # to comment.