|
| 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 | +#if __has_include("r_ioport_cfg.h") |
| 25 | + #include "r_ioport_cfg.h" |
| 26 | +#endif |
| 27 | + |
| 28 | +/*********************************************************************************************************************** |
| 29 | + * Macro definitions |
| 30 | + **********************************************************************************************************************/ |
| 31 | + |
| 32 | +/* Private definition to set enumeration values. */ |
| 33 | +#define IOPORT_PRV_PFS_PSEL_OFFSET (24) |
| 34 | + |
| 35 | +/*********************************************************************************************************************** |
| 36 | + * Typedef definitions |
| 37 | + **********************************************************************************************************************/ |
| 38 | + |
| 39 | +/** IOPORT private control block. DO NOT MODIFY. Initialization occurs when R_IOPORT_Open() is called. */ |
| 40 | +typedef struct st_ioport_instance_ctrl |
| 41 | +{ |
| 42 | + uint32_t open; |
| 43 | + void const * p_context; |
| 44 | + ioport_cfg_t const * p_cfg; |
| 45 | +} ioport_instance_ctrl_t; |
| 46 | + |
| 47 | +#ifndef BSP_OVERRIDE_IOPORT_PERIPHERAL_T |
| 48 | + |
| 49 | +/** Superset of all peripheral functions. */ |
| 50 | +typedef enum e_ioport_peripheral |
| 51 | +{ |
| 52 | + /** Pin will function as a Mode0 peripheral pin */ |
| 53 | + IOPORT_PERIPHERAL_MODE0 = (0x0UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 54 | + |
| 55 | + /** Pin will function as a Mode1 peripheral pin */ |
| 56 | + IOPORT_PERIPHERAL_MODE1 = (0x1UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 57 | + |
| 58 | + /** Pin will function as a Mode2 peripheral pin */ |
| 59 | + IOPORT_PERIPHERAL_MODE2 = (0x2UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 60 | + |
| 61 | + /** Pin will function as a Mode3 peripheral pin */ |
| 62 | + IOPORT_PERIPHERAL_MODE3 = (0x3UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 63 | + |
| 64 | + /** Pin will function as a Mode4 peripheral pin */ |
| 65 | + IOPORT_PERIPHERAL_MODE4 = (0x4UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 66 | + |
| 67 | + /** Pin will function as a Mode5 peripheral pin */ |
| 68 | + IOPORT_PERIPHERAL_MODE5 = (0x5UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 69 | + |
| 70 | + /** Pin will function as a Mode6 peripheral pin */ |
| 71 | + IOPORT_PERIPHERAL_MODE6 = (0x6UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 72 | + |
| 73 | + /** Pin will function as a Mode7 peripheral pin */ |
| 74 | + IOPORT_PERIPHERAL_MODE7 = (0x7UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 75 | + |
| 76 | + /** Pin will function as a Mode8 peripheral pin */ |
| 77 | + IOPORT_PERIPHERAL_MODE8 = (0x8UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 78 | + |
| 79 | + /** Pin will function as a Mode9 peripheral pin */ |
| 80 | + IOPORT_PERIPHERAL_MODE9 = (0x9UL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 81 | + |
| 82 | + /** Pin will function as a Mode10 peripheral pin */ |
| 83 | + IOPORT_PERIPHERAL_MODE10 = (0xAUL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 84 | + |
| 85 | + /** Pin will function as a Mode11 peripheral pin */ |
| 86 | + IOPORT_PERIPHERAL_MODE11 = (0xBUL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 87 | + |
| 88 | + /** Pin will function as a Mode12 peripheral pin */ |
| 89 | + IOPORT_PERIPHERAL_MODE12 = (0xCUL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 90 | + |
| 91 | + /** Pin will function as a Mode13 peripheral pin */ |
| 92 | + IOPORT_PERIPHERAL_MODE13 = (0xDUL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 93 | + |
| 94 | + /** Pin will function as a Mode14 peripheral pin */ |
| 95 | + IOPORT_PERIPHERAL_MODE14 = (0xEUL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 96 | + |
| 97 | + /** Pin will function as a Mode15 peripheral pin */ |
| 98 | + IOPORT_PERIPHERAL_MODE15 = (0xFUL << IOPORT_PRV_PFS_PSEL_OFFSET), |
| 99 | +} ioport_peripheral_t; |
| 100 | + |
| 101 | +#endif |
| 102 | + |
| 103 | +#ifndef BSP_OVERRIDE_IOPORT_CFG_OPTIONS_T |
| 104 | + |
| 105 | +/** Options to configure pin functions */ |
| 106 | +typedef enum e_ioport_cfg_options |
| 107 | +{ |
| 108 | + /* For PM Register */ |
| 109 | + IOPORT_CFG_PORT_DIRECTION_HIZ = 0x00000000, ///< Sets the pin direction to Hi-Z (default) |
| 110 | + IOPORT_CFG_PORT_DIRECTION_INPUT = 0x00000004, ///< Sets the pin direction to input |
| 111 | + IOPORT_CFG_PORT_DIRECTION_OUTPUT = 0x00000008, ///< Sets the pin direction to output (input disable) |
| 112 | + IOPORT_CFG_PORT_DIRECTION_OUTPUT_INPUT = 0x0000000C, ///< Sets the pin direction to output (input enable) |
| 113 | + |
| 114 | + /* For P Register */ |
| 115 | + IOPORT_CFG_PORT_OUTPUT_LOW = 0x00000000, ///< Sets the pin level to low |
| 116 | + IOPORT_CFG_PORT_OUTPUT_HIGH = 0x00000001, ///< Sets the pin level to high |
| 117 | + |
| 118 | + /* For PUPD Register */ |
| 119 | + IOPORT_CFG_PULLUP_PULLDOWN_DISABLE = 0x00000000, ///< Disable the pin's internal pull-up and pull-down |
| 120 | + IOPORT_CFG_PULLUP_ENABLE = 0x00000010, ///< Enables the pin's internal pull-up |
| 121 | + IOPORT_CFG_PULLDOWN_ENABLE = 0x00000020, ///< Enables the pin's internal pull-down |
| 122 | + |
| 123 | + /* For NOD Register */ |
| 124 | + IOPORT_CFG_NOD_DISABLE = 0x00000000, ///< Disable the pin's N-ch open-drain |
| 125 | + IOPORT_CFG_NOD_ENABLE = 0x00000040, ///< Enables the pin's N-ch open-drain |
| 126 | + |
| 127 | + /* For SMT Register */ |
| 128 | + IOPORT_CFG_SCHMITT_DISABLE = 0x00000000, ///< Disable the pin's Schmitt-trigger input |
| 129 | + IOPORT_CFG_SCHMITT_ENABLE = 0x80000000, ///< Enables the pin's Schmitt-trigger input |
| 130 | + |
| 131 | + /* For IOLH Register */ |
| 132 | + IOPORT_CFG_DRIVE_B00 = 0x00000000, ///< Sets the IOLH register value to b'00 |
| 133 | + IOPORT_CFG_DRIVE_B01 = 0x00000400, ///< Sets the IOLH register value to b'01 |
| 134 | + IOPORT_CFG_DRIVE_B10 = 0x00000800, ///< Sets the IOLH register value to b'10 |
| 135 | + IOPORT_CFG_DRIVE_B11 = 0x00000C00, ///< Sets the IOLH register value to b'11 |
| 136 | + |
| 137 | + /* For ISEL Register */ |
| 138 | + IOPORT_CFG_TINT_DISABLE = 0x00000000, ///< Disable IRQ functionality for a pin |
| 139 | + IOPORT_CFG_TINT_ENABLE = 0x00004000, ///< Sets pin as an IRQ pin |
| 140 | + |
| 141 | + /* For SR Register */ |
| 142 | + IOPORT_CFG_SLEW_RATE_SLOW = 0x00000000, ///< Sets the pin slew-rate to slow |
| 143 | + IOPORT_CFG_SLEW_RATE_FAST = 0x00020000, ///< Sets the pin slew-rate to fast |
| 144 | + |
| 145 | + /* For IEN Register */ |
| 146 | + IOPORT_CFG_SPECIAL_PURPOSE_PORT_INPUT_DISABLE = 0x00000000, ///< Disable input the pin of special purpose port |
| 147 | + IOPORT_CFG_SPECIAL_PURPOSE_PORT_INPUT_ENABLE = 0x00040000, ///< Sets the pin of special purpose port to input |
| 148 | + |
| 149 | + /* For FILONOFF Register */ |
| 150 | + IOPORT_CFG_NOISE_FILTER_OFF = 0x00000000, ///< Noise filter disable |
| 151 | + IOPORT_CFG_NOISE_FILTER_ON = 0x00080000, ///< Noise filter enable |
| 152 | + |
| 153 | + /* For FILNUM Register */ |
| 154 | + IOPORT_CFG_NOISE_FILTER_NUM_4STAGE = 0x00000000, ///< Sets the pin noise filter to 4-stage filter |
| 155 | + IOPORT_CFG_NOISE_FILTER_NUM_8STAGE = 0x00100000, ///< Sets the pin noise filter to 8-stage filter |
| 156 | + IOPORT_CFG_NOISE_FILTER_NUM_12STAGE = 0x00200000, ///< Sets the pin noise filter to 12-stage filter |
| 157 | + IOPORT_CFG_NOISE_FILTER_NUM_16STAGE = 0x00300000, ///< Sets the pin noise filter to 16-stage filter |
| 158 | + |
| 159 | + /* For FILCLKSEL Register */ |
| 160 | + IOPORT_CFG_NOISE_FILTER_DIVIDED_B00 = 0x00000000, ///< Sets the FILCLKSEL register value to b'00 |
| 161 | + IOPORT_CFG_NOISE_FILTER_DIVIDED_B01 = 0x00400000, ///< Sets the FILCLKSEL register value to b'01 |
| 162 | + IOPORT_CFG_NOISE_FILTER_DIVIDED_B10 = 0x00800000, ///< Sets the FILCLKSEL register value to b'10 |
| 163 | + IOPORT_CFG_NOISE_FILTER_DIVIDED_B11 = 0x00C00000, ///< Sets the FILCLKSEL register value to b'11 |
| 164 | + |
| 165 | + /* For PMC Register */ |
| 166 | + IOPORT_CFG_PERIPHERAL_PIN = 0x00010000 ///< Enables pin to operate as a peripheral pin |
| 167 | +} ioport_cfg_options_t; |
| 168 | + |
| 169 | +#endif |
| 170 | + |
| 171 | +/** Pin selection for port group |
| 172 | + * @note Event link must be configured by the ELC |
| 173 | + */ |
| 174 | +typedef enum e_ioport_event_pin_selection |
| 175 | +{ |
| 176 | + IOPORT_EVENT_PIN_SELECTION_NONE = 0x00, ///< No pin selection for port group |
| 177 | + IOPORT_EVENT_PIN_SELECTION_PIN_0 = 0x01, ///< Select pin 0 to port group |
| 178 | + IOPORT_EVENT_PIN_SELECTION_PIN_1 = 0x02, ///< Select pin 1 to port group |
| 179 | + IOPORT_EVENT_PIN_SELECTION_PIN_2 = 0x04, ///< Select pin 2 to port group |
| 180 | + IOPORT_EVENT_PIN_SELECTION_PIN_3 = 0x08, ///< Select pin 3 to port group |
| 181 | + IOPORT_EVENT_PIN_SELECTION_PIN_4 = 0x10, ///< Select pin 4 to port group |
| 182 | + IOPORT_EVENT_PIN_SELECTION_PIN_5 = 0x20, ///< Select pin 5 to port group |
| 183 | + IOPORT_EVENT_PIN_SELECTION_PIN_6 = 0x40, ///< Select pin 6 to port group |
| 184 | + IOPORT_EVENT_PIN_SELECTION_PIN_7 = 0x80, ///< Select pin 7 to port group |
| 185 | +} ioport_event_pin_selection_t; |
| 186 | + |
| 187 | +/** Port group operation |
| 188 | + * @note Event link must be configured by the ELC |
| 189 | + */ |
| 190 | +typedef enum e_ioport_event_output_operation |
| 191 | +{ |
| 192 | + IOPORT_EVENT_OUTPUT_OPERATION_LOW = 0x0, ///< Set Low output to output operation |
| 193 | + IOPORT_EVENT_OUTPUT_OPERATION_HIGH = 0x1, ///< Set High output to output operation |
| 194 | + IOPORT_EVENT_OUTPUT_OPERATION_TOGGLE = 0x2, ///< Set toggle output to output operation |
| 195 | + IOPORT_EVENT_OUTPUT_OPERATION_BUFFER = 0x3, ///< Set buffer value output to output operation |
| 196 | +} ioport_event_output_operation_t; |
| 197 | + |
| 198 | +/** Input port group event control |
| 199 | + * @note Event link must be configured by the ELC |
| 200 | + */ |
| 201 | +typedef enum e_ioport_event_control |
| 202 | +{ |
| 203 | + IOPORT_EVENT_CONTROL_DISABLE = 0x0, ///< Disable function related with event link |
| 204 | + IOPORT_EVENT_CONTROL_ENABLE = 0x1, ///< Enable function related with event link |
| 205 | +} ioport_event_control_t; |
| 206 | + |
| 207 | +/** Single port event direction |
| 208 | + * @note Event link must be configured by the ELC |
| 209 | + */ |
| 210 | +typedef enum e_ioport_event_direction |
| 211 | +{ |
| 212 | + IOPORT_EVENT_DIRECTION_OUTPUT = 0x0, ///< Set output direction to single port |
| 213 | + IOPORT_EVENT_DIRECTION_INPUT = 0x1, ///< Set input direction to single port |
| 214 | +} ioport_event_direction_t; |
| 215 | + |
| 216 | +/** Input event edge detection |
| 217 | + * @note Event link must be configured by the ELC |
| 218 | + */ |
| 219 | +typedef enum e_ioport_event_detection |
| 220 | +{ |
| 221 | + IOPORT_EVENT_DETECTION_RISING_EDGE = 0x0, ///< Set rising edge to event detection for input event |
| 222 | + IOPORT_EVENT_DETECTION_FALLING_EDGE = 0x1, ///< Set falling edge to event detection for input event |
| 223 | + IOPORT_EVENT_DETECTION_BOTH_EGDE = 0x2, ///< Set both edges to event detection for input event |
| 224 | +} ioport_event_detection_t; |
| 225 | + |
| 226 | +/** Initial value for buffer register |
| 227 | + * @note Event link must be configured by the ELC |
| 228 | + */ |
| 229 | +typedef enum e_ioport_event_initial_buffer_value |
| 230 | +{ |
| 231 | + IOPORT_EVENT_INITIAL_BUFFER_VALUE_LOW = 0U, ///< Set low to initial value of buffer register for input port group |
| 232 | + IOPORT_EVENT_INITIAL_BUFFER_VALUE_HIGH = 1U, ///< Set high to initial value of buffer register for input port group |
| 233 | +} ioport_event_initial_buffer_value_t; |
| 234 | + |
| 235 | +/** Single port configuration |
| 236 | + * @note Event link must be configured by the ELC |
| 237 | + */ |
| 238 | +typedef struct st_ioport_event_single |
| 239 | +{ |
| 240 | + ioport_event_control_t event_control; ///< Event link control for single port |
| 241 | + ioport_event_direction_t direction; ///< Event direction for single port |
| 242 | + uint16_t port_num; ///< Port number specified to single port |
| 243 | + ioport_event_output_operation_t operation; ///< Single port operation select |
| 244 | + ioport_event_detection_t edge_detection; ///< Edge detection select |
| 245 | +} ioport_event_single_t; |
| 246 | + |
| 247 | +/** Output port group configuration |
| 248 | + * @note Event link must be configured by the ELC |
| 249 | + */ |
| 250 | +typedef struct st_ioport_event_group_output |
| 251 | +{ |
| 252 | + uint8_t pin_select; ///< Port number specified to output port group |
| 253 | + ioport_event_output_operation_t operation; ///< Port group operation select |
| 254 | +} ioport_event_group_output_t; |
| 255 | + |
| 256 | +/** Input port group configuration |
| 257 | + * @note Event link must be configured by the ELC |
| 258 | + */ |
| 259 | +typedef struct st_ioport_event_group_input |
| 260 | +{ |
| 261 | + ioport_event_control_t event_control; ///< Event link control for input port group |
| 262 | + ioport_event_detection_t edge_detection; ///< Edge detection select |
| 263 | + ioport_event_control_t overwrite_control; ///< Buffer register overwrite control |
| 264 | + uint8_t pin_select; ///< Port number specified to input port group |
| 265 | + uint8_t buffer_init_value; ///< Buffer register initial value |
| 266 | +} ioport_event_group_input_t; |
| 267 | + |
| 268 | +/** IOPORT extended configuration for event link function |
| 269 | + * @note Event link must be configured by the ELC |
| 270 | + */ |
| 271 | +typedef struct st_ioport_extend_cfg |
| 272 | +{ |
| 273 | + ioport_event_group_output_t const * p_port_group_output_cfg; ///< Pointer to output port group configuration |
| 274 | + ioport_event_group_input_t const * p_port_group_input_cfg; ///< Pointer to input port group configuration |
| 275 | + ioport_event_single_t const * p_single_port_cfg; ///< Pointer to single input port configuration |
| 276 | +} ioport_extend_cfg_t; |
| 277 | + |
| 278 | +/********************************************************************************************************************** |
| 279 | + * Exported global variables |
| 280 | + **********************************************************************************************************************/ |
| 281 | + |
| 282 | +/** @cond INC_HEADER_DEFS_SEC */ |
| 283 | +/** Filled in Interface API structure for this Instance. */ |
| 284 | +extern const ioport_api_t g_ioport_on_ioport; |
| 285 | + |
| 286 | +/** @endcond */ |
| 287 | + |
| 288 | +/*********************************************************************************************************************** |
| 289 | + * Public APIs |
| 290 | + **********************************************************************************************************************/ |
| 291 | + |
| 292 | +fsp_err_t R_IOPORT_Open(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg); |
| 293 | +fsp_err_t R_IOPORT_Close(ioport_ctrl_t * const p_ctrl); |
| 294 | +fsp_err_t R_IOPORT_PinsCfg(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg); |
| 295 | +fsp_err_t R_IOPORT_PinCfg(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, uint32_t cfg); |
| 296 | +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); |
| 297 | +fsp_err_t R_IOPORT_PinEventOutputWrite(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t pin_value); |
| 298 | +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); |
| 299 | +fsp_err_t R_IOPORT_PinWrite(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t level); |
| 300 | +fsp_err_t R_IOPORT_PortDirectionSet(ioport_ctrl_t * const p_ctrl, |
| 301 | + bsp_io_port_t port, |
| 302 | + ioport_size_t direction_values, |
| 303 | + ioport_size_t mask); |
| 304 | +fsp_err_t R_IOPORT_PortEventInputRead(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t * event_data); |
| 305 | +fsp_err_t R_IOPORT_PortEventOutputWrite(ioport_ctrl_t * const p_ctrl, |
| 306 | + bsp_io_port_t port, |
| 307 | + ioport_size_t event_data, |
| 308 | + ioport_size_t mask_value); |
| 309 | +fsp_err_t R_IOPORT_PortRead(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t * p_port_value); |
| 310 | +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); |
| 311 | + |
| 312 | +/*******************************************************************************************************************//** |
| 313 | + * @} (end defgroup IOPORT) |
| 314 | + **********************************************************************************************************************/ |
| 315 | + |
| 316 | +/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ |
| 317 | +FSP_FOOTER |
| 318 | + |
| 319 | +#endif // R_IOPORT_H |
0 commit comments