Skip to content

Commit

Permalink
drivers: gpio fixed according to hal issue #60
Browse files Browse the repository at this point in the history
  • Loading branch information
jnaulet committed Jul 16, 2023
1 parent 41525a9 commit afd146b
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 10 deletions.
16 changes: 14 additions & 2 deletions drivers/gpio/gpio-avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,23 @@ int gpio_avr_init(struct gpio *ctx, int base, size_t pin)
return 0;
}

/* HAL */
static int set_invert(struct gpio *ctx, gpio_invert_t invert)
{
if (!picoRTOS_assert(invert != GPIO_INVERT_IGNORE)) return -EINVAL;
if (!picoRTOS_assert(invert < GPIO_INVERT_COUNT)) return -EINVAL;

ctx->invert = (invert == GPIO_INVERT_ENABLE);
return 0;
}

int gpio_setup(struct gpio *ctx, struct gpio_settings *settings)
{
ctx->invert = settings->invert;
int res;

if (settings->invert != GPIO_INVERT_IGNORE &&
(res = set_invert(ctx, settings->invert)) < 0)
return res;

return 0;
}

Expand Down
16 changes: 15 additions & 1 deletion drivers/gpio/gpio-gd32vf103.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,23 @@ int gpio_gd32vf103_init(struct gpio *ctx, int base, size_t pin)
return 0;
}

static int set_invert(struct gpio *ctx, gpio_invert_t invert)
{
if (!picoRTOS_assert(invert != GPIO_INVERT_IGNORE)) return -EINVAL;
if (!picoRTOS_assert(invert < GPIO_INVERT_COUNT)) return -EINVAL;

ctx->invert = (invert == GPIO_INVERT_ENABLE);
return 0;
}

int gpio_setup(struct gpio *ctx, struct gpio_settings *settings)
{
ctx->invert = settings->invert;
int res;

if (settings->invert != GPIO_INVERT_IGNORE &&
(res = set_invert(ctx, settings->invert)) < 0)
return res;

return 0;
}

Expand Down
16 changes: 15 additions & 1 deletion drivers/gpio/gpio-pic32mx.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,23 @@ int gpio_pic32mx_init(struct gpio *ctx, int base, size_t pin)
return 0;
}

static int set_invert(struct gpio *ctx, gpio_invert_t invert)
{
if (!picoRTOS_assert(invert != GPIO_INVERT_IGNORE)) return -EINVAL;
if (!picoRTOS_assert(invert < GPIO_INVERT_COUNT)) return -EINVAL;

ctx->invert = (invert == GPIO_INVERT_ENABLE);
return 0;
}

int gpio_setup(struct gpio *ctx, struct gpio_settings *settings)
{
ctx->invert = settings->invert;
int res;

if (settings->invert != GPIO_INVERT_IGNORE &&
(res = set_invert(ctx, settings->invert)) < 0)
return res;

return 0;
}

Expand Down
16 changes: 15 additions & 1 deletion drivers/gpio/gpio-rp2040_sio.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,23 @@ int gpio_rp2040_sio_init(struct gpio *ctx, int base,
return 0;
}

static int set_invert(struct gpio *ctx, gpio_invert_t invert)
{
if (!picoRTOS_assert(invert != GPIO_INVERT_IGNORE)) return -EINVAL;
if (!picoRTOS_assert(invert < GPIO_INVERT_COUNT)) return -EINVAL;

ctx->invert = (invert == GPIO_INVERT_ENABLE);
return 0;
}

int gpio_setup(struct gpio *ctx, struct gpio_settings *settings)
{
ctx->invert = settings->invert;
int res;

if (settings->invert != GPIO_INVERT_IGNORE &&
(res = set_invert(ctx, settings->invert)) < 0)
return res;

return 0;
}

Expand Down
16 changes: 15 additions & 1 deletion drivers/gpio/gpio-sam3x_pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,23 @@ int gpio_sam3x_pio_init(struct gpio *ctx, int base, size_t pin)
return 0;
}

static int set_invert(struct gpio *ctx, gpio_invert_t invert)
{
if (!picoRTOS_assert(invert != GPIO_INVERT_IGNORE)) return -EINVAL;
if (!picoRTOS_assert(invert < GPIO_INVERT_COUNT)) return -EINVAL;

ctx->invert = (invert == GPIO_INVERT_ENABLE);
return 0;
}

int gpio_setup(struct gpio *ctx, struct gpio_settings *settings)
{
ctx->invert = settings->invert;
int res;

if (settings->invert != GPIO_INVERT_IGNORE &&
(res = set_invert(ctx, settings->invert)) < 0)
return res;

return 0;
}

Expand Down
16 changes: 15 additions & 1 deletion drivers/gpio/gpio-same5x.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@ int gpio_same5x_init(struct gpio *ctx, int base, size_t pin)
return 0;
}

static int set_invert(struct gpio *ctx, gpio_invert_t invert)
{
if (!picoRTOS_assert(invert != GPIO_INVERT_IGNORE)) return -EINVAL;
if (!picoRTOS_assert(invert < GPIO_INVERT_COUNT)) return -EINVAL;

ctx->invert = (invert == GPIO_INVERT_ENABLE);
return 0;
}

int gpio_setup(struct gpio *ctx, struct gpio_settings *settings)
{
ctx->invert = settings->invert;
int res;

if (settings->invert != GPIO_INVERT_IGNORE &&
(res = set_invert(ctx, settings->invert)) < 0)
return res;

return 0;
}

Expand Down
16 changes: 14 additions & 2 deletions drivers/gpio/gpio-ti_f28x.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,23 @@ int gpio_ti_f28x_init(struct gpio *ctx, int base, size_t pin)
return 0;
}

/* hooks */
static int set_invert(struct gpio *ctx, gpio_invert_t invert)
{
if (!picoRTOS_assert(invert != GPIO_INVERT_IGNORE)) return -EINVAL;
if (!picoRTOS_assert(invert < GPIO_INVERT_COUNT)) return -EINVAL;

ctx->invert = (invert == GPIO_INVERT_ENABLE);
return 0;
}

int gpio_setup(struct gpio *ctx, struct gpio_settings *settings)
{
ctx->invert = settings->invert;
int res;

if (settings->invert != GPIO_INVERT_IGNORE &&
(res = set_invert(ctx, settings->invert)) < 0)
return res;

return 0;
}

Expand Down
16 changes: 15 additions & 1 deletion drivers/gpio/gpio-tinyavr.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,23 @@ int gpio_tinyavr_init(struct gpio *ctx, int base, size_t pin)
return 0;
}

static int set_invert(struct gpio *ctx, gpio_invert_t invert)
{
if (!picoRTOS_assert(invert != GPIO_INVERT_IGNORE)) return -EINVAL;
if (!picoRTOS_assert(invert < GPIO_INVERT_COUNT)) return -EINVAL;

ctx->invert = (invert == GPIO_INVERT_ENABLE);
return 0;
}

int gpio_setup(struct gpio *ctx, struct gpio_settings *settings)
{
ctx->invert = settings->invert;
int res;

if (settings->invert != GPIO_INVERT_IGNORE &&
(res = set_invert(ctx, settings->invert)) < 0)
return res;

return 0;
}

Expand Down

0 comments on commit afd146b

Please sign in to comment.