u8g2的STM32移植,附上一些图片取模和字体取模的方式。
- STM32移植
- 取模方式
- 制作自己的字体库
STM32移植
- 准备一个正常运行的STM32模板
- 下载 U8g2 的源码和 U8g2 的 STM32 实例模板
源码:https://github.com/olikraus/u8g2
STM32 实例模板:https://github.com/nikola-v/u8g2_template_stm32f103c8t6 - 去掉无用的驱动文件,只保留 u8x8_d_s**d1306_128x64_noname.c
- 精简 u8g2_d_setup.c,只保留 u8g2_Setup_ssd1306_i2c_128x64_noname_f ()
/* ssd1306 f */
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)
{uint8_t tile_buf_height;uint8_t *buf;u8g2_SetupDisplay(u8g2, u8x8_d_ssd1306_128x64_noname, u8x8_cad_ssd13xx_fast_i2c, byte_cb, gpio_and_delay_cb);buf = u8g2_m_16_8_f(&tile_buf_height);u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_vertical_top_lsb, rotation);
}
- 精简 u8g2_d_memory.c, 只保留 u8g2_m_16_8_f ()
uint8_t *u8g2_m_16_8_f(uint8_t *page_cnt)
{#ifdef U8G2_USE_DYNAMIC_ALLOC*page_cnt = 8;return 0;#elsestatic uint8_t buf[1024];*page_cnt = 8;return buf;#endif
}
- 对工程进行设置并剔除编译错误
- 写一下软件I2C的驱动
uint8_t u8g2_gpio_and_delay_stm32(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
{switch(msg){case U8X8_MSG_DELAY_MILLI://Function which implements a delay, arg_int contains the amount of msDelayxms(arg_int);break;case U8X8_MSG_DELAY_10MICRO://Function which delays 10usDelayxus(10);break;case U8X8_MSG_DELAY_100NANO://Function which delays 100ns__NOP();break;case U8X8_MSG_GPIO_I2C_CLOCK:if (arg_int) IIC_OLED_SCL_HIGH();else IIC_OLED_SCL_LOW();break;case U8X8_MSG_GPIO_I2C_DATA:if (arg_int) IIC_OLED_SDA_HIGH();else IIC_OLED_SDA_LOW();break;default:return 0; //A message was received which is not implemented, return 0 to indicate an error}return 1; // command processed successfully.
}
- 更改 u8x8_gpio_and_delay ()
uint8_t u8g2_gpio_and_delay_stm32(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
{switch(msg){case U8X8_MSG_DELAY_MILLI://Function which implements a delay, arg_int contains the amount of msDelayxms(arg_int);break;case U8X8_MSG_DELAY_10MICRO://Function which delays 10usDelayxus(10);break;case U8X8_MSG_DELAY_100NANO://Function which delays 100ns__NOP();break;case U8X8_MSG_GPIO_I2C_CLOCK:if (arg_int) IIC_OLED_SCL_HIGH();else IIC_OLED_SCL_LOW();break;case U8X8_MSG_GPIO_I2C_DATA:if (arg_int) IIC_OLED_SDA_HIGH();else IIC_OLED_SDA_LOW();break;default:return 0; //A message was received which is not implemented, return 0 to indicate an error}return 1; // command processed successfully.
}
取模方式
我们如果需要加在图片和特殊字这些需要通过bmp文件取模。
取模这里用的工具是PCtoLCD2002,网上有很多,具体配置如下。
制作自己的字体库
如果需要制作自己的字体库,参考以下两篇文章。
个人已经成功验证了。
https://blog.csdn.net/acktomas/article/details/132188367
添加链接描述