# u8g2_stm32_sw_i2c2 **Repository Path**: deja/u8g2_stm32_sw_i2c2 ## Basic Information - **Project Name**: u8g2_stm32_sw_i2c2 - **Description**: 个人备份,还未测试! - **Primary Language**: Unknown - **License**: LGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-05-30 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README step 0:将u8g2包下载,stm32cubemx生成基本工程(时钟及驱动OLED的引脚基本配置),MDK打开工前一步生成的工程,导入CSR; (网传)有必要时将除主控驱动用的驱动移出项目【例u8x8_d_sh1106_72x40.c】格式基本上为【u8x8_d_主控名_分辨率.c】! (个人认为)个人认为没有必要,函数没有调用到的话应该不会生成占用代码!可能与裁剪memory内容有关! step 1:确认屏幕主控: ----->u8g2_Setup_ssd1306_i2c_128x64_noname_f(...) --->(占用缓存最大) ----->u8g2_Setup_ssd1306_i2c_128x64_noname_1(...)--->(占用缓存最次) ----->u8g2_Setup_ssd1306_i2c_128x64_noname_2(...)--->(占用缓存中等) --->(u8g2_d_setup.c中不相关的可以注释掉) step 2:确认驱动方式: ----->软件IIC u8x8_byte_sw_i2c ----->软件SPI u8x8_byte_4/3wire_sw_spi ----->硬件IIC 可以自定(内部流程可以从软件模拟中重写相应发送功能函数) ----->硬件SPI 可以自定(内部流程可以从软件模拟中重写相应发送功能函数) ---->(u8x8.h) step 3:定义延时和IO引脚: u8x8_stm32_gpio_and_delay(...)主要为引脚定义延时可以不去动 ------>引脚对应宏名参照u8x8.h 例:U8X8_MSG_GPIO_I2C_DATA U8X8_MSG_GPIO_I2C_CLOCK step 4:裁剪memory内容: 留下:uint8_t *u8g2_m_16_8_1(uint8_t *page_cnt) uint8_t *u8g2_m_16_8_2(uint8_t *page_cnt) uint8_t *u8g2_m_16_8_f(uint8_t *page_cnt) 其它注释,猜测是128/8=16、64/8=8才留下这三条内容,还没有找到对应关系!! ---->(u8g2_d_memory.c) ======================以上为大概流程==========以下为代码段(main.c)============================== =====u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2,U8G2_R0,u8x8_byte_sw_i2c,u8x8_stm32_gpio_and_delay)=========== 参数: 1.u8g2 ----定义结构体 2.U8G2_R0 ----填参 3.u8x8_byte_sw_i2c ----若为硬件驱动应该重写 4.u8x8_stm32_gpio_and_delay ----定义函数 step o:添加结构体定义、头文件、引脚定义 #include "u8g2.h" #define OLED_DI_Pin GPIO_PIN_11 #define OLED_DO_Pin GPIO_PIN_10 u8g2_t u8g2; ====== step A:添加定义【uint8_t u8x8_stm32_gpio_and_delay】代码: uint8_t u8x8_stm32_gpio_and_delay(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_GPIO_I2C_DATA: (arg_int)?SET_BIT(GPIOB->ODR,OLED_DI_Pin):CLEAR_BIT(GPIOB->ODR,OLED_DI_Pin); break; case U8X8_MSG_GPIO_I2C_CLOCK: (arg_int)?SET_BIT(GPIOB->ODR,OLED_DO_Pin):CLEAR_BIT(GPIOB->ODR,OLED_DO_Pin); break; case U8X8_MSG_GPIO_AND_DELAY_INIT: HAL_Delay(1); break; case U8X8_MSG_DELAY_MILLI: HAL_Delay(arg_int); break; } return 1; } step step 5:添加测试代码: u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2,U8G2_R0,u8x8_byte_sw_i2c,u8x8_stm32_gpio_and_delay); u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this, u8g2_SetPowerSave(&u8g2, 0); // wake up display HAL_Delay(1000); u8g2_DrawLine(&u8g2, 0,0, 128, 64); u8g2_SendBuffer(&u8g2); ================================writen by E=================================== ================================2020.05.30===================================