]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/drv/gio.h
Split drv/digital_io.h to drv/gio*.h and drv/port.h
[pes-rpp/rpp-lib.git] / rpp / include / drv / gio.h
1 /**
2  * Digital I/O handling
3  *
4  * @file digital_io.h
5  *
6  * @copyright Copyright (C) 2013, 2015 Czech Technical University in Prague
7  *
8  * @author Carlos Jenkins <carlos@jenkins.co.cr>
9  */
10
11 #ifndef DRV_DIGITAL_IO_H
12 #define DRV_DIGITAL_IO_H
13
14 #include "sys/sys.h"
15
16 /* Pin configuration constants */
17 #define GIO_PIN_CONF_MASK      0xff000000
18
19 #define GIO_PIN_CONF_DIR_MASK  0x01000000
20 #define GIO_PIN_CONF_DIR_IN    (0x00000000 | GIO_PIN_CONF_SET_DIR)
21 #define GIO_PIN_CONF_DIR_OUT   (0x01000000 | GIO_PIN_CONF_SET_DIR)
22
23 #define GIO_PIN_CONF_INIT_MASK 0x02000000
24 #define GIO_PIN_CONF_INIT_LOW  0x00000000
25 #define GIO_PIN_CONF_INIT_HIGH 0x02000000
26
27 #define GIO_PIN_CONF_OD_MASK   0x04000000
28 #define GIO_PIN_CONF_OD_OFF    0x00000000
29 #define GIO_PIN_CONF_OD_ON     0x04000000
30
31 #define GIO_PIN_CONF_SET_DIR   0x08000000
32
33 #define GIO_PIN_CONF_MODE_MASK 0x30000000
34 #define GIO_PIN_CONF_MODE_PTYPE_MASK   0x10000000
35 #define GIO_PIN_CONF_MODE_PEN_MASK     0x20000000
36 #define GIO_PIN_CONF_MODE_PU   0x10000000      // Pull-up
37 #define GIO_PIN_CONF_MODE_PD   0x00000000      // Pull-down
38 #define GIO_PIN_CONF_MODE_PEN  0x00000000      // Pull resistor enable
39 #define GIO_PIN_CONF_MODE_PDIS 0x20000000      // Pull resistor disable
40
41 #define GIO_PIN_CONF_FNC_MASK  0xc0000000
42 #define GIO_PIN_CONF_FNC_GPIO  0x00000000
43 #define GIO_PIN_CONF_FNC_0     0x00000000
44 #define GIO_PIN_CONF_FNC_1     0x40000000
45 #define GIO_PIN_CONF_FNC_2     0x80000000
46 #define GIO_PIN_CONF_FNC_3     0xc0000000
47
48 /* Port indexes to portmap */
49 enum gio_port {
50         GIO_PORT_DMM,
51         GIO_PORT_GIOA,
52         GIO_PORT_GIOB,
53         GIO_PORT_HET1,
54         GIO_PORT_HET2,
55 };
56
57 #define GIO_PORT_SHIFT 5
58 #define GIO_PORT_MASK  (0xf << GIO_PORT_SHIFT)
59 #define GIO_PIN_NUM_MASK ((1 << GIO_PORT_SHIFT) - 1)
60
61 /* Computes pin descriptor from port, pin number and pin configuration */
62 #define GIO_PIN_DESC(port,n,conf)  (((port)<<GIO_PORT_SHIFT) | (n) | (conf))
63
64 void gio_setup(uint32_t pin_dsc);
65
66 boolean_t gio_get(uint32_t pin_dsc);
67 void gio_set(uint32_t pin_dsc, boolean_t value);
68
69 static inline uint32_t gio_port(uint32_t pin_dsc)
70 {
71         return (pin_dsc & GIO_PORT_MASK) >> GIO_PORT_SHIFT;
72 }
73
74 #endif /* __HAL_H */