@@ -39,7 +39,8 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
39
39
bt_host_wake (bt_host_wake_name, PIN_INPUT, PullNone, 0 ),
40
40
bt_device_wake (bt_device_wake_name, PIN_OUTPUT, PullNone, 1 ),
41
41
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 )
43
44
{
44
45
enabled_powersave = true ;
45
46
bt_host_wake_active = false ;
@@ -52,10 +53,12 @@ CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, Pi
52
53
bt_host_wake_name (NC),
53
54
bt_device_wake_name (NC),
54
55
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 )
56
58
{
57
59
enabled_powersave = false ;
58
60
bt_host_wake_active = false ;
61
+
59
62
sleep_manager_lock_deep_sleep (); // locking deep sleep because this option
60
63
// does not include a host wake pin
61
64
holding_deep_sleep_lock = true ;
@@ -119,13 +122,9 @@ static void on_controller_irq(void *callback_arg, cyhal_uart_event_t event)
119
122
120
123
void CyH4TransportDriver::initialize ()
121
124
{
122
- #if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
123
- mbed::InterruptIn *host_wake_pin;
124
- #endif
125
-
126
125
sleep_manager_lock_deep_sleep ();
127
126
128
- cyhal_gpio_write (CYBSP_BT_POWER, 0 ) ;
127
+ bt_power = 0 ;
129
128
rtos::ThisThread::sleep_for (1ms);
130
129
131
130
cy_rslt_t rslt = cyhal_uart_init (&uart, tx, rx, NULL , NULL );
@@ -138,7 +137,7 @@ void CyH4TransportDriver::initialize()
138
137
cyhal_uart_register_callback (&uart, &on_controller_irq, &uart);
139
138
cyhal_uart_enable_event (&uart, CYHAL_UART_IRQ_RX_NOT_EMPTY, CYHAL_ISR_PRIORITY_DEFAULT, true );
140
139
141
- cyhal_gpio_write (CYBSP_BT_POWER, 1 ) ;
140
+ bt_power = 1 ;
142
141
143
142
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
144
143
if (bt_host_wake_name != NC) {
@@ -176,11 +175,20 @@ void CyH4TransportDriver::terminate()
176
175
NULL
177
176
);
178
177
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
179
181
if (CYBSP_BT_DEVICE_WAKE != NC) cyhal_gpio_free (CYBSP_BT_DEVICE_WAKE);
180
182
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
+ }
182
190
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
184
192
185
193
cyhal_uart_free (&uart);
186
194
}
0 commit comments