diff --git a/app/by_fan_control.c b/app/by_fan_control.c new file mode 100644 index 0000000..ad7ccc5 --- /dev/null +++ b/app/by_fan_control.c @@ -0,0 +1,26 @@ +#include "by_fan_control.h" +#include "zf_common_headfile.h" + +void by_pwm_init(void) +{ + pwm_init(TIM4_PWM_MAP1_CH1_D12, 10000, 0); // 浮力风扇左 + pwm_init(TIM4_PWM_MAP1_CH2_D13, 10000, 0); // 浮力风扇右 + + pwm_init(TIM4_PWM_MAP1_CH3_D14, 10000, 0); // 动力风扇左 + pwm_init(TIM4_PWM_MAP1_CH4_D15, 10000, 0); // 动力风扇右 +} + +void by_pwm_update_duty(uint32_t update_pwm_duty) +{ + if (7000UL > update_pwm_duty) { + update_pwm_duty = 7000UL; + } + pwm_set_duty(TIM4_PWM_MAP1_CH1_D12, update_pwm_duty); + pwm_set_duty(TIM4_PWM_MAP1_CH2_D13, update_pwm_duty); +} + +void by_pwm_power_duty(uint32_t power_pwm_duty_l, uint32_t power_pwm_duty_r) +{ + pwm_set_duty(TIM4_PWM_MAP1_CH3_D14, power_pwm_duty_l); + pwm_set_duty(TIM4_PWM_MAP1_CH4_D15, power_pwm_duty_r); +} diff --git a/app/by_fan_control.h b/app/by_fan_control.h new file mode 100644 index 0000000..2ae6049 --- /dev/null +++ b/app/by_fan_control.h @@ -0,0 +1,11 @@ +#ifndef _BY_FAN_CONTROL_H_ +#define _BY_FAN_CONTROL_H_ + +#include "stdio.h" +#include "ch32v30x.h" + +extern void by_pwm_init(void); +extern void by_pwm_update_duty(uint32_t update_pwm_duty); +extern void by_pwm_power_duty(uint32_t power_pwm_duty_l, uint32_t power_pwm_duty_r); + +#endif \ No newline at end of file diff --git a/app/by_pt_button.c b/app/by_pt_button.c new file mode 100644 index 0000000..fc0a5ce --- /dev/null +++ b/app/by_pt_button.c @@ -0,0 +1,27 @@ +#include "by_pt_button.h" +#include "zf_common_headfile.h" +uint8_t potate_button; +void by_gpio_init(void) +{ + gpio_init(E10, GPI, GPIO_HIGH, GPI_PULL_UP); +} + +void by_exit_init(void) +{ + exti_init(E9, EXTI_TRIGGER_FALLING); + exti_init(E11, EXTI_TRIGGER_FALLING); +} + +uint8_t by_get_pb_statu(void) +{ + uint8_t temp_s = potate_button; + potate_button = 0; + return temp_s; +} + +void by_ips_show(void) +{ + ips114_show_string(0, 0, "button statu:"); + ips114_show_uint(104, 0, by_get_pb_statu(), 1); + +} \ No newline at end of file diff --git a/app/by_pt_button.h b/app/by_pt_button.h new file mode 100644 index 0000000..4e0ded1 --- /dev/null +++ b/app/by_pt_button.h @@ -0,0 +1,15 @@ +#ifndef _BY_PT_BUTTON_H__ +#define _BY_PT_BUTTON_H__ + +#include "stdio.h" +#include "ch32v30x.h" +#define POTATE_BUTTOM_PRESS 1 +#define POTATE_BUTTOM_FOREWARD 2 +#define POTATE_BUTTOM_BACKWARD 3 +extern uint8_t potate_button; + +extern void by_exit_init(void); +extern void by_gpio_init(void); +extern uint8_t by_get_pb_statu(void); +extern void by_ips_show(void); +#endif \ No newline at end of file diff --git a/app/isr.c b/app/isr.c index 210feae..33f643e 100644 --- a/app/isr.c +++ b/app/isr.c @@ -1,73 +1,75 @@ /********************************************************************************************************************* -* CH32V307VCT6 Opensourec Library CH32V307VCT6 Դ⣩һڹٷ SDK ӿڵĵԴ -* Copyright (c) 2022 SEEKFREE ɿƼ -* -* ļCH32V307VCT6 Դһ -* -* CH32V307VCT6 Դ -* Ըᷢ GPLGNU General Public License GNUͨù֤ -* GPL ĵ3棨 GPL3.0ѡģκκİ汾·/޸ -* -* Դķϣܷãδκεı֤ -* ûԻʺض;ı֤ -* ϸμ GPL -* -* ӦյԴͬʱյһ GPL ĸ -* ûУ -* -* ע -* Դʹ GPL3.0 Դ֤Э Ϊİ汾 -* Ӣİ libraries/doc ļµ GPL3_permission_statement.txt ļ -* ֤ libraries ļ ļµ LICENSE ļ -* ӭλʹò ޸ʱ뱣ɿƼİȨ -* -* ļ isr -* ˾ ɶɿƼ޹˾ -* 汾Ϣ 鿴 libraries/doc ļ version ļ 汾˵ -* MounRiver Studio V1.8.1 -* ƽ̨ CH32V307VCT6 -* https://seekfree.taobao.com/ -* -* ޸ļ¼ -* ע -* 2022-09-15 W first version -********************************************************************************************************************/ + * CH32V307VCT6 Opensourec Library CH32V307VCT6 Դ⣩һڹٷ SDK ӿڵĵԴ + * Copyright (c) 2022 SEEKFREE ɿƼ + * + * ļCH32V307VCT6 Դһ + * + * CH32V307VCT6 Դ + * Ըᷢ GPLGNU General Public License GNUͨù֤ + * GPL ĵ3棨 GPL3.0ѡģκκİ汾·/޸ + * + * Դķϣܷãδκεı֤ + * ûԻʺض;ı֤ + * ϸμ GPL + * + * ӦյԴͬʱյһ GPL ĸ + * ûУ + * + * ע + * Դʹ GPL3.0 Դ֤Э Ϊİ汾 + * Ӣİ libraries/doc ļµ GPL3_permission_statement.txt ļ + * ֤ libraries ļ ļµ LICENSE ļ + * ӭλʹò ޸ʱ뱣ɿƼİȨ + * + * ļ isr + * ˾ ɶɿƼ޹˾ + * 汾Ϣ 鿴 libraries/doc ļ version ļ 汾˵ + * MounRiver Studio V1.8.1 + * ƽ̨ CH32V307VCT6 + * https://seekfree.taobao.com/ + * + * ޸ļ¼ + * ע + * 2022-09-15 W first version + ********************************************************************************************************************/ #include "zf_common_headfile.h" -void NMI_Handler(void) __attribute__((interrupt())); +#include "by_pt_button.h" + +void NMI_Handler(void) __attribute__((interrupt())); void HardFault_Handler(void) __attribute__((interrupt())); void USART1_IRQHandler(void) __attribute__((interrupt())); void USART2_IRQHandler(void) __attribute__((interrupt())); void USART3_IRQHandler(void) __attribute__((interrupt())); -void UART4_IRQHandler (void) __attribute__((interrupt())); -void UART5_IRQHandler (void) __attribute__((interrupt())); -void UART6_IRQHandler (void) __attribute__((interrupt())); -void UART7_IRQHandler (void) __attribute__((interrupt())); -void UART8_IRQHandler (void) __attribute__((interrupt())); -void DVP_IRQHandler (void) __attribute__((interrupt())); -//void TIM1_BRK_IRQHandler (void) __attribute__((interrupt())); -void TIM1_UP_IRQHandler (void) __attribute__((interrupt())); -//void TIM1_TRG_COM_IRQHandler (void) __attribute__((interrupt())); -//void TIM1_CC_IRQHandler (void) __attribute__((interrupt())); -void TIM2_IRQHandler (void) __attribute__((interrupt())); -void TIM3_IRQHandler (void) __attribute__((interrupt())); -void TIM4_IRQHandler (void) __attribute__((interrupt())); -void TIM5_IRQHandler (void) __attribute__((interrupt())); -void TIM6_IRQHandler (void) __attribute__((interrupt())); -void TIM7_IRQHandler (void) __attribute__((interrupt())); -//void TIM8_BRK_IRQHandler (void) __attribute__((interrupt())); -void TIM8_UP_IRQHandler (void) __attribute__((interrupt())); -//void TIM8_TRG_COM_IRQHandler (void) __attribute__((interrupt())); -//void TIM8_CC_IRQHandler (void) __attribute__((interrupt())); -//void TIM9_BRK_IRQHandler (void) __attribute__((interrupt())); -void TIM9_UP_IRQHandler (void) __attribute__((interrupt())); -//void TIM9_TRG_COM_IRQHandler (void) __attribute__((interrupt())); -//void TIM9_CC_IRQHandler (void) __attribute__((interrupt())); -//void TIM10_BRK_IRQHandler (void) __attribute__((interrupt())); -void TIM10_UP_IRQHandler (void) __attribute__((interrupt())); -//void TIM10_TRG_COM_IRQHandler (void) __attribute__((interrupt())); -//void TIM10_CC_IRQHandler (void) __attribute__((interrupt())); +void UART4_IRQHandler(void) __attribute__((interrupt())); +void UART5_IRQHandler(void) __attribute__((interrupt())); +void UART6_IRQHandler(void) __attribute__((interrupt())); +void UART7_IRQHandler(void) __attribute__((interrupt())); +void UART8_IRQHandler(void) __attribute__((interrupt())); +void DVP_IRQHandler(void) __attribute__((interrupt())); +// void TIM1_BRK_IRQHandler (void) __attribute__((interrupt())); +void TIM1_UP_IRQHandler(void) __attribute__((interrupt())); +// void TIM1_TRG_COM_IRQHandler (void) __attribute__((interrupt())); +// void TIM1_CC_IRQHandler (void) __attribute__((interrupt())); +void TIM2_IRQHandler(void) __attribute__((interrupt())); +void TIM3_IRQHandler(void) __attribute__((interrupt())); +void TIM4_IRQHandler(void) __attribute__((interrupt())); +void TIM5_IRQHandler(void) __attribute__((interrupt())); +void TIM6_IRQHandler(void) __attribute__((interrupt())); +void TIM7_IRQHandler(void) __attribute__((interrupt())); +// void TIM8_BRK_IRQHandler (void) __attribute__((interrupt())); +void TIM8_UP_IRQHandler(void) __attribute__((interrupt())); +// void TIM8_TRG_COM_IRQHandler (void) __attribute__((interrupt())); +// void TIM8_CC_IRQHandler (void) __attribute__((interrupt())); +// void TIM9_BRK_IRQHandler (void) __attribute__((interrupt())); +void TIM9_UP_IRQHandler(void) __attribute__((interrupt())); +// void TIM9_TRG_COM_IRQHandler (void) __attribute__((interrupt())); +// void TIM9_CC_IRQHandler (void) __attribute__((interrupt())); +// void TIM10_BRK_IRQHandler (void) __attribute__((interrupt())); +void TIM10_UP_IRQHandler(void) __attribute__((interrupt())); +// void TIM10_TRG_COM_IRQHandler (void) __attribute__((interrupt())); +// void TIM10_CC_IRQHandler (void) __attribute__((interrupt())); void EXTI0_IRQHandler(void) __attribute__((interrupt())); void EXTI1_IRQHandler(void) __attribute__((interrupt())); @@ -79,162 +81,134 @@ void EXTI15_10_IRQHandler(void) __attribute__((interrupt())); void USART1_IRQHandler(void) { - if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) - { + if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(USART1, USART_IT_RXNE); } } void USART2_IRQHandler(void) { - if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) - { - + if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(USART2, USART_IT_RXNE); } } void USART3_IRQHandler(void) { - if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) - { -#if DEBUG_UART_USE_INTERRUPT // debug ж - debug_interrupr_handler(); // debug ڽմ ݻᱻ debug λȡ -#endif // ޸ DEBUG_UART_INDEX δҪŵӦĴжȥ + if (USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) { +#if DEBUG_UART_USE_INTERRUPT // debug ж + debug_interrupr_handler(); // debug ڽմ ݻᱻ debug λȡ +#endif // ޸ DEBUG_UART_INDEX δҪŵӦĴжȥ USART_ClearITPendingBit(USART3, USART_IT_RXNE); } } -void UART4_IRQHandler (void) +void UART4_IRQHandler(void) { - if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) - { + if (USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(UART4, USART_IT_RXNE); } } -void UART5_IRQHandler (void) +void UART5_IRQHandler(void) { - if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) - { + if (USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) { camera_uart_handler(); USART_ClearITPendingBit(UART5, USART_IT_RXNE); } } -void UART6_IRQHandler (void) +void UART6_IRQHandler(void) { - if(USART_GetITStatus(UART6, USART_IT_RXNE) != RESET) - { + if (USART_GetITStatus(UART6, USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(UART6, USART_IT_RXNE); } } -void UART7_IRQHandler (void) +void UART7_IRQHandler(void) { - if(USART_GetITStatus(UART7, USART_IT_RXNE) != RESET) - { + if (USART_GetITStatus(UART7, USART_IT_RXNE) != RESET) { wireless_module_uart_handler(); USART_ClearITPendingBit(UART7, USART_IT_RXNE); } } -void UART8_IRQHandler (void) +void UART8_IRQHandler(void) { - if(USART_GetITStatus(UART8, USART_IT_RXNE) != RESET) - { + if (USART_GetITStatus(UART8, USART_IT_RXNE) != RESET) { gps_uart_callback(); USART_ClearITPendingBit(UART8, USART_IT_RXNE); } - } - - void DVP_IRQHandler(void) { - if (DVP->IFR & RB_DVP_IF_FRM_DONE) - { + if (DVP->IFR & RB_DVP_IF_FRM_DONE) { camera_dvp_handler(); DVP->IFR &= ~RB_DVP_IF_FRM_DONE; } } void EXTI0_IRQHandler(void) { - if(SET == EXTI_GetITStatus(EXTI_Line0)) - { + if (SET == EXTI_GetITStatus(EXTI_Line0)) { EXTI_ClearITPendingBit(EXTI_Line0); - } } void EXTI1_IRQHandler(void) { - if(SET == EXTI_GetITStatus(EXTI_Line1)) - { + if (SET == EXTI_GetITStatus(EXTI_Line1)) { EXTI_ClearITPendingBit(EXTI_Line1); - } } void EXTI2_IRQHandler(void) { - if(SET == EXTI_GetITStatus(EXTI_Line2)) - { + if (SET == EXTI_GetITStatus(EXTI_Line2)) { EXTI_ClearITPendingBit(EXTI_Line2); - } } void EXTI3_IRQHandler(void) { - if(SET == EXTI_GetITStatus(EXTI_Line3)) - { + if (SET == EXTI_GetITStatus(EXTI_Line3)) { EXTI_ClearITPendingBit(EXTI_Line3); - } } void EXTI4_IRQHandler(void) { - if(SET == EXTI_GetITStatus(EXTI_Line4)) - { + if (SET == EXTI_GetITStatus(EXTI_Line4)) { EXTI_ClearITPendingBit(EXTI_Line4); - } } void EXTI9_5_IRQHandler(void) { - if(SET == EXTI_GetITStatus(EXTI_Line5)) - { + if (SET == EXTI_GetITStatus(EXTI_Line5)) { EXTI_ClearITPendingBit(EXTI_Line5); - } - if(SET == EXTI_GetITStatus(EXTI_Line6)) - { + if (SET == EXTI_GetITStatus(EXTI_Line6)) { EXTI_ClearITPendingBit(EXTI_Line6); - } - if(SET == EXTI_GetITStatus(EXTI_Line7)) - { + if (SET == EXTI_GetITStatus(EXTI_Line7)) { EXTI_ClearITPendingBit(EXTI_Line7); - } - if(SET == EXTI_GetITStatus(EXTI_Line8)) - { + if (SET == EXTI_GetITStatus(EXTI_Line8)) { EXTI_ClearITPendingBit(EXTI_Line8); - } - if(SET == EXTI_GetITStatus(EXTI_Line9)) - { + if (SET == EXTI_GetITStatus(EXTI_Line9)) { EXTI_ClearITPendingBit(EXTI_Line9); + if (SET == gpio_get_level(E10)) { + potate_button = POTATE_BUTTOM_BACKWARD; + } else { + potate_button = POTATE_BUTTOM_FOREWARD; + + } } - } void EXTI15_10_IRQHandler(void) { - if(SET == EXTI_GetITStatus(EXTI_Line10)) - { + if (SET == EXTI_GetITStatus(EXTI_Line10)) { // ˴дû (A10/B10..E10) Ŵ @@ -242,18 +216,18 @@ void EXTI15_10_IRQHandler(void) EXTI_ClearITPendingBit(EXTI_Line10); } - if(SET == EXTI_GetITStatus(EXTI_Line11)) - { + if (SET == EXTI_GetITStatus(EXTI_Line11)) { EXTI_ClearITPendingBit(EXTI_Line11); + system_delay_us(200); + if (SET == !gpio_get_level(E11)) { + potate_button = POTATE_BUTTOM_PRESS; + } } - if(SET == EXTI_GetITStatus(EXTI_Line12)) - { + if (SET == EXTI_GetITStatus(EXTI_Line12)) { EXTI_ClearITPendingBit(EXTI_Line12); - } - if(SET == EXTI_GetITStatus(EXTI_Line13)) - { + if (SET == EXTI_GetITStatus(EXTI_Line13)) { // -----------------* ToF INT ж Ԥжϴ *----------------- tof_module_exti_handler(); // -----------------* ToF INT ж Ԥжϴ *----------------- @@ -262,17 +236,14 @@ void EXTI15_10_IRQHandler(void) // ˴дû (A13/B13..E13) Ŵ EXTI_ClearITPendingBit(EXTI_Line13); - } - if(SET == EXTI_GetITStatus(EXTI_Line14)) - { + if (SET == EXTI_GetITStatus(EXTI_Line14)) { // -----------------* DM1XA ź Ԥжϴ *----------------- dm1xa_light_callback(); // -----------------* DM1XA ź Ԥжϴ *----------------- EXTI_ClearITPendingBit(EXTI_Line14); } - if(SET == EXTI_GetITStatus(EXTI_Line15)) - { + if (SET == EXTI_GetITStatus(EXTI_Line15)) { // -----------------* DM1XA /ź Ԥжϴ *----------------- dm1xa_sound_callback(); // -----------------* DM1XA /ź Ԥжϴ *----------------- @@ -280,108 +251,76 @@ void EXTI15_10_IRQHandler(void) } } - void TIM1_UP_IRQHandler(void) { - if(TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET) - { + if (TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM1, TIM_IT_Update); - } } - void TIM2_IRQHandler(void) { - if(TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) - { - TIM_ClearITPendingBit(TIM2, TIM_IT_Update ); - - + if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) { + TIM_ClearITPendingBit(TIM2, TIM_IT_Update); } } void TIM3_IRQHandler(void) { - if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) - { - TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); - - + if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) { + TIM_ClearITPendingBit(TIM3, TIM_IT_Update); } } void TIM4_IRQHandler(void) { - if(TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET) - { - TIM_ClearITPendingBit(TIM4, TIM_IT_Update ); - - + if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET) { + TIM_ClearITPendingBit(TIM4, TIM_IT_Update); } } void TIM5_IRQHandler(void) { - if(TIM_GetITStatus(TIM5, TIM_IT_Update) != RESET) - { - TIM_ClearITPendingBit(TIM5, TIM_IT_Update ); - - + if (TIM_GetITStatus(TIM5, TIM_IT_Update) != RESET) { + TIM_ClearITPendingBit(TIM5, TIM_IT_Update); } } void TIM6_IRQHandler(void) { - if(TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) - { - TIM_ClearITPendingBit(TIM6, TIM_IT_Update ); - + if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) { + TIM_ClearITPendingBit(TIM6, TIM_IT_Update); } } void TIM7_IRQHandler(void) { - if(TIM_GetITStatus(TIM7, TIM_IT_Update) != RESET) - { - TIM_ClearITPendingBit(TIM7, TIM_IT_Update ); - - + if (TIM_GetITStatus(TIM7, TIM_IT_Update) != RESET) { + TIM_ClearITPendingBit(TIM7, TIM_IT_Update); } } - void TIM8_UP_IRQHandler(void) { - if(TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET) - { + if (TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM8, TIM_IT_Update); - } } - void TIM9_UP_IRQHandler(void) { - if(TIM_GetITStatus(TIM9, TIM_IT_Update) != RESET) - { + if (TIM_GetITStatus(TIM9, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM9, TIM_IT_Update); - } } - void TIM10_UP_IRQHandler(void) { - if(TIM_GetITStatus(TIM10, TIM_IT_Update) != RESET) - { + if (TIM_GetITStatus(TIM10, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM10, TIM_IT_Update); - } } - - //.section .text.vector_handler, "ax", @progbits // .weak EXTI0_IRQHandler /* EXTI Line 0 */ @@ -468,26 +407,23 @@ void TIM10_UP_IRQHandler(void) // .weak DMA2_Channel11_IRQHandler /* DMA2 Channel 11 */ /******************************************************************************* -* Function Name : NMI_Handler -* Description : This function handles NMI exception. -* Input : None -* Return : None -*******************************************************************************/ + * Function Name : NMI_Handler + * Description : This function handles NMI exception. + * Input : None + * Return : None + *******************************************************************************/ void NMI_Handler(void) { } /******************************************************************************* -* Function Name : HardFault_Handler -* Description : This function handles Hard Fault exception. -* Input : None -* Return : None -*******************************************************************************/ + * Function Name : HardFault_Handler + * Description : This function handles Hard Fault exception. + * Input : None + * Return : None + *******************************************************************************/ void HardFault_Handler(void) { - while (1) - { - } + while (1) { + } } - - diff --git a/app/main.c b/app/main.c index d71eb23..5822915 100644 --- a/app/main.c +++ b/app/main.c @@ -33,6 +33,8 @@ * 2022-09-15 W first version ********************************************************************************************************************/ #include "zf_common_headfile.h" +#include "by_pt_button.h" +#include "by_fan_control.h" int main (void) @@ -42,15 +44,17 @@ int main (void) // ˴дû ʼ ips114_init(); - mt9v03x_init(); + by_gpio_init(); + by_exit_init(); + by_pwm_init(); + // mt9v03x_init(); // ˴дû ʼ while(1) { // ˴дҪѭִеĴ - if(mt9v03x_finish_flag){ - ips114_show_gray_image(0, 0, mt9v03x_image[0], 188, 120, 188, 120,0); - } + + // ˴дҪѭִеĴ } }