From 434d5999cd80769586461926febd7583a268ded7 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 29 Jun 2021 17:30:11 -0500 Subject: [PATCH] drv/ioport_lpf2: move out of autostart processes This continues the work of getting rid of the autostart processes by changing the LPF2 I/O port driver to use an init function like most other drivers. --- lib/pbio/drv/core.c | 4 +++- lib/pbio/drv/ioport/ioport.h | 26 ++++++++++++++++++++++++++ lib/pbio/drv/ioport/ioport_lpf2.c | 4 ++++ lib/pbio/drv/ioport/ioport_lpf2.h | 13 ++++++++++--- lib/pbio/src/main.c | 3 --- lib/pbio/src/processes.h | 5 ----- 6 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 lib/pbio/drv/ioport/ioport.h diff --git a/lib/pbio/drv/core.c b/lib/pbio/drv/core.c index 26cf60094..21c0aa070 100644 --- a/lib/pbio/drv/core.c +++ b/lib/pbio/drv/core.c @@ -7,6 +7,7 @@ #include "battery/battery.h" #include "bluetooth/bluetooth.h" #include "counter/counter.h" +#include "ioport/ioport.h" #include "led/led_array.h" #include "led/led.h" #include "pwm/pwm.h" @@ -24,8 +25,9 @@ void pbdrv_init(void) { pbdrv_battery_init(); pbdrv_bluetooth_init(); pbdrv_counter_init(); - pbdrv_led_init(); + pbdrv_ioport_init(); pbdrv_led_array_init(); + pbdrv_led_init(); pbdrv_pwm_init(); pbdrv_reset_init(); pbdrv_sound_init(); diff --git a/lib/pbio/drv/ioport/ioport.h b/lib/pbio/drv/ioport/ioport.h new file mode 100644 index 000000000..ea74a0177 --- /dev/null +++ b/lib/pbio/drv/ioport/ioport.h @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: MIT +// Copyright (c) 2021 The Pybricks Authors + +#ifndef _INTERNAL_PBDRV_IOPORT_H_ +#define _INTERNAL_PBDRV_IOPORT_H_ + +#include + +#if PBDRV_CONFIG_IOPORT + +#include "ioport_lpf2.h" + +/** + * Initializes the ioport driver. + */ +static inline void pbdrv_ioport_init(void) { + pbdrv_ioport_lpf2_init(); +} + +#else // PBDRV_CONFIG_IOPORT + +#define pbdrv_ioport_init() + +#endif // PBDRV_CONFIG_IOPORT + +#endif // _INTERNAL_PBDRV_IOPORT_H_ diff --git a/lib/pbio/drv/ioport/ioport_lpf2.c b/lib/pbio/drv/ioport/ioport_lpf2.c index 16a5dba02..b2030b280 100644 --- a/lib/pbio/drv/ioport/ioport_lpf2.c +++ b/lib/pbio/drv/ioport/ioport_lpf2.c @@ -135,6 +135,10 @@ PROCESS(pbdrv_ioport_lpf2_process, "I/O port"); static ioport_dev_t ioport_devs[PBDRV_CONFIG_IOPORT_LPF2_NUM_PORTS]; +void pbdrv_ioport_lpf2_init(void) { + process_start(&pbdrv_ioport_lpf2_process, NULL); +} + static void ioport_enable_uart(ioport_dev_t *ioport) { const pbdrv_ioport_lpf2_port_platform_data_t *pdata = ioport->pdata; diff --git a/lib/pbio/drv/ioport/ioport_lpf2.h b/lib/pbio/drv/ioport/ioport_lpf2.h index f9b5275c8..a95f16d27 100644 --- a/lib/pbio/drv/ioport/ioport_lpf2.h +++ b/lib/pbio/drv/ioport/ioport_lpf2.h @@ -1,12 +1,14 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2018-2020 The Pybricks Authors +// Copyright (c) 2018-2021 The Pybricks Authors #ifndef _INTERNAL_PBDRV_IOPORT_LPF2_H_ #define _INTERNAL_PBDRV_IOPORT_LPF2_H_ -#include - #include + +#if PBDRV_CONFIG_IOPORT_LPF2 + +#include #include // GPIOs associated with ID1 and ID2 pins @@ -40,4 +42,9 @@ typedef struct { // This is defined in platform/*/platform.c extern const pbdrv_ioport_lpf2_platform_data_t pbdrv_ioport_lpf2_platform_data; +void pbdrv_ioport_lpf2_init(void); +#else // PBDRV_CONFIG_IOPORT_LPF2 +#define pbdrv_ioport_lpf2_init() +#endif // PBDRV_CONFIG_IOPORT_LPF2 + #endif // _INTERNAL_PBDRV_IOPORT_LPF2_H_ diff --git a/lib/pbio/src/main.c b/lib/pbio/src/main.c index 19de8f9ad..c253d36c5 100644 --- a/lib/pbio/src/main.c +++ b/lib/pbio/src/main.c @@ -30,9 +30,6 @@ AUTOSTART_PROCESSES( #if PBDRV_CONFIG_ADC &pbdrv_adc_process, #endif -#if PBDRV_CONFIG_IOPORT_LPF2 - &pbdrv_ioport_lpf2_process, -#endif #if PBDRV_CONFIG_UART &pbdrv_uart_process, #endif diff --git a/lib/pbio/src/processes.h b/lib/pbio/src/processes.h index 5d55e2723..d41f08532 100644 --- a/lib/pbio/src/processes.h +++ b/lib/pbio/src/processes.h @@ -15,11 +15,6 @@ PROCESS_NAME(pbdrv_adc_process); #endif - -#if PBDRV_CONFIG_IOPORT_LPF2 -PROCESS_NAME(pbdrv_ioport_lpf2_process); -#endif - #if PBDRV_CONFIG_UART PROCESS_NAME(pbdrv_uart_process); #endif