移植u8g2到stm
int fputc(int ch,FILE *f)
{
ITM_SendChar(ch);
return (ch);
}
void delay_us(uint32_t time)
{
uint32_t i=8*time;
while(i--);
}
uint8_t STM32_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
//printf("%s:msg = %d,arg_int = %d\r\n",__FUNCTION__,msg,arg_int);
switch(msg)
{
case U8X8_MSG_DELAY_100NANO: // delay arg_int * 100 nano seconds
__NOP();
break;
case U8X8_MSG_DELAY_10MICRO: // delay arg_int * 10 micro seconds
for (uint16_t n = 0; n < 320; n++)
{
__NOP();
}
break;
case U8X8_MSG_DELAY_MILLI: // delay arg_int * 1 milli second
HAL_Delay(1);
break;
case U8X8_MSG_DELAY_I2C: // arg_int is the I2C speed in 100KHz, e.g. 4 = 400 KHz
//delay 5us
delay_us(5); // arg_int=1: delay by 5us, arg_int = 4: delay by 1.25us
case U8X8_MSG_GPIO_I2C_CLOCK: // arg_int=0: Output low at I2C clock pin
if(arg_int == 1)
{
HAL_GPIO_WritePin(GPIOB, SCL2_Pin, GPIO_PIN_SET);
}
else if(arg_int == 0)
{
HAL_GPIO_WritePin(GPIOB, SCL2_Pin, GPIO_PIN_RESET);
}
break; // arg_int=1: Input dir with pullup high for I2C clock pin
case U8X8_MSG_GPIO_I2C_DATA: // arg_int=0: Output low at I2C data pin
// printf("U8X8_MSG_GPIO_I2C_DATA:%d\r\n",arg_int);
if(arg_int == 1)
{
HAL_GPIO_WritePin(GPIOB, SDA2_Pin, GPIO_PIN_SET);
}
else if(arg_int == 0)
{
HAL_GPIO_WritePin(GPIOB, SDA2_Pin, GPIO_PIN_RESET);
}
break; // arg_int=1: Input dir with pullup high for I2C data pin
default:
u8x8_SetGPIOResult(u8x8, 1); // default return value
break;
}
return 1;
}
这里是驱动iic
u8g2_t u8g2; // a structure which will contain all the data for one display
u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, U8G2_R0, u8x8_byte_sw_i2c, STM32_gpio_and_delay); // init u8g2 structure
u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this,
u8g2_SetPowerSave(&u8g2, 0); // wake up display
int t;
这里可以驱动u8g2 具体作用后续学习文章来源:https://www.toymoban.com/news/detail-666969.html
下面就基本上可以驱动成功 最主要是修改后的u8g2的图文章来源地址https://www.toymoban.com/news/detail-666969.html
到了这里,关于STM32移植u8g2玩转oled 用软件iic实现驱动oled的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!