手把手教你写Kconfig---基于tiny4412开发板(增强版)

Kconfig怎么写的在上节就已经教大家写了。

这节我们来写写增强版的,因为Kconfig有太多太多可以配置的,所以这里我就不给出图片演示了,请参考上节的文章,再来看这节大家就会大彻大悟,然后自己去尝试吧。

基本上最常见的配置就是以下的这些。

文章链接如下:

http://blog.csdn.net/morixinguan/article/details/54744237

在make menuconfig添加Kconfig配置简单的选项
有很多的Kconfig组成
./scripts/Kconfig/mconf  arch/arm/Kconfig---->drivers/Kconfig
cd driver/yangyx/
touch Kconfig
vim Kconfig
语法:
config MY_UP
bool "select up.c" //提示
default y          //这里是默认选项,可以为y,也可以为n
help           //帮助选项
If you select this , you will be happy


然后可以用./scripts/Kconfig/mconf 解析 driver/yangyx/Kconfig


这样子很不方便,在上层的Kconfig添加Kconfig
vim 
source "driver/yangyx/Kconfig"
vim include/generated/autoconf.h   会被.c包含
vim inlcude/config/auto.conf   这个文件根据.config生成,而.config是根据make menuconfig来进行生成,内核中的makefile包含了这个文件
在驱动代码中启动条件编译
#include/generated/autoconf.h

#ifdef CONFIG_XXX
	xxx
#else 
	xxx
#endif


config MY_UP
	bool "select up.c" //提示
	default y          //这里是默认选项,可以为y,也可以为n
	help	           //帮助选项
	If you select this , you will be happy
config CONFIG_XXX
    bool "select lcd07"
	default n 
	help
	if you ...
如何做一个目录型选项,关键字menu

1、不能整体选中

menu "my_4412 support"

config ...
	bool ...
	default n
	help
	if ....

endmenu

2、 多级定义(可以整体选中)
menuconfig MY_MENU   定义选项
	bool "anthor menu"
if MY_MENU
	config TEST3
		bool ...
		default n
		help
		if ....	
		
	config ...
	config ...
endif

3、目录套目录,并支持三态选择
menu "my_4412 support"

config ...
	bool ...
	default n
	help
	if ....
config ...
	tristate "test5"    加上tristate表示有三种状态可以配置,M以模块编译,*编译成.o
	default n
	help
	if ....
endmenu
4、在Kconfig中支持依赖关系的条件选项
config My_IIC
	bool ..
	default n
	help
	...
config MY_TS
    bool "my ts"
	default n
	depends on My_IIC     ---->如果没有选中IIC,那么这个选项不会让用户选  ,如果是依赖于多个,可以用&&连接,也可以||,还可以!,根据自己的需求定制
	help
	if ...

5、多选一的选项:
三态的意思就是.o , .ko , 或者不选。

choice 
prompt "selct your driver"
	    config LCD70 
		        bool "lcd70"   这里不能三态
				help ...
				if ...
		config LCD60 
		        bool "lcd70"   这里不能三态
				help ...
				if ...
		config LCD80 
		        bool "lcd70"   这里不能三态
				help ...
				if ...
		config LCD90 
		        bool "lcd70"   这里不能三态
				help ...
				if ...
endchoice
6、配置依赖模块
config MYADC
	    bool "my_adc"
		default n
		help
		if ...
config MY_PM2.5
	    bool "your pm2.5"
		default n
		select MY_ADC    //只要选中MYPM2.5,也会去选择MYADC
		help
		if ...


		
config TEST8
       bool "test8"
	   default n 
	   help 
	   if  ...
if   TEST8
config  TEST9
    bool "test8"
	   default n 
	   help 
	   if  ...
endif
7、配置设置数字的选项
config NUM
    int "thread num"
	default 3
	help
	if ...

8、配置字符串的选项
config MY_STRING
    string "my string"
	default "hello"
	help 
	if ...
	
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值