6 * @copyright Copyright (C) 2013, 2015 Czech Technical University in Prague
8 * @author Carlos Jenkins <carlos@jenkins.co.cr>
11 #ifndef DRV_DIGITAL_IO_H
12 #define DRV_DIGITAL_IO_H
16 /* Pin configuration constants */
17 #define GIO_PIN_CONF_MASK 0xff000000
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)
23 #define GIO_PIN_CONF_INIT_MASK 0x02000000
24 #define GIO_PIN_CONF_INIT_LOW 0x00000000
25 #define GIO_PIN_CONF_INIT_HIGH 0x02000000
27 #define GIO_PIN_CONF_OD_MASK 0x04000000
28 #define GIO_PIN_CONF_OD_OFF 0x00000000
29 #define GIO_PIN_CONF_OD_ON 0x04000000
31 #define GIO_PIN_CONF_SET_DIR 0x08000000
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
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
48 /* Port indexes to portmap */
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)
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))
64 void gio_setup(uint32_t pin_dsc);
66 boolean_t gio_get(uint32_t pin_dsc);
67 void gio_set(uint32_t pin_dsc, boolean_t value);
69 static inline uint32_t gio_port(uint32_t pin_dsc)
71 return (pin_dsc & GIO_PORT_MASK) >> GIO_PORT_SHIFT;