Skip to content

Commit befc911

Browse files
authored
Add files via upload
1 parent 3b80fc0 commit befc911

File tree

10 files changed

+518
-0
lines changed

10 files changed

+518
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "M6.h"
2+
#include "drive_control.h"
3+
4+
/*Voice control init*/
5+
/*Pmod5_pin8<-->M6_RX,Pmod5_pin9<-->M6_TX*/
6+
void M6_init(void)
7+
{
8+
M6 = uart_get_dev(DW_UART_2_ID);
9+
M6->uart_open(UART_BAUDRATE_9600);
10+
M6->uart_control(UART_CMD_SET_BAUD,(void*)(UART_BAUDRATE_9600));
11+
}
12+
13+
void voice_control(uint8_t M6_rcv_buf[],uint32_t M6_rcv_cnt)
14+
{
15+
switch(M6_rcv_buf[M6_rcv_cnt-1])
16+
{
17+
18+
case 1:
19+
car_set(0,PWM_L,PWM_R);//stop
20+
EMBARC_PRINTF("ble command is %s,停下\r\n",M6_rcv_buf);
21+
break;
22+
case 2:
23+
car_set(1,PWM_L,PWM_R);//forward
24+
EMBARC_PRINTF("ble command is %s,向前\r\n",M6_rcv_buf);
25+
break;
26+
case 3:
27+
car_set(2,PWM_L,PWM_R);//left
28+
EMBARC_PRINTF("ble command is %s,向左\r\n",M6_rcv_buf);
29+
break;
30+
case 4:
31+
car_set(3,PWM_L,PWM_R);//right
32+
EMBARC_PRINTF("ble command is %s,向右\r\n",M6_rcv_buf);
33+
break;
34+
case 5:
35+
car_set(6,PWM_L,PWM_R);//backward
36+
EMBARC_PRINTF("ble command is %s,向前\r\n",M6_rcv_buf);
37+
break;
38+
default:
39+
EMBARC_PRINTF("ble command error\r\n");
40+
break;
41+
}
42+
43+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "embARC.h"
2+
#include "embARC_debug.h"
3+
4+
#include "board.h"
5+
#include "dev_uart.h"
6+
7+
#include "stdio.h"
8+
9+
static DEV_UART_PTR M6;
10+
11+
extern void M6_init(void);
12+
extern void voice_control(uint8_t M6_rcv_buf[],uint32_t M6_rcv_cnt);
13+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "ble.h"
2+
#include "buzzer.h"
3+
4+
#include "drive_control.h"
5+
6+
7+
/*******Use PMOD1*******/
8+
9+
void ble_control(uint8_t ble_rcv_buf[])
10+
{
11+
switch (ble_rcv_buf[0])
12+
{
13+
EMBARC_PRINTF("%s\n",ble_rcv_buf);
14+
case 'p':
15+
car_set(0,PWM_L,PWM_R);//stop
16+
EMBARC_PRINTF("ble command is %s,停下\r\n",ble_rcv_buf);
17+
break;
18+
case 'w':
19+
car_set(1,PWM_L,PWM_R);//forward
20+
EMBARC_PRINTF("ble command is %s,向前\r\n",ble_rcv_buf);
21+
break;
22+
case 'a':
23+
car_set(2,PWM_L,PWM_R);//left
24+
EMBARC_PRINTF("ble command is %s,向左\r\n",ble_rcv_buf);
25+
break;
26+
case 'd':
27+
car_set(3,PWM_L,PWM_R);//right
28+
EMBARC_PRINTF("ble command is %s,向右\r\n",ble_rcv_buf);
29+
break;
30+
case 's':
31+
car_set(6,PWM_L,PWM_R);//backward
32+
EMBARC_PRINTF("ble command is %s,向前\r\n",ble_rcv_buf);
33+
break;
34+
case 'u':
35+
car_set(4,PWM_L,PWM_R);//speed up
36+
EMBARC_PRINTF("ble command is %s,speed=%d,加速\r\n",ble_rcv_buf,speed);
37+
break;
38+
case 'i':
39+
car_set(5,PWM_L,PWM_R);//speed down
40+
EMBARC_PRINTF("ble command is %s,减速\r\n",ble_rcv_buf);
41+
break;
42+
case 'b':
43+
buzzer_open();
44+
EMBARC_PRINTF("buzzer_open\n");
45+
break;
46+
case 'n':
47+
buzzer_close();
48+
EMBARC_PRINTF("buzzer_close\n");
49+
break;
50+
default:
51+
EMBARC_PRINTF("ble command error\r\n");
52+
break;
53+
}
54+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "embARC.h"
2+
#include "embARC_debug.h"
3+
4+
#include "board.h"
5+
6+
#include "stdio.h"
7+
8+
extern void ble_control(uint8_t ble_rcv_buf[]);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "buzzer.h"
2+
3+
#define BUZZER_MASK 0x00010000
4+
5+
void buzzer_init(void)
6+
{
7+
buzzer = gpio_get_dev(DW_GPIO_PORT_A);//Pmod3_pin7<--->BUZZER
8+
buzzer->gpio_open(BUZZER_MASK);
9+
buzzer->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)BUZZER_MASK);
10+
buzzer->gpio_write(0x00010000,BUZZER_MASK);
11+
}
12+
13+
void buzzer_open(void)
14+
{
15+
buzzer->gpio_write(0x00000000,BUZZER_MASK);
16+
}
17+
18+
void buzzer_close(void)
19+
{
20+
buzzer->gpio_write(0x00010000,BUZZER_MASK);
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "embARC.h"
2+
#include "embARC_debug.h"
3+
4+
#include "board.h"
5+
#include "dev_gpio.h"
6+
7+
static DEV_GPIO_PTR buzzer;
8+
9+
extern void buzzer_init(void);
10+
extern void buzzer_open(void);
11+
extern void buzzer_close(void);
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include "drive_control.h"
2+
3+
4+
/*L298N_init*/
5+
void L298N_init(void)
6+
{
7+
8+
PMOD_L = gpio_get_dev(DW_GPIO_PORT_A);
9+
PMOD_L->gpio_open(L298N_L_MASK);
10+
PMOD_L->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)L298N_L_MASK);
11+
12+
PMOD_R = gpio_get_dev(DW_GPIO_PORT_A);
13+
PMOD_R->gpio_open(L298N_R_MASK);
14+
PMOD_R->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)L298N_R_MASK);
15+
16+
PMOD_F = gpio_get_dev(DW_GPIO_PORT_A);
17+
PMOD_F->gpio_open(L298N_F_MASK);
18+
PMOD_F->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)L298N_F_MASK);
19+
20+
PMOD_H = gpio_get_dev(DW_GPIO_PORT_C);
21+
PMOD_H->gpio_open(L298N_H_MASK);
22+
PMOD_H->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)L298N_H_MASK);
23+
24+
}
25+
26+
27+
/**
28+
* \brief Control move.
29+
* \param dire.Direction of move.
30+
* \param pwm_left.Left PWM control.
31+
* \param pwm_right.Right PWM control.
32+
*/
33+
void car_set(uint32_t dire,uint32_t pwm_left, uint32_t pwm_right)
34+
{
35+
switch(dire)
36+
{
37+
//stop
38+
case 0:
39+
PWM_L = 0;
40+
PWM_R = 0;
41+
break;
42+
//forward
43+
case 1:
44+
PMOD_F->gpio_write(0x30000000,L298N_F_MASK);
45+
PMOD_H->gpio_write(0x00000000,L298N_H_MASK);
46+
PWM_L = speed;
47+
PWM_R = speed;
48+
break;
49+
//left
50+
case 2:
51+
PMOD_F->gpio_write(0x30000000,L298N_F_MASK);
52+
PMOD_H->gpio_write(0x00000000,L298N_H_MASK);
53+
54+
PMOD_R->gpio_write(0x80000000,L298N_R_MASK);
55+
PWM_L = 0;
56+
PWM_R = speed;
57+
break;
58+
//right
59+
case 3:
60+
PMOD_F->gpio_write(0x30000000,L298N_F_MASK);
61+
PMOD_H->gpio_write(0x00000000,L298N_H_MASK);
62+
63+
PMOD_L->gpio_write(0x40000000,L298N_L_MASK);
64+
PWM_L = speed;
65+
PWM_R = 0;
66+
break;
67+
case 4: //speed up
68+
if(speed < 9)
69+
{
70+
speed = speed + 1;
71+
PWM_L = speed;
72+
PWM_R = speed;
73+
}
74+
break;
75+
case 5: //speed down
76+
if(speed > 0)
77+
{
78+
speed = speed - 1;
79+
PWM_L = speed;
80+
PWM_R = speed;
81+
}
82+
break;
83+
//backward
84+
case 6:
85+
PMOD_F->gpio_write(0x00000000,L298N_F_MASK);
86+
PMOD_H->gpio_write(0xC0000000,L298N_H_MASK);
87+
PWM_L = speed;
88+
PWM_R = speed;
89+
break;
90+
}
91+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "embARC.h"
2+
#include "embARC_debug.h"
3+
4+
#include "board.h"
5+
#include "dev_gpio.h"
6+
7+
#define L298N_L_MASK 0x40000000 //Pmod6_pin9<--->L298N_LEFT_EN
8+
#define L298N_R_MASK 0x80000000 //Pmod6_pin10<--->L298N_RIGHT_EN
9+
#define L298N_F_MASK 0x30000000 //Pmod6_pin7,pin8<--->L298N_FORWORD_EN
10+
#define L298N_H_MASK 0xC0000000 //Pmod6_pin3,pin4<--->L298N_BACK_EN
11+
12+
static DEV_GPIO_PTR PMOD_L;
13+
static DEV_GPIO_PTR PMOD_R;
14+
static DEV_GPIO_PTR PMOD_F;
15+
static DEV_GPIO_PTR PMOD_H;
16+
17+
static uint32_t PWM_L = 0;
18+
static uint32_t PWM_R = 0;
19+
20+
static uint32_t speed = 4;
21+
22+
extern void L298N_init(void);
23+
extern void car_set(uint32_t dire,uint32_t pwm_left, uint32_t pwm_right);

0 commit comments

Comments
 (0)