杨培文

Yang Peiwen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0"?>
<root>
<item>
<name>罗技鼠标反转</name>
<identifier>logitech.mouse_reverse</identifier>
<device_only>
DeviceVendor::LOGITECH
</device_only>
<autogen>
__FlipScrollWheel__
<!-- reverse vertical scrolling -->
Option::FLIPSCROLLWHEEL_VERTICAL
</autogen>
</item>
</root>

在 Misc & Uninstall 中 Open private.xml ,然后将上面的代码粘贴,在 Change Key 中 Reload XML ,勾选罗技鼠标反转,即可自动区分鼠标与触控板,触控板保持自然方向,鼠标保持原来的滚动方向。

1
2
3
4
5
mkdir ~/.pip/ 
nano ~/.pip/pip.conf
[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com

首先我们需要将启动的命令写入/etc/init.d/目录下:

1
2
3
sudo nano /etc/init.d/ypwtest

/usr/bin/aria2c --enable-rpc --rpc-listen-all=true --rpc-allow-origin-all
然后Ctrl+X保存退出,执行下面的命令:
1
update-rc.d ypwtest defaults 99
如果不想要这个启动项了,可以执行这个:
1
update-rc.d -f ypwtest remove

makefile:

1
2
3
4
5
6
7
8
9
obj-m:=gpio.o
mymodule-objs:=gpio
KDIR:=/home/ypw/Desktop/linux-3.4.y/
MAKE:=make
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <mach/platform.h>
#include <mach/devices.h>
#include <mach/soc.h>
#include <mach/gpio.h>

#define DEVICE_NAME “gpio”

#define OUTPUT 1
#define INPUT 0
#define HIGH 1
#define LOW 0

unsigned int GPIOC11 = PAD_GPIO_C + 11;

//GPIOC11
static int gpio_init(void){
printk(“init\n”);
gpio_request(GPIOC11, “test”);
gpio_direction_output(GPIOC11, 1);
gpio_set_value(GPIOC11, HIGH);
printk(“gpio_set_value HIGH\n”);
return 0;
}

static void gpio_exit(void){
printk(“gpio_set_value LOW\n”);
gpio_set_value(GPIOC11, LOW);
gpio_free(GPIOC11);
printk(“exit\n”);
}

module_init(gpio_init);
module_exit(gpio_exit);

MODULE_LICENSE(“GPL”);
MODULE_AUTHOR(“YPW”);

今天我们目的是实现串口回环测试,意思就是自己给自己发,然后自己接收到自己发送的内容。

首先呢,根据pinMap我们可以知道,8脚是UART3_TXD,10脚是UART3_RXD,所以我们需要将NanoPi2的8脚和10脚用杜邦线接起来。

然后呢,我们连接NanoPi2,写一个程序循环读取串口数据,并打印到屏幕上。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
int main()
{
int fd = -1;
fd = open("/dev/ttyAMA2", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
perror("Open Serial Port Error!\n");
return -1;
}

struct termios options;
tcgetattr(fd, &options);
//115200, 8N1
options.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
options.c_iflag = IGNPAR;
options.c_oflag = 0;
options.c_lflag = 0;
options.c_cc[VTIME]=0;
options.c_cc[VMIN]=1;
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &options);
unsigned char rx_buffer[256];
while(1){
int rx_length = read(fd, (void*)rx_buffer, 255);
if (rx_length > 0)
{
//Bytes received
rx_buffer[rx_length] = '\0';
printf("%i bytes read : %s\n", rx_length, rx_buffer);
}
}
close(fd);
return 0;
}

1
2
3
nano read.c
gcc read.c -o read
./read

然后我们向串口写入数据:

1
2
3
echo hello > /dev/ttyAMA2
echo test > /dev/ttyAMA2
echo hahaha > /dev/ttyAMA2

read程序就会输出刚才发送的字符,带换行。

0%