asrpro u8g2

源码:GitHub - olikraus/u8glib: Arduino Monochrom Graphics Library for LCDs and OLEDs

wiki github 下查看帮助 Home · olikraus/u8glib Wiki · GitHub

软件spi

/my init 
  void ssd1306_spi_init()
  {
  pinMode(CS,output);
	pinMode(DC,output);
	//pinMode(ST7735_RST_PIN,output);
	pinMode(SCK,output);
	pinMode(MOSI,output);
  }
  
uint8_t u8x8_avr_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  {
	// Re-use library for delays

	switch(msg)
	{
	  //ms
	  	case U8X8_MSG_DELAY_MILLI:
        delay(1);
      break;
      
      //10 us
      case U8X8_MSG_DELAY_10MICRO:
        delay10us();
      break;
      
      //1 ns
	   case U8X8_MSG_DELAY_NANO:
        delay1us();
      break;
      
    case U8X8_MSG_DELAY_100NANO:
      delay1us();
      break;
      
		case U8X8_MSG_GPIO_AND_DELAY_INIT:  // called once during init phase of u8g2/u8x8
        ssd1306_spi_init();
			break;              // can be used to setup pins
		case U8X8_MSG_GPIO_SPI_CLOCK:        // Clock pin: Output level in arg_int
			if(arg_int)
				digitalWrite(SCK,1);
			else
				digitalWrite(SCK,0);
			break;
		case U8X8_MSG_GPIO_SPI_DATA:        // MOSI pin: Output level in arg_int
			if(arg_int)
				digitalWrite(MOSI,1);
			else
				digitalWrite(MOSI,0);
			break;
		case U8X8_MSG_GPIO_CS:        // CS (chip select) pin: Output level in arg_int
			if(arg_int)
				digitalWrite(CS,1);
			else
				digitalWrite(CS,0);
			break;
		case U8X8_MSG_GPIO_DC:        // DC (data/cmd, A0, register select) pin: Output level in arg_int
      if(arg_int)
				digitalWrite(DC,1);
			else
				digitalWrite(DC,0);
			break;
		
		case U8X8_MSG_GPIO_RESET:     // Reset pin: Output level in arg_int

		default:
		  break;

	}
	return 1;
}

初始化

  u8g2_t u8g2;
  void u8g2_init()
  {
    u8g2_Setup_ssd1306_128x64_noname_f(&u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_avr_gpio_and_delay);
  	u8g2_InitDisplay(&u8g2);
  	u8g2_SetPowerSave(&u8g2, 0);
  	u8g2_ClearBuffer(&u8g2);
  }

软件iic

uint8_t u8x8_avr_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  {
	// Re-use library for delays
  switch(msg){
		//初始化GPIO
		case U8X8_MSG_GPIO_AND_DELAY_INIT:        //此状态下初始化IO以及延时函数
          // pinMode(SDA,output);
          // pinMode(SCL,output);

          // digitalWrite(SDA,1);
          // digitalWrite(SCL,1);
    //Serial.println("u8x8 init");
       	  break;

    case U8X8_MSG_DELAY_100NANO:              //此状态下对接100ns延时函数
		    //for(int i=0;i<100;i++);
      delayMicroseconds(1);
		  break;
      
    case U8X8_MSG_DELAY_10MICRO:              //此状态下对接10usus延时函数
			delayMicroseconds(10);
		  break;

		case U8X8_MSG_DELAY_MILLI:                //此状态下对接ms延时函数,延时arg_int ms
			delay(1);
		break;

		case U8X8_MSG_DELAY_I2C:                  //此状态下对接IIC延时函数
		 delayMicroseconds(5);
		break;

  	case U8X8_MSG_GPIO_I2C_CLOCK:             //此状态下修改IIC SCL信号线电平
			if (arg_int)
      {
        //pinMode(2,output);
        digitalWrite(2,1);
      }

			else 
      {
       // pinMode(2,output);
        digitalWrite(2,0);
      }
        
		break;

		case U8X8_MSG_GPIO_I2C_DATA:              //此状态下修改IIC SDA信号线电平
        if (arg_int)
        {
          digitalWrite(3,1);
        }
			else {
          digitalWrite(3,0);
          }
		      break;


    
    default:
        u8x8_SetGPIOResult(u8x8, 1); // default return value
        break;
	}

	return 1;
}

初始化

u8g2_t u8g2;
void u8g2_init()
  {
    ssd1306_iic_init();
    

     u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, U8G2_R0,u8x8_byte_sw_i2c, u8x8_avr_gpio_and_delay);
  
  	u8g2_InitDisplay(&u8g2);
  	u8g2_SetPowerSave(&u8g2, 0);
  	u8g2_ClearBuffer(&u8g2);

    //u8x8_SetPin_SW_I2C(getU8x8(), SCL,  SDA,  0);
  }

硬件spi(asrpro 可能没有硬件spi ; 内部有个spi用于flash读写

硬件iic (包含 asrpro_iic.h头文件

asrpro 硬件IIC地址为PA2 PA3 SDA SCL 引脚复用功能为3

dpmu_set_io_reuse(PA2,THIRD_FUNCTION);

dpmu_set_io_reuse(PA3,THIRD_FUNCTION);

iic_polling_init(IIC0,100,0,LONG_TIME_OUT); //**SSD1306 BEGIN() 使用 ASRPRO_IIC.H

  void ssd1306_HW_iic_init()
  {
       pinMode(SDA,output);
       pinMode(SCL,output);

        dpmu_set_io_reuse(PA2,THIRD_FUNCTION);  //SDA
        dpmu_set_io_reuse(PA3,THIRD_FUNCTION);//SCL
        iic_polling_init(IIC0,100,0,LONG_TIME_OUT);

    //digitalWrite(SDA,1);
    //digitalWrite(SCL,1);
  }

uint8_t u8x8_avr_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
  {
	// Re-use library for delays
  switch(msg){
		//初始化GPIO
		case U8X8_MSG_GPIO_AND_DELAY_INIT:        //此状态下初始化IO以及延时函数
       	  break;

		case U8X8_MSG_DELAY_MILLI:                //此状态下对接ms延时函数,延时arg_int ms
			  delay(1);
		break;

    default:
        return 0;
        break;
	}

	return 1;
}


uint8_t u8x8_byte_hw_i2c2(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
  static uint8_t buffer[32];		/* u8g2/u8x8 will never send more than 32 bytes between START_TRANSFER and END_TRANSFER */
  static uint8_t buf_idx;
  uint8_t *data;
 
  switch(msg)
  {
    case U8X8_MSG_BYTE_SEND:
      data = (uint8_t *)arg_ptr;      
      while( arg_int > 0 )
      {
	buffer[buf_idx++] = *data;
	data++;
	arg_int--;
      }      
      break;
    case U8X8_MSG_BYTE_INIT:
      /* add your custom code to init i2c subsystem */
      break;
    case U8X8_MSG_BYTE_SET_DC:
      /* ignored for i2c */
      break;
    case U8X8_MSG_BYTE_START_TRANSFER:
      buf_idx = 0;
      break;
    case U8X8_MSG_BYTE_END_TRANSFER:
      //i2c_transfer(u8x8_GetI2CAddress(u8x8) >> 1, buf_idx, buffer);
      i2c_master_only_send(u8x8_GetI2CAddress(u8x8) >> 1,(uint8_t *)buffer,buf_idx);
      break;
    default:
      return 0;
  }
  return 1;
}

初始化

u8g2_t u8g2;
  void u8g2_init()
  {
     
      // u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, U8G2_R0,u8x8_byte_sw_i2c, u8x8_avr_gpio_and_delay);
     //u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2,U8G2_R0,u8x8_byte_hw_i2c ,u8g2_gpio_and_delay_stm32);
  	ssd1306_HW_iic_init();
    u8g2_Setup_ssd1306_i2c_128x64_noname_f(&u8g2, U8G2_R0,u8x8_byte_hw_i2c2, u8x8_avr_gpio_and_delay);
    u8g2_InitDisplay(&u8g2);
  	u8g2_SetPowerSave(&u8g2, 0);
  	u8g2_ClearBuffer(&u8g2);

    //u8x8_SetPin_SW_I2C(getU8x8(), SCL,  SDA,  0);
  }

参考:Porting to new MCU platform · olikraus/u8g2 Wiki · GitHub

https://www.cnblogs.com/frozencandles/p/16358483.html

https://www.baidu.com/link?url=su8kA7SexkICVQ9cxr6adm0row_JJLFb92jpc0z95BZDQP2FRMcW0Vpuvn_AJdeI2XFas5B4XH4cLO0CZetEka&wd=&eqid=9f86ce8c018b86f000000006664febc6

【开源】硬件/软件i2c两种方式移植u8g2单色图形库驱动0.96吋OLED-腾讯云开发者社区-腾讯云

使用

 u8g2c.u8g2_init();

    
    
    u8g2c.clearBuffer();

    u8g2c.drawBox(0,0,10,10);
    
    
    u8g2c.sendBuffer();

初始化函数差异

软件spi

u8g2_Setup_ssd1306_128x64_noname_f (&u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_avr_gpio_and_delay);

软件i2c

u8g2_Setup_ssd1306_i2c_128x64_noname_f (&u8g2,U8G2_R0,u8x8_byte_sw_i2c, u8x8_avr_gpio_and_delay);

硬件i2c

u8g2_Setup_ssd1306_i2c_128x64_noname_f (&u8g2, U8G2_R0,u8x8_byte_hw_i2c2, u8x8_avr_gpio_and_delay);

dac操作

pcb绘板

u8g2font arduino

相关推荐
代码之光_1980几秒前
保障性住房管理:SpringBoot技术优势分析
java·spring boot·后端
ajsbxi6 分钟前
苍穹外卖学习记录
java·笔记·后端·学习·nginx·spring·servlet
&岁月不待人&21 分钟前
Kotlin by lazy和lateinit的使用及区别
android·开发语言·kotlin
StayInLove25 分钟前
G1垃圾回收器日志详解
java·开发语言
对许29 分钟前
SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“
java·log4j
无尽的大道33 分钟前
Java字符串深度解析:String的实现、常量池与性能优化
java·开发语言·性能优化
爱吃生蚝的于勒36 分钟前
深入学习指针(5)!!!!!!!!!!!!!!!
c语言·开发语言·数据结构·学习·计算机网络·算法
小鑫记得努力42 分钟前
Java类和对象(下篇)
java
binishuaio1 小时前
Java 第11天 (git版本控制器基础用法)
java·开发语言·git
zz.YE1 小时前
【Java SE】StringBuffer
java·开发语言