-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathuser_lib.h
More file actions
62 lines (52 loc) · 2.14 KB
/
Copy pathuser_lib.h
File metadata and controls
62 lines (52 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
****************************(C) COPYRIGHT 2024 HZMI****************************
* @file struct_typedef.h
* @brief 常用运算函数
* @note
* @history
* Version Date Author Modification
* V1.0.0 Aug-11-2024 ZSB 1. done
*
@verbatim
==============================================================================
==============================================================================
@endverbatim
****************************(C) COPYRIGHT 2024 HZMI****************************
*/
#ifndef USER_LIB_H
#define USER_LIB_H
// Includes
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include "struct_typedef.h"
#include "main.h"
//#define DEBUGMODE 1
// Data Define
#define M_PI_F (3.14159265358979f)
//#define PI (3.14159265358979f)
#define ONE_PI (3.14159265358979f)
#define EPS (1e-6)
// Function Define
#define USER_ABS(x) (((x) > 0) ? (x) : (-(x))) // 宏定义实现返回绝对值(x里不能有自加自减的语句,否则变量出错)
#define LIMIT_MIN_MAX(x, min, max) ((x) = (((x)<=(min))?(min):(((x)>=(max))?(max):(x)))) // 限幅
#define USER_LIMIT_MINMAX(x, min, max) \
{ \
if ((x) > (max)) { \
(x) = (max); \
} else if ((x) < (min)) { \
(x) = (min); \
} \
}
#define USER_MIN(x, y) (((x) < (y)) ? (x) : (y)) // 取最小值
#define USER_MAX(x, y) (((x) > (y)) ? (x) : (y)) // 取最大值
#define USER_MINF(x, y) (((x) + (y) - fabs((x) - (y))) / 2)
#define USER_MF(x, y) (((x) + (y) + fabs((x) - (y))) / 2)
#define USER_SIGN(x) (((x) > 0) ? 1 :-1) //((int32)(((x) > 0 ? 1 : -1) * ceil(ABS((x)))))// 取符号
#define USER_SWAP(x, y) do{(x) ^= (y); (y) ^= (x); (x) ^= (y);} while(0) // 交换 x, y 的值
#define USER_ARR_SIZE(a) ( sizeof( (a) ) / sizeof( ((a)[0]) ) ) // 返回数组元素的个数
#define USER_OFFSET(type, member) ((uint32_t)(&(((type *)0)->member))) // 获取结构体某成员偏移
#endif