Dawn Framework 1.0
Universal data acquisition framework for embedded systems
pot.cxx
1// dawn/src/porting/nuttx/pot.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/porting/pot.hxx"
7
8#include <errno.h>
9#include <fcntl.h>
10#include <nuttx/analog/pot.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: pot_open
23//***************************************************************************
24
25int pot_open(const char *path)
26{
27 int fd;
28
29 fd = open(path, O_RDWR | O_NONBLOCK);
30 DAWNINFO("POT: open %s %d\n", path, fd);
31 if (fd < 0)
32 {
33 DAWNERR("Failed to open POT file %s (error %d)\n", path, fd);
34 return -EIO;
35 }
36 return fd;
37}
38
39//***************************************************************************
40// Name: pot_close
41//***************************************************************************
42
43void pot_close(int fd)
44{
45 if (fd >= 0)
46 {
47 close(fd);
48 }
49}
50
51//***************************************************************************
52// Name: pot_get_nwipers
53//***************************************************************************
54
55int pot_get_nwipers(int fd, uint8_t *nwipers)
56{
57 struct pot_info_s info;
58 int ret;
59
60 ret = ioctl(fd, POTIOC_GET_INFO, reinterpret_cast<unsigned long>(&info));
61 if (ret < 0)
62 {
63 return -errno;
64 }
65
66 *nwipers = info.nwipers;
67 return ret;
68}
69
70//***************************************************************************
71// Name: pot_set_wiper
72//***************************************************************************
73
74int pot_set_wiper(int fd, dawn::porting::pot_rw_s *pot)
75{
76 struct pot_wiper_s wiper;
77 int ret;
78
79 wiper.wiper = pot->wiper;
80 wiper.val = pot->val;
81
82 ret = ioctl(fd, POTIOC_SET_WIPER, reinterpret_cast<unsigned long>(&wiper));
83 if (ret < 0)
84 {
85 return -errno;
86 }
87
88 return ret;
89}
90
91//***************************************************************************
92// Name: pot_get_wiper
93//***************************************************************************
94
95int pot_get_wiper(int fd, dawn::porting::pot_rw_s *pot)
96{
97 struct pot_wiper_s wiper;
98 int ret;
99
100 wiper.wiper = pot->wiper;
101 wiper.val = 0;
102
103 ret = ioctl(fd, POTIOC_GET_WIPER, reinterpret_cast<unsigned long>(&wiper));
104 if (ret < 0)
105 {
106 return -errno;
107 }
108
109 pot->val = wiper.val;
110 return ret;
111}
POT wiper access data.
Definition pot.hxx:22