add rt-thread cpp support

This commit is contained in:
wuhanstudio 2021-08-04 20:19:24 +01:00
parent 25e711556e
commit 6caa2ae955
22 changed files with 25725 additions and 116 deletions

View File

@ -1,19 +1,63 @@
from building import *
import rtconfig
# get current directory
cwd = GetCurrentDir()
# The set of source files associated with this SConscript file.
src = Glob('csrc/*.c')
src += Glob('sys/rt-thread/port/*.c')
src += Glob('sys/rt-thread/examples/*.c')
path = [cwd + '/']
# The set of source files associated with this SConscript file.
src = Glob('sys/rt-thread/port/u8g2_port.c')
src += Glob('csrc/*.c')
if(GetDepend('U8G2_USE_CPP')):
src += Glob('sys/rt-thread/port/*.cpp')
if(not GetDepend('U8G2_USE_CPP')):
if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
src += Glob('sys/rt-thread/examples/ssd1306_12864_sw_i2c_example.c')
if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
src += Glob('sys/rt-thread/examples/ssd1306_12864_hw_i2c_example.c')
if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
src += Glob('sys/rt-thread/examples/ssd1306_12864_4wire_sw_spi_example.c')
if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
src += Glob('sys/rt-thread/examples/ssd1306_12864_4wire_hw_spi_example.c')
if GetDepend('U8G2_USING_8080_ST7920'):
src += Glob('sys/rt-thread/examples/st7920_12864_8080_example.c')
if GetDepend('U8G2_USING_I2C_YL40'):
src += Glob('sys/rt-thread/examples/yl_40_example.c')
else:
# Basic Examples
if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
src += Glob('sys/rt-thread/examples/ssd1306_12864_sw_i2c_example.cpp')
if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
src += Glob('sys/rt-thread/examples/ssd1306_12864_hw_i2c_example.cpp')
if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
src += Glob('sys/rt-thread/examples/ssd1306_12864_4wire_sw_spi_example.cpp')
if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
src += Glob('sys/rt-thread/examples/ssd1306_12864_4wire_hw_spi_example.cpp')
if GetDepend('U8G2_USING_8080_ST7920'):
src += Glob('sys/rt-thread/examples/st7920_12864_8080_example.cpp')
if GetDepend('U8G2_USING_I2C_YL40'):
src += Glob('sys/rt-thread/examples/yl_40_example.c')
path = [cwd + '/sys/rt-thread/port']
path += [cwd + '/csrc']
path += [cwd + '/sys/rt-thread/port']
LOCAL_CCFLAGS = ''
group = DefineGroup('u8g2s', src, depend = [''], CPPPATH = path, LOCAL_CCFLAGS = LOCAL_CCFLAGS, CPPDEFINES=['RTT_U8G2'])
group = DefineGroup('U8G2', src, depend = ['PKG_USING_U8G2'], CPPPATH = path, LOCAL_CCFLAGS = LOCAL_CCFLAGS, CPPDEFINES=['RTT_U8G2'])
Return('group')
Return('group')

View File

@ -1,27 +1,26 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <u8g2_port.h>
// You may reference Drivers/drv_gpio.c for pinout
// In u8x8.h #define U8X8_USE_PINS
// In u8x8.h #define U8X8_USE_PINS
#define OLED_SPI_PIN_RES GET_PIN(A, 2) // PA2
#define OLED_SPI_PIN_DC GET_PIN(A, 1) // PA1
#define OLED_SPI_PIN_CS GET_PIN(A, 0) // PA0
#define OLED_SPI_PIN_RES 2 // PA2
#define OLED_SPI_PIN_DC 1 // PA1
#define OLED_SPI_PIN_CS 0 // PA0
static void ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[])
static void u8g2_ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[])
{
u8g2_t u8g2;
// Initialization
u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rt_4wire_hw_spi, u8x8_rt_gpio_and_delay);
u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rtthread_4wire_hw_spi, u8x8_gpio_and_delay_rtthread);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_CS, OLED_SPI_PIN_CS);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_DC, OLED_SPI_PIN_DC);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_RESET, OLED_SPI_PIN_RES);
u8g2_InitDisplay(&u8g2);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
// Draw Graphics
@ -35,4 +34,4 @@ static void ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[])
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
u8g2_SendBuffer(&u8g2);
}
MSH_CMD_EXPORT(ssd1306_12864_4wire_hw_spi_example, sw 4wire spi ssd1306 sample);
MSH_CMD_EXPORT(u8g2_ssd1306_12864_4wire_hw_spi_example, hardware 4 wire spi ssd1306 sample);

View File

@ -0,0 +1,33 @@
#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 2 // PA2
#define OLED_SPI_PIN_DC 1 // PA1
#define OLED_SPI_PIN_CS 0 // PA0
// Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
static U8G2_SSD1306_128X64_NONAME_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 u8g2_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.setFont(u8g2_font_5x8_tr); // choose a suitable font
u8g2.drawStr(1, 56, "2.29 Milestone"); // 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(u8g2_ssd1306_12864_4wire_hw_spi_example, hw 4wire spi ssd1306 sample);

View File

@ -1,24 +1,23 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <u8g2_port.h>
// You may reference Drivers/drv_gpio.c for pinout
// In u8x8.h #define U8X8_USE_PINS
// In u8x8.h #define U8X8_USE_PINS
#define OLED_SPI_PIN_CLK GET_PIN(A, 5) // PA5
#define OLED_SPI_PIN_MOSI GET_PIN(A, 7) // PA7
#define OLED_SPI_PIN_RES GET_PIN(A, 2) // PA2
#define OLED_SPI_PIN_DC GET_PIN(A, 1) // PA1
#define OLED_SPI_PIN_CS GET_PIN(A, 0) // PA0
#define OLED_SPI_PIN_CLK 5 // PA5
#define OLED_SPI_PIN_MOSI 7 // PA7
#define OLED_SPI_PIN_RES 2 // PA2
#define OLED_SPI_PIN_DC 1 // PA1
#define OLED_SPI_PIN_CS 0 // PA0
static void ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[])
static void u8g2_ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[])
{
u8g2_t u8g2;
// Initialization
u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_rt_gpio_and_delay);
u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_gpio_and_delay_rtthread);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_SPI_CLOCK, OLED_SPI_PIN_CLK);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_SPI_DATA, OLED_SPI_PIN_MOSI);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_CS, OLED_SPI_PIN_CS);
@ -39,4 +38,4 @@ static void ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[])
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
u8g2_SendBuffer(&u8g2);
}
MSH_CMD_EXPORT(ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample);
MSH_CMD_EXPORT(u8g2_ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample);

View File

@ -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 5 // PA5
#define OLED_SPI_PIN_MOSI 7 // PA7
#define OLED_SPI_PIN_RES 2 // PA2
#define OLED_SPI_PIN_DC 1 // PA1
#define OLED_SPI_PIN_CS 0 // 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 u8g2_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(u8g2_ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample);

View File

@ -3,12 +3,12 @@
#include <rtdevice.h>
#include <u8g2_port.h>
static void ssd1306_12864_hw_i2c_example(int argc,char *argv[])
static void u8g2_ssd1306_12864_hw_i2c_example(int argc,char *argv[])
{
u8g2_t u8g2;
// Initialization
u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rt_hw_i2c, u8x8_rt_gpio_and_delay);
u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rtthread_hw_i2c, u8x8_gpio_and_delay_rtthread);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
@ -23,4 +23,4 @@ static void ssd1306_12864_hw_i2c_example(int argc,char *argv[])
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
u8g2_SendBuffer(&u8g2);
}
MSH_CMD_EXPORT(ssd1306_12864_hw_i2c_example, i2c ssd1306 sample);
MSH_CMD_EXPORT(u8g2_ssd1306_12864_hw_i2c_example, i2c ssd1306 sample);

View File

@ -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 u8g2_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(u8g2_ssd1306_12864_hw_i2c_example, i2c ssd1306 sample);

View File

@ -1,20 +1,19 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <u8g2_port.h>
#define OLED_I2C_PIN_SCL GET_PIN(B, 6) // PB6
#define OLED_I2C_PIN_SDA GET_PIN(B, 7) // PB7
#define OLED_I2C_PIN_SCL 22 // PB6
#define OLED_I2C_PIN_SDA 23 // PB7
static void ssd1306_12864_sw_i2c_example(int argc,char *argv[])
static void u8g2_ssd1306_12864_sw_i2c_example(int argc,char *argv[])
{
u8g2_t u8g2;
// Initialization
u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_rt_gpio_and_delay);
u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_gpio_and_delay_rtthread);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_CLOCK, OLED_I2C_PIN_SCL);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_DATA, OLED_I2C_PIN_SDA);
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_DATA, OLED_I2C_PIN_SDA);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
@ -30,4 +29,4 @@ static void ssd1306_12864_sw_i2c_example(int argc,char *argv[])
u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
u8g2_SendBuffer(&u8g2);
}
MSH_CMD_EXPORT(ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);
MSH_CMD_EXPORT(u8g2_ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);

View File

@ -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 22 // PB6
#define OLED_I2C_PIN_SDA 23 // 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 u8g2_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(u8g2_ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);

View File

@ -0,0 +1,66 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <u8g2_port.h>
// You may reference Drivers/drv_gpio.c for pinout
// In u8x8.h #define U8X8_USE_PINS
#define ST7920_8080_PIN_D0 31 // PB15
#define ST7920_8080_PIN_D1 30 // PB14
#define ST7920_8080_PIN_D2 29 // PB13
#define ST7920_8080_PIN_D3 28 // PB12
#define ST7920_8080_PIN_D4 38 // PC6
#define ST7920_8080_PIN_D5 39 // PC7
#define ST7920_8080_PIN_D6 40 // PC8
#define ST7920_8080_PIN_D7 41 // PC9
#define ST7920_8080_PIN_EN 15 // PA15
#define ST7920_8080_PIN_CS U8X8_PIN_NONE
#define ST7920_8080_PIN_DC 11 // PA11
#define ST7920_8080_PIN_RST 12 // 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 u8g2_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_gpio_and_delay_rtthread);
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(u8g2_st7920_12864_8080_example, st7920 12864 LCD sample);

View File

@ -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 31 // PB15
#define ST7920_8080_PIN_D1 30 // PB14
#define ST7920_8080_PIN_D2 29 // PB13
#define ST7920_8080_PIN_D3 28 // PB12
#define ST7920_8080_PIN_D4 38 // PC6
#define ST7920_8080_PIN_D5 39 // PC7
#define ST7920_8080_PIN_D6 40 // PC8
#define ST7920_8080_PIN_D7 41 // PC9
#define ST7920_8080_PIN_EN 15 // PA15
#define ST7920_8080_PIN_CS U8X8_PIN_NONE
#define ST7920_8080_PIN_DC 11 // PA11
#define ST7920_8080_PIN_RST 12 // 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 u8g2_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(u8g2_st7920_12864_8080_example, st7920 12864 LCD sample);

View File

@ -0,0 +1,234 @@
/*
Print.cpp - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 23 November 2006 by David A. Mellis
Modified 03 August 2015 by Chuck Todd
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// Use Self-defined isnan isinf in Print.h
//#include <math.h>
#include "Print.h"
// Public Methods //////////////////////////////////////////////////////////////
/* default implementation: may be overridden */
size_t Print::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
while (size--) {
if (write(*buffer++)) n++;
else break;
}
return n;
}
size_t Print::print(const char str[])
{
return write(str);
}
size_t Print::print(char c)
{
return write(c);
}
size_t Print::print(unsigned char b, int base)
{
return print((unsigned long) b, base);
}
size_t Print::print(int n, int base)
{
return print((long) n, base);
}
size_t Print::print(unsigned int n, int base)
{
return print((unsigned long) n, base);
}
size_t Print::print(long n, int base)
{
if (base == 0) {
return write(n);
} else if (base == 10) {
if (n < 0) {
int t = print('-');
n = -n;
return printNumber(n, 10) + t;
}
return printNumber(n, 10);
} else {
return printNumber(n, base);
}
}
size_t Print::print(unsigned long n, int base)
{
if (base == 0) return write(n);
else return printNumber(n, base);
}
size_t Print::print(double n, int digits)
{
return printFloat(n, digits);
}
size_t Print::print(const Printable& x)
{
return x.printTo(*this);
}
size_t Print::println(void)
{
return write("\r\n");
}
size_t Print::println(const char c[])
{
size_t n = print(c);
n += println();
return n;
}
size_t Print::println(char c)
{
size_t n = print(c);
n += println();
return n;
}
size_t Print::println(unsigned char b, int base)
{
size_t n = print(b, base);
n += println();
return n;
}
size_t Print::println(int num, int base)
{
size_t n = print(num, base);
n += println();
return n;
}
size_t Print::println(unsigned int num, int base)
{
size_t n = print(num, base);
n += println();
return n;
}
size_t Print::println(long num, int base)
{
size_t n = print(num, base);
n += println();
return n;
}
size_t Print::println(unsigned long num, int base)
{
size_t n = print(num, base);
n += println();
return n;
}
size_t Print::println(double num, int digits)
{
size_t n = print(num, digits);
n += println();
return n;
}
size_t Print::println(const Printable& x)
{
size_t n = print(x);
n += println();
return n;
}
// Private Methods /////////////////////////////////////////////////////////////
size_t Print::printNumber(unsigned long n, uint8_t base)
{
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
char *str = &buf[sizeof(buf) - 1];
*str = '\0';
// prevent crash if called with base == 1
if (base < 2) base = 10;
do {
char c = n % base;
n /= base;
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
return write(str);
}
size_t Print::printFloat(double number, uint8_t digits)
{
size_t n = 0;
if (isnan(number)) return print("nan");
if (isinf(number)) return print("inf");
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
// Handle negative numbers
if (number < 0.0)
{
n += print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
n += print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
n += print('.');
}
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
unsigned int toPrint = (unsigned int)(remainder);
n += print(toPrint);
remainder -= toPrint;
}
return n;
}

View File

@ -0,0 +1,94 @@
/*
Print.h - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef Print_h
#define Print_h
#include <inttypes.h>
#include <stdio.h> // for size_t
#include <string.h>
#include "Printable.h"
#define DEC 10
#define HEX 16
#define OCT 8
#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
#undef BIN
#endif
#define BIN 2
class Print
{
private:
int write_error;
size_t printNumber(unsigned long, uint8_t);
size_t printFloat(double, uint8_t);
int isnan(double x) { return x != x; };
int isinf(double x) { return !isnan(x) && isnan(x - x); };
protected:
void setWriteError(int err = 1) { write_error = err; }
public:
Print() : write_error(0) {}
int getWriteError() { return write_error; }
void clearWriteError() { setWriteError(0); }
virtual size_t write(uint8_t) = 0;
size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
virtual size_t write(const uint8_t *buffer, size_t size);
size_t write(const char *buffer, size_t size) {
return write((const uint8_t *)buffer, size);
}
// default to zero, meaning "a single write may block"
// should be overriden by subclasses with buffering
virtual int availableForWrite() { return 0; }
// size_t print(const __FlashStringHelper *);
// size_t print(const String &);
size_t print(const char[]);
size_t print(char);
size_t print(unsigned char, int = DEC);
size_t print(int, int = DEC);
size_t print(unsigned int, int = DEC);
size_t print(long, int = DEC);
size_t print(unsigned long, int = DEC);
size_t print(double, int = 2);
size_t print(const Printable&);
// size_t println(const __FlashStringHelper *);
// size_t println(const String &s);
size_t println(const char[]);
size_t println(char);
size_t println(unsigned char, int = DEC);
size_t println(int, int = DEC);
size_t println(unsigned int, int = DEC);
size_t println(long, int = DEC);
size_t println(unsigned long, int = DEC);
size_t println(double, int = 2);
size_t println(const Printable&);
size_t println(void);
virtual void flush() { /* Empty implementation for backward compatibility */ }
};
#endif

View File

@ -0,0 +1,39 @@
/*
Printable.h - Interface class that allows printing of complex types
Copyright (c) 2011 Adrian McEwen. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef Printable_h
#define Printable_h
#include <stdlib.h>
class Print;
/** The Printable class provides a way for new classes to allow themselves to be printed.
By deriving from Printable and implementing the printTo method, it will then be possible
for users to print out instances of this class by passing them into the usual
Print::print and Print::println methods.
*/
class Printable
{
public:
virtual size_t printTo(Print& p) const = 0;
};
#endif

View File

@ -0,0 +1,76 @@
/*
U8g2lib.cpp
Arduino specific functions
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
Copyright (c) 2016, olikraus@gmail.com
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "U8g2lib.h"
static Print *u8g2_print_for_screenshot;
void u8g2_print_callback(const char *s)
{
// yield();
u8g2_print_for_screenshot->print(s);
}
void U8G2::writeBufferPBM(Print &p)
{
u8g2_print_for_screenshot = &p;
u8g2_WriteBufferPBM(getU8g2(), u8g2_print_callback);
}
void U8G2::writeBufferXBM(Print &p)
{
u8g2_print_for_screenshot = &p;
u8g2_WriteBufferXBM(getU8g2(), u8g2_print_callback);
}
void U8G2::writeBufferPBM2(Print &p)
{
u8g2_print_for_screenshot = &p;
u8g2_WriteBufferPBM2(getU8g2(), u8g2_print_callback);
}
void U8G2::writeBufferXBM2(Print &p)
{
u8g2_print_for_screenshot = &p;
u8g2_WriteBufferXBM2(getU8g2(), u8g2_print_callback);
}

15175
sys/rt-thread/port/U8g2lib.h Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

5185
sys/rt-thread/port/U8x8lib.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,4 @@
#include "u8g2_port.h"
#include <rtthread.h>
#include <string.h>
#define MAX_RETRY 3
@ -53,43 +52,44 @@ int rt_hw_spi_config(uint8_t spi_mode, uint32_t max_hz, uint8_t cs_pin )
}
#endif /* U8G2_USE_HW_SPI */
uint8_t u8x8_rt_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
uint8_t u8x8_gpio_and_delay_rtthread(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
uint8_t i;
switch(msg)
{
case U8X8_MSG_DELAY_NANO: // delay arg_int * 1 nano second
case U8X8_MSG_DELAY_NANO: // delay arg_int * 1 nano second
__asm__ volatile("nop");
break;
case U8X8_MSG_DELAY_100NANO: // delay arg_int * 100 nano seconds
case U8X8_MSG_DELAY_100NANO: // delay arg_int * 100 nano seconds
__asm__ volatile("nop");
break;
case U8X8_MSG_DELAY_10MICRO: // delay arg_int * 10 micro seconds
case U8X8_MSG_DELAY_10MICRO: // delay arg_int * 10 micro seconds
for (uint16_t n = 0; n < 320; n++)
{
__asm__ volatile("nop");
}
break;
case U8X8_MSG_DELAY_MILLI: // delay arg_int * 1 milli second
rt_thread_delay(arg_int);
case U8X8_MSG_DELAY_MILLI: // delay arg_int * 1 milli second
rt_thread_mdelay(arg_int);
break;
case U8X8_MSG_GPIO_AND_DELAY_INIT:
// 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_CLOCK],PIN_MODE_OUTPUT);
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 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);
@ -102,7 +102,15 @@ uint8_t u8x8_rt_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
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 menu pin mode
rt_pin_mode(u8x8->pins[U8X8_PIN_MENU_HOME],PIN_MODE_INPUT_PULLUP);
rt_pin_mode(u8x8->pins[U8X8_PIN_MENU_SELECT],PIN_MODE_INPUT_PULLUP);
rt_pin_mode(u8x8->pins[U8X8_PIN_MENU_PREV],PIN_MODE_INPUT_PULLUP);
rt_pin_mode(u8x8->pins[U8X8_PIN_MENU_NEXT],PIN_MODE_INPUT_PULLUP);
rt_pin_mode(u8x8->pins[U8X8_PIN_MENU_UP],PIN_MODE_INPUT_PULLUP);
rt_pin_mode(u8x8->pins[U8X8_PIN_MENU_DOWN],PIN_MODE_INPUT_PULLUP);
// set value
rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK],1);
rt_pin_write(u8x8->pins[U8X8_PIN_SPI_DATA],1);
@ -110,7 +118,7 @@ uint8_t u8x8_rt_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
rt_pin_write(u8x8->pins[U8X8_PIN_DC],1);
rt_pin_write(u8x8->pins[U8X8_PIN_CS],1);
break;
case U8X8_MSG_DELAY_I2C:
// arg_int is the I2C speed in 100KHz, e.g. 4 = 400 KHz
// arg_int=1: delay by 5us, arg_int = 4: delay by 1.25us
@ -126,101 +134,107 @@ uint8_t u8x8_rt_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
//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);
case U8X8_MSG_GPIO_D2: // D2 pin: Output level in arg_int
rt_pin_write(u8x8->pins[U8X8_PIN_D2],arg_int);
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);
case U8X8_MSG_GPIO_D3: // D3 pin: Output level in arg_int
rt_pin_write(u8x8->pins[U8X8_PIN_D3], arg_int);
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);
case U8X8_MSG_GPIO_D4: // D4 pin: Output level in arg_int
rt_pin_write(u8x8->pins[U8X8_PIN_D4], arg_int);
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);
case U8X8_MSG_GPIO_D5: // D5 pin: Output level in arg_int
rt_pin_write(u8x8->pins[U8X8_PIN_D5], arg_int);
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);
case U8X8_MSG_GPIO_D6: // D6 pin: Output level in arg_int
rt_pin_write(u8x8->pins[U8X8_PIN_D6], arg_int);
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);
case U8X8_MSG_GPIO_D7: // D7 pin: Output level in arg_int
rt_pin_write(u8x8->pins[U8X8_PIN_D7], arg_int);
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);
case U8X8_MSG_GPIO_E: // E/WR pin: Output level in arg_int
rt_pin_write(u8x8->pins[U8X8_PIN_E], arg_int);
break;
case U8X8_MSG_GPIO_I2C_CLOCK:
// arg_int=0: Output low at I2C clock pin
// arg_int=1: Input dir with pullup high for 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);
rt_pin_write(u8x8->pins[U8X8_PIN_I2C_CLOCK], arg_int);
break;
case U8X8_MSG_GPIO_I2C_DATA:
// arg_int=0: Output low at I2C data pin
// arg_int=1: Input dir with pullup high for I2C data pin
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_I2C_DATA],1);
else rt_pin_write(u8x8->pins[U8X8_PIN_I2C_DATA],0);
break;
rt_pin_write(u8x8->pins[U8X8_PIN_I2C_DATA], arg_int);
break;
case U8X8_MSG_GPIO_SPI_CLOCK:
//Function to define the logic level of the clockline
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK],1);
else rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK],0);
// Function to define the logic level of the clockline
rt_pin_write(u8x8->pins[U8X8_PIN_SPI_CLOCK], arg_int);
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);
else rt_pin_write(u8x8->pins[U8X8_PIN_SPI_DATA],0);
// Function to define the logic level of the data line to the display
rt_pin_write(u8x8->pins[U8X8_PIN_SPI_DATA], arg_int);
break;
case U8X8_MSG_GPIO_CS:
// Function to define the logic level of the CS line
if(arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_CS],1);
else rt_pin_write(u8x8->pins[U8X8_PIN_CS],0);
rt_pin_write(u8x8->pins[U8X8_PIN_CS], arg_int);
break;
case U8X8_MSG_GPIO_DC:
//Function to define the logic level of the Data/ Command line
if(arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_DC],1);
else rt_pin_write(u8x8->pins[U8X8_PIN_DC],0);
// Function to define the logic level of the Data/ Command line
rt_pin_write(u8x8->pins[U8X8_PIN_DC], arg_int);
break;
case U8X8_MSG_GPIO_RESET:
//Function to define the logic level of the RESET line
if (arg_int) rt_pin_write(u8x8->pins[U8X8_PIN_RESET],1);
else rt_pin_write(u8x8->pins[U8X8_PIN_RESET],0);
// Function to define the logic level of the RESET line
rt_pin_write(u8x8->pins[U8X8_PIN_RESET], arg_int);
break;
default:
//A message was received which is not implemented, return 0 to indicate an error
return 0;
if ( msg >= U8X8_MSG_GPIO(0) )
{
i = u8x8_GetPinValue(u8x8, msg);
if ( i != U8X8_PIN_NONE )
{
if ( u8x8_GetPinIndex(u8x8, msg) < U8X8_PIN_OUTPUT_CNT )
{
rt_pin_write(i, arg_int);
}
else
{
if ( u8x8_GetPinIndex(u8x8, msg) == U8X8_PIN_OUTPUT_CNT )
{
// call yield() for the first pin only, u8x8 will always request all the pins, so this should be ok
// yield();
}
u8x8_SetGPIOResult(u8x8, rt_pin_read(i) == 0 ? 0 : 1);
}
}
break;
}
return 0;
}
return 1;
}
#if defined U8G2_USE_HW_I2C
uint8_t u8x8_byte_rt_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
uint8_t u8x8_byte_rtthread_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
/* u8g2/u8x8 will never send more than 32 bytes between START_TRANSFER and END_TRANSFER */
struct rt_i2c_msg msgs;
static uint8_t buffer[32];
static uint8_t buf_idx;
uint8_t *data;
rt_uint8_t t = 0;
switch(msg)
{
@ -279,7 +293,7 @@ uint8_t u8x8_byte_rt_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *ar
#endif /* U8G2_USE_HW_I2C */
#if defined U8G2_USE_HW_SPI
uint8_t u8x8_byte_rt_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
uint8_t u8x8_byte_rtthread_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
struct rt_spi_message spi_msg;
switch(msg)
{
@ -308,7 +322,7 @@ uint8_t u8x8_byte_rt_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, vo
break;
case U8X8_MSG_BYTE_START_TRANSFER:
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
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;

View File

@ -1,21 +1,23 @@
#ifndef __U8G_PORT_H__
#define __U8G_PORT_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <rtthread.h>
#include <rtdevice.h>
#define U8X8_USE_PINS
#include <u8x8.h>
#include <u8g2.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define U8X8_USE_PINS
#define U8G2_USE_HW_I2C
#define U8G2_USE_HW_SPI
#if defined U8G2_USE_HW_SPI
#include <drv_spi.h>
#endif
#include <string.h>
#include <u8g2.h>
#include <u8x8.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#if defined U8G2_USE_HW_SPI
#ifndef U8G2_SPI_BUS_NAME
#define U8G2_SPI_BUS_NAME "spi1"
@ -25,20 +27,24 @@
#define U8G2_SPI_DEVICE_NAME "spi10"
#endif
uint8_t u8x8_byte_rt_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8x8_byte_rtthread_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
#endif
#if defined U8G2_USE_HW_I2C
#ifndef U8G2_I2C_DEVICE_NAME
#define U8G2_I2C_DEVICE_NAME "i2c1"
#define U8G2_I2C_DEVICE_NAME "i2c2"
#endif
uint8_t u8x8_byte_rt_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8x8_byte_rtthread_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
#endif
uint8_t u8x8_rt_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8x8_gpio_and_delay_rtthread(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
#ifdef __cplusplus
}
#endif
#endif /* __U8G_PORT_H__ */

View File

@ -0,0 +1,20 @@
#
# U8g2 codebuilder
#
CFLAGS = -g -Wall
#CFLAGS = -O4 -Wall
SRC = codebuild.c
OBJ = $(SRC:.c=.o)
codebuild: $(SRC)
$(CC) -Wall -g $(LDFLAGS) $(SRC) -o codebuild
clean:
-rm ./codebuild codebuild.o
build: codebuild
./codebuild

File diff suppressed because it is too large Load Diff