Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multipass
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
derf
multipass
Commits
178835c1
Commit
178835c1
authored
6 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Add AM2320 driver
parent
8579b2a1
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+5
-0
5 additions, 0 deletions
Makefile
include/driver/am2320.h
+22
-0
22 additions, 0 deletions
include/driver/am2320.h
src/app/i2cdetect/main.cc
+14
-0
14 additions, 0 deletions
src/app/i2cdetect/main.cc
src/driver/am2320.cc
+61
-0
61 additions, 0 deletions
src/driver/am2320.cc
with
102 additions
and
0 deletions
Makefile
+
5
−
0
View file @
178835c1
...
...
@@ -14,6 +14,11 @@ ifneq ($(findstring lm75,${drivers}), )
COMMON_FLAGS
+=
-DDRIVER_LM75
endif
ifneq
($(findstring am2320,${drivers}), )
TARGETS
+=
src/driver/am2320.cc
COMMON_FLAGS
+=
-DDRIVER_AM2320
endif
ifneq
($(findstring max44006,${drivers}), )
TARGETS
+=
src/driver/max44006.cc
COMMON_FLAGS
+=
-DDRIVER_MAX44006
...
...
This diff is collapsed.
Click to expand it.
include/driver/am2320.h
0 → 100644
+
22
−
0
View file @
178835c1
#ifndef AM2320_H
#define AM2320_H
class
AM2320
{
private:
AM2320
(
const
AM2320
&
copy
);
unsigned
char
const
address
;
unsigned
char
txbuf
[
3
];
unsigned
char
rxbuf
[
8
];
public:
AM2320
(
unsigned
char
const
addr
)
:
address
(
addr
)
{}
void
read
();
unsigned
char
getStatus
();
float
getTemp
();
float
getHumidity
();
};
extern
AM2320
am2320
;
#endif
This diff is collapsed.
Click to expand it.
src/app/i2cdetect/main.cc
+
14
−
0
View file @
178835c1
...
...
@@ -9,6 +9,9 @@
#ifdef DRIVER_LM75
#include
"driver/lm75.h"
#endif
#ifdef DRIVER_AM2320
#include
"driver/am2320.h"
#endif
#ifdef DRIVER_MAX44009
#include
"driver/max44009.h"
#endif
...
...
@@ -22,6 +25,17 @@ void loop(void)
kout
.
printf_float
(
lm75
.
getTemp
());
kout
<<
endl
;
#endif
#ifdef DRIVER_AM2320
am2320
.
read
();
if
(
am2320
.
getStatus
()
==
0
)
{
kout
.
printf_float
(
am2320
.
getTemp
());
kout
<<
" degC @ "
;
kout
.
printf_float
(
am2320
.
getHumidity
());
kout
<<
" rel%"
<<
endl
;
}
else
{
kout
<<
"AM2320 error "
<<
dec
<<
am2320
.
getStatus
()
<<
endl
;
}
#endif
#ifdef DRIVER_MAX44009
kout
.
printf_float
(
max44009
.
getLux
());
kout
<<
endl
;
...
...
This diff is collapsed.
Click to expand it.
src/driver/am2320.cc
0 → 100644
+
61
−
0
View file @
178835c1
#include
"driver/am2320.h"
#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C)
#include
"driver/i2c.h"
#else
#include
"driver/soft_i2c.h"
#endif
#include
"arch.h"
void
AM2320
::
read
()
{
txbuf
[
0
]
=
0
;
i2c
.
xmit
(
address
,
1
,
txbuf
,
0
,
rxbuf
);
arch
.
delay_ms
(
1
);
txbuf
[
0
]
=
3
;
txbuf
[
1
]
=
0
;
txbuf
[
2
]
=
4
;
rxbuf
[
3
]
=
rxbuf
[
4
]
=
rxbuf
[
5
]
=
rxbuf
[
6
]
=
0
;
i2c
.
xmit
(
address
,
3
,
txbuf
,
0
,
rxbuf
);
arch
.
delay_ms
(
3
);
i2c
.
xmit
(
address
,
0
,
txbuf
,
8
,
rxbuf
);
}
unsigned
char
AM2320
::
getStatus
()
{
if
(
rxbuf
[
0
]
!=
3
)
{
return
1
;
}
if
(
rxbuf
[
1
]
!=
4
)
{
return
2
;
}
unsigned
short
checksum
=
0xffff
;
for
(
unsigned
char
i
=
0
;
i
<
6
;
i
++
)
{
checksum
^=
rxbuf
[
i
]
&
0x00ff
;
for
(
unsigned
char
j
=
0
;
j
<
8
;
j
++
)
{
if
(
checksum
&
0x0001
)
{
checksum
=
(
checksum
>>
1
)
^
0xa001
;
}
else
{
checksum
>>=
1
;
}
}
}
if
((
rxbuf
[
6
]
!=
(
checksum
&
0x00ff
))
||
(
rxbuf
[
7
]
!=
(
checksum
>>
8
)
&
0x00ff
))
{
return
3
;
}
return
0
;
}
float
AM2320
::
getTemp
()
{
if
(
txbuf
[
5
]
&
0x80
)
{
return
(
-
256
*
(
rxbuf
[
4
]
&
0x7f
)
+
rxbuf
[
5
])
/
10.
;
}
return
(
256
*
rxbuf
[
4
]
+
rxbuf
[
5
])
/
10.
;
}
float
AM2320
::
getHumidity
()
{
return
(
rxbuf
[
2
]
*
256
+
rxbuf
[
3
])
/
10.
;
}
AM2320
am2320
(
0x5c
);
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