Skip to content

Commit bca5475

Browse files
gmarullcarlescufi
authored andcommitted
lib: custom: simplify naming scheme
Improve the naming scheme of the custom library. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 877a4dd commit bca5475

File tree

15 files changed

+94
-83
lines changed

15 files changed

+94
-83
lines changed

include/app/custom_lib/custom_lib.h

Lines changed: 0 additions & 24 deletions
This file was deleted.

include/app/lib/custom.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2021, Legrand North America, LLC.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef APP_LIB_CUSTOM_H_
8+
#define APP_LIB_CUSTOM_H_
9+
10+
/**
11+
* @defgroup lib_custom Custom library
12+
* @ingroup lib
13+
* @{
14+
*
15+
* @brief An example of a custom out-of-tree library.
16+
*
17+
* This library illustrates how create custom out-of-tree libraries. Splitting
18+
* code in libraries enables code reuse and modularity, also easing testing.
19+
*/
20+
21+
/**
22+
* @brief Return @p val if non-zero, or Kconfig-controlled default.
23+
*
24+
* Function returns the provided value if non-zero, or a Kconfig-controlled
25+
* default value if the parameter is zero. This trivial function is provided in
26+
* order to have a library interface example that is trivial to test.
27+
*
28+
* @param val Value to return if non-zero
29+
*
30+
* @retval val if @p val is non-zero
31+
* @retval CONFIG_CUSTOM_GET_VALUE_DEFAULT if @p val is zero
32+
*/
33+
int custom_get_value(int val);
34+
35+
/** @} */
36+
37+
#endif /* APP_LIB_CUSTOM_H_ */

lib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
add_subdirectory_ifdef(CONFIG_CUSTOM_LIB custom_lib)
3+
add_subdirectory_ifdef(CONFIG_CUSTOM custom)

lib/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright (c) 2021 Legrand North America, LLC.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
menu "Libraries"
4+
menu "Custom libraries"
55

6-
rsource "custom_lib/Kconfig"
6+
rsource "custom/Kconfig"
77

88
endmenu

lib/custom_lib/CMakeLists.txt renamed to lib/custom/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
zephyr_library()
5-
zephyr_library_sources(custom_lib.c)
5+
zephyr_library_sources(custom.c)

lib/custom/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2021, Legrand North America, LLC.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config CUSTOM
5+
bool "Support for custom library"
6+
help
7+
This option enables the 'custom' library
8+
9+
config CUSTOM_GET_VALUE_DEFAULT
10+
int "custom_get_value() default return value"
11+
depends on CUSTOM
12+
default 0
13+
help
14+
This option primarily exists as an example of a library Kconfig
15+
setting.
16+
17+
This option specifies the value for custom_get_value() to return
18+
when the input parameter is zero. (Otherwise the function returns the
19+
input parameter value.)

lib/custom/custom.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2021, Legrand North America, LLC.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <app/lib/custom.h>
8+
9+
int custom_get_value(int val)
10+
{
11+
return (val != 0) ? val : CONFIG_CUSTOM_GET_VALUE_DEFAULT;
12+
}

lib/custom_lib/Kconfig

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/custom_lib/custom_lib.c

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/lib/custom_lib/CMakeLists.txt renamed to tests/lib/custom/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
cmake_minimum_required(VERSION 3.20.0)
55
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6-
project(custom_lib)
6+
project(app_lib_custom_test)
77

8-
FILE(GLOB app_sources src/*.c)
9-
target_sources(app PRIVATE ${app_sources})
8+
target_sources(app PRIVATE src/main.c)

0 commit comments

Comments
 (0)