]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/hal/port_gpio.c
099e839f5bbc53a43eb3c91eefcfa6e1859b4c4b
[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 extern port_def_t port_definition[PORT_CNT];
20
21 uint32_t hal_gio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values)
22 {
23         uint32_t i;
24
25         for (i = 0; i < num_val; i++) {
26                 values[i] = hal_gpio_pin_get_value(config[i]);
27         }
28         return 0;
29 }
30
31 uint32_t hal_gio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values)
32 {
33         uint32_t i;
34
35         for (i = 0; i < num_val; i++) {
36                 hal_gpio_pin_set_value(config[i], (values[i/8] >> i%8) & 0x1);
37         }
38         return 0;
39 }
40
41 const port_def_t *hal_port_get_definitions()
42 {
43         return (const port_def_t *)port_definition;
44 }
45
46 port_desc_t *hal_port_get_dsc(const char *port_name, int len)
47 {
48         uint32_t i;
49         const char *port_name_ptr;
50         char port_name_term[32];
51
52         if (len != -1) {    // port name not terminated by '\0'
53                 strncpy(port_name_term, port_name, len);
54                 port_name_term[len] = '\0';
55                 port_name_ptr = port_name_term;
56         }
57         else port_name_ptr = port_name;
58
59         for (i = 0; i < PORT_CNT; i++) {
60                 if (strcmp(port_name_ptr, port_definition[i].name) == 0)
61                         return port_definition[i].desc;
62         }
63         return NULL;
64 }