当前位置: 编程技术>综合
本页文章导读:
▪Mac OS X 支持Noppoo mini 84键盘 刚刚入手一个Noppoo Choc mini 84青轴键盘,有没有买之前没做功课,发现mac尽然无法识别这款键盘。
google了一下,发现github上有一个项目专门来解决这个问题,按照这个项目给出的方法,就能够.........
▪L,_T(),_TEXT()的秘密 L,_T(),_TEXT()的秘密
jiese1990
L的含义
L"字符串" 表示字符串为unicode的字符串,每个字符占用两个字节。
_T()与_TEXT()源码
在tchar.h文件里有如下宏定义:
#ifdef __cplusplus //__cplusplus该宏.........
▪ioctl实验 本文是我在andoid实验的ioctl的功能,如双向传递参数。贴出来希望对学习ioctl的人很有帮助。
linux的ioctl功能是很强大的,android显示模块还有camera模块都离不开ioctl.........
[1]Mac OS X 支持Noppoo mini 84键盘
刚刚入手一个Noppoo Choc mini 84青轴键盘,有没有买之前没做功课,发现mac尽然无法识别这款键盘。
google了一下,发现github上有一个项目专门来解决这个问题,按照这个项目给出的方法,就能够让mac支持Noppoo Choc mini 84键盘了,地址记录下来,方便后面用:
https://github.com/thefloweringash/iousbhiddriver-descriptor-override
http://likidu.com/2012/11/noppoo-chic-mini84-osx-support/
http://geekhack.org/index.php?topic=24672.0
http://superuser.com/questions/47233/how-can-i-force-a-mac-os-x-kext-to-load-prior-to-login
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
google了一下,发现github上有一个项目专门来解决这个问题,按照这个项目给出的方法,就能够让mac支持Noppoo Choc mini 84键盘了,地址记录下来,方便后面用:
https://github.com/thefloweringash/iousbhiddriver-descriptor-override
http://likidu.com/2012/11/noppoo-chic-mini84-osx-support/
http://geekhack.org/index.php?topic=24672.0
http://superuser.com/questions/47233/how-can-i-force-a-mac-os-x-kext-to-load-prior-to-login
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
- —软件人才免语言低担保 赴美带薪读研!—
[2]L,_T(),_TEXT()的秘密
来源: 互联网 发布时间: 2013-11-10
L,_T(),_TEXT()的秘密
去掉c++的宏__cplusplus的部分再来看这段源码:
L,_T(),_TEXT()的用法
jiese1990
L的含义
L"字符串" 表示字符串为unicode的字符串,每个字符占用两个字节。
_T()与_TEXT()源码在tchar.h文件里有如下宏定义:
#ifdef __cplusplus //__cplusplus该宏代表是否是c++,如果不是c++是c语言的话就不会定义该宏 extern "C" { #endif ... #ifdef _UNICODE //_UNICODE代表工程是否使用Unicode字符,在工程属性--General-->Character Set里设置 #ifdef __cplusplus } /* ... extern "C" */ #endif #include <wchar.h> #ifdef __cplusplus extern "C" { #endif ... #define __T(x) L ## x //在tchar.h的第206行 //“##”:当c++宏展开时,##会作为连接操作符!如__T("jiese1990") --> L"jiese1990" ... #else /* ndef _UNICODE */ #ifdef __cplusplus } /* ... extern "C" */ #endif #include <string.h> #ifdef __cplusplus extern "C" { #endif ... #define __T(x) x //在tchar.h的第850行 ... #ifdef __cplusplus } /* ... extern "C" */ #endif ... #endif /* _UNICODE */ #define _T(x) __T(x) //在tchar.h的第2388行 #define _TEXT(x) __T(x) //在tchar.h的第2389行
去掉c++的宏__cplusplus的部分再来看这段源码:
extern "C" { ... //如果工程属性里设置了Use Unicode Character Set(使用Unicode字符集) #ifdef _UNICODE } /* ... extern "C" */ #include <wchar.h> extern "C" { .. #define __T(x) L ## x //在tchar.h的第206行 //“##”当c++宏展开时,##会作为连接操作符!即__T("jiese1990") --> L"jiese1990" ... //如果没设置为Use Unicode Character Set设置成Use Multi-Byte Character Set了 #else /* ndef _UNICODE */ } /* ... extern "C" */ #include <string.h> extern "C" { ... #define __T(x) x //在tchar.h的第850行 ... } /* ... extern "C" */ ... #endif /* _UNICODE */ #define _T(x) __T(x) //在tchar.h的第2388行 #define _TEXT(x) __T(x) //在tchar.h的第2389行; //_T()与_TEXT()两个宏是一样的 ...
参考下面这篇博客,写的挺好的
http://blog.csdn.net/awey_001/article/details/6130795
作者:jiese1990 发表于2013-1-12 14:44:31 原文链接
阅读:12 评论:0 查看评论
[3]ioctl实验
来源: 互联网 发布时间: 2013-11-10
本文是我在andoid实验的ioctl的功能,如双向传递参数。贴出来希望对学习ioctl的人很有帮助。
linux的ioctl功能是很强大的,android显示模块还有camera模块都离不开ioctl让上层和内核交互。
board中添加platform_devce
static struct ioctl_test_platform_data ioctl_pdata = {
static struct ioctl_test_platform_data ioctl_pdata = {
.gpio=17,
};
static struct platform_device msm_device_ioctl = {
.name = "gpio_test",
.id = -1,
.dev = {
.platform_data = &ioctl_pdata,
},
};
头文件:
ioctl_test.h
#ifndef IOCTL_TEST_H
#define IOCTL_TEST_H
/* platform data from board file */
struct ioctl_test_platform_data{
u16 gpio;
};
struct gpio_priv_t {
int gpio;
int state0;
int state1;
int state2;
int state3;
};
#define GPIO_TEST_IOC_MAGIC 0x92
#define GPIO_TEST_SET_HIGH _IO(GPIO_TEST_IOC_MAGIC, 1)
#define GPIO_TEST_SET_LOW _IO(GPIO_TEST_IOC_MAGIC, 2)
#define GPIO_TEST_WRITE_STRUCT _IOW(GPIO_TEST_IOC_MAGIC, 3,struct gpio_priv_t *)
#define GPIO_TEST_WRITE_INT _IOW(GPIO_TEST_IOC_MAGIC, 4,unsigned int *)
#define GPIO_TEST_READ_STRUCT _IOR(GPIO_TEST_IOC_MAGIC, 5,struct gpio_priv_t *)
#define GPIO_TEST_READ_INT _IOR(GPIO_TEST_IOC_MAGIC, 6,unsigned int *)
#endif
driver:
生成设备节点:/dev/gpio_test
ioctl_test.c
#define pr_fmt(fmt) "%s: " fmt, __func__
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <linux/regulator/consumer.h>
#include <linux/platform_device.h>
#include <linux/mutex.h>
#include <mach/gpio.h>
#include<linux/ioctl_test.h>
static struct gpio_priv_t *gpio_priv;
static int gpio_test_open(struct inode *inode, struct file *filp)
{
if (gpio_priv == NULL)
return -ENODEV;
filp->private_data = gpio_priv;
return 0;
}
static int gpio_test_release(struct inode *inode, struct file *filp)
{
filp->private_data = NULL;
return 0;
}
static long
gpio_test_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
int err = 0;
void __user *argp = (void __user *)arg;
int value0;
int value1 ;
/* Verify user arguments. */
if (_IOC_TYPE(cmd) != GPIO_TEST_IOC_MAGIC)
return -ENOTTY;
switch (cmd) {
case GPIO_TEST_SET_HIGH:
printk("GPIO_TEST_SET_HIGH\n");
if (arg == 0) {
pr_err("user space arg not supplied\n");
err = -EFAULT;
break;
}
gpio_set_value(17,1);
break;
case GPIO_TEST_SET_LOW:
printk("GPIO_TEST_SET_LOW\n");
if (arg == 0) {
pr_err("user space arg not supplied\n");
err = -EFAULT;
break;
}
gpio_set_value(17,0);
break;
case GPIO_TEST_WRITE_STRUCT:
printk("GPIO_TEST_WRITE\n");
if (copy_from_user(gpio_priv, argp, sizeof(struct gpio_priv_t)))
return -EFAULT;
printk("gpio_priv->state0=%d\n",gpio_priv->state0);
printk("gpio_priv->state1=%d\n",gpio_priv->state1);
printk("gpio_priv->state2=%d\n",gpio_priv->state2);
break;
case GPIO_TEST_READ_STRUCT:
printk("GPIO_TEST_READ\n");
gpio_priv->state0=1;
gpio_priv->state1=2;
gpio_priv->state2=3;
if (copy_to_user(argp, gpio_priv, sizeof(struct gpio_priv_t)))
return -EFAULT;
break;
case GPIO_TEST_WRITE_INT:
printk("GPIO_TEST_WRITE_INT\n");
if(copy_from_user(&value0,argp,sizeof(int)))
return -EFAULT;
printk("value0 = %d\n",value0);
break;
case GPIO_TEST_READ_INT:
printk("GPIO_TEST_READ_INT\n");
value1=101;
if (copy_to_user(argp, &value1, sizeof(int)))
return -EFAULT;
break;
default:
pr_err("Invalid ioctl command.\n");
return -ENOTTY;
}
return err;
}
static const struct file_operations gpio_test_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = gpio_test_ioctl,
.open = gpio_test_open,
.release = gpio_test_release
};
static struct miscdevice gpio_test_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "gpio_test",
.fops = &gpio_test_fops
};
static int gpio_test_probe(struct platform_device *pdev)
{
int ret = 0;
printk("gpio_test_probe 0\n");
/* Initialize */
gpio_priv = kzalloc(sizeof(struct gpio_priv_t), GFP_KERNEL);
if (gpio_priv == NULL) {
pr_alert("Not enough memory to initialize device\n");
return -ENOMEM;
}
ret = misc_register(&gpio_test_dev);
if (ret < 0)
goto err;
return 0;
err:
printk("gpio_test register failed\n");
kfree(gpio_priv);
gpio_priv = NULL;
return ret;
}
static int __devexit gpio_test_remove(struct platform_device *plat)
{
kfree(gpio_priv);
gpio_priv = NULL;
misc_deregister(&gpio_test_dev);
printk("gpio_test remove\n");
return 0;
}
static struct platform_driver gpio_test_driver = {
.probe = gpio_test_probe,
.remove = gpio_test_remove,
.driver = {
.name = "gpio_test",
.owner = THIS_MODULE,
},
};
static int __init gpio_test_init(void)
{
printk("
linux的ioctl功能是很强大的,android显示模块还有camera模块都离不开ioctl让上层和内核交互。
board中添加platform_devce
static struct ioctl_test_platform_data ioctl_pdata = {
static struct ioctl_test_platform_data ioctl_pdata = {
.gpio=17,
};
static struct platform_device msm_device_ioctl = {
.name = "gpio_test",
.id = -1,
.dev = {
.platform_data = &ioctl_pdata,
},
};
头文件:
ioctl_test.h
#ifndef IOCTL_TEST_H
#define IOCTL_TEST_H
/* platform data from board file */
struct ioctl_test_platform_data{
u16 gpio;
};
struct gpio_priv_t {
int gpio;
int state0;
int state1;
int state2;
int state3;
};
#define GPIO_TEST_IOC_MAGIC 0x92
#define GPIO_TEST_SET_HIGH _IO(GPIO_TEST_IOC_MAGIC, 1)
#define GPIO_TEST_SET_LOW _IO(GPIO_TEST_IOC_MAGIC, 2)
#define GPIO_TEST_WRITE_STRUCT _IOW(GPIO_TEST_IOC_MAGIC, 3,struct gpio_priv_t *)
#define GPIO_TEST_WRITE_INT _IOW(GPIO_TEST_IOC_MAGIC, 4,unsigned int *)
#define GPIO_TEST_READ_STRUCT _IOR(GPIO_TEST_IOC_MAGIC, 5,struct gpio_priv_t *)
#define GPIO_TEST_READ_INT _IOR(GPIO_TEST_IOC_MAGIC, 6,unsigned int *)
#endif
driver:
生成设备节点:/dev/gpio_test
ioctl_test.c
#define pr_fmt(fmt) "%s: " fmt, __func__
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <linux/regulator/consumer.h>
#include <linux/platform_device.h>
#include <linux/mutex.h>
#include <mach/gpio.h>
#include<linux/ioctl_test.h>
static struct gpio_priv_t *gpio_priv;
static int gpio_test_open(struct inode *inode, struct file *filp)
{
if (gpio_priv == NULL)
return -ENODEV;
filp->private_data = gpio_priv;
return 0;
}
static int gpio_test_release(struct inode *inode, struct file *filp)
{
filp->private_data = NULL;
return 0;
}
static long
gpio_test_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
int err = 0;
void __user *argp = (void __user *)arg;
int value0;
int value1 ;
/* Verify user arguments. */
if (_IOC_TYPE(cmd) != GPIO_TEST_IOC_MAGIC)
return -ENOTTY;
switch (cmd) {
case GPIO_TEST_SET_HIGH:
printk("GPIO_TEST_SET_HIGH\n");
if (arg == 0) {
pr_err("user space arg not supplied\n");
err = -EFAULT;
break;
}
gpio_set_value(17,1);
break;
case GPIO_TEST_SET_LOW:
printk("GPIO_TEST_SET_LOW\n");
if (arg == 0) {
pr_err("user space arg not supplied\n");
err = -EFAULT;
break;
}
gpio_set_value(17,0);
break;
case GPIO_TEST_WRITE_STRUCT:
printk("GPIO_TEST_WRITE\n");
if (copy_from_user(gpio_priv, argp, sizeof(struct gpio_priv_t)))
return -EFAULT;
printk("gpio_priv->state0=%d\n",gpio_priv->state0);
printk("gpio_priv->state1=%d\n",gpio_priv->state1);
printk("gpio_priv->state2=%d\n",gpio_priv->state2);
break;
case GPIO_TEST_READ_STRUCT:
printk("GPIO_TEST_READ\n");
gpio_priv->state0=1;
gpio_priv->state1=2;
gpio_priv->state2=3;
if (copy_to_user(argp, gpio_priv, sizeof(struct gpio_priv_t)))
return -EFAULT;
break;
case GPIO_TEST_WRITE_INT:
printk("GPIO_TEST_WRITE_INT\n");
if(copy_from_user(&value0,argp,sizeof(int)))
return -EFAULT;
printk("value0 = %d\n",value0);
break;
case GPIO_TEST_READ_INT:
printk("GPIO_TEST_READ_INT\n");
value1=101;
if (copy_to_user(argp, &value1, sizeof(int)))
return -EFAULT;
break;
default:
pr_err("Invalid ioctl command.\n");
return -ENOTTY;
}
return err;
}
static const struct file_operations gpio_test_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = gpio_test_ioctl,
.open = gpio_test_open,
.release = gpio_test_release
};
static struct miscdevice gpio_test_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "gpio_test",
.fops = &gpio_test_fops
};
static int gpio_test_probe(struct platform_device *pdev)
{
int ret = 0;
printk("gpio_test_probe 0\n");
/* Initialize */
gpio_priv = kzalloc(sizeof(struct gpio_priv_t), GFP_KERNEL);
if (gpio_priv == NULL) {
pr_alert("Not enough memory to initialize device\n");
return -ENOMEM;
}
ret = misc_register(&gpio_test_dev);
if (ret < 0)
goto err;
return 0;
err:
printk("gpio_test register failed\n");
kfree(gpio_priv);
gpio_priv = NULL;
return ret;
}
static int __devexit gpio_test_remove(struct platform_device *plat)
{
kfree(gpio_priv);
gpio_priv = NULL;
misc_deregister(&gpio_test_dev);
printk("gpio_test remove\n");
return 0;
}
static struct platform_driver gpio_test_driver = {
.probe = gpio_test_probe,
.remove = gpio_test_remove,
.driver = {
.name = "gpio_test",
.owner = THIS_MODULE,
},
};
static int __init gpio_test_init(void)
{
printk("
最新技术文章: