From eb7eeb838bdf0728f2f93d4933ff105a43308016 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Sun, 14 Dec 2014 18:00:11 +0100 Subject: [PATCH] Add a set_pins() core function which can configure all GPIO in one loop. --- core/pio.c | 12 ++++++++---- include/core/pio.h | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/pio.c b/core/pio.c index 149cbc0..f2fe4a3 100644 --- a/core/pio.c +++ b/core/pio.c @@ -144,7 +144,11 @@ void config_pio(const struct pio* pp, uint32_t mode) } -/* FIXME: We should add some system-wide way to "reserve" a pin, but anyway this - * would not prevent anyone from configuring the same pin for two diferent functions - * when not using our code. - */ +void set_pins(const struct pio_config* pins) +{ + int i = 0; + for (i = 0; pins[i].pio.port != 0xFF; i++) { + config_pio(&(pins[i].pio), pins[i].mode); + } +} + diff --git a/include/core/pio.h b/include/core/pio.h index fb558fe..30d9c73 100644 --- a/include/core/pio.h +++ b/include/core/pio.h @@ -35,6 +35,13 @@ struct pio { }; #define ARRAY_LAST_PIN {0xFF, 0xFF, 0xFF} +#define PIO_LAST ARRAY_LAST_PIN + +struct pio_config { + struct pio pio; + uint32_t mode; +}; +#define ARRAY_LAST_PIO { PIO_LAST, 0xFF } #define PORT0_NB_PINS 32 @@ -47,6 +54,8 @@ void pio_copy(struct pio* dst, const struct pio* src); /* Configure the pin in the requested function and mode. */ void config_pio(const struct pio* pp, uint32_t mode); +/* Configure a set (array) of pins in a single loop */ +void set_pins(const struct pio_config* pins); /****************************************************************************/ /* GPIO Pins */ -- 2.43.0