2 * Copyright (c) 2016-2018 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.
17 #ifndef __TIZEN_SYSTEM_PERIPHERAL_IO_H__
18 #define __TIZEN_SYSTEM_PERIPHERAL_IO_H__
28 * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_MODULE
33 * @file peripheral_io.h
34 * @brief This file contains the peripheral-io API.
38 * @brief Enumeration for peripheral-io error.
42 PERIPHERAL_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
43 PERIPHERAL_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
44 PERIPHERAL_ERROR_NO_DEVICE = TIZEN_ERROR_NO_SUCH_DEVICE, /**< No such device */
45 PERIPHERAL_ERROR_TRY_AGAIN = TIZEN_ERROR_TRY_AGAIN, /**< Try again */
46 PERIPHERAL_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
47 PERIPHERAL_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
48 PERIPHERAL_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */
49 PERIPHERAL_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
50 PERIPHERAL_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
51 PERIPHERAL_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN, /**< Unknown error */
59 * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE
64 * @brief Enumeration of GPIO direction options.
68 PERIPHERAL_GPIO_DIRECTION_IN = 0, /**< Input Mode */
69 PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH, /**< Output mode with high value */
70 PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW, /**< Output mode with low value */
71 } peripheral_gpio_direction_e;
74 * @brief Enumeration of edge types for the GPIO interrupt.
78 PERIPHERAL_GPIO_EDGE_NONE = 0, /**< No interrupt on GPIO */
79 PERIPHERAL_GPIO_EDGE_RISING, /**< Interrupt on rising only */
80 PERIPHERAL_GPIO_EDGE_FALLING, /**< Interrupt on falling only */
81 PERIPHERAL_GPIO_EDGE_BOTH, /**< Interrupt on rising & falling */
82 } peripheral_gpio_edge_e;
85 * @brief The handle of a GPIO pin.
88 typedef struct _peripheral_gpio_s *peripheral_gpio_h;
92 * @brief Opens a GPIO pin.
95 * @privilege http://tizen.org/privilege/peripheralio
96 * @remarks @a gpio should be released with peripheral_gpio_close()
98 * @param[in] gpio_pin The GPIO pin number
99 * @param[out] gpio The GPIO handle is created on success
101 * @return 0 on success, otherwise a negative error value
102 * @retval #PERIPHERAL_ERROR_NONE Successful
103 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
104 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
105 * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
106 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
107 * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
108 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
109 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
110 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
112 * @post peripheral_gpio_close()
114 EXPORT_API int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio);
118 * @brief Closes a GPIO pin.
120 * @privlevel platform
121 * @privilege http://tizen.org/privilege/peripheralio
123 * @param[in] gpio The GPIO handle
125 * @return 0 on success, otherwise a negative error value
126 * @retval #PERIPHERAL_ERROR_NONE Successful
127 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
128 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
129 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
130 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
131 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
132 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
134 * @pre peripheral_gpio_open()
136 EXPORT_API int peripheral_gpio_close(peripheral_gpio_h gpio);
140 * @brief Sets the GPIO direction.
142 * @privlevel platform
143 * @privilege http://tizen.org/privilege/peripheralio
144 * @remarks To set the direction to #PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH or #PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW, the edge mode must be set to #PERIPHERAL_GPIO_EDGE_NONE.
146 * @param[in] gpio The GPIO handle
147 * @param[in] direction The direction of the GPIO pin
149 * @return 0 on success, otherwise a negative error value
150 * @retval #PERIPHERAL_ERROR_NONE Successful
151 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
152 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
153 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
154 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
155 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
156 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
158 * @see peripheral_gpio_direction_e
159 * @see peripheral_gpio_set_edge_mode()
161 EXPORT_API int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
165 * @brief Sets the GPIO edge mode.
167 * @privlevel platform
168 * @privilege http://tizen.org/privilege/peripheralio
169 * @remarks To set the edge mode to #PERIPHERAL_GPIO_EDGE_RISING, #PERIPHERAL_GPIO_EDGE_FALLING, #PERIPHERAL_GPIO_EDGE_BOTH, the data direction must be set to the #PERIPHERAL_GPIO_DIRECTION_IN.
171 * @param[in] gpio The GPIO handle
172 * @param[in] edge The edge mode of the GPIO pin
174 * @return 0 on success, otherwise a negative error value
175 * @retval #PERIPHERAL_ERROR_NONE Successful
176 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
177 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
178 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
179 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
180 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
181 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
183 * @see peripheral_gpio_edge_e
184 * @see peripheral_gpio_set_direction()
186 EXPORT_API int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
190 * @brief The GPIO interrupted callback called when the GPIO interrupt is triggered.
191 * @details The following errors can be received: \n
192 * #PERIPHERAL_ERROR_NONE Successful \n
193 * #PERIPHERAL_ERROR_IO_ERROR I/O operation failed \n
194 * #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed \n
195 * #PERIPHERAL_ERROR_TRY_AGAIN Try again \n
196 * #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed \n
197 * #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied \n
198 * #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use \n
199 * #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter \n
200 * #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported \n
201 * #PERIPHERAL_ERROR_UNKNOWN Unknown internal error \n
204 * @param[in] gpio The GPIO handle
205 * @param[in] error The GPIO error
206 * @param[in] user_data The user data passed from the callback registration function
208 * @see peripheral_gpio_set_interrupted_cb()
210 typedef void(*peripheral_gpio_interrupted_cb)(peripheral_gpio_h gpio, peripheral_error_e error, void *user_data);
214 * @brief Sets the GPIO interrupted callback to be invoked when the GPIO interrupt is triggered.
216 * @privlevel platform
217 * @privilege http://tizen.org/privilege/peripheralio
218 * @remarks The interrupted callback is unset when called peripheral_gpio_unset_interrupted_cb() or callback receives an error value other than #PERIPHERAL_ERROR_NONE.
220 * @param[in] gpio The GPIO handle
221 * @param[in] callback The GPIO interrupted callback function to set
222 * @param[in] user_data The user data to be passed to the callback function
224 * @return 0 on success, otherwise a negative error value
225 * @retval #PERIPHERAL_ERROR_NONE Successful
226 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
227 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
228 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
230 * @post peripheral_gpio_unset_interrupted_cb()
231 * @see peripheral_gpio_set_edge_mode()
233 EXPORT_API int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data);
237 * @brief Unsets the GPIO interrupted callback.
239 * @privlevel platform
240 * @privilege http://tizen.org/privilege/peripheralio
242 * @param[in] gpio The GPIO handle
244 * @return 0 on success, otherwise a negative error value
245 * @retval #PERIPHERAL_ERROR_NONE Successful
246 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
247 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
248 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
250 * @pre peripheral_gpio_set_interrupted_cb()
252 EXPORT_API int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio);
256 * @brief Gets the current value of the GPIO pin.
258 * @privlevel platform
259 * @privilege http://tizen.org/privilege/peripheralio
261 * @param[in] gpio The GPIO handle
262 * @param[out] value The value to get
264 * @return 0 on success, otherwise a negative error value
265 * @retval #PERIPHERAL_ERROR_NONE Successful
266 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
267 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
268 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
269 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
270 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
271 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
273 * @see peripheral_gpio_write()
275 EXPORT_API int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value);
279 * @brief Sets the value of the GPIO pin.
281 * @privlevel platform
282 * @privilege http://tizen.org/privilege/peripheralio
283 * @remarks To write binary data, the direction must be set to #PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_HIGH or #PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW.
285 * @param[in] gpio The GPIO handle
286 * @param[in] value The value to set (must be 0 or 1)
288 * @return 0 on success, otherwise a negative error value
289 * @retval #PERIPHERAL_ERROR_NONE Successful
290 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
291 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
292 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
293 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
294 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
295 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
297 * @see peripheral_gpio_read()
298 * @see peripheral_gpio_set_direction()
300 EXPORT_API int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value);
307 * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE
312 * @brief The handle of the I2C slave device.
315 typedef struct _peripheral_i2c_s *peripheral_i2c_h;
319 * @brief Opens an I2C slave device.
321 * @privlevel platform
322 * @privilege http://tizen.org/privilege/peripheralio
323 * @remarks @a i2c should be released with peripheral_i2c_close()
325 * @param[in] bus The I2C bus number that the slave device is connected
326 * @param[in] address The address of the slave device
327 * @param[out] i2c The I2C handle is created on success
329 * @return 0 on success, otherwise a negative error value
330 * @retval #PERIPHERAL_ERROR_NONE Successful
331 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
332 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
333 * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
334 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
335 * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
336 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
337 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
338 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
340 * @post peripheral_i2c_close()
342 EXPORT_API int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c);
345 * @brief Enumeration for open flags (bitmask).
348 * @remarks Enum values are supposed to be used as bitmask, where only one
349 * value can be specified for following flag groups:
350 * - locking mode - either #PERIPHERAL_OPEN_FLAGS_PRIVATE or #PERIPHERAL_OPEN_FLAGS_SHARED can be used
352 * The #PERIPHERAL_OPEN_FLAGS_NONBLOCK can be used with all other available flags.
355 PERIPHERAL_OPEN_FLAGS_PRIVATE = 0, /**< Exclusive access to device */
356 PERIPHERAL_OPEN_FLAGS_SHARED = 1, /**< Shared access to device */
357 PERIPHERAL_OPEN_FLAGS_NONBLOCK = 2, /**< Nonblocking read/write flag,
358 available for only uart (Since 7.5) */
359 } peripheral_open_flags_e;
363 * @brief Opens an I2C slave device.
365 * @privlevel platform
366 * @privilege http://tizen.org/privilege/peripheralio
367 * @remarks @a i2c should be released with peripheral_i2c_close()
369 * @param[in] bus The I2C bus number that the slave device is connected
370 * @param[in] address The address of the slave device
371 * @param[in] flags The flags to open call
372 * @param[out] i2c The I2C handle is created on success
374 * @return 0 on success, otherwise a negative error value
375 * @retval #PERIPHERAL_ERROR_NONE Successful
376 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
377 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
378 * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
379 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
380 * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
381 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
382 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
383 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
385 * @post peripheral_i2c_close()
387 EXPORT_API int peripheral_i2c_open_flags(int bus, int address, peripheral_open_flags_e flags, peripheral_i2c_h *i2c);
391 * @brief Closes an I2C slave device.
393 * @privlevel platform
394 * @privilege http://tizen.org/privilege/peripheralio
396 * @param[in] i2c The I2C handle
398 * @return 0 on success, otherwise a negative error value
399 * @retval #PERIPHERAL_ERROR_NONE Successful
400 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
401 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
402 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
403 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
405 * @pre peripheral_i2c_open()
407 EXPORT_API int peripheral_i2c_close(peripheral_i2c_h i2c);
411 * @brief Reads the bytes data from the I2C slave device.
413 * @privlevel platform
414 * @privilege http://tizen.org/privilege/peripheralio
416 * @param[in] i2c The I2C handle
417 * @param[out] data The data buffer to read
418 * @param[in] length The size of data buffer (in bytes)
420 * @return 0 on success, otherwise a negative error value
421 * @retval #PERIPHERAL_ERROR_NONE Successful
422 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
423 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
424 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
425 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
426 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
428 * @see peripheral_i2c_write()
430 EXPORT_API int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length);
434 * @brief Writes the bytes data to the I2C slave device.
436 * @privlevel platform
437 * @privilege http://tizen.org/privilege/peripheralio
439 * @param[in] i2c The I2C handle
440 * @param[in] data The data buffer to write
441 * @param[in] length The size of data buffer (in bytes)
443 * @return 0 on success, otherwise a negative error value
444 * @retval #PERIPHERAL_ERROR_NONE Successful
445 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
446 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
447 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
448 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
449 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
451 * @see peripheral_i2c_read()
453 EXPORT_API int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length);
457 * @brief Reads single byte data from the register of the I2C slave device.
459 * @privlevel platform
460 * @privilege http://tizen.org/privilege/peripheralio
462 * @param[in] i2c The I2C handle
463 * @param[in] reg The register address of the I2C slave device to read
464 * @param[out] data The single byte data to read
466 * @return 0 on success, otherwise a negative error value
467 * @retval #PERIPHERAL_ERROR_NONE Successful
468 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
469 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
470 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
471 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
472 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
474 * @see peripheral_i2c_write_register_byte()
476 EXPORT_API int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data);
480 * @brief Writes single byte data to the register of the I2C slave device.
482 * @privlevel platform
483 * @privilege http://tizen.org/privilege/peripheralio
485 * @param[in] i2c The I2C handle
486 * @param[in] reg The register address of the I2C slave device to write
487 * @param[in] data The single byte data to write
489 * @return 0 on success, otherwise a negative error value
490 * @retval #PERIPHERAL_ERROR_NONE Successful
491 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
492 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
493 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
494 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
495 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
497 * @see peripheral_i2c_read_register_byte()
499 EXPORT_API int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data);
503 * @brief Reads word data from the register of the I2C slave device.
505 * @privlevel platform
506 * @privilege http://tizen.org/privilege/peripheralio
508 * @param[in] i2c The I2C handle
509 * @param[in] reg The register address of the I2C slave device to read
510 * @param[out] data The word(2 bytes) data to read
512 * @return 0 on success, otherwise a negative error value
513 * @retval #PERIPHERAL_ERROR_NONE Successful
514 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
515 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
516 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
517 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
518 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
520 * @see peripheral_i2c_write_register_word()
522 EXPORT_API int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data);
526 * @brief Writes word data to the register of the I2C slave device.
528 * @privlevel platform
529 * @privilege http://tizen.org/privilege/peripheralio
531 * @param[in] i2c The I2C handle
532 * @param[in] reg The register address of the I2C slave device to write
533 * @param[in] data The word(2 bytes) data to write
535 * @return 0 on success, otherwise a negative error value
536 * @retval #PERIPHERAL_ERROR_NONE Successful
537 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
538 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
539 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
540 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
541 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
543 * @see peripheral_i2c_read_register_word()
545 EXPORT_API int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data);
552 * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE
557 * @brief The handle of the PWM peripherals.
560 typedef struct _peripheral_pwm_s *peripheral_pwm_h;
563 * @brief Enumeration for Polarity.
567 PERIPHERAL_PWM_POLARITY_ACTIVE_HIGH = 0, /**< PWM signal start in the active high state (Normal) */
568 PERIPHERAL_PWM_POLARITY_ACTIVE_LOW, /**< PWM signal start in the active low state (Inversed) */
569 } peripheral_pwm_polarity_e;
573 * @brief Opens the PWM pin.
575 * @privlevel platform
576 * @privilege http://tizen.org/privilege/peripheralio
577 * @remarks @a pwm should be released with peripheral_pwm_close()
579 * @param[in] chip The PWM chip number
580 * @param[in] pin The PWM pin(channel) number to control
581 * @param[out] pwm The PWM handle is created on success
583 * @return 0 on success, otherwise a negative error value
584 * @retval #PERIPHERAL_ERROR_NONE Successful
585 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
586 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
587 * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
588 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
589 * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
590 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
591 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
592 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
594 * @post peripheral_pwm_close()
596 EXPORT_API int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm);
600 * @brief Closes the PWM pin.
602 * @privlevel platform
603 * @privilege http://tizen.org/privilege/peripheralio
605 * @param[in] pwm The PWM handle
607 * @return 0 on success, otherwise a negative error value
608 * @retval #PERIPHERAL_ERROR_NONE Successful
609 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
610 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
611 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
612 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
613 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
614 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
616 * @pre peripheral_pwm_open()
618 EXPORT_API int peripheral_pwm_close(peripheral_pwm_h pwm);
622 * @brief Sets period of the PWM pin.
624 * @privlevel platform
625 * @privilege http://tizen.org/privilege/peripheralio
627 * @param[in] pwm The PWM handle
628 * @param[in] period_ns The total period of the PWM pin (in nanoseconds)
630 * @return 0 on success, otherwise a negative error value
631 * @retval #PERIPHERAL_ERROR_NONE Successful
632 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
633 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
634 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
635 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
636 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
637 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
639 EXPORT_API int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns);
643 * @brief Sets duty cycle of the PWM pin.
645 * @privlevel platform
646 * @privilege http://tizen.org/privilege/peripheralio
648 * @param[in] pwm The PWM handle
649 * @param[in] duty_cycle_ns The duty cycle of the PWM pin (in nanoseconds)
651 * @return 0 on success, otherwise a negative error value
652 * @retval #PERIPHERAL_ERROR_NONE Successful
653 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
654 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
655 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
656 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
657 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
658 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
660 EXPORT_API int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns);
664 * @brief Sets polarity of the PWM pin.
666 * @privlevel platform
667 * @privilege http://tizen.org/privilege/peripheralio
669 * @param[in] pwm The PWM handle
670 * @param[in] polarity The polarity of the PWM pin
672 * @return 0 on success, otherwise a negative error value
673 * @retval #PERIPHERAL_ERROR_NONE Successful
674 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
675 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
676 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
677 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
678 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
679 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
681 * @see peripheral_pwm_polarity_e
683 EXPORT_API int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity);
687 * @brief Enables the PWM pin.
689 * @privlevel platform
690 * @privilege http://tizen.org/privilege/peripheralio
692 * @param[in] pwm The PWM handle
693 * @param[in] enabled Enable/disable the PWM pin
695 * @return 0 on success, otherwise a negative error value
696 * @retval #PERIPHERAL_ERROR_NONE Successful
697 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
698 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
699 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
700 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
701 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
702 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
704 EXPORT_API int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enabled);
711 * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_ADC_MODULE
716 * @brief The handle of the ADC peripherals.
719 typedef struct _peripheral_adc_s *peripheral_adc_h;
723 * @brief Opens the ADC pin.
725 * @privlevel platform
726 * @privilege http://tizen.org/privilege/peripheralio
727 * @remarks @a adc should be released with peripheral_adc_close()
729 * @param[in] device The ADC device number
730 * @param[in] channel The ADC channel number to control
731 * @param[out] adc The ADC handle is created on success
733 * @return 0 on success, otherwise a negative error value
734 * @retval #PERIPHERAL_ERROR_NONE Successful
735 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
736 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
737 * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
738 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
739 * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
740 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
741 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
742 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
744 * @post peripheral_adc_close()
746 EXPORT_API int peripheral_adc_open(int device, int channel, peripheral_adc_h *adc);
750 * @brief Closes the ADC pin.
752 * @privlevel platform
753 * @privilege http://tizen.org/privilege/peripheralio
755 * @param[in] adc The ADC handle
757 * @return 0 on success, otherwise a negative error value
758 * @retval #PERIPHERAL_ERROR_NONE Successful
759 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
760 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
761 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
762 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
763 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
764 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
766 * @pre peripheral_adc_open()
768 EXPORT_API int peripheral_adc_close(peripheral_adc_h adc);
772 * @brief Gets the current value of the ADC pin.
774 * @privlevel platform
775 * @privilege http://tizen.org/privilege/peripheralio
777 * @param[in] adc The ADC handle
778 * @param[out] value The value to get
780 * @return 0 on success, otherwise a negative error value
781 * @retval #PERIPHERAL_ERROR_NONE Successful
782 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
783 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
784 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
785 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
786 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
787 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
790 EXPORT_API int peripheral_adc_read(peripheral_adc_h adc, uint32_t *value);
797 * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE
802 * @brief The handle to the UART peripherals.
805 typedef struct _peripheral_uart_s *peripheral_uart_h;
808 * @brief Enumeration for baud rate.
812 PERIPHERAL_UART_BAUD_RATE_0 = 0, /**< The number of signal in one second is 0 */
813 PERIPHERAL_UART_BAUD_RATE_50, /**< The number of signal in one second is 50 */
814 PERIPHERAL_UART_BAUD_RATE_75, /**< The number of signal in one second is 75 */
815 PERIPHERAL_UART_BAUD_RATE_110, /**< The number of signal in one second is 110 */
816 PERIPHERAL_UART_BAUD_RATE_134, /**< The number of signal in one second is 134 */
817 PERIPHERAL_UART_BAUD_RATE_150, /**< The number of signal in one second is 150 */
818 PERIPHERAL_UART_BAUD_RATE_200, /**< The number of signal in one second is 200 */
819 PERIPHERAL_UART_BAUD_RATE_300, /**< The number of signal in one second is 300 */
820 PERIPHERAL_UART_BAUD_RATE_600, /**< The number of signal in one second is 600 */
821 PERIPHERAL_UART_BAUD_RATE_1200, /**< The number of signal in one second is 1200 */
822 PERIPHERAL_UART_BAUD_RATE_1800, /**< The number of signal in one second is 1800 */
823 PERIPHERAL_UART_BAUD_RATE_2400, /**< The number of signal in one second is 2400 */
824 PERIPHERAL_UART_BAUD_RATE_4800, /**< The number of signal in one second is 4800 */
825 PERIPHERAL_UART_BAUD_RATE_9600, /**< The number of signal in one second is 9600 */
826 PERIPHERAL_UART_BAUD_RATE_19200, /**< The number of signal in one second is 19200 */
827 PERIPHERAL_UART_BAUD_RATE_38400, /**< The number of signal in one second is 38400 */
828 PERIPHERAL_UART_BAUD_RATE_57600, /**< The number of signal in one second is 57600 */
829 PERIPHERAL_UART_BAUD_RATE_115200, /**< The number of signal in one second is 115200 */
830 PERIPHERAL_UART_BAUD_RATE_230400, /**< The number of signal in one second is 230400 */
831 } peripheral_uart_baud_rate_e;
834 * @brief Enumeration for byte size.
838 PERIPHERAL_UART_BYTE_SIZE_5BIT = 0, /**< 5 data bits */
839 PERIPHERAL_UART_BYTE_SIZE_6BIT, /**< 6 data bits */
840 PERIPHERAL_UART_BYTE_SIZE_7BIT, /**< 7 data bits */
841 PERIPHERAL_UART_BYTE_SIZE_8BIT, /**< 8 data bits */
842 } peripheral_uart_byte_size_e;
845 * @brief Enumeration for parity bit.
849 PERIPHERAL_UART_PARITY_NONE = 0, /**< No parity is used */
850 PERIPHERAL_UART_PARITY_EVEN, /**< Even parity is used */
851 PERIPHERAL_UART_PARITY_ODD, /**< ODD parity is used */
852 } peripheral_uart_parity_e;
855 * @brief Enumeration for stop bits.
859 PERIPHERAL_UART_STOP_BITS_1BIT = 0, /**< One stop bit */
860 PERIPHERAL_UART_STOP_BITS_2BIT, /**< Two stop bits */
861 } peripheral_uart_stop_bits_e;
864 * @brief Enumeration for hardware flow control.
868 PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_NONE = 0, /**< No hardware flow control */
869 PERIPHERAL_UART_HARDWARE_FLOW_CONTROL_AUTO_RTSCTS, /**< Automatic RTS/CTS hardware flow control*/
870 } peripheral_uart_hardware_flow_control_e;
873 * @brief Enumeration for software flow control.
877 PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_NONE = 0, /**< No software flow control */
878 PERIPHERAL_UART_SOFTWARE_FLOW_CONTROL_XONXOFF, /**< XON/XOFF software flow control */
879 } peripheral_uart_software_flow_control_e;
883 * @brief Opens the UART slave device.
885 * @privlevel platform
886 * @privilege http://tizen.org/privilege/peripheralio
887 * @remarks @a uart should be released with peripheral_uart_close()
889 * @param[in] port The UART port number that the slave device is connected
890 * @param[out] uart The UART handle is created on success
892 * @return 0 on success, otherwise a negative error value
893 * @retval #PERIPHERAL_ERROR_NONE Successful
894 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
895 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
896 * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
897 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
898 * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
899 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
900 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
901 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
903 * @post peripheral_uart_close()
905 EXPORT_API int peripheral_uart_open(int port, peripheral_uart_h *uart);
909 * @brief Opens the UART slave device.
911 * @privlevel platform
912 * @privilege http://tizen.org/privilege/peripheralio
913 * @remarks @a uart should be released with peripheral_uart_close()
915 * @param[in] port The UART port number that the slave device is connected
916 * @param[in] flags The flags to open call
917 * @param[out] uart The UART handle is created on success
919 * @return 0 on success, otherwise a negative error value
920 * @retval #PERIPHERAL_ERROR_NONE Successful
921 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
922 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
923 * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
924 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
925 * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
926 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
927 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
928 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
930 * @post peripheral_uart_close()
932 EXPORT_API int peripheral_uart_open_flags(int port, peripheral_open_flags_e flags, peripheral_uart_h *uart);
936 * @brief Closes the UART slave device.
938 * @privlevel platform
939 * @privilege http://tizen.org/privilege/peripheralio
941 * @param[in] uart The UART handle
943 * @return 0 on success, otherwise a negative error value
944 * @retval #PERIPHERAL_ERROR_NONE Successful
945 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
946 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
947 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
948 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
950 * @pre peripheral_uart_open()
952 EXPORT_API int peripheral_uart_close(peripheral_uart_h uart);
956 * @brief Sets baud rate of the UART slave device.
958 * @privlevel platform
959 * @privilege http://tizen.org/privilege/peripheralio
961 * @param[in] uart The UART handle
962 * @param[in] baud Baud rate of the UART slave device
964 * @return 0 on success, otherwise a negative error value
965 * @retval #PERIPHERAL_ERROR_NONE Successful
966 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
967 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
968 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
969 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
970 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
971 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
973 * @see peripheral_uart_baud_rate_e
975 EXPORT_API int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud);
979 * @brief Sets byte size of the UART slave device.
981 * @privlevel platform
982 * @privilege http://tizen.org/privilege/peripheralio
984 * @param[in] uart The UART handle
985 * @param[in] byte_size Byte size of the UART slave device
987 * @return 0 on success, otherwise a negative error value
988 * @retval #PERIPHERAL_ERROR_NONE Successful
989 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
990 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
991 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
992 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
993 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
994 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
996 * @see peripheral_uart_byte_size_e
998 EXPORT_API int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size);
1002 * @brief Sets parity bit of the UART slave device.
1004 * @privlevel platform
1005 * @privilege http://tizen.org/privilege/peripheralio
1007 * @param[in] uart The UART handle
1008 * @param[in] parity Parity bit of the UART slave device
1010 * @return 0 on success, otherwise a negative error value
1011 * @retval #PERIPHERAL_ERROR_NONE Successful
1012 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1013 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1014 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1015 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1016 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1017 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1019 * @see peripheral_uart_parity_e
1021 EXPORT_API int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity);
1025 * @brief Sets stop bits of the UART slave device.
1027 * @privlevel platform
1028 * @privilege http://tizen.org/privilege/peripheralio
1030 * @param[in] uart The UART handle
1031 * @param[in] stop_bits Stop bits of the UART slave device
1033 * @return 0 on success, otherwise a negative error value
1034 * @retval #PERIPHERAL_ERROR_NONE Successful
1035 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1036 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1037 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1038 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1039 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1040 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1042 * @see peripheral_uart_stop_bits_e
1044 EXPORT_API int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits);
1048 * @brief Sets flow control of the UART slave device.
1050 * @privlevel platform
1051 * @privilege http://tizen.org/privilege/peripheralio
1053 * @param[in] uart The UART handle
1054 * @param[in] sw_flow_control Software flow control (Turns a transmitter on or off)
1055 * @param[in] hw_flow_control Hardware flow control (Turns "Request to Send/Clear to Send" on or off)
1057 * @return 0 on success, otherwise a negative error value
1058 * @retval #PERIPHERAL_ERROR_NONE Successful
1059 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1060 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1061 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1062 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1063 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1064 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1066 * @see peripheral_uart_software_flow_control_e
1067 * @see peripheral_uart_hardware_flow_control_e
1069 EXPORT_API int peripheral_uart_set_flow_control(peripheral_uart_h uart,
1070 peripheral_uart_software_flow_control_e sw_flow_control,
1071 peripheral_uart_hardware_flow_control_e hw_flow_control);
1075 * @brief Reads data from the UART slave device.
1077 * @privlevel platform
1078 * @privilege http://tizen.org/privilege/peripheralio
1080 * @param[in] uart The UART handle
1081 * @param[out] data The buffer to read
1082 * @param[out] length The size of buffer (in bytes)
1084 * @return the number of bytes read on success, otherwise a negative error value
1085 * @retval #PERIPHERAL_ERROR_NONE Successful
1086 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1087 * @retval #PERIPHERAL_ERROR_TRY_AGAIN Try again
1088 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1089 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1090 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1091 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1093 * @see peripheral_uart_write()
1095 EXPORT_API int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length);
1100 * @brief Discards data queued for writing to UART slave device, but not yet transmitted.
1102 * @privlevel platform
1103 * @privilege http://tizen.org/privilege/peripheralio
1105 * @param[in] uart The UART handle
1107 * @return #PERIPHERAL_ERROR_NONE on success, otherwise a negative error value
1108 * @retval #PERIPHERAL_ERROR_NONE Successful
1109 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1110 * @retval #PERIPHERAL_ERROR_TRY_AGAIN Try again
1111 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1112 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1113 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1114 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1117 EXPORT_API int peripheral_uart_flush(peripheral_uart_h uart);
1121 * @brief Waits for all data queued for UART to be transmitted.
1123 * @privlevel platform
1124 * @privilege http://tizen.org/privilege/peripheralio
1126 * @param[in] uart The UART handle
1128 * @return #PERIPHERAL_ERROR_NONE on success, otherwise a negative error value
1129 * @retval #PERIPHERAL_ERROR_NONE Successful
1130 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1131 * @retval #PERIPHERAL_ERROR_TRY_AGAIN Try again
1132 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1133 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1134 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1135 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1138 EXPORT_API int peripheral_uart_drain(peripheral_uart_h uart);
1142 * @brief Writes data to the UART slave device.
1144 * @privlevel platform
1145 * @privilege http://tizen.org/privilege/peripheralio
1147 * @param[in] uart The UART handle
1148 * @param[in] data The buffer to write
1149 * @param[in] length The size of buffer (in bytes)
1151 * @return the number of bytes write on success, otherwise a negative error value
1152 * @retval #PERIPHERAL_ERROR_NONE Successful
1153 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1154 * @retval #PERIPHERAL_ERROR_TRY_AGAIN Try again
1155 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1156 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1157 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1158 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1160 * @see peripheral_uart_read()
1162 EXPORT_API int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length);
1169 * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE
1174 * @brief The handle of a SPI peripherals.
1177 typedef struct _peripheral_spi_s *peripheral_spi_h;
1180 * @brief Enumeration of SPI transfer modes.
1184 PERIPHERAL_SPI_MODE_0 = 0, /**< CPOL = 0, CPHa = 0 Mode */
1185 PERIPHERAL_SPI_MODE_1, /**< CPOL = 0, CPHa = 1 Mode */
1186 PERIPHERAL_SPI_MODE_2, /**< CPOL = 1, CPHa = 0 Mode */
1187 PERIPHERAL_SPI_MODE_3, /**< CPOL = 1, CPHa = 1 Mode */
1188 } peripheral_spi_mode_e;
1191 * @brief Enumeration of bit orders.
1195 PERIPHERAL_SPI_BIT_ORDER_MSB = 0, /**< Use most siginificant bit first */
1196 PERIPHERAL_SPI_BIT_ORDER_LSB, /**< Use least significant bit first */
1197 } peripheral_spi_bit_order_e;
1201 * @brief Opens a SPI slave device.
1203 * @privlevel platform
1204 * @privilege http://tizen.org/privilege/peripheralio
1205 * @remarks @a spi should be released with peripheral_spi_close()
1207 * @param[in] bus The SPI bus number
1208 * @param[in] cs The SPI chip select number
1209 * @param[out] spi The SPI slave device handle
1211 * @return 0 on success, otherwise a negative error value
1212 * @retval #PERIPHERAL_ERROR_NONE Successful
1213 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1214 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1215 * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
1216 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1217 * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
1218 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1219 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1220 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1222 * @post peripheral_spi_close()
1224 EXPORT_API int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi);
1228 * @brief Closes the SPI slave device.
1230 * @privlevel platform
1231 * @privilege http://tizen.org/privilege/peripheralio
1233 * @param[in] spi The SPI slave device handle
1235 * @return 0 on success, otherwise a negative error value
1236 * @retval #PERIPHERAL_ERROR_NONE Successful
1237 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1238 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1239 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1240 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1241 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1242 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1244 * @see peripheral_spi_open()
1246 EXPORT_API int peripheral_spi_close(peripheral_spi_h spi);
1250 * @brief Sets the SPI transfer mode.
1252 * @privlevel platform
1253 * @privilege http://tizen.org/privilege/peripheralio
1255 * @param[in] spi The SPI slave device handle
1256 * @param[in] mode The SPI transfer mode
1258 * @return 0 on success, otherwise a negative error value
1259 * @retval #PERIPHERAL_ERROR_NONE Successful
1260 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1261 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1262 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1263 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1264 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1265 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1267 * @see peripheral_spi_mode_e
1269 EXPORT_API int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode);
1273 * @brief Sets the SPI bit order.
1275 * @privlevel platform
1276 * @privilege http://tizen.org/privilege/peripheralio
1277 * @remarks ARTIK530 and Raspberry Pi 3 do not support LSB first bit order.
1279 * @param[in] spi The SPI slave device handle
1280 * @param[in] bit_order The transfer bit order
1282 * @return 0 on success, otherwise a negative error value
1283 * @retval #PERIPHERAL_ERROR_NONE Successful
1284 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1285 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1286 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1287 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1288 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1289 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1291 * @see peripheral_spi_bit_order_e
1293 EXPORT_API int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order);
1297 * @brief Sets the number of bits per word.
1299 * @privlevel platform
1300 * @privilege http://tizen.org/privilege/peripheralio
1302 * @param[in] spi The SPI slave device handle
1303 * @param[in] bits The number of bits per word (in bits)
1305 * @return 0 on success, otherwise a negative error value
1306 * @retval #PERIPHERAL_ERROR_NONE Successful
1307 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1308 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1309 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1310 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1311 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1312 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1314 EXPORT_API int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits);
1318 * @brief Sets the frequency of the SPI bus.
1320 * @privlevel platform
1321 * @privilege http://tizen.org/privilege/peripheralio
1322 * @remarks The frequencies supported are board dependent.
1324 * @param[in] spi The SPI slave device handle
1325 * @param[in] freq_hz Frequency to set (in Hz)
1327 * @return 0 on success, otherwise a negative error value
1328 * @retval #PERIPHERAL_ERROR_NONE Successful
1329 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1330 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1331 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1332 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1333 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1334 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1336 EXPORT_API int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz);
1340 * @brief Reads the bytes data from the SPI slave device.
1342 * @privlevel platform
1343 * @privilege http://tizen.org/privilege/peripheralio
1345 * @param[in] spi The SPI slave device handle
1346 * @param[out] data The data buffer to read
1347 * @param[in] length The size of data buffer (in bytes)
1349 * @return 0 on success, otherwise a negative error value
1350 * @retval #PERIPHERAL_ERROR_NONE Successful
1351 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1352 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1353 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1354 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1355 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1356 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1358 * @see peripheral_spi_write()
1360 EXPORT_API int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length);
1364 * @brief Writes the bytes data to the SPI slave device.
1366 * @privlevel platform
1367 * @privilege http://tizen.org/privilege/peripheralio
1369 * @param[in] spi The SPI slave device handle
1370 * @param[in] data The data buffer to write
1371 * @param[in] length The size of data buffer (in bytes)
1373 * @return 0 on success, otherwise a negative error value
1374 * @retval #PERIPHERAL_ERROR_NONE Successful
1375 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1376 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1377 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1378 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1379 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1380 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1382 * @see peripheral_spi_read()
1384 EXPORT_API int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length);
1388 * @brief Exchanges the bytes data to the SPI slave device.
1390 * @privlevel platform
1391 * @privilege http://tizen.org/privilege/peripheralio
1393 * @param[in] spi The SPI slave device handle
1394 * @param[in] txdata The data buffer to write
1395 * @param[out] rxdata The data buffer to read
1396 * @param[in] length The size of txdata and rxdata buffer (in bytes)
1398 * @return 0 on success, otherwise a negative error value
1399 * @retval #PERIPHERAL_ERROR_NONE Successful
1400 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1401 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device does not exist or is removed
1402 * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
1403 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1404 * @retval #PERIPHERAL_ERROR_NOT_SUPPORTED Not supported
1405 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1407 * @see peripheral_spi_read()
1408 * @see peripheral_spi_write()
1410 EXPORT_API int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length);
1420 #endif /* __TIZEN_SYSTEM_PERIPHERAL_IO_H__ */