Dawn Framework 1.0
Universal data acquisition framework for embedded systems
dac.cxx
1// dawn/src/porting/nuttx/dac.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/porting/dac.hxx"
7
8#include <errno.h>
9#include <fcntl.h>
10#include <nuttx/analog/dac.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: dac_open
23//***************************************************************************
24
25int dac_open(const char *path)
26{
27 int fd;
28
29 fd = open(path, O_WRONLY | O_NONBLOCK);
30 DAWNINFO("DAC: open %s %d\n", path, fd);
31 if (fd < 0)
32 {
33 DAWNERR("Failed to open DAC file %s (error %d)\n", path, fd);
34 return -EIO;
35 }
36 return fd;
37}
38
39//***************************************************************************
40// Name: dac_close
41//***************************************************************************
42
43void dac_close(int fd)
44{
45 if (fd)
46 {
47 close(fd);
48 }
49}
50
51//***************************************************************************
52// Name: dac_init
53//***************************************************************************
54
55void dac_init(int fd)
56{
57 // Channel validation is the IO layer's responsibility.
58
59 (void)fd;
60}
61
62//***************************************************************************
63// Name: dac_write
64//***************************************************************************
65
66int dac_write(int fd, dawn::porting::dac_write_s *dac)
67{
68 struct dac_msg_s msg;
69
70 msg.am_channel = 0;
71 msg.am_data = dac->data;
72
73 return static_cast<int>(write(fd, &msg, sizeof(struct dac_msg_s)));
74}
DAC write data.
Definition dac.hxx:22