From b566c7de4dca004ed6633dd7410d989541a5f2eb Mon Sep 17 00:00:00 2001 From: but0n Date: Tue, 24 Jan 2017 01:02:26 +0800 Subject: [PATCH] refactor:(define) Syntax Enhancement --- libs/include/i2c.h | 2 +- libs/include/motor.h | 8 ++++---- libs/include/uart.h | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/include/i2c.h b/libs/include/i2c.h index 12cedbc..2738a9c 100644 --- a/libs/include/i2c.h +++ b/libs/include/i2c.h @@ -13,7 +13,7 @@ #define GPIOB_IDR_Addr (GPIOB_BASE + 8) #define READ_SDA BIT_ADDR(GPIOB_IDR_Addr, SDA_PINNUM) -#define IIC_DELAY() {delay_us(1);} +#define IIC_DELAY() delay_us(1) diff --git a/libs/include/motor.h b/libs/include/motor.h index 62f32b2..891bec7 100644 --- a/libs/include/motor.h +++ b/libs/include/motor.h @@ -16,20 +16,20 @@ #define THROTTLE_MID (unsigned short)1650 #ifdef MOTOR_NORMAL_STARTUP - #define MOTOR_SETTING() {\ + #define MOTOR_SETTING() do {\ motor_PWM_Init(36000,40);\ MOTOR_ALL = THROTTLE_MIN;\ delay(4000);\ MOTOR_ALL = THROTTLE_MID;\ - } + } while(0) #else - #define MOTOR_SETTING() {\ + #define MOTOR_SETTING() do {\ motor_PWM_Init(36000,40);\ MOTOR_ALL = THROTTLE_MAX;\ delay(3000);\ MOTOR_ALL = THROTTLE_MIN;\ delay(8000);\ - } + } while(0) #endif void motor_PWM_Init(unsigned short arr, unsigned short psc); //72MHz / (arr + 1)*(psc + 1) diff --git a/libs/include/uart.h b/libs/include/uart.h index 008808b..2559ef7 100644 --- a/libs/include/uart.h +++ b/libs/include/uart.h @@ -7,10 +7,10 @@ void uart_showData(short k); //THIS FUNCTION IS NOT SO GOOD, EG: uart_showDat unsigned char uart_Float2Char(float value); void uart_sendStr(char * cmd); -#define UART_CR() {\ +#define UART_CR() do {\ uart_sendData(0x0D);\ uart_sendData(0x0A);\ -} -#define UART_CLEAR() {uart_sendStr("\033[H\033[J");} +} while(0) +#define UART_CLEAR() uart_sendStr("\033[H\033[J") #endif