From 219b3cd82a42c8904f3607d9b661b152901256c5 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 28 Jun 2021 23:17:53 -0500 Subject: [PATCH] drv: drop deinit Since 95883860, driver deinit is no longer needed (it was a hack to make things look like they were powered off before doing it properly in pbsys). --- lib/pbio/drv/core.c | 26 ----------------------- lib/pbio/drv/core.h | 27 +----------------------- lib/pbio/drv/pwm/pwm.h | 2 -- lib/pbio/drv/pwm/pwm_core.c | 11 ---------- lib/pbio/drv/pwm/pwm_stm32_tim.c | 22 -------------------- lib/pbio/drv/pwm/pwm_stm32_tim.h | 2 -- lib/pbio/drv/pwm/pwm_test.h | 2 -- lib/pbio/drv/pwm/pwm_tlc5955_stm32.c | 31 +--------------------------- lib/pbio/drv/pwm/pwm_tlc5955_stm32.h | 2 -- lib/pbio/include/pbdrv/core.h | 1 - lib/pbio/test/drv/pwm.c | 4 ---- 11 files changed, 2 insertions(+), 128 deletions(-) diff --git a/lib/pbio/drv/core.c b/lib/pbio/drv/core.c index db8694a14..26cf60094 100644 --- a/lib/pbio/drv/core.c +++ b/lib/pbio/drv/core.c @@ -15,7 +15,6 @@ #include "watchdog/watchdog.h" uint32_t pbdrv_init_busy_count; -uint32_t pbdrv_deinit_busy_count; /** Initializes all enabled drivers. */ void pbdrv_init(void) { @@ -35,28 +34,3 @@ void pbdrv_init(void) { process_run(); } } - -/** - * Deinitializes drivers. - * - * This is intended to handle things like turning off lights on power down, so - * not all drivers need to have a deinit. This is needed since power doesn't - * actually turn off until the button is released and the USB cable is disconnected - * on Powered Up hubs, so we need to make it look like the power is off already - * so that users will know when to release the button. - * - * Some drivers still need to be useable after this, like reset and battery - * charger drivers. - */ -void pbdrv_deinit(void) { - // REVISIT: It probably makes more sense to have a pbio_deinit() that stops - // things at a higher level instead of pbdrv_deinit(). But that isn't - // possible right now, e.g. since pbio_light* isn't aware of the async nature - // of the underlying drivers. - - // TODO: need to power down I/O ports here - pbdrv_pwm_deinit(); - while (pbdrv_deinit_busy()) { - process_run(); - } -} diff --git a/lib/pbio/drv/core.h b/lib/pbio/drv/core.h index 1c4bc24d7..09d567137 100644 --- a/lib/pbio/drv/core.h +++ b/lib/pbio/drv/core.h @@ -32,32 +32,7 @@ */ #define pbdrv_init_busy() (pbdrv_init_busy_count) -/** - * Increases driver deinit reference count. - * - * Driver that have async deinit must call this when deinitialization is started - * to indicate that deinit is still busy. - */ -#define pbdrv_deinit_busy_up() (pbdrv_deinit_busy_count++) - -/** - * Decreases driver deinit reference count. - * - * Driver that have async deinit must call this when deinitialization is finished - * to indicate that deinit is no longer busy. - */ -#define pbdrv_deinit_busy_down() (pbdrv_deinit_busy_count--) - -/** - * Tests if driver deinitialization is still busy. - * - * After calling pbdrv_deinit(), the Contiki event loop should run until this - * returns true to wait for all drivers to be deinitalized. - */ -#define pbdrv_deinit_busy() (pbdrv_deinit_busy_count) - -// Don't use these directly, use macros above instead. +// Don't use this directly, use macros above instead. extern uint32_t pbdrv_init_busy_count; -extern uint32_t pbdrv_deinit_busy_count; #endif // _INTERNAL_PBDRV_CORE_H_ diff --git a/lib/pbio/drv/pwm/pwm.h b/lib/pbio/drv/pwm/pwm.h index a704deaf0..a121fd21e 100644 --- a/lib/pbio/drv/pwm/pwm.h +++ b/lib/pbio/drv/pwm/pwm.h @@ -32,12 +32,10 @@ struct _pbdrv_pwm_dev_t { #if PBDRV_CONFIG_PWM void pbdrv_pwm_init(void); -void pbdrv_pwm_deinit(void); #else // PBDRV_CONFIG_PWM #define pbdrv_pwm_init() -#define pbdrv_pwm_deinit() #endif // PBDRV_CONFIG_PWM diff --git a/lib/pbio/drv/pwm/pwm_core.c b/lib/pbio/drv/pwm/pwm_core.c index 6b415a1bb..b523b9430 100644 --- a/lib/pbio/drv/pwm/pwm_core.c +++ b/lib/pbio/drv/pwm/pwm_core.c @@ -28,17 +28,6 @@ void pbdrv_pwm_init(void) { pbdrv_pwm_tlc5955_stm32_init(pbdrv_pwm_dev); } -/** - * Deinitializes all PWM drivers. - * - * This should turn off the output of each PWM. - */ -void pbdrv_pwm_deinit(void) { - pbdrv_pwm_stm32_tim_deinit(pbdrv_pwm_dev); - pbdrv_pwm_test_deinit(pbdrv_pwm_dev); - pbdrv_pwm_tlc5955_stm32_deinit(pbdrv_pwm_dev); -} - /** * Gets the PWM device with the given ID. * @param [in] id The ID of the PWM device. diff --git a/lib/pbio/drv/pwm/pwm_stm32_tim.c b/lib/pbio/drv/pwm/pwm_stm32_tim.c index ede2da986..4e290f2ed 100644 --- a/lib/pbio/drv/pwm/pwm_stm32_tim.c +++ b/lib/pbio/drv/pwm/pwm_stm32_tim.c @@ -120,26 +120,4 @@ void pbdrv_pwm_stm32_tim_init(pbdrv_pwm_dev_t *devs) { } } -void pbdrv_pwm_stm32_tim_deinit(pbdrv_pwm_dev_t *devs) { - for (int i = 0; i < PBDRV_CONFIG_PWM_STM32_TIM_NUM_DEV; i++) { - const pbdrv_pwm_stm32_tim_platform_data_t *pdata = &pbdrv_pwm_stm32_tim_platform_data[i]; - TIM_TypeDef *TIMx = pdata->TIMx; - - #ifdef STM32F413xx - // HACK: Prevent LED driver GSCLK from stopping on Prime hub. - // Otherwise LEDs may get stuck on. Ideally, we could implement some - // sort of reference counting on drivers so that they shut down when - // they are no longer used instead. - if (TIMx != TIM12) - #endif - { - TIMx->CR1 &= ~TIM_CR1_CEN; - TIMx->EGR &= ~TIM_EGR_UG; - // Disable outputs (the value 0 assumes that all channels are PWMs - // or unused - which should be a safe assumption) - TIMx->CCER = 0; - } - } -} - #endif // PBDRV_CONFIG_PWM_STM32_TIM diff --git a/lib/pbio/drv/pwm/pwm_stm32_tim.h b/lib/pbio/drv/pwm/pwm_stm32_tim.h index ba42f08dc..80da78fac 100644 --- a/lib/pbio/drv/pwm/pwm_stm32_tim.h +++ b/lib/pbio/drv/pwm/pwm_stm32_tim.h @@ -55,12 +55,10 @@ extern const pbdrv_pwm_stm32_tim_platform_data_t pbdrv_pwm_stm32_tim_platform_data[PBDRV_CONFIG_PWM_STM32_TIM_NUM_DEV]; void pbdrv_pwm_stm32_tim_init(pbdrv_pwm_dev_t *dev); -void pbdrv_pwm_stm32_tim_deinit(pbdrv_pwm_dev_t *dev); #else // PBDRV_CONFIG_PWM_STM32_TIM #define pbdrv_pwm_stm32_tim_init(dev) -#define pbdrv_pwm_stm32_tim_deinit(dev) #endif // PBDRV_CONFIG_PWM_STM32_TIM diff --git a/lib/pbio/drv/pwm/pwm_test.h b/lib/pbio/drv/pwm/pwm_test.h index f1d383378..b05e17266 100644 --- a/lib/pbio/drv/pwm/pwm_test.h +++ b/lib/pbio/drv/pwm/pwm_test.h @@ -13,12 +13,10 @@ #include void pbdrv_pwm_test_init(pbdrv_pwm_dev_t *devs); -void pbdrv_pwm_test_deinit(pbdrv_pwm_dev_t *devs); #else // PBDRV_CONFIG_PWM_TEST #define pbdrv_pwm_test_init(dev) -#define pbdrv_pwm_test_deinit(dev) #endif // PBDRV_CONFIG_PWM_TEST diff --git a/lib/pbio/drv/pwm/pwm_tlc5955_stm32.c b/lib/pbio/drv/pwm/pwm_tlc5955_stm32.c index 1e1b80045..f524efba3 100644 --- a/lib/pbio/drv/pwm/pwm_tlc5955_stm32.c +++ b/lib/pbio/drv/pwm/pwm_tlc5955_stm32.c @@ -119,12 +119,6 @@ enum { /* bits 7-0 */ [96] = (((dc) << 7) | ((dc) >> 0)) & 0xff, \ } -typedef enum { - DEINIT_NOT_STARTED, - DEINIT_STARTED, - DEINIT_DONE, -} deinit_t; - typedef struct { /** HAL SPI data */ SPI_HandleTypeDef hspi; @@ -140,8 +134,6 @@ typedef struct { uint8_t *grayscale_latch; /** grayscale value has changed, update needed */ bool changed; - /** syncronization state for deinit */ - deinit_t deinit; } pbdrv_pwm_tlc5955_stm32_priv_t; PROCESS(pwm_tlc5955_stm32, "pwm_tlc5955_stm32"); @@ -254,18 +246,6 @@ void pbdrv_pwm_tlc5955_stm32_init(pbdrv_pwm_dev_t *devs) { process_start(&pwm_tlc5955_stm32, NULL); } -void pbdrv_pwm_tlc5955_stm32_deinit(pbdrv_pwm_dev_t *devs) { - - for (int i = 0; i < PBDRV_CONFIG_PWM_TLC5955_STM32_NUM_DEV; i++) { - pbdrv_pwm_tlc5955_stm32_priv_t *priv = &dev_priv[i]; - for (int ch = 0; ch < TLC5955_NUM_CHANNEL; ch++) { - pbdrv_pwm_tlc5955_stm32_set_duty(priv->pwm, ch, 0); - } - priv->deinit = DEINIT_STARTED; - pbdrv_deinit_busy_up(); - } -} - // toggles LAT signal on and off to latch data in shift register static void pbdrv_pwm_tlc5955_toggle_latch(pbdrv_pwm_tlc5955_stm32_priv_t *priv) { const pbdrv_pwm_tlc5955_stm32_platform_data_t *pdata = priv->pwm->pdata; @@ -295,13 +275,6 @@ static PT_THREAD(pbdrv_pwm_tlc5955_stm32_handle_event(pbdrv_pwm_tlc5955_stm32_pr priv->changed = false; PT_WAIT_UNTIL(&priv->pt, priv->hspi.State == HAL_SPI_STATE_READY); pbdrv_pwm_tlc5955_toggle_latch(priv); - if (priv->deinit == DEINIT_STARTED && !priv->changed) { - // if deinit has been requested and there are no more pending changes - // then we can say deint is done - priv->deinit = DEINIT_DONE; - pbdrv_deinit_busy_down(); - break; - } } PT_END(&priv->pt); @@ -347,9 +320,7 @@ PROCESS_THREAD(pwm_tlc5955_stm32, ev, data) { for (;;) { for (int i = 0; i < PBDRV_CONFIG_PWM_TLC5955_STM32_NUM_DEV; i++) { pbdrv_pwm_tlc5955_stm32_priv_t *priv = &dev_priv[i]; - if (priv->deinit != DEINIT_DONE) { - pbdrv_pwm_tlc5955_stm32_handle_event(priv, ev); - } + pbdrv_pwm_tlc5955_stm32_handle_event(priv, ev); } PROCESS_WAIT_EVENT(); } diff --git a/lib/pbio/drv/pwm/pwm_tlc5955_stm32.h b/lib/pbio/drv/pwm/pwm_tlc5955_stm32.h index b9650e698..28a48ad71 100644 --- a/lib/pbio/drv/pwm/pwm_tlc5955_stm32.h +++ b/lib/pbio/drv/pwm/pwm_tlc5955_stm32.h @@ -47,7 +47,6 @@ extern const pbdrv_pwm_tlc5955_stm32_platform_data_t pbdrv_pwm_tlc5955_stm32_platform_data[PBDRV_CONFIG_PWM_TLC5955_STM32_NUM_DEV]; void pbdrv_pwm_tlc5955_stm32_init(pbdrv_pwm_dev_t *dev); -void pbdrv_pwm_tlc5955_stm32_deinit(pbdrv_pwm_dev_t *dev); void pbdrv_pwm_tlc5955_stm32_rx_dma_irq(uint8_t index); void pbdrv_pwm_tlc5955_stm32_tx_dma_irq(uint8_t index); @@ -56,7 +55,6 @@ void pbdrv_pwm_tlc5955_stm32_spi_irq(uint8_t index); #else // PBDRV_CONFIG_PWM_TLC5955_STM32 #define pbdrv_pwm_tlc5955_stm32_init(dev) -#define pbdrv_pwm_tlc5955_stm32_deinit(dev) #endif // PBDRV_CONFIG_PWM_TLC5955_STM32 diff --git a/lib/pbio/include/pbdrv/core.h b/lib/pbio/include/pbdrv/core.h index c14b959ab..db07b1dcb 100644 --- a/lib/pbio/include/pbdrv/core.h +++ b/lib/pbio/include/pbdrv/core.h @@ -13,7 +13,6 @@ #define _PBDRV_CORE_H_ void pbdrv_init(void); -void pbdrv_deinit(void); #endif // _PBDRV_CORE_H_ diff --git a/lib/pbio/test/drv/pwm.c b/lib/pbio/test/drv/pwm.c index c3db2178c..3e896b80b 100644 --- a/lib/pbio/test/drv/pwm.c +++ b/lib/pbio/test/drv/pwm.c @@ -35,10 +35,6 @@ void pbdrv_pwm_test_init(pbdrv_pwm_dev_t *devs) { devs[0].priv = &test_private_data; } -void pbdrv_pwm_test_deinit(pbdrv_pwm_dev_t *devs) { - devs[0].funcs = NULL; -} - static void test_pwm_get(void *env) { pbdrv_pwm_dev_t *dev;