Pārlūkot izejas kodu

Добавил логику.

TelenkovDmitry 11 mēneši atpakaļ
vecāks
revīzija
0caa6d81ef

BIN
doc/photo_2024-04-27_14-02-43.jpg


BIN
doc/photo_2024-05-20_22-28-11.jpg


+ 4 - 4
modules/gpio.c

@@ -3,14 +3,14 @@
 
 
 #define SET_OUT_1   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET)
-#define SET_OUT_2   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET)
+#define SET_OUT_2   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET)
 #define SET_OUT_3   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET)
-#define SET_OUT_4   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET)
+#define SET_OUT_4   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET)
 
 #define RESET_OUT_1   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET)
-#define RESET_OUT_2   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET)
+#define RESET_OUT_2   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET)
 #define RESET_OUT_3   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET)
-#define RESET_OUT_4   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET)
+#define RESET_OUT_4   HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET)
 
 
 static uint8_t next_out_number = 0;

+ 38 - 3
modules/logic.c

@@ -2,18 +2,53 @@
 #include "logic.h"
 #include "pwm_in.h"
 #include "gpio.h"
+#include "pwm_out.h"
 
 
+static uint8_t step_number = 0;
+
 
 //
 void logic_main(void)
 {
-    //static uint8_t main_counter = 0;
-  
-    
     if (get_button()) 
     {   
         gpio_set_output(true);
+        HAL_Delay(1000);
+        logic_set_out_pwm();
+        HAL_Delay(500);
+        gpio_set_output(false);
+        tim_pwm_pulse_idle();
+        
+        set_button(false);
     }   
     
 }
+
+//
+void logic_set_out_pwm(void)
+{
+    switch (step_number)
+    {
+        case 0:
+            tim_pwm_out_set_pulse(PWM_OUT_CH_1, 1300);
+        break;
+    
+        case 1:
+            tim_pwm_out_set_pulse(PWM_OUT_CH_2, 1300);
+        break;
+    
+        case 2:
+            tim_pwm_out_set_pulse(PWM_OUT_CH_1, 1850);
+        break;
+    
+        case 3:
+            tim_pwm_out_set_pulse(PWM_OUT_CH_2, 1850);
+        break;
+    
+        default : break;
+    }
+    
+    step_number = step_number == 3 ? 0 : step_number + 1;
+}
+

+ 2 - 0
modules/logic.h

@@ -7,6 +7,8 @@
 //
 void logic_main(void);
 
+//
+void logic_set_out_pwm(void);
 
   
 #endif

+ 3 - 0
modules/pwm_in.h

@@ -12,4 +12,7 @@ void tim_print_out_pwm(void);
 //
 bool get_button(void);
 
+//
+void set_button(bool state);
+
 #endif

+ 24 - 0
modules/pwm_out.c

@@ -57,4 +57,28 @@ void tim_pwm_out_init(void)
     
     HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2);
     HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_3);
+}
+
+//
+void tim_pwm_out_set_pulse(pwm_out_ch channel, uint16_t pulse)
+{
+    switch (channel)
+    {
+        case PWM_OUT_CH_1: 
+            TIM1->CCR2 = pulse;
+        break;
+        
+        case PWM_OUT_CH_2:
+            TIM1->CCR3 = pulse;
+        break;
+        
+        default : break;
+    }  
+}
+
+//
+void tim_pwm_pulse_idle(void)
+{
+    TIM1->CCR2 = IDLE_PULSE;
+    TIM1->CCR3 = IDLE_PULSE;
 }

+ 23 - 7
modules/pwm_out.h

@@ -1,8 +1,24 @@
-#ifndef __PWM_OUT_H
-#define __PWM_OUT_H
-
-//
-void tim_pwm_out_init(void);
-
-
+#ifndef __PWM_OUT_H
+#define __PWM_OUT_H
+
+
+
+typedef enum
+{
+    PWM_OUT_CH_1 = 1,
+    PWM_OUT_CH_2,
+    PWM_OUT_CH_MAX,
+  
+} pwm_out_ch;
+
+
+//
+void tim_pwm_out_init(void);
+
+//
+void tim_pwm_out_set_pulse(pwm_out_ch channel, uint16_t pulse);
+
+//
+void tim_pwm_pulse_idle(void);
+
 #endif

BIN
output/lasertag.bin


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 382 - 376
project/ewarm/drone.dep


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
project/settings/drone.wsdt


+ 2 - 23
user/main.c

@@ -27,36 +27,15 @@ int main()
     gpio_init();
     tim_pwm_out_init();
     tim_pwm_in_init();
-    
+
+#if 0    
     usart_init();
     printf("FW started...\r\n");
-    
-// -----------------------------------------------------------------------------    
-// Тесты     
-#if 0
-    gpio_set_output(true);
-    gpio_set_output(false);
-    gpio_set_output(true);
-    gpio_set_output(false);
-    gpio_set_output(true);
-    gpio_set_output(false);
-    gpio_set_output(true);
-    gpio_set_output(false);
-    gpio_set_output(true);
-    gpio_set_output(false);
-
 #endif    
     
-    
     while(1) 
     {
         logic_main();
-      
-#if 0      
-        HAL_Delay(1000);
-        tim_print_out_pwm();
-        timer_Main();
-#endif        
     }
 }
 

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels