Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rtl872x] Implement WiFi.selectAntenna #2651

Merged
merged 4 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hal/inc/radio_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
typedef enum radio_antenna_type {
RADIO_ANT_DEFAULT = 0, ///< Default antenna (platform-specific).
RADIO_ANT_INTERNAL = 1, ///< Internal antenna.
RADIO_ANT_EXTERNAL = 2 ///< External antenna.
RADIO_ANT_EXTERNAL = 2, ///< External antenna.
} radio_antenna_type;
27 changes: 24 additions & 3 deletions hal/network/ncp/wifi/wlan_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "wlan_hal.h"
#include "radio_common.h"

#include "network/ncp/wifi/ncp.h"
#include "network/ncp/wifi/wifi_network_manager.h"
Expand Down Expand Up @@ -289,14 +290,34 @@ void HAL_WLAN_notify_simple_config_done() {
}

int wlan_select_antenna(WLanSelectAntenna_TypeDef antenna) {
if (antenna != ANT_AUTO) {
return SYSTEM_ERROR_NOT_SUPPORTED;
radio_antenna_type new_antenna;

if (antenna == ANT_AUTO) {
new_antenna = RADIO_ANT_DEFAULT;
} else if (antenna == ANT_INTERNAL) {
new_antenna = RADIO_ANT_INTERNAL;
} else if (antenna == ANT_EXTERNAL) {
new_antenna = RADIO_ANT_EXTERNAL;
} else {
return SYSTEM_ERROR_NOT_SUPPORTED;
}

CHECK(selectRadioAntenna(new_antenna));
return 0;
}

WLanSelectAntenna_TypeDef wlan_get_antenna(void* reserved) {
return ANT_AUTO;
radio_antenna_type antenna;

if (getRadioAntenna(&antenna) || antenna == RADIO_ANT_DEFAULT) {
return ANT_AUTO;
} else if (antenna == RADIO_ANT_INTERNAL) {
return ANT_INTERNAL;
} else if (antenna == RADIO_ANT_EXTERNAL) {
return ANT_EXTERNAL;
} else {
return ANT_AUTO;
}
}

void wlan_connect_cancel(bool called_from_isr) {
Expand Down
18 changes: 16 additions & 2 deletions hal/src/rtl872x/radio_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ int selectAntenna(radio_antenna_type antenna) {
#if HAL_PLATFORM_RADIO_ANTENNA_INTERNAL
case RADIO_ANT_INTERNAL: {
CHECK(selectInternalAntenna());
LOG(TRACE, "Using internal BLE antenna");
LOG(TRACE, "Using internal antenna");
break;
}
#endif
#if HAL_PLATFORM_RADIO_ANTENNA_EXTERNAL
case RADIO_ANT_EXTERNAL: {
CHECK(selectExtenalAntenna());
LOG(TRACE, "Using external BLE antenna");
LOG(TRACE, "Using external antenna");
break;
}
#endif
Expand Down Expand Up @@ -122,4 +122,18 @@ int selectRadioAntenna(radio_antenna_type antenna) {
return SYSTEM_ERROR_NONE;
}

int getRadioAntenna(radio_antenna_type * antenna) {
if (!antenna) {
return SYSTEM_ERROR_INVALID_ARGUMENT;
}
uint8_t dctAntenna = 0xff;
CHECK(dct_read_app_data_copy(DCT_RADIO_ANTENNA_OFFSET, &dctAntenna, sizeof(dctAntenna)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do exactly the same thing as currently done in initRadioAntenna() and return default normally unless dct read value is exactly INTERNAL or EXTERNAL and replace that block with getRadioAntenna() so that we don't have duplicate logic.

if ((radio_antenna_type)dctAntenna <= RADIO_ANT_EXTERNAL) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we validate the DCT data or just return it if its present?

*antenna = (radio_antenna_type)dctAntenna;
return 0;
}

return SYSTEM_ERROR_INTERNAL;
}

} // namespace particle
8 changes: 8 additions & 0 deletions hal/src/rtl872x/radio_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ int enableRadioAntenna();
*/
int selectRadioAntenna(radio_antenna_type antenna);

/**
* Return the currently configured antenna type from DCT.
*
* @param antenna Currently configured Antenna type.
* @return 0 on success or a negative result code in case of an error.
*/
int getRadioAntenna(radio_antenna_type * antenna);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit/style: radio_antenna_type* antenna, same above


} // particle