Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
8f4e8066
R
rt-thread
项目概览
wwsmg1
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8f4e8066
编写于
7月 20, 2017
作者:
A
Aubr.Cool
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Components] driver i2c add fm24clxx drv
上级
6ab02767
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
197 addition
and
0 deletion
+197
-0
components/drivers/i2c/fm24clxx.c
components/drivers/i2c/fm24clxx.c
+157
-0
components/drivers/i2c/fm24clxx.h
components/drivers/i2c/fm24clxx.h
+40
-0
未找到文件。
components/drivers/i2c/fm24clxx.c
0 → 100644
浏览文件 @
8f4e8066
/*
* File : fm24clxx.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-07-14 aubr.cool 1st version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "fm24clxx.h"
struct
fm24clxx_device
{
struct
rt_device
parent
;
struct
rt_i2c_bus_device
*
bus
;
};
/* RT-Thread device interface */
static
rt_err_t
fm24clxx_init
(
rt_device_t
dev
)
{
return
RT_EOK
;
}
static
rt_err_t
fm24clxx_open
(
rt_device_t
dev
,
rt_uint16_t
oflag
)
{
return
RT_EOK
;
}
static
rt_err_t
fm24clxx_close
(
rt_device_t
dev
)
{
return
RT_EOK
;
}
static
rt_err_t
fm24clxx_control
(
rt_device_t
dev
,
rt_uint8_t
cmd
,
void
*
args
)
{
return
RT_EOK
;
}
static
rt_size_t
fm24clxx_read
(
rt_device_t
dev
,
rt_off_t
pos
,
void
*
buffer
,
rt_size_t
size
)
{
struct
fm24clxx_device
*
fm24clxx
;
const
struct
fm24clxx_config
*
cfg
;
struct
rt_i2c_msg
msg
[
2
];
rt_uint8_t
mem_addr
[
2
]
=
{
0
,};
rt_size_t
ret
=
0
;
RT_ASSERT
(
dev
!=
0
);
fm24clxx
=
(
struct
fm24clxx_device
*
)
dev
;
RT_ASSERT
(
fm24clxx
->
parent
.
user_data
!=
0
);
cfg
=
(
const
struct
fm24clxx_config
*
)
fm24clxx
->
parent
.
user_data
;
if
(
pos
>
cfg
->
size
)
{
return
0
;
}
if
(
pos
+
size
>
cfg
->
size
)
{
size
=
cfg
->
size
-
pos
;
}
msg
[
0
].
addr
=
cfg
->
addr
;
msg
[
0
].
flags
=
cfg
->
flags
|
RT_I2C_WR
;
mem_addr
[
0
]
=
(
pos
>>
8
);
mem_addr
[
1
]
=
(
rt_uint8_t
)
pos
;
msg
[
0
].
buf
=
(
rt_uint8_t
*
)
mem_addr
;
msg
[
0
].
len
=
2
;
msg
[
1
].
addr
=
cfg
->
addr
;
msg
[
1
].
flags
=
cfg
->
flags
|
RT_I2C_RD
;
msg
[
1
].
buf
=
(
rt_uint8_t
*
)
buffer
;
msg
[
1
].
len
=
size
;
ret
=
rt_i2c_transfer
(
fm24clxx
->
bus
,
msg
,
2
);
return
(
ret
==
2
)
?
size
:
0
;
}
static
rt_size_t
fm24clxx_write
(
rt_device_t
dev
,
rt_off_t
pos
,
const
void
*
buffer
,
rt_size_t
size
)
{
struct
fm24clxx_device
*
fm24clxx
;
const
struct
fm24clxx_config
*
cfg
;
struct
rt_i2c_msg
msg
[
2
];
rt_uint8_t
mem_addr
[
2
]
=
{
0
,};
rt_size_t
ret
=
0
;
RT_ASSERT
(
dev
!=
0
);
fm24clxx
=
(
struct
fm24clxx_device
*
)
dev
;
RT_ASSERT
(
fm24clxx
->
parent
.
user_data
!=
0
);
cfg
=
(
const
struct
fm24clxx_config
*
)
fm24clxx
->
parent
.
user_data
;
if
(
pos
>
cfg
->
size
)
{
return
0
;
}
if
(
pos
+
size
>
cfg
->
size
)
{
size
=
cfg
->
size
-
pos
;
}
msg
[
0
].
addr
=
cfg
->
addr
;
msg
[
0
].
flags
=
cfg
->
flags
|
RT_I2C_WR
;
mem_addr
[
0
]
=
(
pos
>>
8
);
mem_addr
[
1
]
=
(
rt_uint8_t
)
pos
;
msg
[
0
].
buf
=
(
rt_uint8_t
*
)
mem_addr
;
msg
[
0
].
len
=
2
;
msg
[
1
].
addr
=
cfg
->
addr
;
msg
[
1
].
flags
=
cfg
->
flags
|
RT_I2C_WR
|
RT_I2C_NO_START
;
msg
[
1
].
buf
=
(
rt_uint8_t
*
)
buffer
;
msg
[
1
].
len
=
size
;
ret
=
rt_i2c_transfer
(
fm24clxx
->
bus
,
msg
,
2
);
return
(
ret
==
2
)
?
size
:
0
;
}
rt_err_t
fm24clxx_register
(
const
char
*
fm_device_name
,
const
char
*
i2c_bus
,
void
*
user_data
)
{
static
struct
fm24clxx_device
fm24clxx_drv
;
struct
rt_i2c_bus_device
*
bus
;
bus
=
rt_i2c_bus_device_find
(
i2c_bus
);
if
(
bus
==
RT_NULL
)
{
return
RT_ENOSYS
;
}
fm24clxx_drv
.
bus
=
bus
;
fm24clxx_drv
.
parent
.
type
=
RT_Device_Class_Block
;
fm24clxx_drv
.
parent
.
init
=
fm24clxx_init
;
fm24clxx_drv
.
parent
.
open
=
fm24clxx_open
;
fm24clxx_drv
.
parent
.
close
=
fm24clxx_close
;
fm24clxx_drv
.
parent
.
read
=
fm24clxx_read
;
fm24clxx_drv
.
parent
.
write
=
fm24clxx_write
;
fm24clxx_drv
.
parent
.
control
=
fm24clxx_control
;
fm24clxx_drv
.
parent
.
user_data
=
user_data
;
return
rt_device_register
(
&
fm24clxx_drv
.
parent
,
fm_device_name
,
RT_DEVICE_FLAG_RDWR
);
}
\ No newline at end of file
components/drivers/i2c/fm24clxx.h
0 → 100644
浏览文件 @
8f4e8066
/*
* File : fm24clxx.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2017-07-14 aubr.cool 1st version
*/
#ifndef __FM24CLXX_H__
#define __FM24CLXX_H__
#include <rtthread.h>
struct
fm24clxx_config
{
rt_uint32_t
size
;
rt_uint16_t
addr
;
rt_uint16_t
flags
;
};
extern
rt_err_t
fm24clxx_register
(
const
char
*
e2m_device_name
,
const
char
*
i2c_bus
,
void
*
user_data
);
#endif
/*__FM24CLXX_H__*/
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录