Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
cm-projects
RIOT
Commits
a13ab5ee
Commit
a13ab5ee
authored
6 years ago
by
Leandro Lanzieri
Browse files
Options
Downloads
Patches
Plain Diff
drivers/ad7746: Add SAUL integration
parent
afeb5c1e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
drivers/ad7746/ad7746_saul.c
+95
-0
95 additions, 0 deletions
drivers/ad7746/ad7746_saul.c
sys/auto_init/auto_init.c
+4
-0
4 additions, 0 deletions
sys/auto_init/auto_init.c
sys/auto_init/saul/auto_init_ad7746.c
+93
-0
93 additions, 0 deletions
sys/auto_init/saul/auto_init_ad7746.c
with
192 additions
and
0 deletions
drivers/ad7746/ad7746_saul.c
0 → 100644
+
95
−
0
View file @
a13ab5ee
/*
* Copyright (C) 2019 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup drivers_ad7746
* @{
*
* @file
* @brief AD7746 adaption to the RIOT actuator/sensor interface
*
* @author Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
*
* @}
*/
#include
<string.h>
#include
<stdio.h>
#include
"saul.h"
#include
"ad7746.h"
static
int
_read_cap
(
const
void
*
dev
,
phydat_t
*
res
)
{
int
val
;
if
(
ad7746_read_capacitance_1
((
ad7746_t
*
)
dev
,
&
val
))
{
return
-
ECANCELED
;
}
res
->
val
[
0
]
=
val
;
res
->
unit
=
UNIT_F
;
res
->
scale
=
-
15
;
return
1
;
}
static
int
_read_temp
(
const
void
*
dev
,
phydat_t
*
res
)
{
int
val
;
int
result
;
do
{
result
=
ad7746_read_temperature_int
((
ad7746_t
*
)
dev
,
&
val
);
}
while
(
result
==
AD7746_NODATA
);
if
(
result
==
AD7746_OK
)
{
res
->
val
[
0
]
=
val
;
res
->
unit
=
UNIT_TEMP_C
;
res
->
scale
=
0
;
return
1
;
}
else
{
return
-
ECANCELED
;
}
}
static
int
_read_volt
(
const
void
*
dev
,
phydat_t
*
res
)
{
int
val
;
int
result
;
do
{
result
=
ad7746_read_voltage_in
((
ad7746_t
*
)
dev
,
&
val
);
}
while
(
result
==
AD7746_NODATA
);
if
(
result
==
AD7746_OK
)
{
res
->
val
[
0
]
=
val
;
res
->
unit
=
UNIT_V
;
res
->
scale
=
-
3
;
return
1
;
}
else
{
return
-
ECANCELED
;
}
}
const
saul_driver_t
ad7746_saul_driver_cap
=
{
.
read
=
_read_cap
,
.
write
=
saul_notsup
,
.
type
=
SAUL_SENSE_CAPACITANCE
,
};
const
saul_driver_t
ad7746_saul_driver_temp
=
{
.
read
=
_read_temp
,
.
write
=
saul_notsup
,
.
type
=
SAUL_SENSE_TEMP
};
const
saul_driver_t
ad7746_saul_driver_volt
=
{
.
read
=
_read_volt
,
.
write
=
saul_notsup
,
.
type
=
SAUL_SENSE_VOLTAGE
};
This diff is collapsed.
Click to expand it.
sys/auto_init/auto_init.c
+
4
−
0
View file @
a13ab5ee
...
...
@@ -321,6 +321,10 @@ void auto_init(void)
extern
void
auto_init_gpio
(
void
);
auto_init_gpio
();
#endif
#ifdef MODULE_AD7746
extern
void
auto_init_ad7746
(
void
);
auto_init_ad7746
();
#endif
#ifdef MODULE_ADCXX1C
extern
void
auto_init_adcxx1c
(
void
);
auto_init_adcxx1c
();
...
...
This diff is collapsed.
Click to expand it.
sys/auto_init/saul/auto_init_ad7746.c
0 → 100644
+
93
−
0
View file @
a13ab5ee
/*
* Copyright (C) 2019 HAW Hamburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*
*/
/**
* @ingroup sys_auto_init_saul
* @{
*
* @file
* @brief Auto initialization of AD7746
*
* @author Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
*
* @}
*/
#ifdef MODULE_AD7746
#include
"assert.h"
#include
"log.h"
#include
"saul_reg.h"
#include
"ad7746.h"
#include
"ad7746_params.h"
/**
* @brief Define the number of configured sensors
*/
#define AD7746_NUM (sizeof(ad7746_params) / sizeof(ad7746_params[0]))
/**
* @brief Allocate memory for the device descriptors.
*/
static
ad7746_t
ad7746_devs
[
AD7746_NUM
];
/**
* @brief Memory for the SAUL registry entries. Each device provides
* 3 SAUL entries (capacitance, temperature and voltage)
*/
static
saul_reg_t
saul_entries
[
AD7746_NUM
*
3
];
/**
* @brief Define the number of saul info
*/
#define AD7746_INFO_NUM (sizeof(ad7746_saul_info) / sizeof(ad7746_saul_info[0]))
/**
* @brief Reference the driver structs
* @{
*/
extern
saul_driver_t
ad7746_saul_driver_cap
;
extern
saul_driver_t
ad7746_saul_driver_temp
;
extern
saul_driver_t
ad7746_saul_driver_volt
;
/** @} */
void
auto_init_ad7746
(
void
)
{
assert
(
AD7746_INFO_NUM
==
AD7746_NUM
);
for
(
unsigned
i
=
0
;
i
<
AD7746_NUM
;
i
++
)
{
LOG_DEBUG
(
"[auto_init_saul] initializing ad7746 #%d
\n
"
,
i
);
if
(
ad7746_init
(
&
ad7746_devs
[
i
],
&
ad7746_params
[
i
])
<
0
)
{
LOG_ERROR
(
"[auto_init_saul] error initializing ad7746 #%d
\n
"
,
i
);
continue
;
}
/* add capacitance driver */
saul_entries
[
i
].
dev
=
&
(
ad7746_devs
[
i
]);
saul_entries
[
i
].
name
=
ad7746_saul_info
[
i
].
name
;
saul_entries
[
i
].
driver
=
&
ad7746_saul_driver_cap
;
saul_reg_add
(
&
(
saul_entries
[
i
]));
/* add temperature driver */
saul_entries
[
i
+
1
].
dev
=
&
(
ad7746_devs
[
i
]);
saul_entries
[
i
+
1
].
name
=
ad7746_saul_info
[
i
].
name
;
saul_entries
[
i
+
1
].
driver
=
&
ad7746_saul_driver_temp
;
saul_reg_add
(
&
(
saul_entries
[
i
+
1
]));
/* add voltage driver */
saul_entries
[
i
+
2
].
dev
=
&
(
ad7746_devs
[
i
]);
saul_entries
[
i
+
2
].
name
=
ad7746_saul_info
[
i
].
name
;
saul_entries
[
i
+
2
].
driver
=
&
ad7746_saul_driver_volt
;
saul_reg_add
(
&
(
saul_entries
[
i
+
2
]));
}
}
#else
typedef
int
dont_be_pedantic
;
#endif
/* MODULE_AD7746 */
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