文章目录
1. menu 嵌套
- 设置 menu 可见性
- 设置嵌套目录,支持多级嵌套
menu "ESP32S2-specific"
visible if IDF_TARGET_ESP32S2 # 设置可见性
menu "Cache config" #嵌套目录
#
#
#
endmenu
endmenu
2. 条件式默认值
- 使用
default
可以设置配置项的默认值 - 使用
default () if ()
设置不同条件下的默认值 if
后可以添加操作符如if !IDF_ENV_FPGA
config ESP32S2_DEFAULT_CPU_FREQ_MHZ
int
default 40 if IDF_ENV_FPGA
default 80 if ESP32S2_DEFAULT_CPU_FREQ_80
default 160 if ESP32S2_DEFAULT_CPU_FREQ_160
default 240 if ESP32S2_DEFAULT_CPU_FREQ_240
使用条件默认之后,一般不再要求用户自行输入,因此不在类型后面加提示符,也不使用prompt
添加提示,但是并不是不可以,如以下例子:
config ESP32S2_ULP_COPROC_RESERVE_MEM
int
prompt "RTC slow memory reserved for coprocessor" if ESP32S2_ULP_COPROC_ENABLED
default 512 if ESP32S2_ULP_COPROC_ENABLED
range 32 8192 if ESP32S2_ULP_COPROC_ENABLED
default 0 if !ESP32S2_ULP_COPROC_ENABLED
range 0 0 if !ESP32S2_ULP_COPROC_ENABLED
help
Bytes of memory to reserve for ULP coprocessor firmware & data.
Data is reserved at the beginning of RTC slow memory.
3. 条件式范围
- 使用
range () () if ()
设置条件式范围
config ESP32S2_ULP_COPROC_RESERVE_MEM
int
prompt "RTC slow memory reserved for coprocessor" if ESP32S2_ULP_COPROC_ENABLED
default 512 if ESP32S2_ULP_COPROC_ENABLED
range 32 8192 if ESP32S2_ULP_COPROC_ENABLED
default 0 if !ESP32S2_ULP_COPROC_ENABLED
range 0 0 if !ESP32S2_ULP_COPROC_ENABLED
help
Bytes of memory to reserve for ULP coprocessor firmware & data.
Data is reserved at the beginning of RTC slow memory.
4. 条件式提示
- 可以直接在类型后面添加
"string"
,添加配置项的界面提示 - 不添加提示,默认不再界面进行显示,不与用户直接交互
- 也可通过
prompt
添加提示,相比直接在类型后面添加"string"
,该方式更加灵活。可以通过prompt "string" if ()
实现条件提示
例:只在 ESP32S2_ULP_COPROC_ENABLED
使能时添加界面提示,否则使用默认值
config ESP32S2_ULP_COPROC_RESERVE_MEM
int
prompt "RTC slow memory reserved for coprocessor" if ESP32S2_ULP_COPROC_ENABLED
default 512 if ESP32S2_ULP_COPROC_ENABLED
range 32 8192 if ESP32S2_ULP_COPROC_ENABLED
default 0 if !ESP32S2_ULP_COPROC_ENABLED
range 0 0 if !ESP32S2_ULP_COPROC_ENABLED
help
Bytes of memory to reserve for ULP coprocessor firmware & data.
Data is reserved at the beginning of RTC slow memory.
5. 多选一选项
- 使用
choice ...endchoice
可以配置多选一选项 - 使用
default
设置选择默认值 - 使用
prompt
设置选择提示
选项的变量类型只能是 bool
和 tristate
,为了实现其他类型的选择,可以使用以下方式:
choice ESP32S2_DEFAULT_CPU_FREQ_MHZ
prompt "CPU frequency"
default ESP32S2_DEFAULT_CPU_FREQ_160 if !IDF_ENV_FPGA
default ESP32S2_DEFAULT_CPU_FREQ_FPGA if IDF_ENV_FPGA
help
CPU frequency to be set on application startup.
config ESP32S2_DEFAULT_CPU_FREQ_FPGA
depends on IDF_ENV_FPGA
bool "FPGA"
config ESP32S2_DEFAULT_CPU_FREQ_80
bool "80 MHz"
config ESP32S2_DEFAULT_CPU_FREQ_160
bool "160 MHz"
config ESP32S2_DEFAULT_CPU_FREQ_240
bool "240 MHz"
endchoice
config ESP32S2_DEFAULT_CPU_FREQ_MHZ
int
default 40 if IDF_ENV_FPGA
default 80 if ESP32S2_DEFAULT_CPU_FREQ_80
default 160 if ESP32S2_DEFAULT_CPU_FREQ_160
default 240 if ESP32S2_DEFAULT_CPU_FREQ_240
6. 选项依赖关系
A depends on B
只有 B 选中,才能对 A 进行操作A select B
只要 A 选中,就会同时选中 Bdepends on
为依赖关系,select
为反向依赖- 也可以
depends on !B
,只有B不选中,才能对 A 进行操作
ESP32S2_TRAX
反向依赖ESP32S2_MEMMAP_TRACEMEM
,当ESP32S2_TRAX
使能时,ESP32S2_MEMMAP_TRACEMEM
也同时被使能。
config ESP32S2_MEMMAP_TRACEMEM
bool
default "n"
config ESP32S2_TRAX
bool "Use TRAX tracing feature"
default "n"
select ESP32S2_MEMMAP_TRACEMEM
help
The ESP32S2 contains a feature which allows you to trace the execution path the processor
has taken through the program. This is stored in a chunk of 32K (16K for single-processor)
of memory that can't be used for general purposes anymore. Disable this if you do not know
what this is.
7. 为菜单添加注释
menu "motors config"
comment "config gpio for motors"
...
endmenu
8. 引用其他 Kconfig
- 相当于包含文档,将其在添加位置处展开
source "path/to/kconfig"
9. kconfig 配置项类型
参考文档
- Kconfig详解-文件的基本要素 :https://www.cnblogs.com/jiangzhaowei/p/7528099.html