u8g2-copy/sys/rt-thread/examples/ssd1306_12864_sw_i2c_example.c

33 lines
1.1 KiB
C
Raw Normal View History

2021-08-04 01:25:47 +08:00
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <u8g2_port.h>
2021-08-05 03:19:24 +08:00
#define OLED_I2C_PIN_SCL 22 // PB6
#define OLED_I2C_PIN_SDA 23 // PB7
2021-08-04 01:25:47 +08:00
2021-08-05 03:19:24 +08:00
static void u8g2_ssd1306_12864_sw_i2c_example(int argc,char *argv[])
2021-08-04 01:25:47 +08:00
{
u8g2_t u8g2;
// Initialization
2021-08-05 03:19:24 +08:00
u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_gpio_and_delay_rtthread);
2021-08-04 01:25:47 +08:00
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_CLOCK, OLED_I2C_PIN_SCL);
2021-08-05 03:19:24 +08:00
u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_DATA, OLED_I2C_PIN_SDA);
2021-08-04 01:25:47 +08:00
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_ncenB08_tr);
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);
}
2021-08-05 03:19:24 +08:00
MSH_CMD_EXPORT(u8g2_ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);