• 基于STM32的u8g2移植以及学习


     实验硬件:STM32F103C8T6;0.96寸OLED(128×64)

     U8g2库开源网址:https://github.com/olikraus/u8g2

    一、u8g2库知识

    1.1 什么是u8g2?

            U8g2是嵌入式设备的单色图形库。主要应用于嵌入式设备,包括我们常见的单片机使用,最常用的是OLED屏或者LCD屏进行使用的一个库;

            我们常用的OLED屏其内部原理一个M x n 的像素点阵,想显示什么就得把具体位置的像素点亮起来。对于每一个像素点,有可能是1点亮,也有可能是0点亮;

    其坐标系如下所示

    1.2  u8g2支持的驱动

            U8g2支持单色OLED和LCD,包括以下控制器:SSD1305,SSD1306,SSD1309,SSD1322,SSD1325,SSD1327,SSD1329,SSD1606,SSD1607,SH1106,SH1107,SH1108,SH1122,T6963,RA8835,LC7981,PCD8544,PCF8812,HX1230 ,UC1601,UC1604,UC1608,UC1610,UC1611,UC1701,ST7565,ST7567,ST7588,ST75256,NT7534,IST3020,ST7920,LD7032,KS0108,SED1520,SBN1661,IL3820,MAX7219(有关完整列表,请参见 此处)。可以说,基本上主流的显示控制器都支持,比如我们常见的SSD1306 12864,读者在使用该库之前请查阅自己的OLED显示控制器是否处于支持列表中。

    1.3 u8g2库的优势

            为什么要运用U8g2库?也就是说U8g2库能带给我们什么样的开发便利。在博主看来,主要考虑几个方面:

    1、U8g2库平台支持性好,基本上支持绝大部分开发板,如51单片机、STM32单片机;
    2、U8g2库显示控制器支持性好,基本上市面上的OLED和lLCD都完美支持;
    3、U8g2库 API众多,特别支持了中文,支持了不同字体,对于开发者俩说不小的福利。

    因为u8g2内部包含很多不同屏幕驱动的接口,入下(这还是部分接口)

    1. void u8g2_Setup_ssd1305_128x32_noname_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    2. void u8g2_Setup_ssd1305_128x32_adafruit_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    3. void u8g2_Setup_ssd1305_128x32_noname_2(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    4. void u8g2_Setup_ssd1305_128x32_adafruit_2(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    5. void u8g2_Setup_ssd1305_128x32_noname_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    6. void u8g2_Setup_ssd1305_128x32_adafruit_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    7. void u8g2_Setup_ssd1305_i2c_128x32_noname_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    8. void u8g2_Setup_ssd1305_i2c_128x32_adafruit_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    9. void u8g2_Setup_ssd1305_i2c_128x32_noname_2(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    10. void u8g2_Setup_ssd1305_i2c_128x32_adafruit_2(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    11. void u8g2_Setup_ssd1305_i2c_128x32_noname_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    12. void u8g2_Setup_ssd1305_i2c_128x32_adafruit_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    13. void u8g2_Setup_ssd1305_128x64_adafruit_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    14. void u8g2_Setup_ssd1305_128x64_raystar_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    15. void u8g2_Setup_ssd1305_128x64_adafruit_2(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    16. void u8g2_Setup_ssd1305_128x64_raystar_2(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    17. void u8g2_Setup_ssd1305_128x64_adafruit_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);
    18. void u8g2_Setup_ssd1305_128x64_raystar_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb);

            其实,我们可以把U8g2当作一个工具箱,需要使用的时候就去打开工具箱,使用里面的已经写好的API函数去实现我们需要达到的显示效果。(当然,前提是需要熟悉U8g2的使用,这一点网上有很多用法博客写得都很详细,感兴趣的读者朋友可以去看看)

    二、CubexMX配置

            在移植U8g2库之前,我们需要使用CubeMX软件配置一下MCU的部分功能。特别注意:U8g2图形库自带兼容的IC控制驱动程序,所以移植完成后不需要自己在写OLED或是LCD的驱动 

    1、RCC配置外部高速晶振(精度更高)——HSE;

     

    2、SYS配置:Debug设置成Serial Wire(否则可能导致芯片自锁);

    3、I2C2配置:作为OLED的通讯方式;

    4、TIM1配置:U8g2图形库需要us级延迟推动(U8g2的心跳)

    5、时钟树配置:

    6、工程配置 

    三、U8g2移植

    3.1 准备U8g2库文件

            移植U8g2图像库需要准备好,U8g2的源码是在GitHub上开源的。

            U8g2下载地址: https://github.com/olikraus/u8g2如果打开不了读者朋友,可以评论区留言邮箱笔者有时间会发送过去

    进入源码地址后下载整个U8g2图形库的压缩包

    3.2 精简U8g2库文件

            U8g2支持多种显示驱动的屏幕,因为源码中也包含了各个驱动对应的文件(所以不需要自己去写屏幕底层驱动了),为了减小整个工程的代码体积,在移植U8g2时,可以删除一些无用的文件。这里我们主要关注的是U8g2库文件中的csrc文件

    3.2.1 去掉无用的驱动文件

            这些驱动文件通常是u8x8_d_xxx.cxxx包括驱动的型号屏幕分辨率ssd1306驱动芯片的OLED,使用u8x8_ssd1306_128x64_noname.c这个文件,其它的屏幕驱动和分辨率的文件可以删掉。

    3.2.2 精简u8g2_d_setup.c 

            由于笔者的OLED是IIC接口,只留一个u8g2_Setup_ssd1306_i2c_128x64_noname_f就好(如果是SPI接口,需要使用u8g2_Setup_ssd1306_128x64_noname_f这个函数),其它的可以删掉或注释掉。

    将里面的内容全部删除,复制下面的内容到里面去

    1. #include "u8g2.h"
    2. #include "tim.h"
    3. /* ssd1306 f */
    4. void u8g2_Setup_ssd1306_i2c_128x64_noname_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb)
    5. {
    6. uint8_t tile_buf_height;
    7. uint8_t *buf;
    8. u8g2_SetupDisplay(u8g2, u8x8_d_ssd1306_128x64_noname, u8x8_cad_ssd13xx_fast_i2c, byte_cb, gpio_and_delay_cb);
    9. buf = u8g2_m_16_8_f(&tile_buf_height);
    10. u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_vertical_top_lsb, rotation);
    11. }

    注意,与这个函数看起来十分相似的函数的有:

    • u8g2_Setup_ssd1306_128x64_noname_1
    • u8g2_Setup_ssd1306_128x64_noname_2
    • u8g2_Setup_ssd1306_128x64_noname_f
    • u8g2_Setup_ssd1306_i2c_128x64_noname_1
    • u8g2_Setup_ssd1306_i2c_128x64_noname_2
    • u8g2_Setup_ssd1306_i2c_128x64_noname_f

    其中,前面3个,是给SPI接口的OLED用的,函数最后的数字或字母,代表显示时的buf大小:

    • 1:128字节
    • 2:256字节
    • f:1024字节

    3.2.3 精简u8g2_d_memory.c

             由于用u8g2_Setup_ssd1306_i2c_128x64_noname_f函数,只调用u8g2_m_16_8_f这个函数,所以留下这个函数,其它的函数一定要删掉或注释掉,否则编译时很可能会提示内存不足!!

     直接将u8g2_d_memory.c全选,复制下面的内容也是可以的

    1. #include "u8g2.h"
    2. uint8_t *u8g2_m_16_8_f(uint8_t *page_cnt)
    3. {
    4. #ifdef U8G2_USE_DYNAMIC_ALLOC
    5. *page_cnt = 8;
    6. return 0;
    7. #else
    8. static uint8_t buf[1024];
    9. *page_cnt = 8;
    10. return buf;
    11. #endif
    12. }

    3.3 将精简后的U8g2库添加至Keil

            左侧Keil工程目录添加自己精简后U8g2库文件中的csrc文件,然后再添加U8g2的头文件搜寻目录(U8g2里面都是csrc文件里面的文件,读者朋友可以根据自己的需要删减),如下:

    四、代码

    4.1 编写移植函数

    stm32_u8g2.h:

    1. #ifndef __STM32_U8G2_H
    2. #define __STM32_U8G2_H
    3. /* Includes ------------------------------------------------------------------*/
    4. #include "main.h"
    5. #include "u8g2.h"
    6. /* USER CODE BEGIN Includes */
    7. /* USER CODE END Includes */
    8. /* USER CODE BEGIN Private defines */
    9. /* USER CODE END Private defines */
    10. #define u8 unsigned char // ?unsigned char ????
    11. #define MAX_LEN 128 //
    12. #define OLED_ADDRESS 0x78 // oled
    13. #define OLED_CMD 0x00 //
    14. #define OLED_DATA 0x40 //
    15. /* USER CODE BEGIN Prototypes */
    16. uint8_t u8x8_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
    17. uint8_t u8x8_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
    18. void u8g2Init(u8g2_t *u8g2);
    19. void draw(u8g2_t *u8g2);
    20. void testDrawPixelToFillScreen(u8g2_t *u8g2);
    21. #endif

     stm32_u8g2.c:

    1. #include "stm32_u8g2.h"
    2. #include "tim.h"
    3. #include "i2c.h"
    4. uint8_t u8x8_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
    5. {
    6. /* u8g2/u8x8 will never send more than 32 bytes between START_TRANSFER and END_TRANSFER */
    7. static uint8_t buffer[128];
    8. static uint8_t buf_idx;
    9. uint8_t *data;
    10. switch (msg)
    11. {
    12. case U8X8_MSG_BYTE_INIT:
    13. {
    14. /* add your custom code to init i2c subsystem */
    15. MX_I2C2_Init(); //I2C初始化
    16. }
    17. break;
    18. case U8X8_MSG_BYTE_START_TRANSFER:
    19. {
    20. buf_idx = 0;
    21. }
    22. break;
    23. case U8X8_MSG_BYTE_SEND:
    24. {
    25. data = (uint8_t *)arg_ptr;
    26. while (arg_int > 0)
    27. {
    28. buffer[buf_idx++] = *data;
    29. data++;
    30. arg_int--;
    31. }
    32. }
    33. break;
    34. case U8X8_MSG_BYTE_END_TRANSFER:
    35. {
    36. if (HAL_I2C_Master_Transmit(&hi2c2, OLED_ADDRESS, buffer, buf_idx, 1000) != HAL_OK)
    37. return 0;
    38. }
    39. break;
    40. case U8X8_MSG_BYTE_SET_DC:
    41. break;
    42. default:
    43. return 0;
    44. }
    45. return 1;
    46. }
    47. uint8_t u8x8_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
    48. {
    49. switch (msg)
    50. {
    51. case U8X8_MSG_DELAY_100NANO: // delay arg_int * 100 nano seconds
    52. __NOP();
    53. break;
    54. case U8X8_MSG_DELAY_10MICRO: // delay arg_int * 10 micro seconds
    55. for (uint16_t n = 0; n < 320; n++)
    56. {
    57. __NOP();
    58. }
    59. break;
    60. case U8X8_MSG_DELAY_MILLI: // delay arg_int * 1 milli second
    61. HAL_Delay(1);
    62. break;
    63. case U8X8_MSG_DELAY_I2C: // arg_int is the I2C speed in 100KHz, e.g. 4 = 400 KHz
    64. Tims_delay_us(5);
    65. break; // arg_int=1: delay by 5us, arg_int = 4: delay by 1.25us
    66. case U8X8_MSG_GPIO_I2C_CLOCK: // arg_int=0: Output low at I2C clock pin
    67. break; // arg_int=1: Input dir with pullup high for I2C clock pin
    68. case U8X8_MSG_GPIO_I2C_DATA: // arg_int=0: Output low at I2C data pin
    69. break; // arg_int=1: Input dir with pullup high for I2C data pin
    70. case U8X8_MSG_GPIO_MENU_SELECT:
    71. u8x8_SetGPIOResult(u8x8, /* get menu select pin state */ 0);
    72. break;
    73. case U8X8_MSG_GPIO_MENU_NEXT:
    74. u8x8_SetGPIOResult(u8x8, /* get menu next pin state */ 0);
    75. break;
    76. case U8X8_MSG_GPIO_MENU_PREV:
    77. u8x8_SetGPIOResult(u8x8, /* get menu prev pin state */ 0);
    78. break;
    79. case U8X8_MSG_GPIO_MENU_HOME:
    80. u8x8_SetGPIOResult(u8x8, /* get menu home pin state */ 0);
    81. break;
    82. default:
    83. u8x8_SetGPIOResult(u8x8, 1); // default return value
    84. break;
    85. }
    86. return 1;
    87. }
    88. //U8g2的初始化,需要调用下面这个u8g2_Setup_ssd1306_128x64_noname_f函数,该函数的4个参数含义:
    89. //u8g2:传入的U8g2结构体
    90. //U8G2_R0:默认使用U8G2_R0即可(用于配置屏幕是否要旋转)
    91. //u8x8_byte_sw_i2c:使用软件IIC驱动,该函数由U8g2源码提供
    92. //u8x8_gpio_and_delay:就是上面我们写的配置函数
    93. void u8g2Init(u8g2_t *u8g2)
    94. {
    95. u8g2_Setup_ssd1306_i2c_128x64_noname_f(u8g2, U8G2_R0, u8x8_byte_hw_i2c, u8x8_gpio_and_delay); // 初始化u8g2 结构体
    96. u8g2_InitDisplay(u8g2); //
    97. u8g2_SetPowerSave(u8g2, 0); //
    98. u8g2_ClearBuffer(u8g2);
    99. }
    100. void draw(u8g2_t *u8g2)
    101. {
    102. u8g2_ClearBuffer(u8g2);
    103. u8g2_SetFontMode(u8g2, 1); /*字体模式选择*/
    104. u8g2_SetFontDirection(u8g2, 0); /*字体方向选择*/
    105. u8g2_SetFont(u8g2, u8g2_font_inb24_mf); /*字库选择*/
    106. u8g2_DrawStr(u8g2, 0, 20, "U");
    107. u8g2_SetFontDirection(u8g2, 1);
    108. u8g2_SetFont(u8g2, u8g2_font_inb30_mn);
    109. u8g2_DrawStr(u8g2, 21,8,"8");
    110. u8g2_SetFontDirection(u8g2, 0);
    111. u8g2_SetFont(u8g2, u8g2_font_inb24_mf);
    112. u8g2_DrawStr(u8g2, 51,30,"g");
    113. u8g2_DrawStr(u8g2, 67,30,"\xb2");
    114. u8g2_DrawHLine(u8g2, 2, 35, 47);
    115. u8g2_DrawHLine(u8g2, 3, 36, 47);
    116. u8g2_DrawVLine(u8g2, 45, 32, 12);
    117. u8g2_DrawVLine(u8g2, 46, 33, 12);
    118. u8g2_SetFont(u8g2, u8g2_font_4x6_tr);
    119. u8g2_DrawStr(u8g2, 1,54,"github.com/olikraus/u8g2");
    120. u8g2_SendBuffer(u8g2);
    121. HAL_Delay(1000);
    122. }
    123. //画点填充
    124. void testDrawPixelToFillScreen(u8g2_t *u8g2)
    125. {
    126. int t = 1000;
    127. u8g2_ClearBuffer(u8g2);
    128. for (int j = 0; j < 64; j++)
    129. {
    130. for (int i = 0; i < 128; i++)
    131. {
    132. u8g2_DrawPixel(u8g2,i, j);
    133. }
    134. }
    135. HAL_Delay(1000);
    136. }

            上述编写的移植函数代码属于HAL库下的代码,有个别地方需要注意修改。有一定MCU编程基础的朋友应该很简单就可以做到仿写,如果有疑问可以留言。移植代码的本质:这些函数代码就是对应的U8g2图形库的接口函数,通过这些函数去启用U8g2图形库。

    4.2 U8g2图形库测试函数

    测试文件stm32_test.c

    1. #include "u8g2_test.h"
    2. //---------------U8g2测试函数
    3. #define SEND_BUFFER_DISPLAY_MS(u8g2, ms)\
    4. do {\
    5. u8g2_SendBuffer(u8g2); \
    6. HAL_Delay(ms);\
    7. }while(0);
    8. //进度条显示
    9. void testDrawProcess(u8g2_t *u8g2)
    10. {
    11. for(int i=10;i<=80;i=i+2)
    12. {
    13. u8g2_ClearBuffer(u8g2);
    14. char buff[20];
    15. sprintf(buff,"%d%%",(int)(i/80.0*100));
    16. u8g2_SetFont(u8g2,u8g2_font_ncenB12_tf);
    17. u8g2_DrawStr(u8g2,16,32,"STM32 U8g2");//字符显示
    18. u8g2_SetFont(u8g2,u8g2_font_ncenB08_tf);
    19. u8g2_DrawStr(u8g2,100,49,buff);//当前进度显示
    20. u8g2_DrawRBox(u8g2,16,40,i,10,4);//圆角填充框矩形框
    21. u8g2_DrawRFrame(u8g2,16,40,80,10,4);//圆角矩形
    22. u8g2_SendBuffer(u8g2);
    23. }
    24. HAL_Delay(500);
    25. }
    26. //字体测试 数字英文可选用 u8g2_font_ncenB..(粗) 系列字体
    27. //u8g2_font_unifont_t_symbols/u8g2_font_unifont_h_symbols(细 圆润)
    28. void testShowFont(u8g2_t *u8g2)
    29. {
    30. int t = 1000;
    31. char testStr[14] = "STM32F103C8T6";
    32. u8g2_ClearBuffer(u8g2);
    33. u8g2_SetFont(u8g2,u8g2_font_u8glib_4_tf);
    34. u8g2_DrawStr(u8g2,0,5,testStr);
    35. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    36. u8g2_SetFont(u8g2,u8g2_font_ncenB08_tf);
    37. u8g2_DrawStr(u8g2,0,30,testStr);
    38. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    39. u8g2_SetFont(u8g2,u8g2_font_ncenB10_tr);
    40. u8g2_DrawStr(u8g2,0,60,testStr);
    41. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    42. }
    43. //画空心矩形
    44. void testDrawFrame(u8g2_t *u8g2)
    45. {
    46. int t = 1000;
    47. int x = 16;
    48. int y = 32;
    49. int w = 50;
    50. int h = 20;
    51. u8g2_ClearBuffer(u8g2);
    52. u8g2_DrawStr(u8g2,0, 15, "DrawFrame");
    53. u8g2_DrawFrame(u8g2, x, y, w, h);
    54. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    55. u8g2_DrawFrame(u8g2, x+w+5, y-10, w-20, h+20);
    56. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    57. }
    58. //画实心圆角矩形
    59. void testDrawRBox(u8g2_t *u8g2)
    60. {
    61. int t = 1000;
    62. int x = 16;
    63. int y = 32;
    64. int w = 50;
    65. int h = 20;
    66. int r = 3;
    67. u8g2_ClearBuffer(u8g2);
    68. u8g2_DrawStr(u8g2,0, 15, "DrawRBox");
    69. u8g2_DrawRBox(u8g2, x, y, w, h, r);
    70. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    71. u8g2_DrawRBox(u8g2, x+w+5, y-10, w-20, h+20, r);
    72. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    73. }
    74. //画空心圆
    75. void testDrawCircle(u8g2_t *u8g2)
    76. {
    77. int t = 600;
    78. int stx = 0; //画图起始x
    79. int sty = 16; //画图起始y
    80. int with = 16;//一个图块的间隔
    81. int r = 15; //圆的半径
    82. u8g2_ClearBuffer(u8g2);
    83. u8g2_DrawStr(u8g2, 0, 15, "DrawCircle");
    84. u8g2_DrawCircle(u8g2, stx, sty - 1 + with, r, U8G2_DRAW_UPPER_RIGHT); //右上
    85. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    86. u8g2_DrawCircle(u8g2, stx + with, sty, r, U8G2_DRAW_LOWER_RIGHT); //右下
    87. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    88. u8g2_DrawCircle(u8g2, stx - 1 + with * 3, sty - 1 + with, r, U8G2_DRAW_UPPER_LEFT); //左上
    89. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    90. u8g2_DrawCircle(u8g2, stx - 1 + with * 4, sty, r, U8G2_DRAW_LOWER_LEFT); //左下
    91. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    92. u8g2_DrawCircle(u8g2, stx - 1 + with * 2, sty - 1 + with * 2, r, U8G2_DRAW_ALL);//整个圆
    93. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    94. u8g2_DrawCircle(u8g2, 32*3, 32, 31, U8G2_DRAW_ALL);//右侧整个圆
    95. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    96. }
    97. //画实心椭圆
    98. void testDrawFilledEllipse(u8g2_t *u8g2)
    99. {
    100. int t = 800;
    101. int with = 16;//一个图块的间隔
    102. int rx = 27; //椭圆x方向的半径
    103. int ry = 22; //椭圆y方向的半径
    104. u8g2_ClearBuffer(u8g2);
    105. u8g2_DrawStr(u8g2,0, 14, "DrawFilledEllipse");
    106. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    107. u8g2_DrawFilledEllipse(u8g2, 0, with, rx, ry, U8G2_DRAW_LOWER_RIGHT);//右下
    108. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    109. u8g2_DrawFilledEllipse(u8g2, with * 4 - 1, with, rx, ry, U8G2_DRAW_LOWER_LEFT); //左下
    110. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    111. u8g2_DrawFilledEllipse(u8g2, 0, with * 4 - 1, rx, ry, U8G2_DRAW_UPPER_RIGHT); //右上
    112. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    113. u8g2_DrawFilledEllipse(u8g2, with * 4 - 1, with * 4 - 1, rx, ry, U8G2_DRAW_UPPER_LEFT); //左上
    114. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    115. u8g2_DrawFilledEllipse(u8g2, with * 6, with * 2.5, rx, ry, U8G2_DRAW_ALL);//整个椭圆
    116. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    117. }
    118. //环形测试
    119. void testDrawMulti(u8g2_t *u8g2)
    120. {
    121. u8g2_ClearBuffer(u8g2);
    122. for (int j = 0; j < 64; j+=16)
    123. {
    124. for (int i = 0; i < 128; i+=16)
    125. {
    126. u8g2_DrawPixel(u8g2, i, j);
    127. u8g2_SendBuffer(u8g2);
    128. }
    129. }
    130. //实心矩形逐渐变大
    131. u8g2_ClearBuffer(u8g2);
    132. for(int i=30; i>0; i-=2)
    133. {
    134. u8g2_DrawBox(u8g2,i*2,i,128-i*4,64-2*i);
    135. u8g2_SendBuffer(u8g2);
    136. }
    137. //空心矩形逐渐变小
    138. u8g2_ClearBuffer(u8g2);
    139. for(int i=0; i<32; i+=2)
    140. {
    141. u8g2_DrawFrame(u8g2,i*2,i,128-i*4,64-2*i);
    142. u8g2_SendBuffer(u8g2);
    143. }
    144. //实心圆角矩形逐渐变大
    145. u8g2_ClearBuffer(u8g2);
    146. for(int i=30; i>0; i-=2)
    147. {
    148. u8g2_DrawRBox(u8g2,i*2,i,128-i*4,64-2*i,10-i/3);
    149. u8g2_SendBuffer(u8g2);
    150. }
    151. //空心圆角矩形逐渐变小
    152. u8g2_ClearBuffer(u8g2);
    153. for(int i=0; i<32; i+=2)
    154. {
    155. u8g2_DrawRFrame(u8g2,i*2,i,128-i*4,64-2*i,10-i/3);
    156. u8g2_SendBuffer(u8g2);
    157. }
    158. //实心圆逐渐变大
    159. u8g2_ClearBuffer(u8g2);
    160. for(int i=2; i<64; i+=3)
    161. {
    162. u8g2_DrawDisc(u8g2,64,32,i, U8G2_DRAW_ALL);
    163. u8g2_SendBuffer(u8g2);
    164. }
    165. //空心圆逐渐变小
    166. u8g2_ClearBuffer(u8g2);
    167. for(int i=64; i>0; i-=3)
    168. {
    169. u8g2_DrawCircle(u8g2,64,32,i, U8G2_DRAW_ALL);
    170. u8g2_SendBuffer(u8g2);
    171. }
    172. //实心椭圆逐渐变大
    173. u8g2_ClearBuffer(u8g2);
    174. for(int i=2; i<32; i+=3)
    175. {
    176. u8g2_DrawFilledEllipse(u8g2,64,32, i*2, i, U8G2_DRAW_ALL);
    177. u8g2_SendBuffer(u8g2);
    178. }
    179. //空心椭圆逐渐变小
    180. u8g2_ClearBuffer(u8g2);
    181. for(int i=32; i>0; i-=3)
    182. {
    183. u8g2_DrawEllipse(u8g2,64,32, i*2, i, U8G2_DRAW_ALL);
    184. u8g2_SendBuffer(u8g2);
    185. }
    186. }
    187. // width: 128, height: 48
    188. const unsigned char bilibili[] U8X8_PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0xe0, 0x03, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0xf0, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x01, 0xfc, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x03, 0xfc, 0x00, 0x00, 0x3c, 0xc0, 0x0f, 0x00, 0x80, 0x03, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x07, 0xfc, 0x00, 0x00, 0x3c, 0xc0, 0x0f, 0x00, 0xc0, 0x07, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfc, 0x00, 0x00, 0x3c, 0x80, 0x0f, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0xf8, 0x00, 0x00, 0x3c, 0x80, 0x0f, 0x00, 0x80, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x78, 0x80, 0x0f, 0x00, 0x80, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x78, 0x80, 0x0f, 0x00, 0x80, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x80, 0x79, 0x80, 0x0f, 0x00, 0x98, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0xe0, 0x79, 0x9f, 0x0f, 0x00, 0xbe, 0xe7, 0x01, 0xc0, 0x07, 0x10, 0x40, 0x00, 0x1f, 0xf8, 0x00, 0xe0, 0x7b, 0x1f, 0x0f, 0x00, 0xbe, 0xe7, 0x01, 0xc0, 0x87, 0x1f, 0xe0, 0x0f, 0x1f, 0xf8, 0x00, 0xe0, 0x7b, 0x1e, 0x0f, 0x00, 0x3e, 0xe7, 0x01, 0xc0, 0xe7, 0x3f, 0xe0, 0x3f, 0x1f, 0xf0, 0x00, 0xe0, 0x7b, 0x1e, 0x0f, 0x00, 0x3e, 0xe7, 0x01, 0xc0, 0xe7, 0x3f, 0xe0, 0x3f, 0x1f, 0xf0, 0x00, 0x60, 0x71, 0x1e, 0x0f, 0x00, 0x34, 0xe7, 0x01, 0xc0, 0xe7, 0x07, 0x00, 0x3f, 0x1f, 0xf0, 0x00, 0x00, 0x70, 0x00, 0x1f, 0x00, 0x00, 0x07, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0xc0, 0x73, 0x1e, 0x1f, 0x00, 0x3c, 0xc7, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0xc0, 0x73, 0x1e, 0x1f, 0x00, 0x7c, 0xe7, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0xc0, 0x73, 0x1e, 0x1f, 0x00, 0x7c, 0xef, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x01, 0xc0, 0x77, 0x1e, 0x1e, 0x00, 0x7c, 0xef, 0x01, 0xc0, 0x07, 0x00, 0x03, 0x00, 0x1f, 0xf0, 0xff, 0xc1, 0xf7, 0x1e, 0xfe, 0x1f, 0x78, 0xef, 0x01, 0xc0, 0x07, 0x70, 0x37, 0x00, 0x1f, 0xe0, 0xff, 0x87, 0xf7, 0x1e, 0xfe, 0xff, 0x78, 0xee, 0x01, 0xc0, 0x07, 0xe0, 0x3f, 0x00, 0x1f, 0xe0, 0xff, 0x9f, 0xf7, 0x1e, 0xfe, 0xff, 0x79, 0xce, 0x01, 0xc0, 0x07, 0xc0, 0x18, 0x00, 0x1f, 0xe0, 0xff, 0xbf, 0xe7, 0x1e, 0xfe, 0xff, 0x7b, 0xce, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0xc7, 0xbf, 0xe7, 0x1e, 0xfe, 0xf8, 0x77, 0xce, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x0f, 0x3f, 0xe7, 0x1c, 0xfe, 0xf0, 0x77, 0xce, 0x03, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0xcf, 0x3f, 0xe7, 0x1c, 0xfe, 0xf8, 0xf3, 0xce, 0x03, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xef, 0x1f, 0xe7, 0x1c, 0xfe, 0xfe, 0xf1, 0xce, 0x03, 0x80, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0x0f, 0xcf, 0x1c, 0xfc, 0xff, 0xf0, 0xc0, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0x07, 0xe0, 0xff, 0x03, 0x06, 0x1c, 0xfc, 0x7f, 0x60, 0xc0, 0x01, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x03, 0xe0, 0xff, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    189. // width: 128, height: 48
    190. const unsigned char three_support[] U8X8_PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x80, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0x80, 0x0f, 0xf0, 0x01, 0x00, 0x00, 0xfc, 0xff, 0x01, 0x00, 0x00, 0xc0, 0xfd, 0xff, 0x00, 0x00, 0xc0, 0x7f, 0xfe, 0x01, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x01, 0x00, 0xc0, 0x1f, 0xf8, 0x03, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x01, 0x00, 0xc0, 0x0f, 0xf0, 0x03, 0x00, 0x00, 0xfe, 0xff, 0x07, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x01, 0x00, 0xc0, 0x67, 0xe6, 0x03, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x01, 0x00, 0xc0, 0x67, 0xe6, 0x03, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x00, 0x00, 0xc0, 0x67, 0xe6, 0x03, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x00, 0x00, 0xc0, 0x67, 0xee, 0x03, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x00, 0x00, 0x80, 0x7f, 0xfe, 0x01, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0xff, 0x00, 0x00, 0x80, 0x7f, 0xfe, 0x01, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x7f, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x00, 0x00, 0x00, 0xf8, 0xf9, 0x01, 0x00, 0x00, 0xe0, 0xfd, 0x7f, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0x00, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0xe0, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    191. void testDrawXBM(u8g2_t *u8g2)
    192. {
    193. int t = 1000;
    194. u8g2_ClearBuffer(u8g2);
    195. u8g2_DrawStr(u8g2,0, 14, "DrawXBM");
    196. u8g2_DrawXBM(u8g2,0, 16, 128, 48, bilibili);
    197. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    198. u8g2_ClearBuffer(u8g2);
    199. u8g2_DrawStr(u8g2,0, 14, "bilibili");
    200. u8g2_DrawXBM(u8g2,0, 16, 128, 48, three_support);
    201. SEND_BUFFER_DISPLAY_MS(u8g2,t);
    202. }
    203. void u8g2DrawTest(u8g2_t *u8g2)
    204. {
    205. testDrawProcess(u8g2);
    206. testDrawMulti(u8g2);
    207. //testDrawFrame(u8g2);
    208. //testDrawRBox(u8g2);
    209. //testDrawCircle(u8g2);
    210. //testDrawFilledEllipse(u8g2);
    211. testShowFont(u8g2);
    212. testDrawXBM(u8g2);
    213. }

    u8g2_test.h

    1. #ifndef __U8G2_TEST_H
    2. #define __U8G2_TEST_H
    3. #include "main.h"
    4. #include "u8g2.h"
    5. #include <stdio.h>
    6. void testDrawProcess(u8g2_t *u8g2);
    7. void testShowFont(u8g2_t *u8g2);
    8. void testDrawFrame(u8g2_t *u8g2);
    9. void testDrawRBox(u8g2_t *u8g2);
    10. void testDrawCircle(u8g2_t *u8g2);
    11. void testDrawFilledEllipse(u8g2_t *u8g2);
    12. void testDrawMulti(u8g2_t *u8g2);
    13. void testDrawXBM(u8g2_t *u8g2);
    14. void u8g2DrawTest(u8g2_t *u8g2);
    15. #endif

    因为使用了TIM定时器作为心跳跳动,则需要添加以下代码

    tim.c 最后一个用户添加里面

    1. /* USER CODE BEGIN 1 */
    2. void Tims_delay_us(uint16_t nus)
    3. {
    4. __HAL_TIM_SET_COUNTER(DLY_TIM_Handle, 0);
    5. __HAL_TIM_ENABLE(DLY_TIM_Handle);
    6. while (__HAL_TIM_GET_COUNTER(DLY_TIM_Handle) < nus)
    7. {
    8. }
    9. __HAL_TIM_DISABLE(DLY_TIM_Handle);
    10. }
    11. /* USER CODE END 1 */

    tim.h进行声明

    1. /* USER CODE BEGIN Private defines */
    2. #define DLY_TIM_Handle (&htim1)
    3. void Tims_delay_us(uint16_t nus);
    4. /* USER CODE END Private defines */

    4.3 main函数:

    需要添加头文件

    1. /* USER CODE BEGIN Includes */
    2. #include "stm32_u8g2.h"
    3. #include "u8g2_test.h"
    4. /* USER CODE END Includes */
    1. int main(void)
    2. {
    3. /* USER CODE BEGIN 1 */
    4. u8g2_t u8g2;
    5. /* USER CODE END 1 */
    6. /* MCU Configuration--------------------------------------------------------*/
    7. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    8. HAL_Init();
    9. /* USER CODE BEGIN Init */
    10. /* USER CODE END Init */
    11. /* Configure the system clock */
    12. SystemClock_Config();
    13. /* USER CODE BEGIN SysInit */
    14. /* USER CODE END SysInit */
    15. /* Initialize all configured peripherals */
    16. MX_GPIO_Init();
    17. MX_I2C2_Init();
    18. MX_TIM1_Init();
    19. /* USER CODE BEGIN 2 */
    20. u8g2Init(&u8g2);
    21. /* USER CODE END 2 */
    22. /* Infinite loop */
    23. /* USER CODE BEGIN WHILE */
    24. while (1)
    25. {
    26. u8g2_FirstPage(&u8g2);
    27. do
    28. {
    29. draw(&u8g2);
    30. u8g2DrawTest(&u8g2);
    31. } while (u8g2_NextPage(&u8g2));
    32. /* USER CODE END WHILE */
    33. /* USER CODE BEGIN 3 */
    34. }
    35. /* USER CODE END 3 */
    36. }

    做到这里就可以进行工程编译,下载到单片机上面观察现象了。如下所示

     

    六、总结 
            U8g2图形库可以说目前小尺寸OLED首选的GUI,其可以呈现出的图形远不止上述测试中的图形,更多的功能还需要读者朋友们自己去好好发掘。优秀GUI的移植是一名合格嵌入式工程师必须掌握的技能之一,其可以达到大大缩短开发周期,优化UI界面等目的。LCD屏幕也存在类似的优秀开源GUI库,后续笔者会进行更新,感兴趣的读者朋友可以点波关注,感谢!!!

    代码开源

    链接:https://pan.baidu.com/s/16SCXGKyoBlVZwUR4bse6ug 提取码:93ig

  • 相关阅读:
    IDEA插件开发(25)--Color Scheme Management
    【RocketMQ】数据的清理机制
    蚂蚁金服杨军:蚂蚁数据分析平台的演进及数据分析方法的应用
    汇聚荣拼多多电商好不好?
    Mybatis对象分析
    C++ 内存管理 - primitives - 侯捷
    【QT+CUDA】QT中使用cuda,QT+VS+cuda下载安装配置
    什么蓝牙耳机适合运动、运动用的蓝牙耳机推荐
    R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化箱图、width参数自定义箱图中箱体的宽度
    微信小程序-蓝牙功能
  • 原文地址:https://blog.csdn.net/m0_51274562/article/details/127892817