From 1f469c4abeea1e296ec94b4eef995a6977ca5329 Mon Sep 17 00:00:00 2001 From: ranchuan Date: Tue, 19 Sep 2023 09:07:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=BB=E5=8F=96=E8=B5=8B?= =?UTF-8?q?=E7=A0=81=E4=BB=AA=E6=8C=89=E9=94=AEke1=20,=E6=8E=A7=E5=88=B6le?= =?UTF-8?q?dr,ledg=20=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- RTE/_app/RTE_Components.h | 22 ------- ReadMe.txt | 9 ++- checker_m4.uvoptx | 30 +++++++-- checker_m4.uvprojx | 16 ++++- source/main/mymain.c | 114 +++++++++++++++++++++++++++++++++- source/rt_thread/core_delay.c | 13 ++++ source/rt_thread/core_delay.h | 2 +- 8 files changed, 175 insertions(+), 35 deletions(-) delete mode 100644 RTE/_app/RTE_Components.h diff --git a/.gitignore b/.gitignore index 81a1c73..94028e1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ JLinkSettings.ini build_log.txt __pycache__/ *.pid -*.pkt \ No newline at end of file +*.pkt +*quest_info.txt +RTE/_app/RTE_Components.h diff --git a/RTE/_app/RTE_Components.h b/RTE/_app/RTE_Components.h deleted file mode 100644 index 15c73f4..0000000 --- a/RTE/_app/RTE_Components.h +++ /dev/null @@ -1,22 +0,0 @@ - -/* - * Auto generated Run-Time-Environment Component Configuration File - * *** Do not modify ! *** - * - * Project: 'checker_m4' - * Target: 'app' - */ - -#ifndef RTE_COMPONENTS_H -#define RTE_COMPONENTS_H - - -/* - * Define the Device Header File: - */ -#define CMSIS_device_header "stm32mp157dxx_cm4.h" - -#define RTE_Compiler_IO_STDOUT /* Compiler I/O: STDOUT */ - #define RTE_Compiler_IO_STDOUT_User /* Compiler I/O: STDOUT Breakpoint */ - -#endif /* RTE_COMPONENTS_H */ diff --git a/ReadMe.txt b/ReadMe.txt index 44304b1..6f7edf6 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -7,4 +7,11 @@ 在m4上使用定时器,实现pwm控制的时候没有找到光感输入脚 如果发现程序不能运行,检查RTE文件 2023.7.14 - 使用单线程方式执行命令 \ No newline at end of file + 使用单线程方式执行命令 +2023.7.21 + 屏蔽日志输出,解决控制电机会引发id读取回复的bug +2023.8.2 + 读取按键时,连续读取5次,5次都为相同时才触发 + 添加build命令来获取编译时间 +2023.8.17 + 添加读取赋码仪按键ke1 ,控制ledr,ledg 的功能 \ No newline at end of file diff --git a/checker_m4.uvoptx b/checker_m4.uvoptx index ff5fa8e..9074cc2 100644 --- a/checker_m4.uvoptx +++ b/checker_m4.uvoptx @@ -331,7 +331,7 @@ rtthread - 1 + 0 0 0 0 @@ -567,7 +567,7 @@ stm32lib - 1 + 0 0 0 0 @@ -979,7 +979,7 @@ interface - 1 + 0 0 0 0 @@ -1023,7 +1023,7 @@ dev - 1 + 0 0 0 0 @@ -1043,7 +1043,7 @@ soft - 1 + 0 0 0 0 @@ -1225,6 +1225,26 @@ + + readme + 1 + 0 + 0 + 0 + + 10 + 82 + 5 + 0 + 0 + 0 + .\ReadMe.txt + ReadMe.txt + 0 + 0 + + + ::CMSIS 0 diff --git a/checker_m4.uvprojx b/checker_m4.uvprojx index fdd4b9d..b9fbb0b 100644 --- a/checker_m4.uvprojx +++ b/checker_m4.uvprojx @@ -80,9 +80,9 @@ 0 - 0 + 1 0 - + upload checker_m4 ./Objects/checker_m4.axf 0 0 @@ -336,7 +336,7 @@ 0 - CORE_CM4,NO_ATOMIC_64_SUPPORT,USE_HAL_DRIVER,STM32MP157Dxx,METAL_INTERNAL,METAL_MAX_DEVICE_REGIONS=2,METAL_INTERNAL,VIRTIO_SLAVE_ONLY,__LOG_TRACE_IO_,RT_THREAD + CORE_CM4,NO_ATOMIC_64_SUPPORT,USE_HAL_DRIVER,STM32MP157Dxx,METAL_INTERNAL,METAL_MAX_DEVICE_REGIONS=2,METAL_INTERNAL,VIRTIO_SLAVE_ONLY,RT_THREAD .\source\core;.\source\main;.\source\rt_thread;.\source\rt_thread\include;.\source\stm32lib\STM32MP1xx_HAL_Driver\Inc;.\source\stm32lib\CMSIS\Include;.\source\OpenAMP\open-amp\lib\include;.\source\OpenAMP\libmetal\lib\include;.\source\OpenAMP\virtual_driver;.\source\soft;.\source\task;.\source\dev @@ -1207,6 +1207,16 @@ + + readme + + + ReadMe.txt + 5 + .\ReadMe.txt + + + ::CMSIS diff --git a/source/main/mymain.c b/source/main/mymain.c index 727a247..3c3f649 100644 --- a/source/main/mymain.c +++ b/source/main/mymain.c @@ -11,6 +11,8 @@ typedef struct{ pwm_def *pwm; int key_old; int key; + int key1_old; + int key1; int sen; char str_buff[200]; }mymain_def; @@ -42,6 +44,18 @@ void *mymain_init(void) HAL_GPIO_WritePin(GPIOF,GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9,GPIO_PIN_RESET); PERIPH_UNLOCK(GPIOF); + // ָʾPF1() PG15() + init.Pin = GPIO_PIN_1; + PERIPH_LOCK(GPIOF); + HAL_GPIO_Init(GPIOF, &init); + HAL_GPIO_WritePin(GPIOF,GPIO_PIN_1,GPIO_PIN_RESET); + PERIPH_UNLOCK(GPIOF); + init.Pin = GPIO_PIN_15; + PERIPH_LOCK(GPIOG); + HAL_GPIO_Init(GPIOG, &init); + HAL_GPIO_WritePin(GPIOG,GPIO_PIN_15,GPIO_PIN_RESET); + PERIPH_UNLOCK(GPIOG); + // λ init.Mode = GPIO_MODE_INPUT; @@ -52,12 +66,18 @@ void *mymain_init(void) PERIPH_UNLOCK(GPIOI); // + // PG3 key2 ʹ + // PH7 key1 ʹ init.Mode = GPIO_MODE_INPUT; init.Pull = GPIO_NOPULL; init.Pin = GPIO_PIN_3; PERIPH_LOCK(GPIOG); HAL_GPIO_Init(GPIOG, &init); PERIPH_UNLOCK(GPIOG); + init.Pin = GPIO_PIN_7; + PERIPH_LOCK(GPIOH); + HAL_GPIO_Init(GPIOH, &init); + PERIPH_UNLOCK(GPIOH); // init.Mode = GPIO_MODE_INPUT; @@ -91,6 +111,22 @@ void out_set(int index,int power) send_str_to_a7(m->str_buff); } +// ledr +void ledr_set(int power) +{ + PERIPH_LOCK(GPIOG); + HAL_GPIO_WritePin(GPIOG,1<<15,power?GPIO_PIN_SET:GPIO_PIN_RESET); + PERIPH_UNLOCK(GPIOG); + send_str_to_a7("ledr seted"); +} +// ledg +void ledg_set(int power) +{ + PERIPH_LOCK(GPIOF); + HAL_GPIO_WritePin(GPIOF,1<<1,power?GPIO_PIN_SET:GPIO_PIN_RESET); + PERIPH_UNLOCK(GPIOF); + send_str_to_a7("ledg seted"); +} // һ @@ -176,6 +212,44 @@ static int str_ainttoi(const char *s) +int read_key(void *mymain) +{ + mymain_def *m=mymain; + int key=0,key2=0; + key=HAL_GPIO_ReadPin(GPIOG,1<<3); + if(key!=m->key_old) + { + //ɼ5ΣΪ෴ƽʱ˵ƽ + for(int i=0;i<2;i++) + { + delay_ms(20); + key2=HAL_GPIO_ReadPin(GPIOG,1<<3); + if(key!=key2) return key2; + } + return key; + } + return m->key_old; + +} +int read_key1(void *mymain) +{ + mymain_def *m=mymain; + int key=0,key2=0; + key=HAL_GPIO_ReadPin(GPIOH,1<<7); + if(key!=m->key1_old) + { + //ɼ5ΣΪ෴ƽʱ˵ƽ + for(int i=0;i<2;i++) + { + delay_ms(20); + key2=HAL_GPIO_ReadPin(GPIOH,1<<7); + if(key!=key2) return key2; + } + return key; + } + return m->key1_old; + +} @@ -183,7 +257,8 @@ static int str_ainttoi(const char *s) void mymain_scan(void *mymain) { mymain_def *m=mymain; - m->key=HAL_GPIO_ReadPin(GPIOG,1<<3); + m->key=read_key(mymain); + m->key1=read_key1(mymain); m->sen=HAL_GPIO_ReadPin(GPIOI,1<<6); if(m->key_old!=m->key){ if(m->key==RESET) @@ -195,6 +270,16 @@ void mymain_scan(void *mymain) } m->key_old=m->key; } + if(m->key1_old!=m->key1){ + if(m->key1==RESET) + { + send_str_to_a7("ke1 press"); + }else + { + send_str_to_a7("ke1 up"); + } + m->key1_old=m->key1; + } } @@ -211,6 +296,7 @@ int read_sw(void *mymain) + void mymain_loop(void *mymain,char *cmd_str) { mymain_def *m=mymain; @@ -219,7 +305,6 @@ void mymain_loop(void *mymain,char *cmd_str) // ½ int count=str_ainttoi(cmd_str+6); if(count!=0){ - send_str_to_a7(m->str_buff); moter_run(0,count); if(count>0){ send_str_to_a7("moter down"); @@ -252,6 +337,12 @@ void mymain_loop(void *mymain,char *cmd_str) else send_str_to_a7("key press"); } + else if(strncmp(cmd_str,"readke1",7)==0){ + if(m->key1) + send_str_to_a7("ke1 up"); + else + send_str_to_a7("ke1 press"); + } else if(strncmp(cmd_str,"readsen",7)==0){ // if(m->sen) @@ -268,6 +359,25 @@ void mymain_loop(void *mymain,char *cmd_str) } } } + else if(strncmp(cmd_str,"ledr",4)==0){ + if(strncmp(cmd_str+5,"on",2)==0){ + ledr_set(1); + }else{ + ledr_set(0); + } + } + else if(strncmp(cmd_str,"ledg",4)==0){ + if(strncmp(cmd_str+5,"on",2)==0){ + ledg_set(1); + }else{ + ledg_set(0); + } + } + else if(strncmp(cmd_str,"build",5)==0){ + send_str_to_a7("buildtime: " __DATE__ " " __TIME__); + }else{ + send_str_to_a7("unknown cmd"); + } } diff --git a/source/rt_thread/core_delay.c b/source/rt_thread/core_delay.c index 9dd2f58..b0945b8 100644 --- a/source/rt_thread/core_delay.c +++ b/source/rt_thread/core_delay.c @@ -87,3 +87,16 @@ void rt_hw_us_delay(rt_uint32_t us) delay_us(us); } + +void delay_ms(uint32_t ms) +{ + for(int i=0;i