]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/drv/gio_tab.c
87d3322641f6577b28d0d6d5b85e09bf22bb1fdb
[pes-rpp/rpp-lib.git] / rpp / src / drv / gio_tab.c
1 /*
2  * Copyright (C) 2015 Czech Technical University in Prague
3  *
4  * Authors:
5  *     - Michal Sojka <sojkam1@fel.cvut.cz>
6  *
7  * This document contains proprietary information belonging to Czech
8  * Technical University in Prague. Passing on and copying of this
9  * document, and communication of its contents is not permitted
10  * without prior written authorization.
11  *
12  */
13
14 #include "drv/gio_tab.h"
15
16 const struct gio_pin gio_table[_PIN_COUNT] = {
17   #define GIO_PIN_DEF_GEN(name, port, pin, conf) { .pin_name = #name, .pin_dsc = GIO_PIN_DESC(GIO_PORT_##port, pin, conf) },
18   #include "drv/gio_def.h"
19   #undef GIO_PIN_DEF_GEN
20 };
21
22 int8_t port_gioset_get(const struct port_desc *port, void *values, size_t size)
23 {
24         int i;
25         uint32_t val = 0;
26
27         if (size != sizeof(uint32_t) ||
28                 port->numchn > 32 ||
29                 port->bpch != 1)
30                 return FAILURE;
31
32         for (i = 0; i < port->numchn; i++)
33                 val |= gio_tab_get(port->cfg.gioset.pins[i]) ? (1 << i) : 0;
34
35         *(uint32_t*)values = val;
36         return SUCCESS;
37 }
38
39 int8_t port_gioset_set(const struct port_desc *port, void *values, size_t size)
40 {
41         int i;
42
43         if (size != sizeof(uint32_t) ||
44                 port->numchn > 32 ||
45                 port->bpch != 1)
46                 return FAILURE;
47
48         for (i = 0; i < port->numchn; i++)
49                 gio_tab_set(port->cfg.gioset.pins[i], *(uint32_t*)values & (1 << i));
50
51         return SUCCESS;
52 }