在Android studio 中如果要change layout的類型,要換成tablelayout,relativelayout....等,
可以到Component tree透過morphing來達成.
但是很可惜的預設建立的project找不到這個選項,似乎是官方IDE的一個bug.
如果堅持要在圖形化界面中使用這個功能,可能就必須先到"TEXT"模式下更改.
在"TEXT"模式改過一次之後,該選項就可以使用了
2015年4月22日 星期三
2015年4月20日 星期一
[Android]Linux kernel 開發基礎 (四)- 新增I2C device 範例
新增platform device 範例 是直接向platform bus註冊一個裝置
其他較常見的裝置要註冊也是大同小異,
makefile 與 kconfig 寫法是相同的,差異在於在哪個Bus下註冊裝置
底下為新增I2C device 範例:
1. makefile
根據kconfig的設定,定義要build的檔案
例如範例中的
obj-$(CONFIG_HELLO_DRIVER) += hello.o
這裡定義了:當CONFIG_HELLO_DRIVER為y
就將hello這個檔案build進kernel
2. kconfig
定義了driver 簡易描述以及預設值,與makefile一起,為kernel建立tree管理之用,
在make menuconfig時,可將該driver相關訊息顯示在視窗界面
config HELLO_DRIVER
default y
tristate "Hello Driver"
help
Say Y here if you want to enable hello driver.
這裡定義了一個新的driver HELLO_DRIVER,,
預設值為y
3.如果要向I2C bus註冊新裝置,必須先找到I2C bus initial 的檔案(根據每個BSP設計不同,這個位置與名稱也不同,通常位於kernel/arch/arm/"cpu_name"),透過i2c_register_board_info來註冊新裝置,
(參考自: https://www.kernel.org/doc/htmldocs/device-drivers/API-i2c-register-board-info.html)
例如:
i2c_register_board_info(i2c_bus_num, i2c_devs_define, ARRAY_SIZE(i2c_devs_define));
而i2c_devs_define 必須明確指出i2c device address 與i2c_bus_num才能根據設定將資料送到該裝置 ,定義範例如下:
static struct i2c_board_info i2c_devs_define[] __initdata = {
{
I2C_BOARD_INFO(i2c_device_name, i2c_address >> 1),
.irq = IRQ_EINT(IRQ_num),
},
};
4.最後調用i2c_add_driver(&i2c_driver);即可完成I2C device 新增
static const unsigned short normal_i2c[2] = {i2c_address,I2C_CLIENT_END};
static struct i2c_driver i2c_driver = {
.driver = {
.name = i2c_device_name,
.owner = THIS_MODULE,
},
.class = I2C_CLASS_HWMON,
.address_list = normal_i2c,
.id_table = id,
.probe = probe,
.remove = __exit_p(remove),
.suspend = suspend,
.resume = resume,
};
i2c_add_driver(&i2c_driver);
其他較常見的裝置要註冊也是大同小異,
makefile 與 kconfig 寫法是相同的,差異在於在哪個Bus下註冊裝置
底下為新增I2C device 範例:
1. makefile
根據kconfig的設定,定義要build的檔案
例如範例中的
obj-$(CONFIG_HELLO_DRIVER) += hello.o
這裡定義了:當CONFIG_HELLO_DRIVER為y
就將hello這個檔案build進kernel
2. kconfig
定義了driver 簡易描述以及預設值,與makefile一起,為kernel建立tree管理之用,
在make menuconfig時,可將該driver相關訊息顯示在視窗界面
config HELLO_DRIVER
default y
tristate "Hello Driver"
help
Say Y here if you want to enable hello driver.
這裡定義了一個新的driver HELLO_DRIVER,,
預設值為y
3.如果要向I2C bus註冊新裝置,必須先找到I2C bus initial 的檔案(根據每個BSP設計不同,這個位置與名稱也不同,通常位於kernel/arch/arm/"cpu_name"),透過i2c_register_board_info來註冊新裝置,
(參考自: https://www.kernel.org/doc/htmldocs/device-drivers/API-i2c-register-board-info.html)
Name
i2c_register_board_info — statically declare I2C devicesSynopsis
int i2c_register_board_info ( | int busnum, |
| struct i2c_board_info const * info, | |
unsigned len); |
Arguments
busnum- identifies the bus to which these devices belong
info- vector of i2c device descriptors
len- how many descriptors in the vector; may be zero to reserve the specified bus number.
i2c_register_board_info(i2c_bus_num, i2c_devs_define, ARRAY_SIZE(i2c_devs_define));
而i2c_devs_define 必須明確指出i2c device address 與i2c_bus_num才能根據設定將資料送到該裝置 ,定義範例如下:
static struct i2c_board_info i2c_devs_define[] __initdata = {
{
I2C_BOARD_INFO(i2c_device_name, i2c_address >> 1),
.irq = IRQ_EINT(IRQ_num),
},
};
static const unsigned short normal_i2c[2] = {i2c_address,I2C_CLIENT_END};
static struct i2c_driver i2c_driver = {
.driver = {
.name = i2c_device_name,
.owner = THIS_MODULE,
},
.class = I2C_CLASS_HWMON,
.address_list = normal_i2c,
.id_table = id,
.probe = probe,
.remove = __exit_p(remove),
.suspend = suspend,
.resume = resume,
};
i2c_add_driver(&i2c_driver);
Linux kernel 開發基礎 (三)- 新增platform device
新增platform device
並不複雜,
只需要更改三個地方
1. makefile
根據kconfig的設定,
定義要build的檔案
例如範例中的
obj-$(CONFIG_HELLO_DRIVER) += hello.o
這裡定義了:
當CONFIG_HELLO_DRIVER為y
就將hello這個檔案build進kernel
2. kconfig
定義了driver 簡易描述以及預設值,
與makefile一起,
為kernel建立tree管理之用,
在make menuconfig時,
可將該driver相關訊息顯示在視窗界面
config HELLO_DRIVER
default y
tristate "Hello Driver"
help
Say Y here if you want to enable hello driver.
這裡定義了一個新的driver HELLO_DRIVER,,
預設值為y
3. driver本身
static struct platform_driver hello_driver = {
.probe = hello_probe,
.remove = __devexit_p(hello_remove),
.driver = {
.name = "hello",
.owner = THIS_MODULE,
},
.suspend = hello_suspend,
.resume = hello_resume,
};
driver定義著platform device的功能,
如果還是不是很了解,
可以下載範例程式去build 看看
訂閱:
文章 (Atom)

