]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/hal/port_gpio.c
79e990ede0b3dee4674d388e5dc4a9ab4ba0dff2
[pes-rpp/rpp-lib.git] / rpp / src / hal / port_gpio.c
1 /* Copyright (C) 2012-2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Michal Horn <hornmich@fel.cvut.cz>
5  *
6  * This document contains proprietary information belonging to Czech
7  * Technical University in Prague. Passing on and copying of this
8  * document, and communication of its contents is not permitted
9  * without prior written authorization.
10  *
11  * File : port_gpio.c
12  *
13  * Abstract:
14  *          This file contains getter and setter functions for GPIO port type.
15  */
16
17 #include "hal/hal.h"
18
19 /**
20  * Get values of all pins of given port.
21  * @param[in] config    Pointer to array of pin descriptors
22  * @param[in] num_val   Number of pins assigned to the port
23  * @param[out] values   Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1...
24  * @return always 0
25  */
26 uint32_t hal_gio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values)
27 {
28         uint32_t i;
29
30         for (i = 0; i < num_val; i++) {
31                 values[i] = hal_gpio_pin_get_value(config[i]);
32         }
33         return 0;
34 }
35
36 /**
37  * Set values to all pins of given port.
38  * @param[in] config    Pointer to array of pin descriptors
39  * @param[in] num_val   Number of pins assigned to the port
40  * @param[in] values    Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1...
41  * @return always 0
42  */
43 uint32_t hal_gio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values)
44 {
45         uint32_t i;
46
47         for (i = 0; i < num_val; i++) {
48                 hal_gpio_pin_set_value(config[i], (values[i/8] >> i%8) & 0x1);
49         }
50         return 0;
51 }