Skip to content

Commit

Permalink
drv: drop deinit
Browse files Browse the repository at this point in the history
Since 9588386, 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).
  • Loading branch information
dlech committed Jun 29, 2021
1 parent 9588386 commit 219b3cd
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 128 deletions.
26 changes: 0 additions & 26 deletions lib/pbio/drv/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
}
27 changes: 1 addition & 26 deletions lib/pbio/drv/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 0 additions & 2 deletions lib/pbio/drv/pwm/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 0 additions & 11 deletions lib/pbio/drv/pwm/pwm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 0 additions & 22 deletions lib/pbio/drv/pwm/pwm_stm32_tim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions lib/pbio/drv/pwm/pwm_stm32_tim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions lib/pbio/drv/pwm/pwm_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
#include <pbdrv/pwm.h>

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

Expand Down
31 changes: 1 addition & 30 deletions lib/pbio/drv/pwm/pwm_tlc5955_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 0 additions & 2 deletions lib/pbio/drv/pwm/pwm_tlc5955_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion lib/pbio/include/pbdrv/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define _PBDRV_CORE_H_

void pbdrv_init(void);
void pbdrv_deinit(void);

#endif // _PBDRV_CORE_H_

Expand Down
4 changes: 0 additions & 4 deletions lib/pbio/test/drv/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 219b3cd

Please sign in to comment.