2525 *
2626 * Map deferred-init peripherals with their pinctrl configuration from devicetree.
2727 */
28- #define PINCTRL_NODE_DEFERRED (node_id ) DT_PROP_OR (node_id, zephyr_deferred_init, 0 )
28+ #define PINCTRL_NODE_DEFERRED (node_id ) DT_PROP (node_id, zephyr_deferred_init)
2929
30- #define PINCTRL_DEFINE_IF_PRESENT (node_id ) \
31- COND_CODE_1 (PINCTRL_NODE_DEFERRED(node_id), (PINCTRL_DT_DEFINE (node_id);), ())
30+ #define PINCTRL_DECLARE_IF_DEFERRED (node_id ) \
31+ COND_CODE_1 (PINCTRL_NODE_DEFERRED(node_id), (PINCTRL_DT_DEV_CONFIG_DECLARE (node_id);), ())
3232
33- DT_FOREACH_STATUS_OKAY_NODE (PINCTRL_DEFINE_IF_PRESENT )
33+ DT_FOREACH_STATUS_OKAY_NODE (PINCTRL_DECLARE_IF_DEFERRED )
3434
3535struct pinctrl_map_entry {
3636 const struct device *dev;
@@ -66,11 +66,11 @@ static const struct pinctrl_dev_config *get_known_pcfg(const struct device *dev)
6666 * Switches peripheral pins back to ARDUINO pinctrl state (alternate function),
6767 * typically after a temporary transition to GPIO mode.
6868 *
69- * @param idx Index of the pin within the device's ARDUINO pinctrl state
7069 * @param dev Pointer to the peripheral device
70+ * @param state_pin_idx Index of the pin within the device's ARDUINO pinctrl state
7171 * @return 0 on success, negative on error
7272 */
73- int apply_dev_channel_pinctrl (size_t state_pin_idx, const struct device *dev) {
73+ int apply_dev_channel_pinctrl (const struct device *dev, size_t state_pin_idx ) {
7474
7575 const pinctrl_soc_pin_t *soc_pin = NULL ;
7676 const struct pinctrl_state *state;
@@ -97,11 +97,8 @@ int apply_dev_channel_pinctrl(size_t state_pin_idx, const struct device *dev) {
9797 soc_pin = &state->pins [state_pin_idx];
9898
9999 /*
100- * On platforms where CONFIG_PINCTRL_STORE_REG is enabled (e.g. nRF),
101- * the peripheral's PSEL register must be written via the device base
102- * address stored in pcfg->reg.
103- * On platforms without CONFIG_PINCTRL_STORE_REG (e.g. STM32) the reg
104- * argument is ignored by their pinctrl driver, so passing PINCTRL_REG_NONE is safe.
100+ * On platforms without CONFIG_PINCTRL_STORE_REG (e.g. STM32) the pcfg->reg is not present but
101+ * the argument is ignored by their pinctrl driver, so passing PINCTRL_REG_NONE is safe.
105102 */
106103#ifdef CONFIG_PINCTRL_STORE_REG
107104 err = pinctrl_configure_pins (soc_pin, 1 , pcfg->reg );
@@ -116,12 +113,11 @@ int apply_dev_channel_pinctrl(size_t state_pin_idx, const struct device *dev) {
116113}
117114
118115/* *
119- * @brief Optimize peripheral transitions using pinctrl state switching .
116+ * @brief Optimize peripheral transitions applying pinctrl state PINCTRL_STATE_DEFAULT .
120117 *
121118 * @param dev Target peripheral device to acquire pin for
122- * @param target_state Desired pinctrl state (typically PINCTRL_STATE_DEFAULT or SLEEP)
123119 */
124- int apply_dev_pinctrl (const struct device *dev, uint8_t target_state ) {
120+ int apply_dev_pinctrl (const struct device *dev) {
125121
126122 if (dev == NULL || dev->config == NULL ) {
127123 return -EINVAL;
@@ -133,7 +129,7 @@ int apply_dev_pinctrl(const struct device *dev, uint8_t target_state) {
133129 return -ENOTSUP;
134130 }
135131
136- int ret = pinctrl_apply_state (pcfg, target_state );
132+ int ret = pinctrl_apply_state (pcfg, PINCTRL_STATE_DEFAULT );
137133
138134 if (ret < 0 && ret != -ENOENT) {
139135 return ret;
@@ -488,8 +484,8 @@ void analogWrite(pin_size_t pinNumber, int value) {
488484 }
489485 }
490486
491- (void )apply_dev_channel_pinctrl (state_pin_index_from_spec_index ( arduino_pwm, idx) ,
492- arduino_pwm[ idx]. dev );
487+ (void )apply_dev_channel_pinctrl (arduino_pwm[ idx]. dev ,
488+ state_pin_index_from_spec_index ( arduino_pwm, idx) );
493489 value = CLAMP (value, 0 , maxInput);
494490
495491 const uint32_t pulse = map (value, 0 , maxInput, 0 , arduino_pwm[idx].period );
@@ -511,7 +507,7 @@ void analogWrite(enum dacPins dacName, int value) {
511507
512508 // TODO: add reverse map to find pin name from DAC* define
513509 // In the meantime, consider A0 == DAC0
514- apply_dev_pinctrl (dac_dev, PINCTRL_STATE_DEFAULT );
510+ apply_dev_pinctrl (dac_dev);
515511 dac_channel_setup (dac_dev, &dac_ch_cfg[dacName]);
516512
517513 const int max_dac_value = 1U << dac_ch_cfg[dacName].resolution ;
@@ -575,8 +571,8 @@ int analogRead(pin_size_t pinNumber) {
575571 * The pin is selected from the ADC device "arduino" pinctrl state.
576572 * Not checking the return value because the device might not have pinctrl (e.g. nRF SAADC).
577573 */
578- (void )apply_dev_channel_pinctrl (state_pin_index_from_spec_index ( arduino_adc, idx) ,
579- arduino_adc[ idx]. dev );
574+ (void )apply_dev_channel_pinctrl (arduino_adc[ idx]. dev ,
575+ state_pin_index_from_spec_index ( arduino_adc, idx) );
580576
581577 err = adc_channel_setup (arduino_adc[idx].dev , &arduino_adc[idx].channel_cfg );
582578 if (err < 0 ) {
0 commit comments