forked from zhuhuijia0001/ch559-usb-host
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gpio_map.h
32 lines (20 loc) · 970 Bytes
/
Gpio_map.h
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
#ifndef _GPIO_MAP_H_
#define _GPIO_MAP_H_
/**
* Description: To use these macros, you must define PIN, DIR_PIN and OFFSET_PIN,
* PIN is the IO pin of a port, eg. P1_0.
* DIR_PIN is the direction register of the pin, eg. P1DIR.
* OFFSET_PIN is the pin offset from a port, eg. for P1_0, the OFFSET_PIN is 0.
*/
#define MAKE_GPIO_PREP(port, pin) (P##port##_##pin##)
#define PORT_DIR_PREP(port) (P##port##_DIR)
#define MAKE_GPIO(port, pin) MAKE_GPIO_PREP(port, pin)
#define PORT_DIR(port) PORT_DIR_PREP(port)
#define SET_GPIO_VALUE(bit, val) ((bit) = (val))
#define SET_GPIO_BIT(bit) SET_GPIO_VALUE(bit, 1)
#define CLR_GPIO_BIT(bit) SET_GPIO_VALUE(bit, 0)
#define GET_GPIO_BIT(bit) (bit)
#define GET_P4_GPIO_BIT(bit) ((P4_IN >> bit) & 0x01)
#define SET_GPIO_INPUT(bit) (DIR_##bit## &= ~(1 << OFFSET_##bit##))
#define SET_GPIO_OUTPUT(bit) (DIR_##bit## |= (1 << OFFSET_##bit##))
#endif