Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
i2c-bme280
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
robinwilliam.hundt
i2c-bme280
Commits
b0a7e7f9
Commit
b0a7e7f9
authored
5 years ago
by
robinwilliam.hundt
Browse files
Options
Downloads
Patches
Plain Diff
It works!
parent
38620b64
Branches
master
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
i2c-bme280.c
+63
-1
63 additions, 1 deletion
i2c-bme280.c
with
63 additions
and
1 deletion
i2c-bme280.c
+
63
−
1
View file @
b0a7e7f9
...
...
@@ -3,8 +3,70 @@
#include
<linux/module.h>
struct
comp_params
{
unsigned
short
dig_T1
;
short
dig_T2
;
short
dig_T3
;
};
static
int
read_data
(
struct
i2c_client
*
client
,
char
*
buf
,
char
start_addr
,
int
count
)
{
int
ret
=
0
;
ret
=
i2c_master_send
(
client
,
&
start_addr
,
1
);
if
(
ret
<
0
)
{
pr_err
(
"send: %d
\n
"
,
ret
);
}
ret
=
i2c_master_recv
(
client
,
buf
,
count
);
if
(
ret
<
0
)
{
pr_err
(
"recv: %d
\n
"
,
ret
);
}
return
ret
;
}
static
struct
comp_params
get_comp_params
(
struct
i2c_client
*
client
)
{
char
buf
[
6
];
int
ret
;
ret
=
read_data
(
client
,
buf
,
0x88
,
6
);
if
(
ret
<
0
)
{
pr_err
(
"Unable ro read comp params: %d
\n
"
,
ret
);
}
return
(
struct
comp_params
)
{
.
dig_T1
=
buf
[
1
]
<<
8
|
buf
[
0
],
.
dig_T2
=
buf
[
3
]
<<
8
|
buf
[
2
],
.
dig_T3
=
buf
[
5
]
<<
8
|
buf
[
4
]
};
}
// Returns temperature in DegC, resolution is 0.01 DegC. Output value of “5123” equals 51.23 DegC.
// t_fine carries fine temperature as global value
static
int
compensate_temp
(
int
adc_T
,
struct
comp_params
*
params
)
{
unsigned
short
dig_T1
=
params
->
dig_T1
;
short
dig_T2
=
params
->
dig_T2
;
short
dig_T3
=
params
->
dig_T3
;
int
var1
,
var2
,
T
;
var1
=
((((
adc_T
>>
3
)
-
((
int
)
dig_T1
<<
1
)))
*
((
int
)
dig_T2
))
>>
11
;
var2
=
(((((
adc_T
>>
4
)
-
((
int
)
dig_T1
))
*
((
adc_T
>>
4
)
-
((
int
)
dig_T1
)))
>>
12
)
*
((
int
)
dig_T3
))
>>
14
;
T
=
((
var1
+
var2
)
*
5
+
128
)
>>
8
;
return
T
;
}
static
int
i2c_bme_probe
(
struct
i2c_client
*
client
,
const
struct
i2c_device_id
*
id
)
{
pr_info
(
"%s probe"
,
client
->
name
);
char
recv_buf
[
3
];
int
ret
;
int
uncomp_temp
;
struct
comp_params
params
=
get_comp_params
(
client
);
pr_info
(
"%s probe
\n
"
,
client
->
name
);
ret
=
read_data
(
client
,
recv_buf
,
0xFA
,
3
);
if
(
ret
<
0
)
{
pr_err
(
"Unable ro read temp: %d
\n
"
,
ret
);
}
uncomp_temp
=
recv_buf
[
0
]
<<
12
|
recv_buf
[
1
]
<<
4
|
((
recv_buf
[
2
]
>>
4
)
&
0x0F0
);
ret
=
compensate_temp
(
uncomp_temp
,
&
params
);
pr_info
(
"%02X %02X %02X
\n
"
,
recv_buf
[
0
],
recv_buf
[
1
],
recv_buf
[
2
]);
pr_info
(
"Uncomp temp: %d
\n
"
,
uncomp_temp
);
pr_info
(
"Temp: %d
\n
"
,
ret
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment