day4
This commit is contained in:
52
Day4/README.md
Normal file
52
Day4/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
|
||||
### I/O框架
|
||||
显示屏、串口通信、flash、SD卡、以太网接口
|
||||
图
|
||||
open,close...
|
||||
### 派生设备种类
|
||||

|
||||
### 字符设备、块设备
|
||||
#### 字符设备
|
||||
顺序读取:键盘、串口
|
||||
#### 块设备
|
||||
随机读取:硬盘、SD卡、NAND FLASH
|
||||
### 为什么分类设备
|
||||
一类的控制相同
|
||||
### 例子
|
||||
RT_D
|
||||
|
||||
##
|
||||
### 创建销毁设备
|
||||
### 注册销毁
|
||||
### flags
|
||||
分行?
|
||||
### 实验1:注册
|
||||
|
||||
### 访问
|
||||
### 查找、初始化
|
||||
### 打开、关闭
|
||||
### 打开标志位
|
||||
### 控制设备
|
||||
### 读写设备
|
||||
### 回调
|
||||
### 调用关系图
|
||||
|
||||
IO设备管理层
|
||||
PIN设备驱动框架层
|
||||
PIN设备驱动层
|
||||
|
||||
## GPIO
|
||||
引脚:电源、时钟、控制、I/O
|
||||
GPIO,功能复用I/O
|
||||
可编程控制中断
|
||||

|
||||
rt_pin_mode()
|
||||
rt_pin_write()
|
||||
rt_pin_read()
|
||||
|
||||

|
||||
|
||||
### 外部中断
|
||||
|
||||
## I2C总线
|
19
Day4/SConscript
Normal file
19
Day4/SConscript
Normal file
@@ -0,0 +1,19 @@
|
||||
from building import *
|
||||
import os
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
|
||||
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):
|
||||
src += ['arduino_main.cpp']
|
||||
|
||||
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
for item in list:
|
||||
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
||||
group = group + SConscript(os.path.join(item, 'SConscript'))
|
||||
|
||||
Return('group')
|
BIN
Day4/image-1.png
Normal file
BIN
Day4/image-1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
Day4/image-2.png
Normal file
BIN
Day4/image-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 287 KiB |
BIN
Day4/image.png
Normal file
BIN
Day4/image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 466 KiB |
56
Day4/pin_irq_example.c
Normal file
56
Day4/pin_irq_example.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <drv_gpio.h>
|
||||
#include <rtdevice.h>
|
||||
#include <rtthread.h>
|
||||
#define LOG_TAG "pin.irq"
|
||||
#define LOG_LVL LOG_LVL_DBG
|
||||
#include <ulog.h>
|
||||
|
||||
#define KEY_UP GET_PIN(C, 5)
|
||||
#define KEY_DOWN GET_PIN(C, 1)
|
||||
#define KEY_LEFT GET_PIN(C, 0)
|
||||
#define KEY_RIGHT GET_PIN(C, 4)
|
||||
|
||||
void key_up_callback(void *args)
|
||||
{
|
||||
int value = rt_pin_read(KEY_UP);
|
||||
LOG_I("key up value: %d\n", value);
|
||||
}
|
||||
|
||||
void key_down_callback(void *args)
|
||||
{
|
||||
int value = rt_pin_read(KEY_DOWN);
|
||||
LOG_I("key down value: %d\n", value);
|
||||
}
|
||||
|
||||
void key_left_callback(void *args)
|
||||
{
|
||||
int value = rt_pin_read(KEY_LEFT);
|
||||
LOG_I("key left value: %d\n", value);
|
||||
}
|
||||
|
||||
void key_right_callback(void *args)
|
||||
{
|
||||
int value = rt_pin_read(KEY_RIGHT);
|
||||
LOG_I("key right value: %d\n", value);
|
||||
}
|
||||
|
||||
static int rt_pin_irq_example(void)
|
||||
{
|
||||
rt_pin_mode(KEY_UP, PIN_MODE_INPUT_PULLUP);
|
||||
rt_pin_mode(KEY_DOWN, PIN_MODE_INPUT_PULLUP);
|
||||
rt_pin_mode(KEY_LEFT, PIN_MODE_INPUT_PULLUP);
|
||||
rt_pin_mode(KEY_RIGHT, PIN_MODE_INPUT_PULLUP);
|
||||
|
||||
rt_pin_attach_irq(KEY_UP, PIN_IRQ_MODE_FALLING, key_up_callback, RT_NULL);
|
||||
rt_pin_attach_irq(KEY_DOWN, PIN_IRQ_MODE_FALLING, key_down_callback, RT_NULL);
|
||||
rt_pin_attach_irq(KEY_LEFT, PIN_IRQ_MODE_FALLING, key_left_callback, RT_NULL);
|
||||
rt_pin_attach_irq(KEY_RIGHT, PIN_IRQ_MODE_FALLING, key_right_callback, RT_NULL);
|
||||
|
||||
rt_pin_irq_enable(KEY_UP,PIN_IRQ_ENABLE);
|
||||
rt_pin_irq_enable(KEY_DOWN,PIN_IRQ_ENABLE);
|
||||
rt_pin_irq_enable(KEY_LEFT,PIN_IRQ_ENABLE);
|
||||
rt_pin_irq_enable(KEY_RIGHT,PIN_IRQ_ENABLE);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(rt_pin_irq_example,irq, pin_irq_example);
|
18
Day4/test_drv_example.c
Normal file
18
Day4/test_drv_example.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
static int rt_device_test_init(void)
|
||||
{
|
||||
rt_device_t test_dev = rt_device_create(RT_Device_Class_Char,0);
|
||||
if(!test_dev)
|
||||
{
|
||||
rt_kprintf("test_dev create failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
if(rt_device_register(test_dev,"test_dev",RT_DEVICE_FLAG_RDWR)!=RT_EOK)
|
||||
{
|
||||
rt_kprintf("test_dev register failed\n");
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(rt_device_test_init,devtest, test device init);
|
Reference in New Issue
Block a user