Skip to content

Commit

Permalink
drv/ioport/ioport_lpf2: move port power enable
Browse files Browse the repository at this point in the history
This moves the port VCC (pin 4) power management from platform.c to the
LPF2 I/O port driver. This way, the driver can manage shutting down the
I/O ports on power off.
  • Loading branch information
dlech committed Jan 7, 2021
1 parent 01f1e17 commit bd13455
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
19 changes: 18 additions & 1 deletion lib/pbio/drv/ioport/ioport_lpf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,20 @@ static PT_THREAD(poll_dcm(ioport_dev_t * ioport)) {
PROCESS_THREAD(pbdrv_ioport_lpf2_process, ev, data) {
static struct etimer timer;

PROCESS_EXITHANDLER({
// make sure all pins are set to input so they aren't supplying power
// to the I/O device.
for (int i = 0; i < PBDRV_CONFIG_IOPORT_LPF2_NUM_PORTS; i++) {
init_one(i);
}

// TODO: we need to ensure H-bridge power is off here to avoid potentially
// damaging custom I/O devices.

// Turn off power on pin 4 on all ports
pbdrv_gpio_out_low(&pbdrv_ioport_lpf2_platform_data.port_vcc);
});

PROCESS_BEGIN();

etimer_set(&timer, clock_from_msec(2));
Expand All @@ -452,7 +466,10 @@ PROCESS_THREAD(pbdrv_ioport_lpf2_process, ev, data) {
init_one(i);
}

while (true) {
// Turn on power on pin 4 on all ports
pbdrv_gpio_out_high(&pbdrv_ioport_lpf2_platform_data.port_vcc);

for (;;) {
PROCESS_WAIT_EVENT();

// If pbio_uartdev_process tells us the uart device was removed, reset
Expand Down
6 changes: 1 addition & 5 deletions lib/pbio/platform/city_hub/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,10 @@ void SystemInit(void) {
| RCC_APB1ENR_USART4EN;
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN | RCC_APB2ENR_TIM16EN | RCC_APB2ENR_TIM15EN;

// Keep main power on
// Keep main power on (PB11)
GPIOB->MODER = (GPIOB->MODER & ~GPIO_MODER_MODER11_Msk) | (1 << GPIO_MODER_MODER11_Pos);
GPIOB->BSRR = GPIO_BSRR_BS_11;

// Turn on port VCC
GPIOB->MODER = (GPIOB->MODER & ~GPIO_MODER_MODER2_Msk) | (1 << GPIO_MODER_MODER2_Pos);
GPIOB->BSRR = GPIO_BSRR_BS_2;

// Unused pins

// PA5 output, low
Expand Down
6 changes: 1 addition & 5 deletions lib/pbio/platform/move_hub/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,10 @@ void SystemInit(void) {
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN | RCC_APB2ENR_TIM1EN
| RCC_APB2ENR_TIM15EN | RCC_APB2ENR_TIM16EN;

// Keep BOOST alive
// Keep main power on (PB11)
GPIOB->BSRR = GPIO_BSRR_BS_11;
GPIOB->MODER = (GPIOB->MODER & ~GPIO_MODER_MODER11_Msk) | (1 << GPIO_MODER_MODER11_Pos);

// PB2 controls I/O port VCC
GPIOB->BSRR = GPIO_BSRR_BS_2;
GPIOB->MODER = (GPIOB->MODER & ~GPIO_MODER_MODER2_Msk) | (1 << GPIO_MODER_MODER2_Pos);

// Unused pins

// PF0 output, high
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/prime_hub/dual_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static bool check_for_long_press(void) {
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();

// Keep main power on (PA13 == POWER_EN)
// Keep main power on (PA13)
GPIOA->BSRR = GPIO_BSRR_BS_13;
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER13_Msk) | (1 << GPIO_MODER_MODER13_Pos);

Expand Down
6 changes: 1 addition & 5 deletions lib/pbio/platform/prime_hub/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,7 @@ void SystemInit(void) {
RCC_APB2ENR_UART10EN | RCC_APB2ENR_ADC1EN | RCC_APB2ENR_SPI1EN | RCC_APB2ENR_SYSCFGEN;
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;

// Keep main power on (PA13 == POWER_EN)
// Keep main power on (PA13)
GPIOA->BSRR = GPIO_BSRR_BS_13;
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER13_Msk) | (1 << GPIO_MODER_MODER13_Pos);

// Turn VCC_PORT on (PA14 == PORTCE)
GPIOA->BSRR = GPIO_BSRR_BS_14;
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER14_Msk) | (1 << GPIO_MODER_MODER14_Pos);
}
4 changes: 0 additions & 4 deletions lib/pbio/platform/technic_hub/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,4 @@ void SystemInit(void) {
gpio_init.Mode = GPIO_MODE_OUTPUT_PP;
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_Init(GPIOC, &gpio_init);

// Turn VCC_PORT on (PB12)
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
HAL_GPIO_Init(GPIOB, &gpio_init);
}

0 comments on commit bd13455

Please sign in to comment.