]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/gio.c
Give the HAL functions better names
[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         pin_map_element_t* pin_map = hal_gpio_get_pin_map();
29
30
31         for (pin = 0; pin < hal_gpio_get_pin_cnt(); pin++) {
32                 int port_num = hal_gpio_pin_get_port_num(pin_map[pin].pin_desc);
33                 if ((init_ports & (1 << port_num)) &&
34                         !(ports_initialized & (1 << port_num)))
35                         hal_gpio_pin_configure(pin_map[pin].pin_desc);
36         }
37
38         ports_initialized |= init_ports;
39
40         return SUCCESS;
41 }