1 /*
2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 
7 /*******************************************************************************************************************//**
8  * @ingroup RENESAS_INTERFACES
9  * @defgroup IOPORT_API I/O Port Interface
10  * @brief Interface  for accessing I/O ports and configuring I/O functionality.
11  *
12  * @section IOPORT_API_SUMMARY Summary
13  * The IOPort shared interface provides the ability to access the IOPorts of a device at both bit and port level.
14  * Port and pin direction can be changed.
15  *
16  * IOPORT Interface description: @ref IOPORT
17  *
18  * @{
19  **********************************************************************************************************************/
20 
21 #ifndef R_IOPORT_API_H
22 #define R_IOPORT_API_H
23 
24 /***********************************************************************************************************************
25  * Includes
26  **********************************************************************************************************************/
27 
28 /* Common error codes and definitions. */
29 #include "bsp_api.h"
30 
31 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
32 FSP_HEADER
33 
34 /**********************************************************************************************************************
35  * Macro definitions
36  **********************************************************************************************************************/
37 
38 /**********************************************************************************************************************
39  * Typedef definitions
40  **********************************************************************************************************************/
41 
42 /** IO port type used with ports */
43 typedef uint16_t ioport_size_t;        ///< IO port size on this device
44 
45 /** PFS writing enable/disable. */
46 typedef enum e_ioport_pwpr
47 {
48     IOPORT_PFS_WRITE_DISABLE = 0,      ///< Disable PFS write access
49     IOPORT_PFS_WRITE_ENABLE  = 1       ///< Enable PFS write access
50 } ioport_pwpr_t;
51 
52 /** Pin identifier and Pin Function Setting (PFS) value */
53 typedef struct st_ioport_pin_cfg
54 {
55     uint32_t          pin_cfg;         ///< Pin PFS configuration - Use ioport_cfg_options_t parameters to configure
56     bsp_io_port_pin_t pin;             ///< Pin identifier
57 } ioport_pin_cfg_t;
58 
59 /** Multiple pin configuration data for loading into each GPIO register by R_IOPORT_Init()  */
60 typedef struct st_ioport_cfg
61 {
62     uint16_t                 number_of_pins; ///< Number of pins for which there is configuration data
63     ioport_pin_cfg_t const * p_pin_cfg_data; ///< Pin configuration data
64     const void             * p_extend;       ///< Pointer to hardware extend configuration
65 } ioport_cfg_t;
66 
67 /** IOPORT control block.  Allocate an instance specific control block to pass into the IOPORT API calls.
68  * @par Implemented as
69  * - ioport_instance_ctrl_t
70  */
71 typedef void ioport_ctrl_t;
72 
73 /** IOPort driver structure. IOPort functions implemented at the HAL layer will follow this API. */
74 typedef struct st_ioport_api
75 {
76     /** Initialize internal driver data and initial pin configurations.  Called during startup.  Do
77      * not call this API during runtime.  Use @ref ioport_api_t::pinsCfg for runtime reconfiguration of
78      * multiple pins.
79      * @par Implemented as
80      * - @ref R_IOPORT_Open()
81      * @param[in]  p_cfg                Pointer to pin configuration data array.
82      */
83     fsp_err_t (* open)(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg);
84 
85     /** Close the API.
86      * @par Implemented as
87      * - @ref R_IOPORT_Close()
88      *
89      * @param[in]   p_ctrl  Pointer to control structure.
90      **/
91     fsp_err_t (* close)(ioport_ctrl_t * const p_ctrl);
92 
93     /** Configure multiple pins.
94      * @par Implemented as
95      * - @ref R_IOPORT_PinsCfg()
96      * @param[in]  p_cfg                Pointer to pin configuration data array.
97      */
98     fsp_err_t (* pinsCfg)(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg);
99 
100     /** Configure settings for an individual pin.
101      * @par Implemented as
102      * - @ref R_IOPORT_PinCfg()
103      * @param[in]  pin                  Pin to be read.
104      * @param[in]  cfg                  Configuration options for the pin.
105      */
106     fsp_err_t (* pinCfg)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, uint32_t cfg);
107 
108     /** Read the event input data of the specified pin and return the level.
109      * @par Implemented as
110      * - @ref R_IOPORT_PinEventInputRead()
111      * @param[in]  pin                  Pin to be read.
112      * @param[in]  p_pin_event         Pointer to return the event data.
113      */
114     fsp_err_t (* pinEventInputRead)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t * p_pin_event);
115 
116     /** Write pin event data.
117      * @par Implemented as
118      * - @ref R_IOPORT_PinEventOutputWrite()
119      * @param[in]  pin                  Pin event data is to be written to.
120      * @param[in]  pin_value            Level to be written to pin output event.
121      */
122     fsp_err_t (* pinEventOutputWrite)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t pin_value);
123 
124     /** Read level of a pin.
125      * @par Implemented as
126      * - @ref R_IOPORT_PinRead()
127      * @param[in]  pin                  Pin to be read.
128      * @param[in]  p_pin_value          Pointer to return the pin level.
129      */
130     fsp_err_t (* pinRead)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t * p_pin_value);
131 
132     /** Write specified level to a pin.
133      * @par Implemented as
134      * - @ref R_IOPORT_PinWrite()
135      * @param[in]  pin                  Pin to be written to.
136      * @param[in]  level                State to be written to the pin.
137      */
138     fsp_err_t (* pinWrite)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t level);
139 
140     /** Set the direction of one or more pins on a port.
141      * @par Implemented as
142      * - @ref R_IOPORT_PortDirectionSet()
143      * @param[in]  port                 Port being configured.
144      * @param[in]  direction_values     Value controlling direction of pins on port
145      *                                  (3 - output (input enable), 2 - output (input disable), 1 input, 0 - Hi-Z).
146      * @param[in]  mask                 Mask controlling which pins on the port are to be configured.
147      */
148     fsp_err_t (* portDirectionSet)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t direction_values,
149                                    ioport_size_t mask);
150 
151     /** Read captured event data for a port.
152      * @par Implemented as
153      * - @ref R_IOPORT_PortEventInputRead()
154      * @param[in]  port                 Port to be read.
155      * @param[in]  p_event_data         Pointer to return the event data.
156      */
157     fsp_err_t (* portEventInputRead)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t * p_event_data);
158 
159     /** Write event output data for a port.
160      * @par Implemented as
161      * - @ref R_IOPORT_PortEventOutputWrite()
162      * @param[in]  port                 Port event data will be written to.
163      * @param[in]  event_data           Data to be written as event data to specified port.
164      * @param[in]  mask_value           Each bit set to 1 in the mask corresponds to that bit's value in event data.
165      * being written to port.
166      */
167     fsp_err_t (* portEventOutputWrite)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t event_data,
168                                        ioport_size_t mask_value);
169 
170     /** Read states of pins on the specified port.
171      * @par Implemented as
172      * - @ref R_IOPORT_PortRead()
173      * @param[in]  port                 Port to be read.
174      * @param[in]  p_port_value         Pointer to return the port value.
175      */
176     fsp_err_t (* portRead)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t * p_port_value);
177 
178     /** Write to multiple pins on a port.
179      * @par Implemented as
180      * - @ref R_IOPORT_PortWrite()
181      * @param[in]  port                 Port to be written to.
182      * @param[in]  value                Value to be written to the port.
183      * @param[in]  mask                 Mask controlling which pins on the port are written to.
184      */
185     fsp_err_t (* portWrite)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t value, ioport_size_t mask);
186 } ioport_api_t;
187 
188 /** This structure encompasses everything that is needed to use an instance of this interface. */
189 typedef struct st_ioport_instance
190 {
191     ioport_ctrl_t      * p_ctrl;       ///< Pointer to the control structure for this instance
192     ioport_cfg_t const * p_cfg;        ///< Pointer to the configuration structure for this instance
193     ioport_api_t const * p_api;        ///< Pointer to the API structure for this instance
194 } ioport_instance_t;
195 
196 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
197 FSP_FOOTER
198 
199 #endif
200 
201 /*******************************************************************************************************************//**
202  * @} (end defgroup IOPORT_API)
203  **********************************************************************************************************************/
204