Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
60 changes: 60 additions & 0 deletions bee/drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,66 @@ function(add_soc_series_subdir ic_name)
endif()
endfunction()

# Add either a blob library or a stub source for a driver.
#
# Behavior:
# - If CONFIG_BUILD_ONLY_NO_BLOBS=y, always use the stub source.
# - Otherwise, use the blob library when present.
# - If the blob library is absent, fall back to the stub source.
# - If the same blob library is requested multiple times, link it only once.
#
# Usage:
# add_blob_or_stub(
# ${ZEPHYR_CURRENT_LIBRARY}
# adc
# <blob library path>
# <stub source path>
# )
function(add_blob_or_stub TARGET NAME BLOB_LIB_PATH STUB_FILE)
string(TOUPPER "${NAME}" NAME_UPPER)

set(use_stubs FALSE)

if(CONFIG_BUILD_ONLY_NO_BLOBS)
message(STATUS "CONFIG_BUILD_ONLY_NO_BLOBS=y, forcing ${NAME_UPPER} stubs")
set(use_stubs TRUE)
elseif(EXISTS "${BLOB_LIB_PATH}")
get_property(linked_blobs GLOBAL PROPERTY REALTEK_BLOB_LIBS_LINKED)
if(NOT linked_blobs)
set(linked_blobs "")
endif()

list(FIND linked_blobs "${BLOB_LIB_PATH}" blob_index)
if(blob_index EQUAL -1)
message(STATUS "Using ${NAME_UPPER} blob library: ${BLOB_LIB_PATH}")
target_link_libraries(${TARGET} PUBLIC ${BLOB_LIB_PATH})
set_property(GLOBAL APPEND PROPERTY REALTEK_BLOB_LIBS_LINKED "${BLOB_LIB_PATH}")
else()
message(STATUS
"${NAME_UPPER} blob library already linked, skipping duplicate: "
"${BLOB_LIB_PATH}"
)
endif()
else()
message(STATUS
"${NAME_UPPER} blob library not found: ${BLOB_LIB_PATH}\n"
"Falling back to ${NAME_UPPER} stubs"
)
set(use_stubs TRUE)
endif()

if(use_stubs)
if(EXISTS "${STUB_FILE}")
message(STATUS "Using ${NAME_UPPER} stub source: ${STUB_FILE}")
zephyr_library_sources(${STUB_FILE})
else()
message(FATAL_ERROR
"${NAME_UPPER} stub source not found: ${STUB_FILE}"
)
endif()
endif()
endfunction()

add_subdirectory(adc)
add_subdirectory_ifdef(CONFIG_REALTEK_BEE_BT bluetooth)
add_subdirectory(can)
Expand Down
19 changes: 19 additions & 0 deletions bee/drivers/adc/src/device/rtl8752h/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2026, Realtek Semiconductor Corporation
# SPDX-License-Identifier: Apache-2.0

file(GLOB ADC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
zephyr_library_sources(${ADC_SOURCES})
zephyr_include_directories(.)

set(STUB_DIR ${ZEPHYR_HAL_REALTEK_MODULE_DIR}/bee/drivers/stubs)
set(ADC_STUB_FILE ${STUB_DIR}/rtl8752h/adc_stubs.c)
set(ADC_LIB_PATH
${ZEPHYR_HAL_REALTEK_MODULE_DIR}/zephyr/blobs/bee/drivers/rtl8752h/adc/librtl8752h_adc.a
)

add_blob_or_stub(
${ZEPHYR_CURRENT_LIBRARY}
adc
"${ADC_LIB_PATH}"
"${ADC_STUB_FILE}"
)
19 changes: 19 additions & 0 deletions bee/drivers/adc/src/device/rtl87x2g/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2026, Realtek Semiconductor Corporation
# SPDX-License-Identifier: Apache-2.0

file(GLOB ADC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
zephyr_library_sources(${ADC_SOURCES})
zephyr_include_directories(.)

set(STUB_DIR ${ZEPHYR_HAL_REALTEK_MODULE_DIR}/bee/drivers/stubs)
set(ADC_STUB_FILE ${STUB_DIR}/rtl87x2g/adc_stubs.c)
set(ADC_LIB_PATH
${ZEPHYR_HAL_REALTEK_MODULE_DIR}/zephyr/blobs/bee/drivers/rtl87x2g/adc/librtl87x2g_adc.a
)

add_blob_or_stub(
${ZEPHYR_CURRENT_LIBRARY}
adc
"${ADC_LIB_PATH}"
"${ADC_STUB_FILE}"
)
17 changes: 17 additions & 0 deletions bee/drivers/can/src/device/rtl87x2g/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2026, Realtek Semiconductor Corporation
# SPDX-License-Identifier: Apache-2.0

zephyr_include_directories(.)

set(STUB_DIR ${ZEPHYR_HAL_REALTEK_MODULE_DIR}/bee/drivers/stubs)
set(CAN_STUB_FILE ${STUB_DIR}/rtl87x2g/can_stubs.c)
set(CAN_LIB_PATH
${ZEPHYR_HAL_REALTEK_MODULE_DIR}/zephyr/blobs/bee/drivers/rtl87x2g/can/librtl87x2g_can.a
)

add_blob_or_stub(
${ZEPHYR_CURRENT_LIBRARY}
can
"${CAN_LIB_PATH}"
"${CAN_STUB_FILE}"
)
35 changes: 35 additions & 0 deletions bee/drivers/stubs/rtl8752h/adc_stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2026, Realtek Semiconductor Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file adc_stubs.c
* @brief Stub implementations for ADC library functions.
* Used when building without binary blobs (CONFIG_BUILD_ONLY_NO_BLOBS).
*/

#include <stdbool.h>
#include <stdint.h>
#include <adc_lib.h>

/* Stub implementations for ADC functions */
bool ADC_CalibrationInit(void)
{
return true;
}

float ADC_GetVoltage(const ADC_SampleMode vSampleMode, int32_t vSampleData,
ADC_ErrorStatus *pErrorStatus)
{
(void)vSampleMode;
(void)vSampleData;
(void)pErrorStatus;
return 0.0f;
}

uint16_t ADC_GetResistance(void)
{
return 0;
}
35 changes: 35 additions & 0 deletions bee/drivers/stubs/rtl87x2g/adc_stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2026, Realtek Semiconductor Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file adc_stubs.c
* @brief Stub implementations for ADC library functions.
* Used when building without binary blobs (CONFIG_BUILD_ONLY_NO_BLOBS).
*/

#include <stdbool.h>
#include <stdint.h>
#include <adc_lib.h>

/* Stub implementations for ADC functions */
bool ADC_CalibrationInit(void)
{
return true;
}

float ADC_GetVoltage(const ADC_SampleMode vSampleMode, int32_t vSampleData,
ADC_ErrorStatus *pErrorStatus)
{
(void)vSampleMode;
(void)vSampleData;
(void)pErrorStatus;
return 0.0f;
}

uint16_t ADC_GetResistance(void)
{
return 0;
}
Loading