文章目錄
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