]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/gio.c
4c4baad547f2919492606f239afed0d2651cb412
[pes-rpp/rpp-lib.git] / rpp / src / rpp / gio.c
1 /* Copyright (C) 2013-2015 Czech Technical University in Prague
2  * Authors:
3  *     - Michal Horn <hornmich@fel.cvut.cz>
4  *
5  * This document contains proprietary information belonging to Czech
6  * Technical University in Prague. Passing on and copying of this
7  * document, and communication of its contents is not permitted
8  * without prior written authorization.
9  *
10  */
11
12 #include "rpp/gio.h"
13
14 static uint32_t ports_initialized = 0;
15
16 /* Configuration consistency check */
17 #if RPP_GIO_PORT_GIOA != (1 << PORT_ID_GIOA) || \
18         RPP_GIO_PORT_GIOB != (1 << PORT_ID_GIOB) || \
19         RPP_GIO_PORT_NHET1 != (1 << PORT_ID_HET1)
20 #error Port configuration is not consistent.
21 #endif
22
23 int8_t rpp_gio_init(uint32_t init_ports)
24 {
25         unsigned pin;
26
27         gioREG->GCR0 = 1;   // Bring GIO out of reset
28
29         for (pin = 0; pin < sizeof(pin_map)/sizeof(*pin_map); pin++) {
30                 int port_num = hal_gpio_pin_get_port_num(pin_map[pin].pin_desc);
31                 if ((init_ports & (1 << port_num)) &&
32                         !(ports_initialized & (1 << port_num)))
33                         hal_gpio_pin_conf(pin_map[pin].pin_desc);
34         }
35
36         ports_initialized |= init_ports;
37
38         return SUCCESS;
39 }