基本功能移植

Signed-off-by: kevin <kevin@lmve.net>
This commit is contained in:
2022-04-17 01:29:20 +08:00
parent 416395e158
commit f1bbf02955
91 changed files with 3952 additions and 1789 deletions
+97
View File
@@ -0,0 +1,97 @@
#include "buzzer.h"
struct notes *notes;
void play_ones(uint16_t freq,uint8_t dutya)
{
TIM2->ARR = (uint32_t)((72000000/freq)-1);TIM2->CCR3 = (uint32_t)(((72000000/freq)-1)*((float)dutya/100));
}
void add_a_note(uint16_t freq,uint8_t duty,uint16_t deley)
{
struct notes* buff;
buff = (struct notes*)malloc(sizeof(struct notes));
if (buff != NULL)
{
buff->freq = freq;
buff->duty = duty;
buff->deley = deley;
buff->next_note = NULL;
if (notes == NULL)
{
notes = buff;
}
else
{
struct notes *t = notes;
while (t->next_note != NULL)
{
t = t->next_note;
}
t->next_note = buff;
}
}
}
void delhead()
{
if (notes == NULL)
{
return;
}
if (notes->next_note == NULL)
{
free(notes);
notes = NULL;
}
else
{
struct notes *t = notes;
notes = notes->next_note;
free(t);
}
}
char buzzer_play_server()
{
static char busy_flag=0;
static uint32_t play_delay;
if(notes == NULL)
{
//play_ones(0,0);
}else
{
if(busy_flag==0)
{
busy_flag=1;
play_delay=HAL_GetTick()+notes->deley;
play_ones(notes->freq,notes->duty);
}
if(busy_flag==1)
{
if(HAL_GetTick()>play_delay)
{
busy_flag=0;
delhead();
}
}
}
return busy_flag;
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef BUZZER_H_
#define BUZZER_H_
#include "main.h"
struct notes
{
uint16_t freq;
uint8_t duty;
uint16_t deley;
struct notes *next_note;
};
void play_ones(uint16_t freq,uint8_t dutya);
void add_a_note(uint16_t freq,uint8_t duty,uint16_t deley);
char buzzer_play_server();
#endif /* BUZZER_H_ */
@@ -12,8 +12,11 @@
extern I2C_HandleTypeDef hi2c1;
extern TIM_HandleTypeDef htim2;
#define RUNLED(x) HAL_GPIO_WritePin(run_led_GPIO_Port, run_led_Pin, x)
#define MUTE(x) HAL_GPIO_WritePin(mute_GPIO_Port, mute_Pin, x)
#define tack_a() HAL_GPIO_ReadPin(tack_a_GPIO_Port, tack_a_Pin)
#define tack_b() HAL_GPIO_ReadPin(tack_b_GPIO_Port, tack_b_Pin)
#define RUNLED_TICK() HAL_GPIO_TogglePin(run_led_GPIO_Port, run_led_Pin)
void IIC_SAND_DATE(uint16_t DEVICE_ADD,uint16_t IN_DEVICE_ADD,uint8_t *DATAS,uint16_t LONG);
+241 -11
View File
@@ -7,6 +7,147 @@
#include "mymain.h"
#include "hread_interface.h"
#define morse_t1 150
#define morse_t2 (morse_t1*3)
#define morse_hz 100
#define morse_play_t1 50
#define morse_play_t2 (morse_play_t1*3)
#define morse_play_hz 100
char push_key=0,last_key=1;
uint32_t morse_t=0;
uint32_t morse_time_out=0;
uint16_t morse_temp;
#define morse_input_buff_num 128
char morse_input_buff[morse_input_buff_num+1];
int morse_input_flag=0;
int morse_char_flag=0;
int morse_x,morse_y;
char morse_flah=0;
uint8_t morse_letter_temp=0;
uint8_t morse_letter_flag=0;
#define morsecodenum 38
const struct morsecode morsecodes[morsecodenum]=
{
{
2,0x40,'A'
},
{
4,0x80,'B'
},
{
4,0xa0,'C'
},
{
3,0x80,'D'
},
{
1,0x00,'E'
},
{
4,0x20,'F'
},
{
3,0xc0,'G'
},
{
4,0x00,'H'
},
{
2,0x00,'I'
},
{
4,0x70,'J'
},
{
3,0xa0,'K'
},
{
4,0x40,'L'
},
{
2,0xc0,'M'
},
{
2,0x80,'N'
},
{
3,0xe0,'O'
},
{
4,0x60,'P'
},
{
4,0xd0,'Q'
},
{
3,0x40,'R'
},
{
3,0x00,'S'
},
{
1,0x80,'T'
},
{
3,0x20,'U'
},
{
4,0x10,'V'
},
{
3,0x60,'W'
},
{
4,0x90,'X'
},
{
4,0xb0,'Y'
},
{
4,0xc0,'Z'
},
{
5,0x78,'1'
},
{
5,0x38,'2'
},
{
5,0x18,'3'
},
{
5,0x08,'4'
},
{
5,0x00,'5'
},
{
5,0x80,'6'
},
{
5,0xc0,'7'
},
{
5,0xe0,'8'
},
{
5,0xf0,'9'
},
{
5,0xf8,'0'
},
{
6,0x30,'?'
},
{
5,0x90,'/'
},
};
const char testbmp[]=
{
@@ -23,6 +164,20 @@ const char testbmp[]=
};
char getmorsecode(uint8_t len,uint8_t code)
{
for(int a=0;a<morsecodenum;a++)
{
if((morsecodes[a].len==len)&&(morsecodes[a].code==code))
{
return morsecodes[a].letter;
}
}
return 0;
}
void mymain()
{
uint32_t run_tick=0;
@@ -31,21 +186,96 @@ void mymain()
OLED_Init();
HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_3);//启动n通道的pwm
MUTE(0);
add_a_note(1000,50,1000);
while(1)
{
fps_++;
OLED_Pix(0,0,36,30,testbmp,1);
OLED_Str(30,30,16,"ABCD",1);
OLED_Str(30,30+16,12,"ABCD",1);
OLED_Str(30,0,8,"ABCD",1);
sprintf(str,"FPS:%d",fps);
OLED_Str(64,0,8,str,1);
sprintf(str,"RAND:%d",rand());
OLED_Str(30,8,8,str,1);
char get_char_temp;
push_key=tack_b();
if(push_key!=last_key)
{
if(push_key==0)
{
morse_t=HAL_GetTick();
play_ones(morse_hz,50);
}else
{
morse_temp=HAL_GetTick()-morse_t;
if(morse_temp>morse_t2)
{
//time out error
}else if(morse_temp>morse_t1)
{
//-
morse_input_buff[morse_input_flag]='-';
morse_letter_temp|=(0x80>>morse_letter_flag);
}else
{
//.
morse_input_buff[morse_input_flag]='.';
}
morse_input_flag++;
morse_letter_flag++;
//if(morse_input_flag>=morse_char_flag+8){morse_input_flag=morse_char_flag;morse_letter_flag=0;}
play_ones(0,0);
}
last_key=push_key;
morse_time_out=HAL_GetTick();
}
if(push_key==1)
{
//Get cursor on the screen
if((HAL_GetTick()-morse_time_out)>morse_t1)
{
if((morse_input_flag-morse_char_flag)>0)
{
get_char_temp=getmorsecode(morse_letter_flag,morse_letter_temp);
morse_letter_flag=0;
morse_letter_temp=0;
if(get_char_temp!=0)
{
morse_input_buff[morse_char_flag]=get_char_temp;
morse_flah=1;
morse_char_flag+=1;
}
morse_input_flag=morse_char_flag;
}
}
if((HAL_GetTick()-morse_time_out)>morse_t2)
{
if(morse_flah==1)
{
morse_input_buff[morse_char_flag]=' ';
morse_char_flag+=1;
morse_input_flag=morse_char_flag;
morse_flah=0;
}
}
}
OLED_Str(0,0,8,morse_input_buff,1);
fps_++;
sprintf(str,"FPS:%d",fps);
OLED_Str(0,56,8,str,1);
OLED_Cache_to_hardware();
buzzer_play_server();
if(HAL_GetTick()>run_tick)
{
run_tick+=1000;
+8
View File
@@ -10,6 +10,14 @@
#include "main.h"
#include "oled.h"
#include "buzzer.h"
struct morsecode
{
uint8_t len;
uint8_t code;
char letter;
};
void mymain();
+25 -16
View File
@@ -135,10 +135,12 @@ void OLED_Cache_to_hardware()
{
if(a&OLED_speedup[x])
{
OLED_speedup[x]&=~a;
if(b==0){b=1;OLED_Set_Pos(x,y);}
if(b==0){b=1;OLED_Set_Pos(x,y);}
OLED_WrDat(OLED_buff[y][x]);
OLED_speedup[x]&=~a;
//OLED_buff[y][x]=0xff;
}else
{b=0;}
@@ -874,6 +876,7 @@ type=0 清空区域
=2 正片叠底
=3 正片清空
=4 负片
=5 正片负片
*/
void OLED_Pix(unsigned char x,unsigned char y,unsigned char w,unsigned char h,const char *p,unsigned char type)
{
@@ -903,6 +906,9 @@ void OLED_Pix(unsigned char x,unsigned char y,unsigned char w,unsigned char h,co
break;
case 4:
OLED_set_dot(w1+x,h1+y,0);
break;
case 5:
OLED_set_dot(w1+x,h1+y,2);
break;
}
@@ -971,12 +977,26 @@ void OLED_Ascii(unsigned char x,unsigned char y,unsigned char size,char chr,unsi
void OLED_Str(unsigned char x,unsigned char y,unsigned char size,char *str,unsigned char type)
{
unsigned char size2;
switch(size)
{
case 8:
size2=6;
break;
case 12:
size2=7;
break;
case 16:
size2=8;
break;
}
while(*str!='\0')
{
if(x>=X_WIDTH)
if(x+size2>=X_WIDTH)
{
y+=size;
if(y>=Y_WIDTH_)
if(y>=Y_WIDTH)
{
y=0;
}
@@ -987,18 +1007,7 @@ void OLED_Str(unsigned char x,unsigned char y,unsigned char size,char *str,unsig
str++;
switch(size)
{
case 8:
x+=6;
break;
case 12:
x+=7;
break;
case 16:
x+=8;
break;
}
x+=size2;