]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/drv/port.h
3a3e28cc91feb0dc1ff67a74a5b132094e76e904
[pes-rpp/rpp-lib.git] / rpp / include / drv / port.h
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 /**
15  * @file   port.h
16  * @author Michal Sojka <sojkam1@fel.cvut.cz>
17  * @date   Sat Jul 25 23:03:40 2015
18  *
19  * @brief  Port related stuff
20  *
21  * Port is a set of I/O (pins) that are somehow related together. Port
22  * can be on a MCU or attached over SPI or similar bus. Ports can be
23  * of different types, e.g. digital I/O or ADC.
24  */
25
26
27 #ifndef DRV_PORT_H
28 #define DRV_PORT_H
29
30 #include "sys/ti_drv_gio.h"
31 #include "sys/ti_drv_adc.h"
32 #include "drv/port_def.h"
33 #ifdef TARGET_HAS_SPI
34 #include "drv/spi_def.h"
35 #endif
36
37 /**
38  * Port descriptor.
39  *
40  * The structure describes the port. Port here means set of IO pins on
41  * the board. The API is designed to provide an interface for setting
42  * and reading from ports connected to the MCU by SPI, GPIO or ADC.
43  */
44 struct port_desc {
45         char *name;
46         uint16_t numchn;            /**< Number of channels/pins */
47         uint16_t bpch;              /**< Bits per channel */
48         /**
49          * Getter function. If NULL, the port is write only. All SPI ports
50          * are write only, because a command has to be sent to obtain an
51          * response.
52          *
53          * @param[out] values Pointer to memory where to store the values
54          * get from the port. If bpch == 1, the memory is uint32_t,
55          * otherwise it is an array of numch bpch-wide elements.
56          *
57          * @param[out] size    Size of the memory pointed by @a values.
58          */
59         int8_t (*get)(const struct port_desc *port, void *values, size_t size);
60         /**
61          * Setter function. If NULL, the port is read only.
62          *
63          * @param[out] values Pointer to memory specifying how to set the
64          * port channels. If bpch == 1, the memory is uint32_t, otherwise
65          * it is an array of numch bpch-wide elements. The function is
66          * allowed to modify this memory and return there some information
67          * e.g. current or previous values of the port (this is usually
68          * the case for SPI-based ports).
69          *
70          * @param[out] size    Size of the memory pointed by @a values.
71          */
72         int8_t (*set)(const struct port_desc *port, void *values, size_t size);
73
74         union {
75                 struct {
76                         enum pin_name *pins;
77                 } gioset;
78 #ifdef TARGET_HAS_SPI
79                 struct {
80                         enum spi_device dev;
81                 } spi;
82 #endif
83                 struct {
84                         adcBASE_t *reg;
85                         uint32_t group;
86                 } adc;
87                 gioPORT_t *gio_reg;
88         } cfg;
89 };
90
91 extern const struct port_desc port_desc[_PORT_COUNT];
92
93 #endif /* ifndef DRV_PORT_H */