]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blobdiff - rpp/src/drv/gio_tab.c
Split drv/digital_io.h to drv/gio*.h and drv/port.h
[pes-rpp/rpp-lib.git] / rpp / src / drv / gio_tab.c
diff --git a/rpp/src/drv/gio_tab.c b/rpp/src/drv/gio_tab.c
new file mode 100644 (file)
index 0000000..87d3322
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2015 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * This document contains proprietary information belonging to Czech
+ * Technical University in Prague. Passing on and copying of this
+ * document, and communication of its contents is not permitted
+ * without prior written authorization.
+ *
+ */
+
+#include "drv/gio_tab.h"
+
+const struct gio_pin gio_table[_PIN_COUNT] = {
+  #define GIO_PIN_DEF_GEN(name, port, pin, conf) { .pin_name = #name, .pin_dsc = GIO_PIN_DESC(GIO_PORT_##port, pin, conf) },
+  #include "drv/gio_def.h"
+  #undef GIO_PIN_DEF_GEN
+};
+
+int8_t port_gioset_get(const struct port_desc *port, void *values, size_t size)
+{
+       int i;
+       uint32_t val = 0;
+
+       if (size != sizeof(uint32_t) ||
+               port->numchn > 32 ||
+               port->bpch != 1)
+               return FAILURE;
+
+       for (i = 0; i < port->numchn; i++)
+               val |= gio_tab_get(port->cfg.gioset.pins[i]) ? (1 << i) : 0;
+
+       *(uint32_t*)values = val;
+       return SUCCESS;
+}
+
+int8_t port_gioset_set(const struct port_desc *port, void *values, size_t size)
+{
+       int i;
+
+       if (size != sizeof(uint32_t) ||
+               port->numchn > 32 ||
+               port->bpch != 1)
+               return FAILURE;
+
+       for (i = 0; i < port->numchn; i++)
+               gio_tab_set(port->cfg.gioset.pins[i], *(uint32_t*)values & (1 << i));
+
+       return SUCCESS;
+}