asrpro U8G2 SPI

asrpro U8G2 SPI_第1张图片

下载U8G2
安装VS CODE
项目在VSCODE中打开

在asr_pro_sdk下新建目录U8G2
1将U8G2 CSRC下所有文件复制到asr_pro_sdk\U8G2


//U8G2        
source-file: U8G2/u8g2lib.cpp
source-file: U8G2/u8g2_bitmap.c
source-file: U8G2/u8g2_box.c
source-file: U8G2/u8g2_buffer.c
source-file: U8G2/u8g2_button.c
source-file: U8G2/u8g2_circle.c
source-file: U8G2/u8g2_cleardisplay.c
source-file: U8G2/u8g2_d_memory.c
source-file: U8G2/u8g2_d_setup.c
source-file: U8G2/u8g2_font.c
source-file: U8G2/u8g2_fonts.c
source-file: U8G2/u8g2_hvline.c
source-file: U8G2/u8g2_input_value.c
source-file: U8G2/u8g2_intersection.c
source-file: U8G2/u8g2_kerning.c
source-file: U8G2/u8g2_line.c
source-file: U8G2/u8g2_ll_hvline.c
source-file: U8G2/u8g2_message.c
source-file: U8G2/u8g2_polygon.c
source-file: U8G2/u8g2_selection_list.c
source-file: U8G2/u8g2_setup.c
source-file: U8G2/u8x8lib.cpp
source-file: U8G2/u8x8_8x8.c
source-file: U8G2/u8x8_byte.c
source-file: U8G2/u8x8_cad.c
source-file: U8G2/u8x8_capture.c
source-file: U8G2/u8x8_debounce.c
source-file: U8G2/u8x8_display.c
source-file: U8G2/u8x8_d_ssd1306_128x64_noname.c
source-file: U8G2/u8x8_fonts.c
source-file: U8G2/u8x8_gpio.c
source-file: U8G2/u8x8_input_value.c
source-file: U8G2/u8x8_message.c
source-file: U8G2/u8x8_selection_list.c
source-file: U8G2/u8x8_setup.c
source-file: U8G2/u8x8_string.c
source-file: U8G2/u8x8_u16toa.c
source-file: U8G2/u8x8_u8toa.c


//header file path.
include-path: U8G2

2 .添加源文件与头文件 
asr_pro_sdk\projects\offline_asr_sample\project_file\source_file.prj

3. asr_pro_sdk\projects\offline_asr_sample\project_file\rebuild.bat在集成终端中打开
运行./rebuild

主程序

#define ST7735_CS_PIN 2
#define ST7735_CS_GPIO_PIN gpio_pin_2
#define ST7735_DC_PIN 3
#define ST7735_DC_GPIO_PIN gpio_pin_3
#define ST7735_RST_PIN 1
#define ST7735_RST_GPIO_PIN gpio_pin_1
#define ST7735_SCK_PIN 6
#define ST7735_SCK_GPIO_PIN gpio_pin_5
#define ST7735_MOSI_PIN 5
#define ST7735_MOSI_GPIO_PIN gpio_pin_6

/* 宏定义 --------------------------------------------------------------------*/

#define MOSI  ST7735_MOSI_PIN 
#define SCK ST7735_SCK_PIN 
#define DC ST7735_DC_PIN
#define CS ST7735_CS_PIN


//#ifndef _ST7735_H
//#define _ST7735_H



//#include "twen_gfx.h"

#include "asr.h"
#include "setup.h"
#include "myLib/luxiaoban.h"

#include "../U8G2/u8g2.h"

//void delayMicroseconds(uint32_t us);

	volatile uint32_t * _cs_reg = NULL;
	volatile uint32_t * _rst_reg = NULL;
	volatile uint32_t * _dc_reg = NULL;   
	volatile uint32_t * _sck_reg = NULL;
	volatile uint32_t * _t_reg = NULL;  




uint32_t snid;

//SSD1306 回调函数1
u8g2_t u8g2;

extern "C" uint8_t myfont1[]; //��������
void emo_tst(u8g2_t *u8g2)
{
//emo ����
int draw_color = 1;
int k = 0;
  for(int i = 0;i<66;i++)
  {
    k = k+1;
    u8g2_SetDrawColor(u8g2,draw_color);

  
    u8g2_ClearBuffer(u8g2);
  //u8g2.setFont(u8g2_font_8x13B_tf); 

  //u8g2_DrawStr(0,10,num(k));
    u8g2_SetFont(u8g2,myfont1);

    u8g2_DrawGlyph(u8g2,34,60,65+k%71);
    //u8g2.drawGlyphX2(0,0,65+k%45);
    u8g2_SendBuffer(u8g2);
    delay(100);
  }
}



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;
}


void u8g2Init(u8g2_t *u8g2)
{

  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);
	

} 

void draw(u8g2_t *u8g2)
{
	u8g2_ClearBuffer(u8g2); 
   u8g2_SetFontMode(u8g2, 1);
   u8g2_SetFontDirection(u8g2, 0); 
   u8g2_SetFont(u8g2, u8g2_font_inb24_mf); 
   u8g2_DrawStr(u8g2, 0, 20, "U");

   u8g2_SetFontDirection(u8g2, 1);
   u8g2_SetFont(u8g2, u8g2_font_inb30_mn);
   u8g2_DrawStr(u8g2, 21,8,"8");

   u8g2_SetFontDirection(u8g2, 0);
   u8g2_SetFont(u8g2, u8g2_font_inb24_mf);
   u8g2_DrawStr(u8g2, 51,30,"g");
   u8g2_DrawStr(u8g2, 67,30,"\xb2");

   u8g2_DrawHLine(u8g2, 2, 35, 47);
   u8g2_DrawHLine(u8g2, 3, 36, 47);
   u8g2_DrawVLine(u8g2, 45, 32, 12);
   u8g2_DrawVLine(u8g2, 46, 33, 12);

   u8g2_SetFont(u8g2, u8g2_font_4x6_tr);
   u8g2_DrawStr(u8g2, 1,54,"github.com/olikraus/u8g2");
	 u8g2_SendBuffer(u8g2);
	 delay(1000);
}


//u8g2_t u8g2;

//{ID:250,keyword:"命令词",ASR:"最大音量",ASRTO:"音量调整到最大"}
//{ID:251,keyword:"命令词",ASR:"中等音量",ASRTO:"音量调整到中等"}
//{ID:252,keyword:"命令词",ASR:"最小音量",ASRTO:"音量调整到最小"}
//{speak:小美-娇美女声,vol:20,speed:10}
//{playid:10001,voice:鹿唤醒我}
//{playid:10002,voice:我退}
void ASR_CODE()
{
  emo_tst(&u8g2);
  //{ID:500,keyword:"唤醒词",ASR:"小鹿同学",ASRTO:"我在呢"}
  //{ID:501,keyword:"唤醒词",ASR:"小鹿小鹿",ASRTO:"AI"}
  //{ID:502,keyword:"唤醒词",ASR:"你好小鹿",ASRTO:"请吩咐"}
  //{ID:503,keyword:"命令词",ASR:"开灯",ASRTO:"灯已打开,亮度为最亮"}
  if(snid == 503){
    luxiaoban_digital_write(0,0);
  }
  //{ID:504,keyword:"命令词",ASR:"打开灯光",ASRTO:"灯已打开,亮度为最亮"}
  if(snid == 504){
    luxiaoban_digital_write(0,0);
  }
  //{ID:505,keyword:"命令词",ASR:"请开灯",ASRTO:"灯已打开,亮度为最亮"}
  if(snid == 505){
    luxiaoban_digital_write(0,0);
  }
  //{ID:506,keyword:"命令词",ASR:"关灯",ASRTO:"灯已关闭"}
  if(snid == 506){
    luxiaoban_digital_write(0,1);
  }
  //{ID:507,keyword:"命令词",ASR:"关闭灯光",ASRTO:"灯光已关闭"}
  if(snid == 507){
    luxiaoban_digital_write(0,1);
  }
  //{ID:508,keyword:"命令词",ASR:"请关灯",ASRTO:"灯已关闭"}
  if(snid == 508){
    luxiaoban_digital_write(0,1);
  }
}




void setup()
{
  Serial.begin((9600));
 
  


	u8g2Init(&u8g2);
	draw(&u8g2);
	
	emo_tst(&u8g2);
		
	
	

}
void loop()
{
  
}






make时生成的文件在 asr_pro_sdk\projects\offline_asr_sample\project_file\build\objs下 

你可能感兴趣的:(ASRPRO,U8G2)