ssd1306_12864_4wire_hw_spi_example.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233
  1. #include <rthw.h>
  2. #include <rtthread.h>
  3. #include <rtdevice.h>
  4. #include <U8g2lib.h>
  5. // You may reference Drivers/drv_gpio.c for pinout
  6. // In u8x8.h #define U8X8_USE_PINS
  7. #define OLED_SPI_PIN_RES 2 // PA2
  8. #define OLED_SPI_PIN_DC 1 // PA1
  9. #define OLED_SPI_PIN_CS 0 // PA0
  10. // Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
  11. static U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0,
  12. /* cs=*/ OLED_SPI_PIN_CS,
  13. /* dc=*/ OLED_SPI_PIN_DC,
  14. /* reset=*/ OLED_SPI_PIN_RES);
  15. // same as the NONAME variant, but may solve the "every 2nd line skipped" problem
  16. static void u8g2_ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[])
  17. {
  18. u8g2.begin();
  19. u8g2.clearBuffer(); // clear the internal memory
  20. u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
  21. u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
  22. u8g2.setFont(u8g2_font_5x8_tr); // choose a suitable font
  23. u8g2.drawStr(1, 56, "2.29 Milestone"); // write something to the internal memory
  24. u8g2.sendBuffer(); // transfer internal memory to the display
  25. u8g2.setFont(u8g2_font_unifont_t_symbols);
  26. u8g2.drawGlyph(112, 56, 0x2603 );
  27. u8g2.sendBuffer();
  28. }
  29. MSH_CMD_EXPORT(u8g2_ssd1306_12864_4wire_hw_spi_example, hw 4wire spi ssd1306 sample);