Skip to content

Commit ba5032a

Browse files
YuzhuoLiuRTKZhiyuanTang17
authored andcommitted
hal: realtek: add ADC and CAN library for Bee series
Add rtl87x2g/rtl8752h ADC and CAN library to blobs. Signed-off-by: Yuzhuo Liu <yuzhuo_liu@realsil.com.cn>
1 parent 0979520 commit ba5032a

8 files changed

Lines changed: 516 additions & 0 deletions

File tree

bee/drivers/CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,66 @@ function(add_soc_series_subdir ic_name)
3333
endif()
3434
endfunction()
3535

36+
# Add either a blob library or a stub source for a driver.
37+
#
38+
# Behavior:
39+
# - If CONFIG_BUILD_ONLY_NO_BLOBS=y, always use the stub source.
40+
# - Otherwise, use the blob library when present.
41+
# - If the blob library is absent, fall back to the stub source.
42+
# - If the same blob library is requested multiple times, link it only once.
43+
#
44+
# Usage:
45+
# add_blob_or_stub(
46+
# ${ZEPHYR_CURRENT_LIBRARY}
47+
# adc
48+
# <blob library path>
49+
# <stub source path>
50+
# )
51+
function(add_blob_or_stub TARGET NAME BLOB_LIB_PATH STUB_FILE)
52+
string(TOUPPER "${NAME}" NAME_UPPER)
53+
54+
set(use_stubs FALSE)
55+
56+
if(CONFIG_BUILD_ONLY_NO_BLOBS)
57+
message(STATUS "CONFIG_BUILD_ONLY_NO_BLOBS=y, forcing ${NAME_UPPER} stubs")
58+
set(use_stubs TRUE)
59+
elseif(EXISTS "${BLOB_LIB_PATH}")
60+
get_property(linked_blobs GLOBAL PROPERTY REALTEK_BLOB_LIBS_LINKED)
61+
if(NOT linked_blobs)
62+
set(linked_blobs "")
63+
endif()
64+
65+
list(FIND linked_blobs "${BLOB_LIB_PATH}" blob_index)
66+
if(blob_index EQUAL -1)
67+
message(STATUS "Using ${NAME_UPPER} blob library: ${BLOB_LIB_PATH}")
68+
target_link_libraries(${TARGET} PUBLIC ${BLOB_LIB_PATH})
69+
set_property(GLOBAL APPEND PROPERTY REALTEK_BLOB_LIBS_LINKED "${BLOB_LIB_PATH}")
70+
else()
71+
message(STATUS
72+
"${NAME_UPPER} blob library already linked, skipping duplicate: "
73+
"${BLOB_LIB_PATH}"
74+
)
75+
endif()
76+
else()
77+
message(STATUS
78+
"${NAME_UPPER} blob library not found: ${BLOB_LIB_PATH}\n"
79+
"Falling back to ${NAME_UPPER} stubs"
80+
)
81+
set(use_stubs TRUE)
82+
endif()
83+
84+
if(use_stubs)
85+
if(EXISTS "${STUB_FILE}")
86+
message(STATUS "Using ${NAME_UPPER} stub source: ${STUB_FILE}")
87+
zephyr_library_sources(${STUB_FILE})
88+
else()
89+
message(FATAL_ERROR
90+
"${NAME_UPPER} stub source not found: ${STUB_FILE}"
91+
)
92+
endif()
93+
endif()
94+
endfunction()
95+
3696
add_subdirectory(adc)
3797
add_subdirectory_ifdef(CONFIG_REALTEK_BEE_BT bluetooth)
3898
add_subdirectory(can)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2026, Realtek Semiconductor Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
file(GLOB ADC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
5+
zephyr_library_sources(${ADC_SOURCES})
6+
zephyr_include_directories(.)
7+
8+
set(STUB_DIR ${ZEPHYR_HAL_REALTEK_MODULE_DIR}/bee/drivers/stubs)
9+
set(ADC_STUB_FILE ${STUB_DIR}/rtl8752h/adc_stubs.c)
10+
set(ADC_LIB_PATH
11+
${ZEPHYR_HAL_REALTEK_MODULE_DIR}/zephyr/blobs/bee/drivers/rtl8752h/adc/librtl8752h_adc.a
12+
)
13+
14+
add_blob_or_stub(
15+
${ZEPHYR_CURRENT_LIBRARY}
16+
adc
17+
"${ADC_LIB_PATH}"
18+
"${ADC_STUB_FILE}"
19+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2026, Realtek Semiconductor Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
file(GLOB ADC_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
5+
zephyr_library_sources(${ADC_SOURCES})
6+
zephyr_include_directories(.)
7+
8+
set(STUB_DIR ${ZEPHYR_HAL_REALTEK_MODULE_DIR}/bee/drivers/stubs)
9+
set(ADC_STUB_FILE ${STUB_DIR}/rtl87x2g/adc_stubs.c)
10+
set(ADC_LIB_PATH
11+
${ZEPHYR_HAL_REALTEK_MODULE_DIR}/zephyr/blobs/bee/drivers/rtl87x2g/adc/librtl87x2g_adc.a
12+
)
13+
14+
add_blob_or_stub(
15+
${ZEPHYR_CURRENT_LIBRARY}
16+
adc
17+
"${ADC_LIB_PATH}"
18+
"${ADC_STUB_FILE}"
19+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2026, Realtek Semiconductor Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
zephyr_include_directories(.)
5+
6+
set(STUB_DIR ${ZEPHYR_HAL_REALTEK_MODULE_DIR}/bee/drivers/stubs)
7+
set(CAN_STUB_FILE ${STUB_DIR}/rtl87x2g/can_stubs.c)
8+
set(CAN_LIB_PATH
9+
${ZEPHYR_HAL_REALTEK_MODULE_DIR}/zephyr/blobs/bee/drivers/rtl87x2g/can/librtl87x2g_can.a
10+
)
11+
12+
add_blob_or_stub(
13+
${ZEPHYR_CURRENT_LIBRARY}
14+
can
15+
"${CAN_LIB_PATH}"
16+
"${CAN_STUB_FILE}"
17+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2026, Realtek Semiconductor Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file adc_stubs.c
9+
* @brief Stub implementations for ADC library functions.
10+
* Used when building without binary blobs (CONFIG_BUILD_ONLY_NO_BLOBS).
11+
*/
12+
13+
#include <stdbool.h>
14+
#include <stdint.h>
15+
#include <adc_lib.h>
16+
17+
/* Stub implementations for ADC functions */
18+
bool ADC_CalibrationInit(void)
19+
{
20+
return true;
21+
}
22+
23+
float ADC_GetVoltage(const ADC_SampleMode vSampleMode, int32_t vSampleData,
24+
ADC_ErrorStatus *pErrorStatus)
25+
{
26+
(void)vSampleMode;
27+
(void)vSampleData;
28+
(void)pErrorStatus;
29+
return 0.0f;
30+
}
31+
32+
uint16_t ADC_GetResistance(void)
33+
{
34+
return 0;
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2026, Realtek Semiconductor Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file adc_stubs.c
9+
* @brief Stub implementations for ADC library functions.
10+
* Used when building without binary blobs (CONFIG_BUILD_ONLY_NO_BLOBS).
11+
*/
12+
13+
#include <stdbool.h>
14+
#include <stdint.h>
15+
#include <adc_lib.h>
16+
17+
/* Stub implementations for ADC functions */
18+
bool ADC_CalibrationInit(void)
19+
{
20+
return true;
21+
}
22+
23+
float ADC_GetVoltage(const ADC_SampleMode vSampleMode, int32_t vSampleData,
24+
ADC_ErrorStatus *pErrorStatus)
25+
{
26+
(void)vSampleMode;
27+
(void)vSampleData;
28+
(void)pErrorStatus;
29+
return 0.0f;
30+
}
31+
32+
uint16_t ADC_GetResistance(void)
33+
{
34+
return 0;
35+
}

0 commit comments

Comments
 (0)