Skip to content

Commit 0e6ede8

Browse files
dustin-crossmankeithmwheeler
authored andcommitted
Convert cyhal_gpio calls to mbed equivalent.
1 parent 389ed27 commit 0e6ede8

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

connectivity/drivers/ble/FEATURE_BLE/COMPONENT_CYW43XXX/CyH4TransportDriver.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

120123
void 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
}

connectivity/drivers/ble/FEATURE_BLE/COMPONENT_CYW43XXX/CyH4TransportDriver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <stdint.h>
2424
#include "ble/driver/CordioHCITransportDriver.h"
2525
#include "drivers/DigitalInOut.h"
26+
#include "drivers/InterruptIn.h"
2627
#include "cyhal_uart.h"
2728

2829
namespace ble {
@@ -99,8 +100,13 @@ class CyH4TransportDriver : public CordioHCITransportDriver {
99100

100101
mbed::DigitalInOut bt_host_wake;
101102
mbed::DigitalInOut bt_device_wake;
103+
mbed::DigitalInOut bt_power;
102104
bool bt_host_wake_active;
103105

106+
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
107+
mbed::InterruptIn *host_wake_pin;
108+
#endif
109+
104110
bool enabled_powersave;
105111
uint8_t host_wake_irq_event;
106112
uint8_t dev_wake_irq_event;

0 commit comments

Comments
 (0)