@@ -33,30 +33,31 @@ using namespace std::chrono_literals;
33
33
34
34
CyH4TransportDriver::CyH4TransportDriver (PinName tx, PinName rx, PinName cts, PinName rts, int baud, PinName bt_host_wake_name, PinName bt_device_wake_name, uint8_t host_wake_irq, uint8_t dev_wake_irq) :
35
35
cts (cts), rts(rts),
36
+ tx (tx), rx(rx),
36
37
bt_host_wake_name (bt_host_wake_name),
37
38
bt_device_wake_name (bt_device_wake_name),
38
39
bt_host_wake (bt_host_wake_name, PIN_INPUT, PullNone, 0 ),
39
40
bt_device_wake (bt_device_wake_name, PIN_OUTPUT, PullNone, 1 ),
40
41
host_wake_irq_event (host_wake_irq),
41
42
dev_wake_irq_event (dev_wake_irq)
42
43
{
43
- cyhal_uart_init (&uart, tx, rx, NULL , NULL );
44
44
enabled_powersave = true ;
45
45
bt_host_wake_active = false ;
46
46
}
47
47
48
48
CyH4TransportDriver::CyH4TransportDriver (PinName tx, PinName rx, PinName cts, PinName rts, int baud) :
49
49
cts (cts),
50
50
rts (rts),
51
+ tx (tx), rx(rx),
51
52
bt_host_wake_name (NC),
52
53
bt_device_wake_name (NC),
53
54
bt_host_wake (bt_host_wake_name),
54
55
bt_device_wake (bt_device_wake_name)
55
56
{
56
- cyhal_uart_init (&uart, tx, rx, NULL , NULL );
57
57
enabled_powersave = false ;
58
58
bt_host_wake_active = false ;
59
- sleep_manager_lock_deep_sleep ();
59
+ sleep_manager_lock_deep_sleep (); // locking deep sleep because this option
60
+ // does not include a host wake pin
60
61
holding_deep_sleep_lock = true ;
61
62
}
62
63
@@ -124,12 +125,21 @@ void CyH4TransportDriver::initialize()
124
125
125
126
sleep_manager_lock_deep_sleep ();
126
127
128
+ cyhal_gpio_write (CYBSP_BT_POWER, 0 );
129
+ rtos::ThisThread::sleep_for (20ms);
130
+
131
+ cyhal_uart_init (&uart, tx, rx, NULL , NULL );
132
+
127
133
const cyhal_uart_cfg_t uart_cfg = { .data_bits = 8 , .stop_bits = 1 , .parity = CYHAL_UART_PARITY_NONE, .rx_buffer = NULL , .rx_buffer_size = 0 };
128
134
cyhal_uart_configure (&uart, &uart_cfg);
129
135
cyhal_uart_set_flow_control (&uart, cts, rts);
136
+ cyhal_uart_clear (&uart);
130
137
cyhal_uart_register_callback (&uart, &on_controller_irq, &uart);
131
138
cyhal_uart_enable_event (&uart, CYHAL_UART_IRQ_RX_NOT_EMPTY, CYHAL_ISR_PRIORITY_DEFAULT, true );
132
139
140
+ cyhal_gpio_write (CYBSP_BT_POWER, 1 );
141
+ rtos::ThisThread::sleep_for (10ms);
142
+
133
143
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
134
144
if (bt_host_wake_name != NC) {
135
145
// Register IRQ for Host WAKE
@@ -149,26 +159,34 @@ void CyH4TransportDriver::initialize()
149
159
rtos::ThisThread::sleep_for (500ms);
150
160
}
151
161
152
- void CyH4TransportDriver::terminate ()
153
- {
162
+ void CyH4TransportDriver::terminate ()
163
+ {
154
164
cyhal_uart_event_t enable_irq_event = (cyhal_uart_event_t )(CYHAL_UART_IRQ_RX_DONE
155
165
| CYHAL_UART_IRQ_TX_DONE
156
166
| CYHAL_UART_IRQ_RX_NOT_EMPTY
157
- );
167
+ );
158
168
159
169
cyhal_uart_enable_event (&uart,
160
- enable_irq_event,
161
- CYHAL_ISR_PRIORITY_DEFAULT,
162
- false
163
- );
170
+ enable_irq_event,
171
+ CYHAL_ISR_PRIORITY_DEFAULT,
172
+ false
173
+ );
174
+ cyhal_uart_register_callback (&uart,
175
+ NULL ,
176
+ NULL
177
+ );
178
+
179
+ if (CYBSP_BT_DEVICE_WAKE != NC) cyhal_gpio_free (CYBSP_BT_DEVICE_WAKE);
164
180
165
- cyhal_uart_register_callback (&uart, NULL , NULL );
166
- cyhal_uart_free (&uart);
167
181
168
- cyhal_gpio_free (CYBSP_BT_DEVICE_WAKE);
169
- cyhal_gpio_free (CYBSP_BT_HOST_WAKE);
170
- cyhal_gpio_write (CYBSP_BT_POWER, false );
171
- cyhal_gpio_free (CYBSP_BT_POWER);
182
+ if (CYBSP_BT_HOST_WAKE != NC) cyhal_gpio_write (CYBSP_BT_DEVICE_WAKE, false );
183
+
184
+ if (CYBSP_BT_POWER != NC)
185
+ {
186
+ cyhal_gpio_write (CYBSP_BT_POWER, false );
187
+ }
188
+
189
+ cyhal_uart_free (&uart);
172
190
}
173
191
174
192
uint16_t CyH4TransportDriver::write (uint8_t type, uint16_t len, uint8_t *pData)
0 commit comments