analogdevicesinc / msdk

Software Development Kit for Analog Device's MAX-series microcontrollers
Apache License 2.0
60 stars 76 forks source link

fix(PeriphDrivers): Update MAX32662 GPIO PAD configuration #874

Closed hfakkiz closed 6 months ago

hfakkiz commented 6 months ago

Pull Request Template

Description

ME12 only supports high-impedance, weak pullup and weak pulldown options.

image

This commit removes other options and corrects related register values of PAD configuration.

Checklist Before Requesting Review

sihyung-maxim commented 6 months ago

This PR is related to this one: https://github.com/Analog-Devices-MSDK/msdk/pull/866

The final changes should be consistent across these two PRs.

ozersa commented 6 months ago

@sihyung-maxim correct the changes shall be consistent.

Default pullup pulldown shall be "MXC_GPIO_PAD_PULL_UP" and "MXC_GPIO_PAD_PULL_DOWN" to be consistent and simplify things. The below configuration will work on Zephyr side.

gpio.h file

typedef enum {
    MXC_GPIO_PAD_NONE, ///< No pull-up or pull-down
    MXC_GPIO_PAD_PULL_UP, ///< Set pad to weak pull-up
    MXC_GPIO_PAD_PULL_DOWN, ///< Set pad to weak pull-down
    MXC_GPIO_PAD_WEAK_PULL_UP = MXC_GPIO_PAD_PULL_UP, ///< Set pad to weak pull-up
    MXC_GPIO_PAD_WEAK_PULL_DOWN = MXC_GPIO_PAD_PULL_DOWN, ///< Set pad to weak pull-down
} mxc_gpio_pad_t;

gpio_me12.c file

    switch (cfg->pad) {
    case MXC_GPIO_PAD_NONE:
        gpio->padctrl0 &= ~cfg->mask;
        break;

    case MXC_GPIO_PAD_PULL_UP:
        gpio->padctrl0 |= cfg->mask;
        gpio->ps |= cfg->mask;
        break;

    case MXC_GPIO_PAD_PULL_DOWN:
        gpio->padctrl0 |= cfg->mask;
        gpio->ps &= ~cfg->mask;
        break;

    default:
        return E_BAD_PARAM;
    }
hfakkiz commented 6 months ago

@sihyung-maxim correct the changes shall be consistent.

Default pullup pulldown shall be "MXC_GPIO_PAD_PULL_UP" and "MXC_GPIO_PAD_PULL_DOWN" to be consistent and simplify things. The below configuration will work on Zephyr side.

gpio.h file

typedef enum {
    MXC_GPIO_PAD_NONE, ///< No pull-up or pull-down
    MXC_GPIO_PAD_PULL_UP, ///< Set pad to weak pull-up
    MXC_GPIO_PAD_PULL_DOWN, ///< Set pad to weak pull-down
    MXC_GPIO_PAD_WEAK_PULL_UP = MXC_GPIO_PAD_PULL_UP, ///< Set pad to weak pull-up
    MXC_GPIO_PAD_WEAK_PULL_DOWN = MXC_GPIO_PAD_PULL_DOWN, ///< Set pad to weak pull-down
} mxc_gpio_pad_t;

gpio_me12.c file

    switch (cfg->pad) {
    case MXC_GPIO_PAD_NONE:
        gpio->padctrl0 &= ~cfg->mask;
        break;

    case MXC_GPIO_PAD_PULL_UP:
        gpio->padctrl0 |= cfg->mask;
        gpio->ps |= cfg->mask;
        break;

    case MXC_GPIO_PAD_PULL_DOWN:
        gpio->padctrl0 |= cfg->mask;
        gpio->ps &= ~cfg->mask;
        break;

    default:
        return E_BAD_PARAM;
    }

Updated code as this.