1 /***********************************************************************************************************************
2  * Copyright [2020-2024] Renesas Electronics Corporation and/or its affiliates.  All Rights Reserved.
3  *
4  * This software and documentation are supplied by Renesas Electronics Corporation and/or its affiliates and may only
5  * be used with products of Renesas Electronics Corp. and its affiliates ("Renesas").  No other uses are authorized.
6  * Renesas products are sold pursuant to Renesas terms and conditions of sale.  Purchasers are solely responsible for
7  * the selection and use of Renesas products and Renesas assumes no liability.  No license, express or implied, to any
8  * intellectual property right is granted by Renesas.  This software is protected under all applicable laws, including
9  * copyright laws. Renesas reserves the right to change or discontinue this software and/or this documentation.
10  * THE SOFTWARE AND DOCUMENTATION IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND
11  * TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY,
12  * INCLUDING WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE
13  * SOFTWARE OR DOCUMENTATION.  RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH.
14  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR
15  * DOCUMENTATION (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER,
16  * INCLUDING, WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY
17  * LOST PROFITS, OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE
18  * POSSIBILITY OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS.
19  **********************************************************************************************************************/
20 
21 /*******************************************************************************************************************//**
22  * @addtogroup IOPORT
23  * @{
24  **********************************************************************************************************************/
25 
26 #ifndef R_IOPORT_H
27 #define R_IOPORT_H
28 
29 /***********************************************************************************************************************
30  * Includes
31  **********************************************************************************************************************/
32 #include "bsp_api.h"
33 
34 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
35 FSP_HEADER
36 
37 #include "r_ioport_api.h"
38 #include "r_ioport_cfg.h"
39 
40 /***********************************************************************************************************************
41  * Macro definitions
42  **********************************************************************************************************************/
43 #define IOPORT_SINGLE_PORT_NUM    (4)
44 #define IOPORT_PORT_GROUP_NUM     (2)
45 #define IOPORT_PORT_GROUP_1       (0)
46 #define IOPORT_PORT_GROUP_2       (1)
47 #define IOPORT_SINGLE_PORT_0      (0)
48 #define IOPORT_SINGLE_PORT_1      (1)
49 #define IOPORT_SINGLE_PORT_2      (2)
50 #define IOPORT_SINGLE_PORT_3      (3)
51 
52 /***********************************************************************************************************************
53  * Typedef definitions
54  **********************************************************************************************************************/
55 
56 /** Pin selection for port group
57  *  @note Event link must be configured by the ELC
58  */
59 typedef enum e_ioport_event_pin_selection
60 {
61     IOPORT_EVENT_PIN_SELECTION_NONE  = 0x00, ///< No pin selection for port group
62     IOPORT_EVENT_PIN_SELECTION_PIN_0 = 0x01, ///< Select pin 0 to port group
63     IOPORT_EVENT_PIN_SELECTION_PIN_1 = 0x02, ///< Select pin 1 to port group
64     IOPORT_EVENT_PIN_SELECTION_PIN_2 = 0x04, ///< Select pin 2 to port group
65     IOPORT_EVENT_PIN_SELECTION_PIN_3 = 0x08, ///< Select pin 3 to port group
66     IOPORT_EVENT_PIN_SELECTION_PIN_4 = 0x10, ///< Select pin 4 to port group
67     IOPORT_EVENT_PIN_SELECTION_PIN_5 = 0x20, ///< Select pin 5 to port group
68     IOPORT_EVENT_PIN_SELECTION_PIN_6 = 0x40, ///< Select pin 6 to port group
69     IOPORT_EVENT_PIN_SELECTION_PIN_7 = 0x80, ///< Select pin 7 to port group
70 } ioport_event_pin_selection_t;
71 
72 /** Port group operation
73  *  @note Event link must be configured by the ELC
74  */
75 typedef enum e_ioport_event_output_operation
76 {
77     IOPORT_EVENT_OUTPUT_OPERATION_LOW    = 0x0, ///< Set Low output to output operation
78     IOPORT_EVENT_OUTPUT_OPERATION_HIGH   = 0x1, ///< Set High output to output operation
79     IOPORT_EVENT_OUTPUT_OPERATION_TOGGLE = 0x2, ///< Set toggle output to output operation
80     IOPORT_EVENT_OUTPUT_OPERATION_BUFFER = 0x3, ///< Set buffer value output to output operation
81 } ioport_event_output_operation_t;
82 
83 /** Input port group event control
84  *  @note Event link must be configured by the ELC
85  */
86 typedef enum e_ioport_event_control
87 {
88     IOPORT_EVENT_CONTROL_DISABLE = 0x0, ///< Disable function related with event link
89     IOPORT_EVENT_CONTROL_ENABLE  = 0x1, ///< Enable function related with event link
90 } ioport_event_control_t;
91 
92 /** Single port event direction
93  *  @note Event link must be configured by the ELC
94  */
95 typedef enum e_ioport_event_direction
96 {
97     IOPORT_EVENT_DIRECTION_OUTPUT = 0x0, ///< Set output direction to single port
98     IOPORT_EVENT_DIRECTION_INPUT  = 0x1, ///< Set input direction to single port
99 } ioport_event_direction_t;
100 
101 /** Input event edge detection
102  *  @note Event link must be configured by the ELC
103  */
104 typedef enum e_ioport_event_detection
105 {
106     IOPORT_EVENT_DETECTION_RISING_EDGE  = 0x0, ///< Set rising edge to event detection for input event
107     IOPORT_EVENT_DETECTION_FALLING_EDGE = 0x1, ///< Set falling edge to event detection for input event
108     IOPORT_EVENT_DETECTION_BOTH_EGDE    = 0x2, ///< Set both edges to event detection for input event
109 } ioport_event_detection_t;
110 
111 /** Initial value for buffer register
112  *  @note Event link must be configured by the ELC
113  */
114 typedef enum e_ioport_event_initial_buffer_value
115 {
116     IOPORT_EVENT_INITIAL_BUFFER_VALUE_LOW  = 0U, ///< Set low input to initial value of buffer register for input port group
117     IOPORT_EVENT_INITIAL_BUFFER_VALUE_HIGH = 1U, ///< Set high input to initial value of buffer register for input port group
118 } ioport_event_initial_buffer_value_t;
119 
120 /** Single port configuration
121  *  @note Event link must be configured by the ELC
122  */
123 typedef struct st_ioport_event_single
124 {
125     ioport_event_control_t          event_control;  ///< Event link control for single port
126     ioport_event_direction_t        direction;      ///< Event direction for single port
127     uint16_t                        port_num;       ///< Port number specified to single port
128     ioport_event_output_operation_t operation;      ///< Single port operation select
129     ioport_event_detection_t        edge_detection; ///< Edge detection select
130 } ioport_event_single_t;
131 
132 /** Output port group configuration
133  *  @note Event link must be configured by the ELC
134  */
135 typedef struct st_ioport_event_group_output
136 {
137     uint8_t pin_select;                        ///< Port number specified to output port group
138     ioport_event_output_operation_t operation; ///< Port group operation select
139 } ioport_event_group_output_t;
140 
141 /** Input port group configuration
142  *  @note Event link must be configured by the ELC
143  */
144 typedef struct st_ioport_event_group_input
145 {
146     ioport_event_control_t   event_control;     ///< Event link control for input port group
147     ioport_event_detection_t edge_detection;    ///< Edge detection select
148     ioport_event_control_t   overwrite_control; ///< Buffer register overwrite control
149     uint8_t pin_select;                         ///< Port number specified to input port group
150     uint8_t buffer_init_value;                  ///< Buffer register initial value
151 } ioport_event_group_input_t;
152 
153 /** IOPORT extended configuration for event link function
154  *  @note Event link must be configured by the ELC
155  */
156 typedef struct  st_ioport_extend_cfg
157 {
158     ioport_event_group_output_t port_group_output_cfg[IOPORT_PORT_GROUP_NUM]; ///< Output port group configuration
159     ioport_event_group_input_t  port_group_input_cfg[IOPORT_PORT_GROUP_NUM];  ///< Input port group configuration
160     ioport_event_single_t       single_port_cfg[IOPORT_SINGLE_PORT_NUM];      ///< Single input port configuration
161 } ioport_extend_cfg_t;
162 
163 /** IOPORT private control block. DO NOT MODIFY. Initialization occurs when R_IOPORT_Open() is called. */
164 typedef struct st_ioport_instance_ctrl
165 {
166     uint32_t             open;         // Whether or not ioport is open
167     void const         * p_context;    // Pointer to context to be passed into callback
168     ioport_cfg_t const * p_cfg;        // Pointer to the configuration block
169 } ioport_instance_ctrl_t;
170 
171 /**********************************************************************************************************************
172  * Exported global variables
173  **********************************************************************************************************************/
174 
175 /** @cond INC_HEADER_DEFS_SEC */
176 /** Filled in Interface API structure for this Instance. */
177 extern const ioport_api_t g_ioport_on_ioport;
178 
179 /** @endcond */
180 
181 /***********************************************************************************************************************
182  * Public APIs
183  **********************************************************************************************************************/
184 
185 fsp_err_t R_IOPORT_Open(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg);
186 fsp_err_t R_IOPORT_Close(ioport_ctrl_t * const p_ctrl);
187 fsp_err_t R_IOPORT_PinsCfg(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg);
188 fsp_err_t R_IOPORT_PinCfg(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, uint32_t cfg);
189 fsp_err_t R_IOPORT_PinEventInputRead(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t * p_pin_event);
190 fsp_err_t R_IOPORT_PinEventOutputWrite(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t pin_value);
191 fsp_err_t R_IOPORT_PinRead(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t * p_pin_value);
192 fsp_err_t R_IOPORT_PinWrite(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t level);
193 fsp_err_t R_IOPORT_PortDirectionSet(ioport_ctrl_t * const p_ctrl,
194                                     bsp_io_port_t         port,
195                                     ioport_size_t         direction_values,
196                                     ioport_size_t         mask);
197 fsp_err_t R_IOPORT_PortEventInputRead(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t * p_event_data);
198 fsp_err_t R_IOPORT_PortEventOutputWrite(ioport_ctrl_t * const p_ctrl,
199                                         bsp_io_port_t         port,
200                                         ioport_size_t         event_data,
201                                         ioport_size_t         mask_value);
202 fsp_err_t R_IOPORT_PortRead(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t * p_port_value);
203 fsp_err_t R_IOPORT_PortWrite(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t value, ioport_size_t mask);
204 
205 /*******************************************************************************************************************//**
206  * @} (end defgroup IOPORT)
207  **********************************************************************************************************************/
208 
209 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
210 FSP_FOOTER
211 
212 #endif                                 // R_IOPORT_H
213