Skip to content

Commit 0756d2d

Browse files
authored
Add files via upload
1 parent 8b38d41 commit 0756d2d

File tree

9 files changed

+497
-0
lines changed

9 files changed

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

0 commit comments

Comments
 (0)