2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <peripheral_io.h>
20 #include "test_peripheral_pwm.h"
23 #define PWM_CHIP_INVALID -99
25 #define PWM_PIN_INVALID -99
26 #define PWM_PERIOD 1000
27 #define PWM_DUTY_CYCLE 100
29 static bool g_feature = true;
33 int test_peripheral_io_pwm_initialize(char *model, bool feature)
37 if ((!strcmp(model, "rpi3")) || (!strcmp(model, "artik"))) {
46 int test_peripheral_io_pwm_peripheral_pwm_open_p(void)
48 int ret = PERIPHERAL_ERROR_NONE;
50 peripheral_pwm_h pwm_h = NULL;
52 if (g_feature == false) {
53 ret = peripheral_pwm_open(chip, pin, &pwm_h);
54 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
57 ret = peripheral_pwm_open(chip, pin, &pwm_h);
58 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
60 ret = peripheral_pwm_close(pwm_h);
61 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
64 return PERIPHERAL_ERROR_NONE;
67 int test_peripheral_io_pwm_peripheral_pwm_open_n1(void)
69 int ret = PERIPHERAL_ERROR_NONE;
71 peripheral_pwm_h pwm_h = NULL;
73 if (g_feature == false) {
74 ret = peripheral_pwm_open(PWM_CHIP_INVALID, pin, &pwm_h);
75 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
78 ret = peripheral_pwm_open(PWM_CHIP_INVALID, pin, &pwm_h);
79 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
82 return PERIPHERAL_ERROR_NONE;
85 int test_peripheral_io_pwm_peripheral_pwm_open_n2(void)
87 int ret = PERIPHERAL_ERROR_NONE;
89 peripheral_pwm_h pwm_h = NULL;
91 if (g_feature == false) {
92 ret = peripheral_pwm_open(chip, PWM_PIN_INVALID, &pwm_h);
93 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
96 ret = peripheral_pwm_open(chip, PWM_PIN_INVALID, &pwm_h);
97 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
100 return PERIPHERAL_ERROR_NONE;
103 int test_peripheral_io_pwm_peripheral_pwm_open_n3(void)
105 int ret = PERIPHERAL_ERROR_NONE;
107 if (g_feature == false) {
108 ret = peripheral_pwm_open(chip, pin, NULL);
109 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
112 ret = peripheral_pwm_open(chip, pin, NULL);
113 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
116 return PERIPHERAL_ERROR_NONE;
119 int test_peripheral_io_pwm_peripheral_pwm_close_p(void)
121 int ret = PERIPHERAL_ERROR_NONE;
123 peripheral_pwm_h pwm_h = NULL;
125 if (g_feature == false) {
126 ret = peripheral_pwm_close(pwm_h);
127 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
130 ret = peripheral_pwm_open(chip, pin, &pwm_h);
131 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
133 ret = peripheral_pwm_close(pwm_h);
134 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
137 return PERIPHERAL_ERROR_NONE;
140 int test_peripheral_io_pwm_peripheral_pwm_close_n(void)
142 int ret = PERIPHERAL_ERROR_NONE;
144 if (g_feature == false) {
145 ret = peripheral_pwm_close(NULL);
146 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
149 ret = peripheral_pwm_close(NULL);
150 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
153 return PERIPHERAL_ERROR_NONE;
156 int test_peripheral_io_pwm_peripheral_pwm_set_period_p(void)
158 int ret = PERIPHERAL_ERROR_NONE;
160 peripheral_pwm_h pwm_h = NULL;
162 if (g_feature == false) {
163 ret = peripheral_pwm_set_period(pwm_h, PWM_PERIOD);
164 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
167 ret = peripheral_pwm_open(chip, pin, &pwm_h);
168 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
170 ret = peripheral_pwm_set_period(pwm_h, PWM_PERIOD);
171 if (ret != PERIPHERAL_ERROR_NONE) {
172 peripheral_pwm_close(pwm_h);
173 return PERIPHERAL_ERROR_UNKNOWN;
176 ret = peripheral_pwm_close(pwm_h);
177 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
180 return PERIPHERAL_ERROR_NONE;
183 int test_peripheral_io_pwm_peripheral_pwm_set_period_n(void)
185 int ret = PERIPHERAL_ERROR_NONE;
187 if (g_feature == false) {
188 ret = peripheral_pwm_set_period(NULL, PWM_PERIOD);
189 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
192 ret = peripheral_pwm_set_period(NULL, PWM_PERIOD);
193 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
196 return PERIPHERAL_ERROR_NONE;
199 int test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_p(void)
201 int ret = PERIPHERAL_ERROR_NONE;
203 peripheral_pwm_h pwm_h = NULL;
205 if (g_feature == false) {
206 ret = peripheral_pwm_set_duty_cycle(pwm_h, PWM_DUTY_CYCLE);
207 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
210 ret = peripheral_pwm_open(chip, pin, &pwm_h);
211 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
213 ret = peripheral_pwm_set_duty_cycle(pwm_h, PWM_DUTY_CYCLE);
214 if (ret != PERIPHERAL_ERROR_NONE) {
215 peripheral_pwm_close(pwm_h);
216 return PERIPHERAL_ERROR_UNKNOWN;
219 ret = peripheral_pwm_close(pwm_h);
220 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
223 return PERIPHERAL_ERROR_NONE;
226 int test_peripheral_io_pwm_peripheral_pwm_set_duty_cycle_n(void)
228 int ret = PERIPHERAL_ERROR_NONE;
230 if (g_feature == false) {
231 ret = peripheral_pwm_set_duty_cycle(NULL, PWM_DUTY_CYCLE);
232 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
235 ret = peripheral_pwm_set_duty_cycle(NULL, PWM_DUTY_CYCLE);
236 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
239 return PERIPHERAL_ERROR_NONE;
242 int test_peripheral_io_pwm_peripheral_pwm_set_polarity_p1(void)
244 int ret = PERIPHERAL_ERROR_NONE;
246 peripheral_pwm_h pwm_h = NULL;
248 if (g_feature == false) {
249 ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH);
250 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
253 ret = peripheral_pwm_open(chip, pin, &pwm_h);
254 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
256 ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH);
257 if (ret != PERIPHERAL_ERROR_NONE) {
258 peripheral_pwm_close(pwm_h);
259 return PERIPHERAL_ERROR_UNKNOWN;
262 ret = peripheral_pwm_close(pwm_h);
263 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
266 return PERIPHERAL_ERROR_NONE;
269 int test_peripheral_io_pwm_peripheral_pwm_set_polarity_p2(void)
271 int ret = PERIPHERAL_ERROR_NONE;
273 peripheral_pwm_h pwm_h = NULL;
275 if (g_feature == false) {
276 ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_LOW);
277 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
280 ret = peripheral_pwm_open(chip, pin, &pwm_h);
281 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
283 ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_LOW);
284 if (ret != PERIPHERAL_ERROR_NONE) {
285 peripheral_pwm_close(pwm_h);
286 return PERIPHERAL_ERROR_UNKNOWN;
289 ret = peripheral_pwm_close(pwm_h);
290 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
293 return PERIPHERAL_ERROR_NONE;
296 int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n1(void)
298 int ret = PERIPHERAL_ERROR_NONE;
300 if (g_feature == false) {
301 ret = peripheral_pwm_set_polarity(NULL, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH);
302 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
305 ret = peripheral_pwm_set_polarity(NULL, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH);
306 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
309 return PERIPHERAL_ERROR_NONE;
312 int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n2(void)
314 int ret = PERIPHERAL_ERROR_NONE;
316 peripheral_pwm_h pwm_h = NULL;
318 if (g_feature == false) {
319 ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH - 1);
320 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
323 ret = peripheral_pwm_open(chip, pin, &pwm_h);
324 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
326 ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH - 1);
327 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
328 peripheral_pwm_close(pwm_h);
329 return PERIPHERAL_ERROR_UNKNOWN;
332 ret = peripheral_pwm_close(pwm_h);
333 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
336 return PERIPHERAL_ERROR_NONE;
339 int test_peripheral_io_pwm_peripheral_pwm_set_polarity_n3(void)
341 int ret = PERIPHERAL_ERROR_NONE;
343 peripheral_pwm_h pwm_h = NULL;
345 if (g_feature == false) {
346 ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_LOW + 1);
347 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
350 ret = peripheral_pwm_open(chip, pin, &pwm_h);
351 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
353 ret = peripheral_pwm_set_polarity(pwm_h, PERIPHERAL_PWM_POLARITY_ACTIVE_LOW + 1);
354 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) {
355 peripheral_pwm_close(pwm_h);
356 return PERIPHERAL_ERROR_UNKNOWN;
359 ret = peripheral_pwm_close(pwm_h);
360 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
363 return PERIPHERAL_ERROR_NONE;
366 int test_peripheral_io_pwm_peripheral_pwm_set_enabled_p1(void)
368 int ret = PERIPHERAL_ERROR_NONE;
370 peripheral_pwm_h pwm_h = NULL;
374 if (g_feature == false) {
375 ret = peripheral_pwm_set_enabled(pwm_h, enable);
376 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
379 ret = peripheral_pwm_open(chip, pin, &pwm_h);
380 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
382 ret = peripheral_pwm_set_enabled(pwm_h, enable);
383 if (ret != PERIPHERAL_ERROR_NONE) {
384 peripheral_pwm_close(pwm_h);
385 return PERIPHERAL_ERROR_UNKNOWN;
388 ret = peripheral_pwm_close(pwm_h);
389 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
392 return PERIPHERAL_ERROR_NONE;
395 int test_peripheral_io_pwm_peripheral_pwm_set_enabled_p2(void)
397 int ret = PERIPHERAL_ERROR_NONE;
399 peripheral_pwm_h pwm_h = NULL;
403 if (g_feature == false) {
404 ret = peripheral_pwm_set_enabled(pwm_h, enable);
405 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
408 ret = peripheral_pwm_open(chip, pin, &pwm_h);
409 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
411 ret = peripheral_pwm_set_enabled(pwm_h, enable);
412 if (ret != PERIPHERAL_ERROR_NONE) {
413 peripheral_pwm_close(pwm_h);
414 return PERIPHERAL_ERROR_UNKNOWN;
417 ret = peripheral_pwm_close(pwm_h);
418 if (ret != PERIPHERAL_ERROR_NONE) return PERIPHERAL_ERROR_UNKNOWN;
421 return PERIPHERAL_ERROR_NONE;
424 int test_peripheral_io_pwm_peripheral_pwm_set_enabled_n(void)
426 int ret = PERIPHERAL_ERROR_NONE;
430 if (g_feature == false) {
431 ret = peripheral_pwm_set_enabled(NULL, enable);
432 if (ret != PERIPHERAL_ERROR_NOT_SUPPORTED) return PERIPHERAL_ERROR_UNKNOWN;
435 ret = peripheral_pwm_set_enabled(NULL, enable);
436 if (ret != PERIPHERAL_ERROR_INVALID_PARAMETER) return PERIPHERAL_ERROR_UNKNOWN;
439 return PERIPHERAL_ERROR_NONE;