@@ -39,7 +39,8 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
3939 bt_host_wake (bt_host_wake_name, PIN_INPUT, PullNone, 0 ),
4040 bt_device_wake (bt_device_wake_name, PIN_OUTPUT, PullNone, 1 ),
4141 host_wake_irq_event (host_wake_irq),
42- dev_wake_irq_event (dev_wake_irq)
42+ dev_wake_irq_event (dev_wake_irq),
43+ bt_power (CYBSP_BT_POWER, PIN_OUTPUT, PullNone, 0 )
4344{
4445 enabled_powersave = true ;
4546 bt_host_wake_active = false ;
@@ -52,10 +53,12 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
5253 bt_host_wake_name (NC),
5354 bt_device_wake_name (NC),
5455 bt_host_wake (bt_host_wake_name),
55- bt_device_wake (bt_device_wake_name)
56+ bt_device_wake (bt_device_wake_name),
57+ bt_power (CYBSP_BT_POWER, PIN_OUTPUT, PullNone, 0 )
5658{
5759 enabled_powersave = false ;
5860 bt_host_wake_active = false ;
61+
5962 sleep_manager_lock_deep_sleep (); // locking deep sleep because this option
6063 // does not include a host wake pin
6164 holding_deep_sleep_lock = true ;
@@ -119,13 +122,9 @@ static void on_controller_irq(void *callback_arg, cyhal_uart_event_t event)
119122
120123void CyH4TransportDriver::initialize ()
121124{
122- #if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
123- mbed::InterruptIn *host_wake_pin;
124- #endif
125-
126125 sleep_manager_lock_deep_sleep ();
127126
128- cyhal_gpio_write (CYBSP_BT_POWER, 0 ) ;
127+ bt_power = 0 ;
129128 rtos::ThisThread::sleep_for (1ms);
130129
131130 cy_rslt_t rslt = cyhal_uart_init (&uart, tx, rx, NULL , NULL );
@@ -138,7 +137,7 @@ void CyH4TransportDriver::initialize()
138137 cyhal_uart_register_callback (&uart, &on_controller_irq, &uart);
139138 cyhal_uart_enable_event (&uart, CYHAL_UART_IRQ_RX_NOT_EMPTY, CYHAL_ISR_PRIORITY_DEFAULT, true );
140139
141- cyhal_gpio_write (CYBSP_BT_POWER, 1 ) ;
140+ bt_power = 1 ;
142141
143142#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
144143 if (bt_host_wake_name != NC) {
@@ -176,11 +175,20 @@ void CyH4TransportDriver::terminate()
176175 NULL
177176 );
178177
178+ // DigitalInOut does not appear to have Destructor nor does it have a
179+ // free() func (though the protected gpio_t does) so must call directly
180+ // into cyhal
179181 if (CYBSP_BT_DEVICE_WAKE != NC) cyhal_gpio_free (CYBSP_BT_DEVICE_WAKE);
180182
181- if (CYBSP_BT_HOST_WAKE != NC) cyhal_gpio_write (CYBSP_BT_DEVICE_WAKE, false );
183+ if (bt_host_wake.is_connected ())
184+ {
185+ #if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
186+ delete host_wake_pin;
187+ #endif
188+ bt_host_wake = false ;
189+ }
182190
183- if (CYBSP_BT_POWER != NC) cyhal_gpio_write (CYBSP_BT_POWER, false ); // BT_POWER is an output, should not be freed only set inactive
191+ bt_power = 0 ; // BT_POWER is an output, should not be freed only set inactive
184192
185193 cyhal_uart_free (&uart);
186194}
0 commit comments