ssd1306_12864_sw_i2c_example.c 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #include <rthw.h>
  2. #include <rtthread.h>
  3. #include <rtdevice.h>
  4. #include <u8g2_port.h>
  5. #define OLED_I2C_PIN_SCL 22 // PB6
  6. #define OLED_I2C_PIN_SDA 23 // PB7
  7. static void u8g2_ssd1306_12864_sw_i2c_example(int argc,char *argv[])
  8. {
  9. u8g2_t u8g2;
  10. // Initialization
  11. u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_gpio_and_delay_rtthread);
  12. u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_CLOCK, OLED_I2C_PIN_SCL);
  13. u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_DATA, OLED_I2C_PIN_SDA);
  14. u8g2_InitDisplay(&u8g2);
  15. u8g2_SetPowerSave(&u8g2, 0);
  16. // Draw Graphics
  17. /* full buffer example, setup procedure ends in _f */
  18. u8g2_ClearBuffer(&u8g2);
  19. u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr);
  20. u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread");
  21. u8g2_SendBuffer(&u8g2);
  22. u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
  23. u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
  24. u8g2_SendBuffer(&u8g2);
  25. }
  26. MSH_CMD_EXPORT(u8g2_ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);