1 /* 2 * Copyright (c) 2024 Michael Hope 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __PINCTRL_SOC_H__ 8 #define __PINCTRL_SOC_H__ 9 10 /** 11 * @brief Type to hold a pin's pinctrl configuration. 12 */ 13 struct ch32v003_pinctrl_soc_pin { 14 uint32_t config: 22; 15 bool bias_pull_up: 1; 16 bool bias_pull_down: 1; 17 bool drive_open_drain: 1; 18 bool drive_push_pull: 1; 19 bool output_high: 1; 20 bool output_low: 1; 21 uint8_t slew_rate: 2; 22 }; 23 24 typedef struct ch32v003_pinctrl_soc_pin pinctrl_soc_pin_t; 25 26 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ 27 { \ 28 .config = DT_PROP_BY_IDX(node_id, prop, idx), \ 29 .bias_pull_up = DT_PROP(node_id, bias_pull_up), \ 30 .bias_pull_down = DT_PROP(node_id, bias_pull_down), \ 31 .drive_open_drain = DT_PROP(node_id, drive_open_drain), \ 32 .drive_push_pull = DT_PROP(node_id, drive_push_pull), \ 33 .output_high = DT_PROP(node_id, output_high), \ 34 .output_low = DT_PROP(node_id, output_low), \ 35 .slew_rate = DT_ENUM_IDX(node_id, slew_rate), \ 36 }, 37 38 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ 39 {DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \ 40 Z_PINCTRL_STATE_PIN_INIT)} 41 42 #endif 43