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

相关推荐
XuanXu38 分钟前
Java AQS原理以及应用
java
风象南3 小时前
SpringBoot中6种自定义starter开发方法
java·spring boot·后端
mghio12 小时前
Dubbo 中的集群容错
java·微服务·dubbo
咖啡教室17 小时前
java日常开发笔记和开发问题记录
java
咖啡教室17 小时前
java练习项目记录笔记
java
鱼樱前端18 小时前
maven的基础安装和使用--mac/window版本
java·后端
RainbowSea18 小时前
6. RabbitMQ 死信队列的详细操作编写
java·消息队列·rabbitmq
RainbowSea18 小时前
5. RabbitMQ 消息队列中 Exchanges(交换机) 的详细说明
java·消息队列·rabbitmq
我不会编程55520 小时前
Python Cookbook-5.1 对字典排序
开发语言·数据结构·python