amiro-lld / source / P9221R / v1 / alld_P9221R_v1.c @ 9797f02a
History | View | Annotate | Download (6.505 KB)
1 | 6ef38c23 | Julia Niermann | /*
|
---|---|---|---|
2 | AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU Lesser General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU Lesser General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | /**
|
||
20 | * @file alld_P9221R_v1.c
|
||
21 | *
|
||
22 | * @brief Power Monitor function implementations
|
||
23 | *
|
||
24 | * @addtogroup lld_power
|
||
25 | * @{
|
||
26 | */
|
||
27 | |||
28 | 54dbb62d | Julia Niermann | #include <alld_P9221R.h> |
29 | 6ef38c23 | Julia Niermann | |
30 | 54dbb62d | Julia Niermann | #if (defined(AMIROLLD_CFG_P9221R) && (AMIROLLD_CFG_P9221R == 1)) || defined(__DOXYGEN__) |
31 | 6ef38c23 | Julia Niermann | |
32 | /******************************************************************************/
|
||
33 | /* LOCAL DEFINITIONS */
|
||
34 | /******************************************************************************/
|
||
35 | |||
36 | /******************************************************************************/
|
||
37 | /* EXPORTED VARIABLES */
|
||
38 | /******************************************************************************/
|
||
39 | |||
40 | /******************************************************************************/
|
||
41 | /* LOCAL TYPES */
|
||
42 | /******************************************************************************/
|
||
43 | |||
44 | /******************************************************************************/
|
||
45 | /* LOCAL VARIABLES */
|
||
46 | /******************************************************************************/
|
||
47 | |||
48 | /******************************************************************************/
|
||
49 | /* LOCAL FUNCTIONS */
|
||
50 | /******************************************************************************/
|
||
51 | |||
52 | /******************************************************************************/
|
||
53 | /* EXPORTED FUNCTIONS */
|
||
54 | /******************************************************************************/
|
||
55 | |||
56 | |||
57 | /**
|
||
58 | * @brief Read the value of one or more of the registers.
|
||
59 | * @param[in] i2cd i2c driver
|
||
60 | * @param[in] PRd p9221r driver
|
||
61 | * @param[in] addr register address
|
||
62 | * @param[out] data register content
|
||
63 | * @param[in] num number of subsequent registers to read
|
||
64 | * @param[in] timeout timeout
|
||
65 | * @return An indicator whether the call was successfull
|
||
66 | */
|
||
67 | 9797f02a | Julia Niermann | apalExitStatus_t p9221r_lld_read_register(const P9221RDriver* const p9221r, const p9221r_lld_register_t addr, uint8_t* const data, const uint8_t num, const apalTime_t timeout) |
68 | 6ef38c23 | Julia Niermann | { |
69 | apalDbgAssert(p9221r != NULL);
|
||
70 | apalDbgAssert(p9221r->i2cd != NULL);
|
||
71 | apalDbgAssert(data != NULL);
|
||
72 | |||
73 | 9797f02a | Julia Niermann | uint8_t buffer[num]; |
74 | for (uint8_t i = 0; i < num; ++i) { |
||
75 | 067c98f7 | Julia Niermann | buffer[i] = 1;
|
76 | } |
||
77 | 9797f02a | Julia Niermann | apalExitStatus_t status = apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), (uint8_t*)&addr, 1, buffer, num, timeout);
|
78 | 6ef38c23 | Julia Niermann | for (uint8_t dataIdx = 0; dataIdx < num; dataIdx++) { |
79 | 9797f02a | Julia Niermann | //data[dataIdx] = (buffer[2*dataIdx] << 8) | buffer[2*dataIdx+1];
|
80 | data[dataIdx] = buffer[dataIdx]; |
||
81 | // TODO test!
|
||
82 | 6ef38c23 | Julia Niermann | } |
83 | return status;
|
||
84 | } |
||
85 | |||
86 | /**
|
||
87 | * @brief Write the value of one or more of the registers.
|
||
88 | * @param[in] i2cd i2c driver
|
||
89 | * @param[in] PRd p9221r driver
|
||
90 | * @param[in] addr register address
|
||
91 | * @param[in] data data to write
|
||
92 | * @param[in] num number of subsequent registers to read
|
||
93 | * @param[in] timeout timeout
|
||
94 | * @return An indicator whether the call was successfull
|
||
95 | */
|
||
96 | 2344a771 | Julia Niermann | apalExitStatus_t p9221r_lld_write_register(const P9221RDriver* const p9221r, const p9221r_lld_register_t addr, const uint16_t* const data, const uint8_t num, const apalTime_t timeout) |
97 | 6ef38c23 | Julia Niermann | { |
98 | apalDbgAssert(p9221r != NULL);
|
||
99 | apalDbgAssert(p9221r->i2cd != NULL);
|
||
100 | apalDbgAssert(data != NULL);
|
||
101 | |||
102 | uint8_t buffer[1+2*num]; |
||
103 | buffer[0] = addr;
|
||
104 | for (uint8_t dataIdx = 0; dataIdx < num; dataIdx++) { |
||
105 | buffer[dataIdx*2+1] = data[dataIdx] >> 8; |
||
106 | buffer[dataIdx*2+2] = data[dataIdx] & (0x00FFu); |
||
107 | } |
||
108 | 2344a771 | Julia Niermann | return apalI2CMasterTransmit(p9221r->i2cd, (P9221R_LLD_I2C_ADDR_FIXED | p9221r->addr), buffer, 1+2*num, NULL, 0, timeout); |
109 | 6ef38c23 | Julia Niermann | } |
110 | |||
111 | 9797f02a | Julia Niermann | /**
|
112 | * @brief Read the x_alignment.
|
||
113 | * @param[in] i2cd i2c driver
|
||
114 | * @param[in] PRd p9221r driver
|
||
115 | * @param[out] x_alignment alignment register content
|
||
116 | * @param[in] timeout timeout
|
||
117 | * @return An indicator whether the call was successfull
|
||
118 | */
|
||
119 | apalExitStatus_t p9221r_lld_read_x_alignment(const P9221RDriver* const p9221r, int32_t const x_alignment, const apalTime_t timeout) |
||
120 | { |
||
121 | apalExitStatus_t status = NULL;
|
||
122 | |||
123 | return status;
|
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * @brief Read the y_alignment.
|
||
128 | * @param[in] i2cd i2c driver
|
||
129 | * @param[in] PRd p9221r driver
|
||
130 | * @param[out] y_alignment alignment register content
|
||
131 | * @param[in] timeout timeout
|
||
132 | * @return An indicator whether the call was successfull
|
||
133 | */
|
||
134 | apalExitStatus_t p9221r_lld_read_y_alignment(const P9221RDriver* const p9221r, int32_t const y_alignment, const apalTime_t timeout) |
||
135 | { |
||
136 | apalExitStatus_t status = NULL;
|
||
137 | |||
138 | return status;
|
||
139 | } |
||
140 | |||
141 | /**
|
||
142 | * @brief Read the voltage.
|
||
143 | * @param[in] i2cd i2c driver
|
||
144 | * @param[in] PRd p9221r driver
|
||
145 | * @param[out] voltage voltage register content
|
||
146 | * @param[in] timeout timeout
|
||
147 | * @return An indicator whether the call was successfull
|
||
148 | */
|
||
149 | apalExitStatus_t p9221r_lld_read_voltage(const P9221RDriver* const p9221r, int32_t const voltage, const apalTime_t timeout) |
||
150 | { |
||
151 | apalExitStatus_t status = NULL;
|
||
152 | |||
153 | return status;
|
||
154 | } |
||
155 | |||
156 | /**
|
||
157 | * @brief Read the current.
|
||
158 | * @param[in] i2cd i2c driver
|
||
159 | * @param[in] PRd p9221r driver
|
||
160 | * @param[out] current register content
|
||
161 | * @param[in] timeout timeout
|
||
162 | * @return An indicator whether the call was successfull
|
||
163 | */
|
||
164 | apalExitStatus_t p9221r_lld_read_current(const P9221RDriver* const p9221r, int32_t const current, const apalTime_t timeout) |
||
165 | { |
||
166 | apalExitStatus_t status = NULL;
|
||
167 | |||
168 | return status;
|
||
169 | } |
||
170 | |||
171 | |||
172 | 54dbb62d | Julia Niermann | #endif /* defined(AMIROLLD_CFG_P9221R) && (AMIROLLD_CFG_P9221R == 1) */ |
173 | 6ef38c23 | Julia Niermann | |
174 | |||
175 | |||
176 | |||
177 | |||
178 | |||
179 | |||
180 | |||
181 | |||
182 | |||
183 | |||
184 | |||
185 | |||
186 | |||
187 | |||
188 | |||
189 | |||
190 | |||
191 | |||
192 | |||
193 | |||
194 | |||
195 | |||
196 | |||
197 | |||
198 | |||
199 | |||
200 |