]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/include/drv/port.h
892b76c43689fedfabe83f2c0b304432021f9826
[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
34 /**
35  * Port descriptor.
36  *
37  * The structure describes the port. Port here means set of IO pins on
38  * the board. The API is designed to provide an interface for setting
39  * and reading from ports connected to the MCU by SPI, GPIO or ADC.
40  */
41 struct port_desc {
42         char *name;
43         uint16_t numchn;                        /**< Number of channels/pins */
44         uint16_t bpch;                          /**< Bits per channel */
45         /**
46          * Getter function. If NULL, the port is write only. All SPI ports
47          * are write only, because a command has to be sent to obtain an
48          * response.
49          *
50          * @param[out] values Pointer to memory where to store the values
51          * get from the port. If bpch == 1, the memory is uint32_t,
52          * otherwise it is an array of numch bpch-wide elements.
53          *
54          * @param[out] size    Size of the memory pointed by @a values.
55          */
56         int8_t (*get)(const struct port_desc *port, void *values, size_t size);
57         /**
58          * Setter function. If NULL, the port is read only.
59          *
60          * @param[out] values Pointer to memory specifying how to set the
61          * port channels. If bpch == 1, the memory is uint32_t, otherwise
62          * it is an array of numch bpch-wide elements. The function is
63          * allowed to modify this memory and return there some information
64          * e.g. current or previous values of the port (this is usually
65          * the case for SPI-based ports).
66          *
67          * @param[out] size    Size of the memory pointed by @a values.
68          */
69         int8_t (*set)(const struct port_desc *port, void *values, size_t size);
70
71         union {
72                 struct {
73                         enum pin_name *pins;
74                 } gioset;
75                 struct {
76                         uint8_t ifc;            /**< SPI interface */
77                         uint8_t cs;                     /**< SPI chipselect */
78                 } spi;
79                 struct {
80                         adcBASE_t *reg;
81                         uint32_t group;
82                 } adc;
83                 gioPORT_t *gio_reg;
84         } cfg;
85 };
86
87 extern const struct port_desc port_desc[_PORT_COUNT];
88
89 #endif