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  * @addtogroup IOPORT
9  * @{
10  **********************************************************************************************************************/
11 
12 #ifndef R_IOPORT_H
13 #define R_IOPORT_H
14 
15 /***********************************************************************************************************************
16  * Includes
17  **********************************************************************************************************************/
18 #include "bsp_api.h"
19 
20 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
21 FSP_HEADER
22 
23 #include "r_ioport_api.h"
24 #include "r_ioport_cfg.h"
25 
26 /***********************************************************************************************************************
27  * Macro definitions
28  **********************************************************************************************************************/
29 #define IOPORT_SINGLE_PORT_NUM    (4)
30 #define IOPORT_PORT_GROUP_NUM     (2)
31 #define IOPORT_PORT_GROUP_1       (0)
32 #define IOPORT_PORT_GROUP_2       (1)
33 #define IOPORT_SINGLE_PORT_0      (0)
34 #define IOPORT_SINGLE_PORT_1      (1)
35 #define IOPORT_SINGLE_PORT_2      (2)
36 #define IOPORT_SINGLE_PORT_3      (3)
37 
38 /***********************************************************************************************************************
39  * Typedef definitions
40  **********************************************************************************************************************/
41 
42 /** Pin selection for port group
43  *  @note Event link must be configured by the ELC
44  */
45 typedef enum e_ioport_event_pin_selection
46 {
47     IOPORT_EVENT_PIN_SELECTION_NONE  = 0x00, ///< No pin selection for port group
48     IOPORT_EVENT_PIN_SELECTION_PIN_0 = 0x01, ///< Select pin 0 to port group
49     IOPORT_EVENT_PIN_SELECTION_PIN_1 = 0x02, ///< Select pin 1 to port group
50     IOPORT_EVENT_PIN_SELECTION_PIN_2 = 0x04, ///< Select pin 2 to port group
51     IOPORT_EVENT_PIN_SELECTION_PIN_3 = 0x08, ///< Select pin 3 to port group
52     IOPORT_EVENT_PIN_SELECTION_PIN_4 = 0x10, ///< Select pin 4 to port group
53     IOPORT_EVENT_PIN_SELECTION_PIN_5 = 0x20, ///< Select pin 5 to port group
54     IOPORT_EVENT_PIN_SELECTION_PIN_6 = 0x40, ///< Select pin 6 to port group
55     IOPORT_EVENT_PIN_SELECTION_PIN_7 = 0x80, ///< Select pin 7 to port group
56 } ioport_event_pin_selection_t;
57 
58 /** Port group operation
59  *  @note Event link must be configured by the ELC
60  */
61 typedef enum e_ioport_event_output_operation
62 {
63     IOPORT_EVENT_OUTPUT_OPERATION_LOW    = 0x0, ///< Set Low output to output operation
64     IOPORT_EVENT_OUTPUT_OPERATION_HIGH   = 0x1, ///< Set High output to output operation
65     IOPORT_EVENT_OUTPUT_OPERATION_TOGGLE = 0x2, ///< Set toggle output to output operation
66     IOPORT_EVENT_OUTPUT_OPERATION_BUFFER = 0x3, ///< Set buffer value output to output operation
67 } ioport_event_output_operation_t;
68 
69 /** Input port group event control
70  *  @note Event link must be configured by the ELC
71  */
72 typedef enum e_ioport_event_control
73 {
74     IOPORT_EVENT_CONTROL_DISABLE = 0x0, ///< Disable function related with event link
75     IOPORT_EVENT_CONTROL_ENABLE  = 0x1, ///< Enable function related with event link
76 } ioport_event_control_t;
77 
78 /** Single port event direction
79  *  @note Event link must be configured by the ELC
80  */
81 typedef enum e_ioport_event_direction
82 {
83     IOPORT_EVENT_DIRECTION_OUTPUT = 0x0, ///< Set output direction to single port
84     IOPORT_EVENT_DIRECTION_INPUT  = 0x1, ///< Set input direction to single port
85 } ioport_event_direction_t;
86 
87 /** Input event edge detection
88  *  @note Event link must be configured by the ELC
89  */
90 typedef enum e_ioport_event_detection
91 {
92     IOPORT_EVENT_DETECTION_RISING_EDGE  = 0x0, ///< Set rising edge to event detection for input event
93     IOPORT_EVENT_DETECTION_FALLING_EDGE = 0x1, ///< Set falling edge to event detection for input event
94     IOPORT_EVENT_DETECTION_BOTH_EGDE    = 0x2, ///< Set both edges to event detection for input event
95 } ioport_event_detection_t;
96 
97 /** Initial value for buffer register
98  *  @note Event link must be configured by the ELC
99  */
100 typedef enum e_ioport_event_initial_buffer_value
101 {
102     IOPORT_EVENT_INITIAL_BUFFER_VALUE_LOW  = 0U, ///< Set low input to initial value of buffer register for input port group
103     IOPORT_EVENT_INITIAL_BUFFER_VALUE_HIGH = 1U, ///< Set high input to initial value of buffer register for input port group
104 } ioport_event_initial_buffer_value_t;
105 
106 /** Single port configuration
107  *  @note Event link must be configured by the ELC
108  */
109 typedef struct st_ioport_event_single
110 {
111     ioport_event_control_t          event_control;  ///< Event link control for single port
112     ioport_event_direction_t        direction;      ///< Event direction for single port
113     uint16_t                        port_num;       ///< Port number specified to single port
114     ioport_event_output_operation_t operation;      ///< Single port operation select
115     ioport_event_detection_t        edge_detection; ///< Edge detection select
116 } ioport_event_single_t;
117 
118 /** Output port group configuration
119  *  @note Event link must be configured by the ELC
120  */
121 typedef struct st_ioport_event_group_output
122 {
123     uint8_t pin_select;                        ///< Port number specified to output port group
124     ioport_event_output_operation_t operation; ///< Port group operation select
125 } ioport_event_group_output_t;
126 
127 /** Input port group configuration
128  *  @note Event link must be configured by the ELC
129  */
130 typedef struct st_ioport_event_group_input
131 {
132     ioport_event_control_t   event_control;     ///< Event link control for input port group
133     ioport_event_detection_t edge_detection;    ///< Edge detection select
134     ioport_event_control_t   overwrite_control; ///< Buffer register overwrite control
135     uint8_t pin_select;                         ///< Port number specified to input port group
136     uint8_t buffer_init_value;                  ///< Buffer register initial value
137 } ioport_event_group_input_t;
138 
139 /** IOPORT extended configuration for event link function
140  *  @note Event link must be configured by the ELC
141  */
142 typedef struct  st_ioport_extend_cfg
143 {
144     ioport_event_group_output_t port_group_output_cfg[IOPORT_PORT_GROUP_NUM]; ///< Output port group configuration
145     ioport_event_group_input_t  port_group_input_cfg[IOPORT_PORT_GROUP_NUM];  ///< Input port group configuration
146     ioport_event_single_t       single_port_cfg[IOPORT_SINGLE_PORT_NUM];      ///< Single input port configuration
147 } ioport_extend_cfg_t;
148 
149 /** IOPORT private control block. DO NOT MODIFY. Initialization occurs when R_IOPORT_Open() is called. */
150 typedef struct st_ioport_instance_ctrl
151 {
152     uint32_t             open;         // Whether or not ioport is open
153     void const         * p_context;    // Pointer to context to be passed into callback
154     ioport_cfg_t const * p_cfg;        // Pointer to the configuration block
155 } ioport_instance_ctrl_t;
156 
157 /**********************************************************************************************************************
158  * Exported global variables
159  **********************************************************************************************************************/
160 
161 /** @cond INC_HEADER_DEFS_SEC */
162 /** Filled in Interface API structure for this Instance. */
163 extern const ioport_api_t g_ioport_on_ioport;
164 
165 /** @endcond */
166 
167 /***********************************************************************************************************************
168  * Public APIs
169  **********************************************************************************************************************/
170 
171 fsp_err_t R_IOPORT_Open(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg);
172 fsp_err_t R_IOPORT_Close(ioport_ctrl_t * const p_ctrl);
173 fsp_err_t R_IOPORT_PinsCfg(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg);
174 fsp_err_t R_IOPORT_PinCfg(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, uint32_t cfg);
175 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);
176 fsp_err_t R_IOPORT_PinEventOutputWrite(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t pin_value);
177 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);
178 fsp_err_t R_IOPORT_PinWrite(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t level);
179 fsp_err_t R_IOPORT_PortDirectionSet(ioport_ctrl_t * const p_ctrl,
180                                     bsp_io_port_t         port,
181                                     ioport_size_t         direction_values,
182                                     ioport_size_t         mask);
183 fsp_err_t R_IOPORT_PortEventInputRead(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t * p_event_data);
184 fsp_err_t R_IOPORT_PortEventOutputWrite(ioport_ctrl_t * const p_ctrl,
185                                         bsp_io_port_t         port,
186                                         ioport_size_t         event_data,
187                                         ioport_size_t         mask_value);
188 fsp_err_t R_IOPORT_PortRead(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t * p_port_value);
189 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);
190 
191 /*******************************************************************************************************************//**
192  * @} (end defgroup IOPORT)
193  **********************************************************************************************************************/
194 
195 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
196 FSP_FOOTER
197 
198 #endif                                 // R_IOPORT_H
199