Skip to content

Commit

Permalink
cpu/stm32: implement periph_gpio_ll_switch_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
maribu committed Aug 2, 2024
1 parent 3cd285b commit 7469811
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpu/stm32/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ FEATURES_PROVIDED += periph_gpio_ll_irq
FEATURES_PROVIDED += periph_gpio_ll_irq_level_triggered_high
FEATURES_PROVIDED += periph_gpio_ll_irq_level_triggered_low
FEATURES_PROVIDED += periph_gpio_ll_open_drain
FEATURES_PROVIDED += periph_gpio_ll_switch_dir
FEATURES_PROVIDED += periph_rtt_overflow
FEATURES_PROVIDED += periph_spi_reconfigure
FEATURES_PROVIDED += periph_timer_periodic
Expand Down
23 changes: 23 additions & 0 deletions cpu/stm32/include/gpio_ll_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,29 @@ static inline void gpio_ll_write(gpio_port_t port, uword_t value)
p->ODR = value;
}

static inline uword_t gpio_ll_prepare_switch_dir(uword_t mask)
{
/* implementation too large to always inline */
extern uword_t gpio_ll_prepare_switch_dir_impl(uword_t mask);
return gpio_ll_prepare_switch_dir_impl(mask);
}

static inline void gpio_ll_switch_dir_output(gpio_port_t port, uword_t pins)
{
GPIO_TypeDef *p = (GPIO_TypeDef *)port;
unsigned irq_state = irq_disable();
p->MODER |= pins;
irq_restore(irq_state);
}

static inline void gpio_ll_switch_dir_input(gpio_port_t port, uword_t pins)
{
GPIO_TypeDef *p = (GPIO_TypeDef *)port;
unsigned irq_state = irq_disable();
p->MODER &= ~pins;
irq_restore(irq_state);
}

static inline gpio_port_t gpio_get_port(gpio_t pin)
{
return pin & 0xfffffff0LU;
Expand Down
2 changes: 2 additions & 0 deletions cpu/stm32/include/periph/cpu_gpio_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extern "C" {
* public view on type */
#ifndef DOXYGEN

#define HAVE_GPIO_LL_PREPARE_SWITCH_DIR

#define HAVE_GPIO_PULL_STRENGTH_T
typedef enum {
GPIO_PULL_WEAKEST = 0,
Expand Down
14 changes: 14 additions & 0 deletions cpu/stm32/periph/gpio_ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,20 @@ int gpio_ll_init(gpio_port_t port, uint8_t pin, gpio_conf_t conf)
return 0;
}

uword_t gpio_ll_prepare_switch_dir_impl(uword_t mask)
{
uword_t output = mask & 0xFFFF;
output |= output << 8;
output &= 0x00FF00FF;
output |= output << 4;
output &= 0x0F0F0F0F;
output |= output << 2;
output &= 0x33333333;
output |= output << 1;
output &= 0x55555555;
return output;
}

gpio_conf_t gpio_ll_query_conf(gpio_port_t port, uint8_t pin)
{
gpio_conf_t result = { 0 };
Expand Down

0 comments on commit 7469811

Please sign in to comment.