]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/arch/arm/mach-lpc17xx/libs/hal/hal_gpio.h
Merge master into can-usb1 branch to include proc update for 3.12+ kernels.
[lincan.git] / embedded / arch / arm / mach-lpc17xx / libs / hal / hal_gpio.h
1 #ifndef _HAL_GPIO_H_
2 #define _HAL_GPIO_H_
3
4 #include <cpu_def.h>
5 #include <LPC17xx.h>
6 #include <hal_gpio_def.h>
7
8 #define HAL_GPIO_PORT_BITS 3
9
10 static inline
11 GPIO_TypeDef *hal_gpio_get_port_base(unsigned port)
12 {
13   char *p = (char*)GPIO0_BASE;
14   p += ((char*)GPIO1_BASE - (char*)GPIO0_BASE) * port;
15   return (GPIO_TypeDef *)p;
16 }
17
18 static inline
19 unsigned hal_gpio_get_port_num(unsigned gpio)
20 {
21   gpio >>= PORT_SHIFT;
22   return gpio & ((1 << HAL_GPIO_PORT_BITS) - 1);
23 }
24
25 static inline
26 GPIO_TypeDef *hal_gpio_get_base(unsigned gpio)
27 {
28   return hal_gpio_get_port_base(hal_gpio_get_port_num(gpio));
29 }
30
31 static inline
32 int hal_gpio_get_value(unsigned gpio)
33 {
34   return ((hal_gpio_get_base(gpio)->FIOPIN) >> (gpio & 0x1f)) & 1;
35 }
36
37 static inline
38 void hal_gpio_set_value(unsigned gpio, int value)
39 {
40   if(value)
41     hal_gpio_get_base(gpio)->FIOSET = 1 << (gpio & 0x1f);
42   else
43     hal_gpio_get_base(gpio)->FIOCLR = 1 << (gpio & 0x1f);
44 }
45
46 static inline
47 int hal_gpio_direction_input(unsigned gpio)
48 {
49   hal_gpio_get_base(gpio)->FIODIR &= ~(1 << (gpio & 0x1f));
50   return 0;
51 }
52
53 static inline
54 int hal_gpio_direction_output(unsigned gpio, int value)
55 {
56   hal_gpio_set_value(gpio, value);
57   hal_gpio_get_base(gpio)->FIODIR |= (1 << (gpio & 0x1f));
58   return 0;
59 }
60
61 int hal_pin_conf_fnc(unsigned gpio, int fnc);
62
63 int hal_pin_conf_mode(unsigned gpio, int mode);
64
65 int hal_pin_conf_od(unsigned gpio, int od);
66
67 int hal_pin_conf_set(unsigned gpio, int conf);
68
69 static inline
70 int hal_pin_conf(unsigned gpio)
71 {
72   return hal_pin_conf_set(gpio, gpio);
73 }
74
75 #endif /*_HAL_GPIO_H_*/