From 1c3131e9c7c8adf61f4fc8ec11d10f90ec56e42f Mon Sep 17 00:00:00 2001 From: bmy <2583236812@qq.com> Date: Wed, 24 Apr 2024 23:22:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E4=BD=8D=E6=9C=BA=E9=80=9A=E4=BF=A1=E6=8E=A5=E5=8F=A3=20(?= =?UTF-8?q?=E5=BA=95=E7=9B=98=E9=80=9F=E5=BA=A6=E5=92=8C=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E6=8E=A7=E5=88=B6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BC1C.ATWP | 8 +- BC1C.code-workspace | 2 +- app/by_can.c | 40 ++ app/by_can.h | 9 + app/by_frame.h | 2 +- app/by_messy.c | 74 ++++ app/by_messy.h | 7 + app/by_motion.c | 94 ++++- app/by_motion.h | 16 + app/by_utils.c | 7 + app/by_utils.h | 23 ++ project/src/at32f403a_407_int.c | 3 + project/src/at32f403a_407_wk_config.c | 556 +++++++++++++------------- project/src/main.c | 13 +- 14 files changed, 560 insertions(+), 294 deletions(-) create mode 100644 app/by_can.c create mode 100644 app/by_can.h create mode 100644 app/by_messy.c create mode 100644 app/by_messy.h create mode 100644 app/by_utils.c create mode 100644 app/by_utils.h diff --git a/BC1C.ATWP b/BC1C.ATWP index b09cdc0..e82e475 100644 --- a/BC1C.ATWP +++ b/BC1C.ATWP @@ -78,8 +78,8 @@ - - + + @@ -90,6 +90,10 @@ + + + + diff --git a/BC1C.code-workspace b/BC1C.code-workspace index fe5d546..38de214 100644 --- a/BC1C.code-workspace +++ b/BC1C.code-workspace @@ -31,7 +31,7 @@ "titleBar.activeBackground": "#693002", "titleBar.activeForeground": "#FFF9F4" }, - "cortex-debug.variableUseNaturalFormat": false + "cortex-debug.variableUseNaturalFormat": true }, "extensions": { } diff --git a/app/by_can.c b/app/by_can.c new file mode 100644 index 0000000..cb1b32a --- /dev/null +++ b/app/by_can.c @@ -0,0 +1,40 @@ +#include "by_can.h" + +#include +#include +#include "dwt_delay.h" +#include "by_utils.h" +#include "by_debug.h" + +by_error_status by_can_send_stdd(uint32_t id, const uint8_t *data, uint8_t len, uint16_t timeout) +{ + + assert(id < 0x7FF); + + if (len > 8) { + len = 8; + } + + uint8_t transmit_mailbox; + can_tx_message_type tx_message_struct; + tx_message_struct.standard_id = id; /* 设置发送数据帧的 ID=0x400 */ + tx_message_struct.extended_id = 0; /* 不设置 */ + tx_message_struct.id_type = CAN_ID_STANDARD; /* 发送数据帧类型(标准/扩展):标准数据帧 */ + tx_message_struct.frame_type = CAN_TFT_DATA; /* 发送帧类型(远程/数据):数据帧 */ + tx_message_struct.dlc = len; /* 发送数据长度(0~8):8 */ + memcpy(tx_message_struct.data, data, len); /* 复制发送数据 */ + transmit_mailbox = can_message_transmit(CAN1, &tx_message_struct); /* 将以上待发送报文写入发送邮箱并请求发送 */ + + /* 等待该邮箱发送成功—对应邮箱发送成功标志置起 */ + while (can_transmit_status_get(CAN1, (can_tx_mailbox_num_type)transmit_mailbox) != CAN_TX_STATUS_SUCCESSFUL) { + // LOGD("CAN#SEND: timeout=%d", timeout); + if (0 == timeout--) { + LOGW("CAN#TIMEOUT: ID=0x%x", id); + + return BY_ERROR; + } + DWT_Delay(10); + } + + return BY_SUCCESS; +} diff --git a/app/by_can.h b/app/by_can.h new file mode 100644 index 0000000..30dec8b --- /dev/null +++ b/app/by_can.h @@ -0,0 +1,9 @@ +#ifndef _BY_CAN_H__ +#define _BY_CAN_H__ + +#include "at32f403a_407.h" +#include "by_utils.h" + +by_error_status by_can_send_stdd(uint32_t id, const uint8_t *data, uint8_t len, uint16_t timeout); + +#endif \ No newline at end of file diff --git a/app/by_frame.h b/app/by_frame.h index 2d570cb..ad69b3f 100644 --- a/app/by_frame.h +++ b/app/by_frame.h @@ -14,7 +14,7 @@ #define BY_FRAME_UART_INDEX (USART3) -#define BY_FRAME_DATA_NUM (3) +#define BY_FRAME_DATA_NUM (2) extern void by_frame_init(void); void by_frame_send(uint8_t cmd, uint32_t *data_array); diff --git a/app/by_messy.c b/app/by_messy.c new file mode 100644 index 0000000..2d05343 --- /dev/null +++ b/app/by_messy.c @@ -0,0 +1,74 @@ +#include "by_messy.h" + +#include "lwprintf.h" +#include "by_frame.h" +#include "by_motion.h" + +void by_messy_init(void) +{ + by_frame_init(); +} + +void by_messy_loop(void) +{ + uint8_t cmd = 0; + uint32_t buff[BY_FRAME_DATA_NUM] = {0}; + + if (!by_frame_parse(&cmd, buff)) { + + lwprintf("get cmd: %X\r\n", cmd); + + switch (cmd) { + case 0x31: // 设置速度 x + memcpy(&motion_speed_struct.v_x, buff, sizeof(motion_speed_struct.v_x)); + by_motion_set_mode(0); + break; + + case 0x32: // 设置速度 y + memcpy(&motion_speed_struct.v_y, buff, sizeof(motion_speed_struct.v_y)); + by_motion_set_mode(0); + break; + + case 0x33: // 设置速度 omega + memcpy(&motion_speed_struct.v_w, buff, sizeof(motion_speed_struct.v_w)); + by_motion_set_mode(0); + break; + + case 0x34: // 设置移动距离 x + by_frame_send(cmd, buff); // 正确接收后直接返回原文 + memcpy(&motion_speed_struct.v_x, buff, sizeof(motion_speed_struct.v_x)); + by_motion_set_mode(1); + motion_time_struct.t_x += buff[1]; + break; + + case 0x35: // 设置移动距离 y + by_frame_send(cmd, buff); // 正确接收后直接返回原文 + memcpy(&motion_speed_struct.v_y, buff, sizeof(motion_speed_struct.v_y)); + by_motion_set_mode(1); + motion_time_struct.t_y += buff[1]; + break; + + case 0x36: // 设置旋转角度 omega + by_frame_send(cmd, buff); // 正确接收后直接返回原文 + memcpy(&motion_speed_struct.v_w, buff, sizeof(motion_speed_struct.v_w)); + by_motion_set_mode(1); + motion_time_struct.t_w += buff[1]; + break; + + case 0x41: // 设置转台 x 轴复位 + by_frame_send(cmd, buff); // 正确接收后直接返回原文 + break; + + case 0x42: // 设置转台 z 轴复位 + by_frame_send(cmd, buff); // 正确接收后直接返回原文 + break; + + case 0x43: // 设置转台末端执行器复位 + by_frame_send(cmd, buff); // 正确接收后直接返回原文 + break; + + default: + break; + } + } +} \ No newline at end of file diff --git a/app/by_messy.h b/app/by_messy.h new file mode 100644 index 0000000..380cd55 --- /dev/null +++ b/app/by_messy.h @@ -0,0 +1,7 @@ +#ifndef _BY_MESSY_H__ +#define _BY_MESSY_H__ + +extern void by_messy_init(void); +extern void by_messy_loop(void); + +#endif diff --git a/app/by_motion.c b/app/by_motion.c index 496b870..5ca2f3c 100644 --- a/app/by_motion.c +++ b/app/by_motion.c @@ -2,13 +2,12 @@ #include #include +#include "by_debug.h" +#include "by_can.h" -#define D_X (0.18f) // 底盘 Y 轴上两轮中心的间距 -#define D_Y (0.25f) // 底盘 X 轴上两轮中心的间距 -#define RX_RY ((D_X + D_Y) / 2.f) - -#define FP2U16_SCALE (1000.f) // 浮点转存为整数缩放尺度,所有设备该参数需对应 -#define FP2U16(x) ((int16_t)(x * FP2U16_SCALE)) // 浮点转存为整数 +#define D_X (0.18f) // 底盘 Y 轴上两轮中心的间距 +#define D_Y (0.25f) // 底盘 X 轴上两轮中心的间距 +#define RX_RY ((D_X + D_Y) / 2.f) /********************************************** * v_1 = v_{ty} + v_{tx} - (r_x + r_y) * \omega @@ -17,11 +16,20 @@ * v_4 = v_{ty} - v_{tx} - (r_x + r_y) * \omega **********************************************/ +/*** 控制模式 ***/ +uint8_t control_mode = 0; // 0-速度模式 1-位置模式 + +/*** 位置控制 ***/ +uint8_t control_timer = 0; // 位置控制定时器状态 +uint32_t control_timer_cnt = 0; // 位置控制计数 + /*** 各轮转速,左上角为 1 号,顺时针标号 ***/ float v_wheel[4] = {0.f}; /** 目标速度 **/ motion_speed_type motion_speed_struct; +motion_speed_type motion_speed_struct_last; +motion_time_type motion_time_struct; /** 下发数据包 **/ int16_t motion_speed_data[4] = {0}; @@ -29,26 +37,88 @@ int16_t motion_speed_data[4] = {0}; void by_motion_init(void) { memset(&motion_speed_struct, 0, sizeof(motion_speed_struct)); + memset(&motion_speed_struct_last, 0, sizeof(motion_speed_struct_last)); + memset(&motion_time_struct, 0, sizeof(motion_time_struct)); + memset(motion_speed_data, 0, sizeof(motion_speed_data)); memset(v_wheel, 0, sizeof(v_wheel)); + + by_can_send_stdd(0x01, (uint8_t *)&motion_speed_data, 8, 100); } -void by_motion_calc_speed(motion_speed_type *speed) +void by_motion_update_speed(void) { - motion_speed_struct = *speed; + const motion_speed_type *speed = &motion_speed_struct; v_wheel[0] = speed->v_x + speed->v_y - RX_RY * speed->v_w; v_wheel[1] = speed->v_x - speed->v_y + RX_RY * speed->v_w; v_wheel[2] = speed->v_x + speed->v_y + RX_RY * speed->v_w; v_wheel[3] = speed->v_x - speed->v_y - RX_RY * speed->v_w; + + for (uint8_t i = 0; i < 4; i++) { + motion_speed_data[i] = (int16_t)v_wheel[i]; + + LOGD("MOTION#SPD wheel[%d] - %d", i, motion_speed_data[i]); + } + + by_can_send_stdd(0x01, (uint8_t *)&motion_speed_data, 8, 100); + LOGD("MOTION#SPD updated"); } /** - * @brief + * @brief 电机控制 - 主循环中调用 * */ -void by_motion_pack_speed(void) +void by_motion_loop(void) { - for (uint8_t i = 0; i < 4; i++) { - motion_speed_data[i] = FP2U16(v_wheel[i]); + if (control_mode == 0) { // 速度控制模式 + memset(&motion_time_struct, 0, sizeof(motion_time_struct)); + } else { // 位置控制模式 + if (0 == motion_time_struct.t_x) { + motion_speed_struct.v_x = 0; + } + if (0 == motion_time_struct.t_y) { + motion_speed_struct.v_y = 0; + } + if (0 == motion_time_struct.t_w) { + motion_speed_struct.v_w = 0; + } } + + if ((motion_speed_struct.v_x != motion_speed_struct_last.v_x) || (motion_speed_struct.v_y != motion_speed_struct_last.v_y) || (motion_speed_struct.v_w != motion_speed_struct_last.v_w)) { + by_motion_update_speed(); + memcpy(&motion_speed_struct_last, &motion_speed_struct, sizeof(motion_speed_type)); + } +} + +/** + * @brief 定时回调 + * + */ +void by_motion_timer_handle(void) +{ + if (control_mode == 0) { + motion_time_struct.t_x = 0; + motion_time_struct.t_y = 0; + motion_time_struct.t_w = 0; + } else { + if (motion_time_struct.t_x > 0) { + motion_time_struct.t_x--; + } + if (motion_time_struct.t_y > 0) { + motion_time_struct.t_y--; + } + if (motion_time_struct.t_w > 0) { + motion_time_struct.t_w--; + } + } +} + +/** + * @brief 设置电机控制模式 + * + * @param mode 0-速度模式 1-位置模式 + */ +void by_motion_set_mode(uint8_t mode) +{ + control_mode = mode; } \ No newline at end of file diff --git a/app/by_motion.h b/app/by_motion.h index bc0039c..42a6b2d 100644 --- a/app/by_motion.h +++ b/app/by_motion.h @@ -9,4 +9,20 @@ typedef struct motion_speed_type { float v_w; } motion_speed_type; +typedef struct motion_time_type { + uint32_t t_x; + uint32_t t_y; + uint32_t t_w; +} motion_time_type; + +extern void by_motion_init(void); +extern void by_motion_update_speed(void); +extern void by_motion_loop(void); +extern void by_motion_set_mode(uint8_t mode); +extern void by_motion_timer_handle(void); +extern void by_motion_set_mode(uint8_t mode); + +extern motion_speed_type motion_speed_struct; +extern motion_time_type motion_time_struct; + #endif diff --git a/app/by_utils.c b/app/by_utils.c new file mode 100644 index 0000000..7e89e69 --- /dev/null +++ b/app/by_utils.c @@ -0,0 +1,7 @@ +#include "by_utils.h" + +inline int32_t clip_s32(int32_t x, int32_t low, int32_t up) +{ + return (x > up ? up : x < low ? low + : x); +} diff --git a/app/by_utils.h b/app/by_utils.h new file mode 100644 index 0000000..b8c69b3 --- /dev/null +++ b/app/by_utils.h @@ -0,0 +1,23 @@ +#ifndef _BY_UTILS_H__ +#define _BY_UTILS_H__ + +#include "at32f403a_407.h" + +typedef enum { + BY_ERROR = 0, + BY_SUCCESS = !BY_ERROR +} by_error_status; + +typedef enum { + T_U8 = 0, + T_U16, + T_U32, + T_S8, + T_S16, + T_S32, + T_F32 +} by_data_type; + +int32_t clip_s32(int32_t x, int32_t low, int32_t up); + +#endif \ No newline at end of file diff --git a/project/src/at32f403a_407_int.c b/project/src/at32f403a_407_int.c index 0560e52..9770b09 100644 --- a/project/src/at32f403a_407_int.c +++ b/project/src/at32f403a_407_int.c @@ -31,6 +31,7 @@ /* add user code begin private includes */ #include "by_debug.h" #include "by_frame.h" +#include "by_motion.h" /* add user code end private includes */ /* private typedef -----------------------------------------------------------*/ @@ -266,6 +267,7 @@ void USART3_IRQHandler(void) { /* add user code begin USART3_IRQ 0 */ if (SET == usart_flag_get(USART3, USART_RDBF_FLAG)) { + by_frame_parse_uart_handle((uint8_t)usart_data_receive(USART3)); // usart_data_transmit(USART1, usart_data_receive(USART3)); usart_flag_clear(USART3, USART_RDBF_FLAG); } @@ -284,6 +286,7 @@ void TMR6_GLOBAL_IRQHandler(void) { /* add user code begin TMR6_GLOBAL_IRQ 0 */ if (SET == tmr_flag_get(TMR6, TMR_OVF_FLAG)) { + by_motion_timer_handle(); tmr_flag_clear(TMR6, TMR_OVF_FLAG); } /* add user code end TMR6_GLOBAL_IRQ 0 */ diff --git a/project/src/at32f403a_407_wk_config.c b/project/src/at32f403a_407_wk_config.c index d8be2c5..bb7fa65 100644 --- a/project/src/at32f403a_407_wk_config.c +++ b/project/src/at32f403a_407_wk_config.c @@ -62,23 +62,23 @@ /* add user code end 0 */ /** - * @brief system clock config program - * @note the system clock is configured as follow: - * system clock (sclk) = hick / 12 * pll_mult - * system clock source = HICK_VALUE - * - hext = HEXT_VALUE - * - sclk = 240000000 - * - ahbdiv = 1 - * - ahbclk = 240000000 - * - apb1div = 2 - * - apb1clk = 120000000 - * - apb2div = 2 - * - apb2clk = 120000000 - * - pll_mult = 60 - * - pll_range = GT72MHZ (greater than 72 mhz) - * @param none - * @retval none - */ + * @brief system clock config program + * @note the system clock is configured as follow: + * system clock (sclk) = hick / 12 * pll_mult + * system clock source = HICK_VALUE + * - hext = HEXT_VALUE + * - sclk = 240000000 + * - ahbdiv = 1 + * - ahbclk = 240000000 + * - apb1div = 2 + * - apb1clk = 120000000 + * - apb2div = 2 + * - apb2clk = 120000000 + * - pll_mult = 60 + * - pll_range = GT72MHZ (greater than 72 mhz) + * @param none + * @retval none + */ void wk_system_clock_config(void) { /* reset crm */ @@ -88,21 +88,24 @@ void wk_system_clock_config(void) crm_clock_source_enable(CRM_CLOCK_SOURCE_LICK, TRUE); /* wait till lick is ready */ - while (crm_flag_get(CRM_LICK_STABLE_FLAG) != SET) { + while(crm_flag_get(CRM_LICK_STABLE_FLAG) != SET) + { } /* enable hext */ crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE); /* wait till hext is ready */ - while (crm_hext_stable_wait() == ERROR) { + while(crm_hext_stable_wait() == ERROR) + { } /* enable hick */ crm_clock_source_enable(CRM_CLOCK_SOURCE_HICK, TRUE); /* wait till hick is ready */ - while (crm_flag_get(CRM_HICK_STABLE_FLAG) != SET) { + while(crm_flag_get(CRM_HICK_STABLE_FLAG) != SET) + { } /* config pll clock resource */ @@ -112,7 +115,8 @@ void wk_system_clock_config(void) crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE); /* wait till pll is ready */ - while (crm_flag_get(CRM_PLL_STABLE_FLAG) != SET) { + while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET) + { } /* config ahbclk */ @@ -131,7 +135,8 @@ void wk_system_clock_config(void) crm_sysclk_switch(CRM_SCLK_PLL); /* wait till pll is used as system clock source */ - while (crm_sysclk_switch_status_get() != CRM_SCLK_PLL) { + while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL) + { } /* disable auto step mode */ @@ -142,10 +147,10 @@ void wk_system_clock_config(void) } /** - * @brief config periph clock - * @param none - * @retval none - */ + * @brief config periph clock + * @param none + * @retval none + */ void wk_periph_clock_config(void) { /* enable crc periph clock */ @@ -201,10 +206,10 @@ void wk_periph_clock_config(void) } /** - * @brief init debug function. - * @param none - * @retval none - */ + * @brief init debug function. + * @param none + * @retval none + */ void wk_debug_config(void) { /* jtag-dp disabled and sw-dp enabled */ @@ -212,10 +217,10 @@ void wk_debug_config(void) } /** - * @brief nvic config - * @param none - * @retval none - */ + * @brief nvic config + * @param none + * @retval none + */ void wk_nvic_config(void) { nvic_priority_group_config(NVIC_PRIORITY_GROUP_4); @@ -229,10 +234,10 @@ void wk_nvic_config(void) } /** - * @brief init gpio_input/gpio_output/gpio_analog/eventout function. - * @param none - * @retval none - */ + * @brief init gpio_input/gpio_output/gpio_analog/eventout function. + * @param none + * @retval none + */ void wk_gpio_config(void) { /* add user code begin gpio_config 0 */ @@ -266,10 +271,10 @@ void wk_gpio_config(void) gpio_bits_reset(GPIOC, GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3); gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; - gpio_init_struct.gpio_pins = GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; + gpio_init_struct.gpio_pins = GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOC, &gpio_init_struct); /* add user code begin gpio_config 2 */ @@ -278,10 +283,10 @@ void wk_gpio_config(void) } /** - * @brief init i2c1 function. - * @param none - * @retval none - */ + * @brief init i2c1 function. + * @param none + * @retval none + */ void wk_i2c1_init(void) { /* add user code begin i2c1_init 0 */ @@ -297,19 +302,19 @@ void wk_i2c1_init(void) /* add user code end i2c1_init 1 */ /* configure the SCL pin */ - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_pins = GPIO_PINS_6; + gpio_init_struct.gpio_pins = GPIO_PINS_6; gpio_init(GPIOB, &gpio_init_struct); /* configure the SDA pin */ - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_pins = GPIO_PINS_7; + gpio_init_struct.gpio_pins = GPIO_PINS_7; gpio_init(GPIOB, &gpio_init_struct); i2c_init(I2C1, I2C_FSMODE_DUTY_2_1, 100000); @@ -326,10 +331,10 @@ void wk_i2c1_init(void) } /** - * @brief init i2c2 function. - * @param none - * @retval none - */ + * @brief init i2c2 function. + * @param none + * @retval none + */ void wk_i2c2_init(void) { /* add user code begin i2c2_init 0 */ @@ -343,21 +348,21 @@ void wk_i2c2_init(void) /* add user code begin i2c2_init 1 */ /* add user code end i2c2_init 1 */ - + /* configure the SCL pin */ - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_pins = GPIO_PINS_10; + gpio_init_struct.gpio_pins = GPIO_PINS_10; gpio_init(GPIOB, &gpio_init_struct); /* configure the SDA pin */ - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_pins = GPIO_PINS_11; + gpio_init_struct.gpio_pins = GPIO_PINS_11; gpio_init(GPIOB, &gpio_init_struct); i2c_init(I2C2, I2C_FSMODE_DUTY_2_1, 100000); @@ -374,10 +379,10 @@ void wk_i2c2_init(void) } /** - * @brief init usart1 function - * @param none - * @retval none - */ + * @brief init usart1 function + * @param none + * @retval none + */ void wk_usart1_init(void) { /* add user code begin usart1_init 0 */ @@ -393,18 +398,18 @@ void wk_usart1_init(void) /* configure the TX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_pins = GPIO_PINS_9; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_pins = GPIO_PINS_9; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); /* configure the RX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; - gpio_init_struct.gpio_pins = GPIO_PINS_10; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; + gpio_init_struct.gpio_pins = GPIO_PINS_10; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); /* configure param */ @@ -431,10 +436,10 @@ void wk_usart1_init(void) } /** - * @brief init usart2 function - * @param none - * @retval none - */ + * @brief init usart2 function + * @param none + * @retval none + */ void wk_usart2_init(void) { /* add user code begin usart2_init 0 */ @@ -450,18 +455,18 @@ void wk_usart2_init(void) /* configure the TX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_pins = GPIO_PINS_2; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_pins = GPIO_PINS_2; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); /* configure the RX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; - gpio_init_struct.gpio_pins = GPIO_PINS_3; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; + gpio_init_struct.gpio_pins = GPIO_PINS_3; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); /* configure param */ @@ -488,10 +493,10 @@ void wk_usart2_init(void) } /** - * @brief init usart3 function - * @param none - * @retval none - */ + * @brief init usart3 function + * @param none + * @retval none + */ void wk_usart3_init(void) { /* add user code begin usart3_init 0 */ @@ -507,18 +512,18 @@ void wk_usart3_init(void) /* configure the TX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_pins = GPIO_PINS_10; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_pins = GPIO_PINS_10; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOC, &gpio_init_struct); /* configure the RX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; - gpio_init_struct.gpio_pins = GPIO_PINS_11; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; + gpio_init_struct.gpio_pins = GPIO_PINS_11; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOC, &gpio_init_struct); gpio_pin_remap_config(USART3_GMUX_0001, TRUE); @@ -547,10 +552,10 @@ void wk_usart3_init(void) } /** - * @brief init tmr6 function. - * @param none - * @retval none - */ + * @brief init tmr6 function. + * @param none + * @retval none + */ void wk_tmr6_init(void) { /* add user code begin tmr6_init 0 */ @@ -562,7 +567,7 @@ void wk_tmr6_init(void) /* add user code end tmr6_init 1 */ /* configure counter settings */ - tmr_base_init(TMR6, 47999, 4999); + tmr_base_init(TMR6, 2399, 499); tmr_cnt_dir_set(TMR6, TMR_COUNT_UP); tmr_period_buffer_enable(TMR6, FALSE); @@ -585,10 +590,10 @@ void wk_tmr6_init(void) } /** - * @brief init tmr8 function. - * @param none - * @retval none - */ + * @brief init tmr8 function. + * @param none + * @retval none + */ void wk_tmr8_init(void) { /* add user code begin tmr8_init 0 */ @@ -606,39 +611,39 @@ void wk_tmr8_init(void) /* add user code end tmr8_init 1 */ /* configure the CH1 pin */ - gpio_init_struct.gpio_pins = GPIO_PINS_6; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_pins = GPIO_PINS_6; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init(GPIOC, &gpio_init_struct); /* configure the CH2 pin */ - gpio_init_struct.gpio_pins = GPIO_PINS_7; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_pins = GPIO_PINS_7; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init(GPIOC, &gpio_init_struct); /* configure the CH3 pin */ - gpio_init_struct.gpio_pins = GPIO_PINS_8; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_pins = GPIO_PINS_8; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init(GPIOC, &gpio_init_struct); /* configure the CH4 pin */ - gpio_init_struct.gpio_pins = GPIO_PINS_9; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_pins = GPIO_PINS_9; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init(GPIOC, &gpio_init_struct); /* configure counter settings */ - tmr_base_init(TMR8, 65535, 0); + tmr_base_init(TMR8, 2399, 1999); tmr_cnt_dir_set(TMR8, TMR_COUNT_UP); tmr_clock_source_div_set(TMR8, TMR_CLOCK_DIV1); tmr_repetition_counter_set(TMR8, 0); @@ -649,63 +654,64 @@ void wk_tmr8_init(void) tmr_primary_mode_select(TMR8, TMR_PRIMARY_SEL_RESET); /* configure channel 1 output settings */ - tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; - tmr_output_struct.oc_output_state = TRUE; + tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; + tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.occ_output_state = FALSE; - tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.oc_idle_state = FALSE; - tmr_output_struct.occ_idle_state = FALSE; + tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.oc_idle_state = FALSE; + tmr_output_struct.occ_idle_state = FALSE; tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_1, &tmr_output_struct); tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_1, 0); tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_1, FALSE); /* configure channel 2 output settings */ - tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; - tmr_output_struct.oc_output_state = TRUE; + tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; + tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.occ_output_state = FALSE; - tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.oc_idle_state = FALSE; - tmr_output_struct.occ_idle_state = FALSE; + tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.oc_idle_state = FALSE; + tmr_output_struct.occ_idle_state = FALSE; tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_2, &tmr_output_struct); tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_2, 0); tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_2, FALSE); /* configure channel 3 output settings */ - tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; - tmr_output_struct.oc_output_state = TRUE; + tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; + tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.occ_output_state = FALSE; - tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.oc_idle_state = FALSE; - tmr_output_struct.occ_idle_state = FALSE; + tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.oc_idle_state = FALSE; + tmr_output_struct.occ_idle_state = FALSE; tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_3, &tmr_output_struct); tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_3, 0); tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_3, FALSE); /* configure channel 4 output settings */ - tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; - tmr_output_struct.oc_output_state = TRUE; + tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; + tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.occ_output_state = FALSE; - tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.oc_idle_state = FALSE; - tmr_output_struct.occ_idle_state = FALSE; + tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.oc_idle_state = FALSE; + tmr_output_struct.occ_idle_state = FALSE; tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_4, &tmr_output_struct); tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_4, 0); tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_4, FALSE); /* configure break and dead-time settings */ - tmr_brkdt_struct.brk_enable = FALSE; + tmr_brkdt_struct.brk_enable = FALSE; tmr_brkdt_struct.auto_output_enable = FALSE; - tmr_brkdt_struct.brk_polarity = TMR_BRK_INPUT_ACTIVE_LOW; - tmr_brkdt_struct.fcsoen_state = FALSE; - tmr_brkdt_struct.fcsodis_state = FALSE; - tmr_brkdt_struct.wp_level = TMR_WP_OFF; - tmr_brkdt_struct.deadtime = 0; + tmr_brkdt_struct.brk_polarity = TMR_BRK_INPUT_ACTIVE_LOW; + tmr_brkdt_struct.fcsoen_state = FALSE; + tmr_brkdt_struct.fcsodis_state = FALSE; + tmr_brkdt_struct.wp_level = TMR_WP_OFF; + tmr_brkdt_struct.deadtime = 0; tmr_brkdt_config(TMR8, &tmr_brkdt_struct); + tmr_output_enable(TMR8, TRUE); tmr_counter_enable(TMR8, TRUE); @@ -716,10 +722,10 @@ void wk_tmr8_init(void) } /** - * @brief init tmr11 function. - * @param none - * @retval none - */ + * @brief init tmr11 function. + * @param none + * @retval none + */ void wk_tmr11_init(void) { /* add user code begin tmr11_init 0 */ @@ -735,10 +741,10 @@ void wk_tmr11_init(void) /* add user code end tmr11_init 1 */ /* configure the CH1 pin */ - gpio_init_struct.gpio_pins = GPIO_PINS_9; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_pins = GPIO_PINS_9; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init(GPIOB, &gpio_init_struct); @@ -749,13 +755,13 @@ void wk_tmr11_init(void) tmr_period_buffer_enable(TMR11, FALSE); /* configure channel 1 output settings */ - tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A; - tmr_output_struct.oc_output_state = TRUE; + tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A; + tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.occ_output_state = FALSE; - tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.oc_idle_state = FALSE; - tmr_output_struct.occ_idle_state = FALSE; + tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.oc_idle_state = FALSE; + tmr_output_struct.occ_idle_state = FALSE; tmr_output_channel_config(TMR11, TMR_SELECT_CHANNEL_1, &tmr_output_struct); tmr_channel_value_set(TMR11, TMR_SELECT_CHANNEL_1, 0); tmr_output_channel_buffer_enable(TMR11, TMR_SELECT_CHANNEL_1, FALSE); @@ -770,10 +776,10 @@ void wk_tmr11_init(void) } /** - * @brief init tmr12 function. - * @param none - * @retval none - */ + * @brief init tmr12 function. + * @param none + * @retval none + */ void wk_tmr12_init(void) { /* add user code begin tmr12_init 0 */ @@ -789,18 +795,18 @@ void wk_tmr12_init(void) /* add user code end tmr12_init 1 */ /* configure the CH1 pin */ - gpio_init_struct.gpio_pins = GPIO_PINS_14; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_pins = GPIO_PINS_14; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init(GPIOB, &gpio_init_struct); /* configure the CH2 pin */ - gpio_init_struct.gpio_pins = GPIO_PINS_15; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_pins = GPIO_PINS_15; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init(GPIOB, &gpio_init_struct); @@ -811,25 +817,25 @@ void wk_tmr12_init(void) tmr_period_buffer_enable(TMR12, FALSE); /* configure channel 1 output settings */ - tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; - tmr_output_struct.oc_output_state = TRUE; + tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; + tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.occ_output_state = FALSE; - tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.oc_idle_state = FALSE; - tmr_output_struct.occ_idle_state = FALSE; + tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.oc_idle_state = FALSE; + tmr_output_struct.occ_idle_state = FALSE; tmr_output_channel_config(TMR12, TMR_SELECT_CHANNEL_1, &tmr_output_struct); tmr_channel_value_set(TMR12, TMR_SELECT_CHANNEL_1, 0); tmr_output_channel_buffer_enable(TMR12, TMR_SELECT_CHANNEL_1, FALSE); /* configure channel 2 output settings */ - tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; - tmr_output_struct.oc_output_state = TRUE; + tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF; + tmr_output_struct.oc_output_state = TRUE; tmr_output_struct.occ_output_state = FALSE; - tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct.oc_idle_state = FALSE; - tmr_output_struct.occ_idle_state = FALSE; + tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct.oc_idle_state = FALSE; + tmr_output_struct.occ_idle_state = FALSE; tmr_output_channel_config(TMR12, TMR_SELECT_CHANNEL_2, &tmr_output_struct); tmr_channel_value_set(TMR12, TMR_SELECT_CHANNEL_2, 0); tmr_output_channel_buffer_enable(TMR12, TMR_SELECT_CHANNEL_2, FALSE); @@ -842,16 +848,16 @@ void wk_tmr12_init(void) } /** - * @brief init can1 function. - * @param none - * @retval none - */ + * @brief init can1 function. + * @param none + * @retval none + */ void wk_can1_init(void) { /* add user code begin can1_init 0 */ /* add user code end can1_init 0 */ - + gpio_init_type gpio_init_struct; can_base_type can_base_struct; can_baudrate_type can_baudrate_struct; @@ -860,57 +866,57 @@ void wk_can1_init(void) /* add user code begin can1_init 1 */ /* add user code end can1_init 1 */ - - /*gpio-----------------------------------------------------------------------------*/ + + /*gpio-----------------------------------------------------------------------------*/ gpio_default_para_init(&gpio_init_struct); /* configure the CAN1 TX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_pins = GPIO_PINS_12; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_pins = GPIO_PINS_12; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); /* configure the CAN1 RX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; - gpio_init_struct.gpio_pins = GPIO_PINS_11; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; + gpio_init_struct.gpio_pins = GPIO_PINS_11; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOA, &gpio_init_struct); - /*can_base_init--------------------------------------------------------------------*/ + /*can_base_init--------------------------------------------------------------------*/ can_default_para_init(&can_base_struct); - can_base_struct.mode_selection = CAN_MODE_COMMUNICATE; - can_base_struct.ttc_enable = FALSE; - can_base_struct.aebo_enable = TRUE; - can_base_struct.aed_enable = TRUE; - can_base_struct.prsf_enable = FALSE; + can_base_struct.mode_selection = CAN_MODE_COMMUNICATE; + can_base_struct.ttc_enable = FALSE; + can_base_struct.aebo_enable = TRUE; + can_base_struct.aed_enable = TRUE; + can_base_struct.prsf_enable = FALSE; can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED; - can_base_struct.mmssr_selection = CAN_SENDING_BY_ID; + can_base_struct.mmssr_selection = CAN_SENDING_BY_ID; can_base_init(CAN1, &can_base_struct); - /*can_baudrate_setting-------------------------------------------------------------*/ - /*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/ - can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/ - can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/ - can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/ - can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/ + /*can_baudrate_setting-------------------------------------------------------------*/ + /*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/ + can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/ + can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/ + can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/ + can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/ can_baudrate_set(CAN1, &can_baudrate_struct); /*can_filter_0_config--------------------------------------------------------------*/ can_filter_init_struct.filter_activate_enable = TRUE; - can_filter_init_struct.filter_number = 0; - can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0; - can_filter_init_struct.filter_bit = CAN_FILTER_16BIT; - can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK; + can_filter_init_struct.filter_number = 0; + can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0; + can_filter_init_struct.filter_bit = CAN_FILTER_16BIT; + can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK; /*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/ - can_filter_init_struct.filter_id_high = 0x0 << 5; - can_filter_init_struct.filter_id_low = 0x0 << 5; + can_filter_init_struct.filter_id_high = 0x0 << 5; + can_filter_init_struct.filter_id_low = 0x0 << 5; can_filter_init_struct.filter_mask_high = 0x0 << 5; - can_filter_init_struct.filter_mask_low = 0x0 << 5; + can_filter_init_struct.filter_mask_low = 0x0 << 5; can_filter_init(CAN1, &can_filter_init_struct); @@ -922,8 +928,8 @@ void wk_can1_init(void) * --void USBFS_L_CAN1_RX0_IRQHandler(void) */ - /*can1 rx0 interrupt config--------------------------------------------------------*/ - // can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); + /*can1 rx0 interrupt config--------------------------------------------------------*/ + //can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); /* add user code begin can1_init 2 */ can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); @@ -931,16 +937,16 @@ void wk_can1_init(void) } /** - * @brief init can2 function. - * @param none - * @retval none - */ + * @brief init can2 function. + * @param none + * @retval none + */ void wk_can2_init(void) { /* add user code begin can2_init 0 */ /* add user code end can2_init 0 */ - + gpio_init_type gpio_init_struct; can_base_type can_base_struct; can_baudrate_type can_baudrate_struct; @@ -949,57 +955,57 @@ void wk_can2_init(void) /* add user code begin can2_init 1 */ /* add user code end can2_init 1 */ - - /*gpio-----------------------------------------------------------------------------*/ + + /*gpio-----------------------------------------------------------------------------*/ gpio_default_para_init(&gpio_init_struct); /* configure the CAN2 TX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_MUX; - gpio_init_struct.gpio_pins = GPIO_PINS_13; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_MUX; + gpio_init_struct.gpio_pins = GPIO_PINS_13; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOB, &gpio_init_struct); /* configure the CAN2 RX pin */ gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; - gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; - gpio_init_struct.gpio_pins = GPIO_PINS_12; - gpio_init_struct.gpio_pull = GPIO_PULL_NONE; + gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; + gpio_init_struct.gpio_pins = GPIO_PINS_12; + gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(GPIOB, &gpio_init_struct); - /*can_base_init--------------------------------------------------------------------*/ + /*can_base_init--------------------------------------------------------------------*/ can_default_para_init(&can_base_struct); - can_base_struct.mode_selection = CAN_MODE_COMMUNICATE; - can_base_struct.ttc_enable = FALSE; - can_base_struct.aebo_enable = TRUE; - can_base_struct.aed_enable = TRUE; - can_base_struct.prsf_enable = FALSE; + can_base_struct.mode_selection = CAN_MODE_COMMUNICATE; + can_base_struct.ttc_enable = FALSE; + can_base_struct.aebo_enable = TRUE; + can_base_struct.aed_enable = TRUE; + can_base_struct.prsf_enable = FALSE; can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED; - can_base_struct.mmssr_selection = CAN_SENDING_BY_ID; + can_base_struct.mmssr_selection = CAN_SENDING_BY_ID; can_base_init(CAN2, &can_base_struct); - /*can_baudrate_setting-------------------------------------------------------------*/ - /*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/ - can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/ - can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/ - can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/ - can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/ + /*can_baudrate_setting-------------------------------------------------------------*/ + /*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/ + can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/ + can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/ + can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/ + can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/ can_baudrate_set(CAN2, &can_baudrate_struct); /*can_filter_0_config--------------------------------------------------------------*/ can_filter_init_struct.filter_activate_enable = TRUE; - can_filter_init_struct.filter_number = 0; - can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0; - can_filter_init_struct.filter_bit = CAN_FILTER_16BIT; - can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK; + can_filter_init_struct.filter_number = 0; + can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0; + can_filter_init_struct.filter_bit = CAN_FILTER_16BIT; + can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK; /*Standard identifier + Mask Mode + Data/Remote frame: id/mask 11bit --------------*/ - can_filter_init_struct.filter_id_high = 0x0 << 5; - can_filter_init_struct.filter_id_low = 0x0 << 5; + can_filter_init_struct.filter_id_high = 0x0 << 5; + can_filter_init_struct.filter_id_low = 0x0 << 5; can_filter_init_struct.filter_mask_high = 0x0 << 5; - can_filter_init_struct.filter_mask_low = 0x0 << 5; + can_filter_init_struct.filter_mask_low = 0x0 << 5; can_filter_init(CAN2, &can_filter_init_struct); @@ -1011,8 +1017,8 @@ void wk_can2_init(void) * --void CAN2_RX0_IRQHandler(void) */ - /*can2 rx0 interrupt config--------------------------------------------------------*/ - // can_interrupt_enable(CAN2, CAN_RF0MIEN_INT, TRUE); + /*can2 rx0 interrupt config--------------------------------------------------------*/ + //can_interrupt_enable(CAN2, CAN_RF0MIEN_INT, TRUE); /* add user code begin can2_init 2 */ can_interrupt_enable(CAN2, CAN_RF0MIEN_INT, TRUE); @@ -1020,10 +1026,10 @@ void wk_can2_init(void) } /** - * @brief init crc function. - * @param none - * @retval none - */ + * @brief init crc function. + * @param none + * @retval none + */ void wk_crc_init(void) { /* add user code begin crc_init 0 */ diff --git a/project/src/main.c b/project/src/main.c index 2f65be1..96cae07 100644 --- a/project/src/main.c +++ b/project/src/main.c @@ -34,6 +34,8 @@ #include "by_debug.h" #include "by_crc16.h" #include "by_frame.h" +#include "by_messy.h" +#include "by_motion.h" /* add user code end private includes */ /* private typedef -----------------------------------------------------------*/ @@ -138,8 +140,12 @@ int main(void) flash_ee_init(); LOGD("eeprom init done"); - /* frame init */ - by_frame_init(); + /* motion init */ + by_motion_init(); + LOGD("motion init done"); + + /* messy init */ + by_messy_init(); LOGD("frame init done"); LOGI("init done"); @@ -148,7 +154,8 @@ int main(void) while (1) { /* add user code begin 3 */ - // DWT_Delay(1000000); + by_messy_loop(); + by_motion_loop(); /* add user code end 3 */ } }