99
1010#include < zephyr/spinlock.h>
1111
12- #ifdef CONFIG_PINCTRL_DYNAMIC
1312// create an array of arduino_pins with functions to reinitialize pins if needed
1413static const struct device *pinmux_array[DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios)] = {
1514 nullptr };
@@ -22,7 +21,6 @@ void _reinit_peripheral_if_needed(pin_size_t pin, const struct device *dev) {
2221 }
2322 }
2423}
25- #endif
2624
2725static const struct gpio_dt_spec arduino_pins[] = {
2826 DT_FOREACH_PROP_ELEM_SEP (
@@ -241,9 +239,7 @@ void yield(void) {
241239void pinMode (pin_size_t pinNumber, PinMode pinMode) {
242240 RETURN_ON_INVALID_PIN (pinNumber);
243241
244- #ifdef CONFIG_PINCTRL_DYNAMIC
245242 _reinit_peripheral_if_needed (pinNumber, NULL );
246- #endif
247243 if (pinMode == INPUT) { // input mode
248244 gpio_pin_configure_dt (&arduino_pins[pinNumber], GPIO_INPUT | GPIO_ACTIVE_HIGH);
249245 } else if (pinMode == INPUT_PULLUP) { // input with internal pull-up
@@ -480,11 +476,8 @@ void analogWrite(pin_size_t pinNumber, int value) {
480476 return ;
481477 }
482478
483- #ifdef CONFIG_PINCTRL_DYNAMIC
484479 _reinit_peripheral_if_needed (pinNumber, arduino_pwm[idx].dev );
485- #endif
486480 value = CLAMP (value, 0 , maxInput);
487- value = map (value, 0 , 1 << _analog_write_resolution, 0 , arduino_pwm[idx].period );
488481
489482 const uint32_t pulse = map64 (value, 0 , maxInput, 0 , arduino_pwm[idx].period );
490483
@@ -514,9 +507,7 @@ void analogWrite(enum dacPins dacName, int value) {
514507
515508 // TODO: add reverse map to find pin name from DAC* define
516509 // In the meantime, consider A0 == DAC0
517- #ifdef CONFIG_PINCTRL_DYNAMIC
518510 _reinit_peripheral_if_needed ((pin_size_t )(dacName + A0), dac_dev);
519- #endif
520511 ret = dac_channel_setup (dac_dev, &dac_ch_cfg[dacName]);
521512 if (ret != 0 ) {
522513 return ;
@@ -579,9 +570,8 @@ int analogRead(pin_size_t pinNumber) {
579570 return -ENOTSUP;
580571 }
581572
582- #ifdef CONFIG_PINCTRL_DYNAMIC
583573 _reinit_peripheral_if_needed (pinNumber, arduino_adc[idx].dev );
584- # endif
574+
585575 err = adc_channel_setup (arduino_adc[idx].dev , &arduino_adc[idx].channel_cfg );
586576 if (err < 0 ) {
587577 return err;
0 commit comments