Skip to content

Commit bd13455

Browse files
committed
drv/ioport/ioport_lpf2: move port power enable
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.
1 parent 01f1e17 commit bd13455

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

lib/pbio/drv/ioport/ioport_lpf2.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,20 @@ static PT_THREAD(poll_dcm(ioport_dev_t * ioport)) {
444444
PROCESS_THREAD(pbdrv_ioport_lpf2_process, ev, data) {
445445
static struct etimer timer;
446446

447+
PROCESS_EXITHANDLER({
448+
// make sure all pins are set to input so they aren't supplying power
449+
// to the I/O device.
450+
for (int i = 0; i < PBDRV_CONFIG_IOPORT_LPF2_NUM_PORTS; i++) {
451+
init_one(i);
452+
}
453+
454+
// TODO: we need to ensure H-bridge power is off here to avoid potentially
455+
// damaging custom I/O devices.
456+
457+
// Turn off power on pin 4 on all ports
458+
pbdrv_gpio_out_low(&pbdrv_ioport_lpf2_platform_data.port_vcc);
459+
});
460+
447461
PROCESS_BEGIN();
448462

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

455-
while (true) {
469+
// Turn on power on pin 4 on all ports
470+
pbdrv_gpio_out_high(&pbdrv_ioport_lpf2_platform_data.port_vcc);
471+
472+
for (;;) {
456473
PROCESS_WAIT_EVENT();
457474

458475
// If pbio_uartdev_process tells us the uart device was removed, reset

lib/pbio/platform/city_hub/platform.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,10 @@ void SystemInit(void) {
232232
| RCC_APB1ENR_USART4EN;
233233
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN | RCC_APB2ENR_TIM16EN | RCC_APB2ENR_TIM15EN;
234234

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

239-
// Turn on port VCC
240-
GPIOB->MODER = (GPIOB->MODER & ~GPIO_MODER_MODER2_Msk) | (1 << GPIO_MODER_MODER2_Pos);
241-
GPIOB->BSRR = GPIO_BSRR_BS_2;
242-
243239
// Unused pins
244240

245241
// PA5 output, low

lib/pbio/platform/move_hub/platform.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,10 @@ void SystemInit(void) {
284284
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN | RCC_APB2ENR_TIM1EN
285285
| RCC_APB2ENR_TIM15EN | RCC_APB2ENR_TIM16EN;
286286

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

291-
// PB2 controls I/O port VCC
292-
GPIOB->BSRR = GPIO_BSRR_BS_2;
293-
GPIOB->MODER = (GPIOB->MODER & ~GPIO_MODER_MODER2_Msk) | (1 << GPIO_MODER_MODER2_Pos);
294-
295291
// Unused pins
296292

297293
// PF0 output, high

lib/pbio/platform/prime_hub/dual_boot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static bool check_for_long_press(void) {
5151
__HAL_RCC_GPIOB_CLK_ENABLE();
5252
__HAL_RCC_GPIOC_CLK_ENABLE();
5353

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

lib/pbio/platform/prime_hub/platform.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,7 @@ void SystemInit(void) {
734734
RCC_APB2ENR_UART10EN | RCC_APB2ENR_ADC1EN | RCC_APB2ENR_SPI1EN | RCC_APB2ENR_SYSCFGEN;
735735
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
736736

737-
// Keep main power on (PA13 == POWER_EN)
737+
// Keep main power on (PA13)
738738
GPIOA->BSRR = GPIO_BSRR_BS_13;
739739
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER13_Msk) | (1 << GPIO_MODER_MODER13_Pos);
740-
741-
// Turn VCC_PORT on (PA14 == PORTCE)
742-
GPIOA->BSRR = GPIO_BSRR_BS_14;
743-
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODER14_Msk) | (1 << GPIO_MODER_MODER14_Pos);
744740
}

lib/pbio/platform/technic_hub/platform.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,4 @@ void SystemInit(void) {
506506
gpio_init.Mode = GPIO_MODE_OUTPUT_PP;
507507
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_SET);
508508
HAL_GPIO_Init(GPIOC, &gpio_init);
509-
510-
// Turn VCC_PORT on (PB12)
511-
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
512-
HAL_GPIO_Init(GPIOB, &gpio_init);
513509
}

0 commit comments

Comments
 (0)