Dawn Framework
1.0
Universal data acquisition framework for embedded systems
dawn
src
porting
nuttx
leds.cxx
1
// dawn/src/porting/nuttx/leds.cxx
2
//
3
// SPDX-License-Identifier: Apache-2.0
4
//
5
6
#include "dawn/porting/leds.hxx"
7
8
#include <errno.h>
9
#include <fcntl.h>
10
#include <nuttx/leds/userled.h>
11
#include <sys/ioctl.h>
12
#include <unistd.h>
13
14
#include "dawn/debug.hxx"
15
#include "dawn/porting/config.hxx"
16
17
//***************************************************************************
18
// Public Functions
19
//***************************************************************************
20
21
//***************************************************************************
22
// Name: leds_open
23
//***************************************************************************
24
25
int
leds_open(
const
char
*path)
26
{
27
int
fd;
28
29
#ifdef CONFIG_DAWN_NUTTX_BOARDS_COMPAT
30
path =
"/dev/userled"
;
31
#endif
32
33
fd = open(path, O_RDWR);
34
DAWNINFO(
"LEDS: open %s %d\n"
, path, fd);
35
if
(fd < 0)
36
{
37
DAWNERR(
"Failed to open LEDS file %s (error %d)\n"
, path, fd);
38
return
-EIO;
39
}
40
return
fd;
41
}
42
43
//***************************************************************************
44
// Name: leds_close
45
//***************************************************************************
46
47
void
leds_close(
int
fd)
48
{
49
if
(fd >= 0)
50
{
51
close(fd);
52
}
53
}
54
55
//***************************************************************************
56
// Name: leds_read
57
//***************************************************************************
58
59
int
leds_read(
int
fd, uint32_t *leds)
60
{
61
return
ioctl(fd, ULEDIOC_GETALL,
reinterpret_cast<
unsigned
long
>
(leds));
62
}
63
64
//***************************************************************************
65
// Name: leds_write
66
//***************************************************************************
67
68
int
leds_write(
int
fd, uint32_t leds)
69
{
70
return
ioctl(fd, ULEDIOC_SETALL, leds);
71
}
Generated by
1.9.8