ssd1306_12864_4wire_sw_spi_example.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  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_CLK 5 // PA5
  8. #define OLED_SPI_PIN_MOSI 7 // PA7
  9. #define OLED_SPI_PIN_RES 2 // PA2
  10. #define OLED_SPI_PIN_DC 1 // PA1
  11. #define OLED_SPI_PIN_CS 0 // PA0
  12. // Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
  13. static U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0,\
  14. /* clock=*/ OLED_SPI_PIN_CLK,\
  15. /* data=*/ OLED_SPI_PIN_MOSI,\
  16. /* cs=*/ OLED_SPI_PIN_CS,\
  17. /* dc=*/ OLED_SPI_PIN_DC,\
  18. /* reset=*/ OLED_SPI_PIN_RES);
  19. static void u8g2_ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[])
  20. {
  21. u8g2.begin();
  22. u8g2.clearBuffer(); // clear the internal memory
  23. u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
  24. u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
  25. u8g2.sendBuffer(); // transfer internal memory to the display
  26. u8g2.setFont(u8g2_font_unifont_t_symbols);
  27. u8g2.drawGlyph(112, 56, 0x2603 );
  28. u8g2.sendBuffer();
  29. }
  30. MSH_CMD_EXPORT(u8g2_ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample);