Add description nonblock open flag
[platform/core/api/peripheral-io.git] / include / peripheral_io.h
1 /*
2  * Copyright (c) 2016-2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __TIZEN_SYSTEM_PERIPHERAL_IO_H__
18 #define __TIZEN_SYSTEM_PERIPHERAL_IO_H__
19
20 #include <stdint.h>
21 #include <tizen.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /**
28  * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_MODULE
29  * @{
30  */
31
32 /**
33  * @file peripheral_io.h
34  * @brief This file contains the peripheral-io API.
35  */
36
37 /**
38  * @brief Enumeration for peripheral-io error.
39  * @since_tizen 4.0
40  */
41 typedef enum {
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 */
52 } peripheral_error_e;
53
54 /**
55 * @}
56 */
57
58 /**
59  * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_GPIO_MODULE
60  * @{
61  */
62
63 /**
64  * @brief Enumeration of GPIO direction options.
65  * @since_tizen 4.0
66  */
67 typedef enum {
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;
72
73 /**
74  * @brief Enumeration of edge types for the GPIO interrupt.
75  * @since_tizen 4.0
76  */
77 typedef enum {
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;
83
84 /**
85  * @brief The handle of a GPIO pin.
86  * @since_tizen 4.0
87  */
88 typedef struct _peripheral_gpio_s *peripheral_gpio_h;
89
90 /**
91  * @platform
92  * @brief Opens a GPIO pin.
93  * @since_tizen 4.0
94  * @privlevel platform
95  * @privilege http://tizen.org/privilege/peripheralio
96  * @remarks @a gpio should be released with peripheral_gpio_close()
97  *
98  * @param[in] gpio_pin The GPIO pin number
99  * @param[out] gpio The GPIO handle is created on success
100  *
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
111  *
112  * @post peripheral_gpio_close()
113  */
114 EXPORT_API int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio);
115
116 /**
117  * @platform
118  * @brief Closes a GPIO pin.
119  * @since_tizen 4.0
120  * @privlevel platform
121  * @privilege http://tizen.org/privilege/peripheralio
122  *
123  * @param[in] gpio The GPIO handle
124  *
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
133  *
134  * @pre peripheral_gpio_open()
135  */
136 EXPORT_API int peripheral_gpio_close(peripheral_gpio_h gpio);
137
138 /**
139  * @platform
140  * @brief Sets the GPIO direction.
141  * @since_tizen 4.0
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.
145  *
146  * @param[in] gpio The GPIO handle
147  * @param[in] direction The direction of the GPIO pin
148  *
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
157  *
158  * @see peripheral_gpio_direction_e
159  * @see peripheral_gpio_set_edge_mode()
160  */
161 EXPORT_API int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
162
163 /**
164  * @platform
165  * @brief Sets the GPIO edge mode.
166  * @since_tizen 4.0
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.
170  *
171  * @param[in] gpio The GPIO handle
172  * @param[in] edge The edge mode of the GPIO pin
173  *
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
182  *
183  * @see peripheral_gpio_edge_e
184  * @see peripheral_gpio_set_direction()
185  */
186 EXPORT_API int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
187
188 /**
189  * @platform
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
202  * @since_tizen 4.0
203  *
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
207  *
208  * @see peripheral_gpio_set_interrupted_cb()
209  */
210 typedef void(*peripheral_gpio_interrupted_cb)(peripheral_gpio_h gpio, peripheral_error_e error, void *user_data);
211
212 /**
213  * @platform
214  * @brief Sets the GPIO interrupted callback to be invoked when the GPIO interrupt is triggered.
215  * @since_tizen 4.0
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.
219  *
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
223  *
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
229  *
230  * @post peripheral_gpio_unset_interrupted_cb()
231  * @see peripheral_gpio_set_edge_mode()
232  */
233 EXPORT_API int peripheral_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data);
234
235 /**
236  * @platform
237  * @brief Unsets the GPIO interrupted callback.
238  * @since_tizen 4.0
239  * @privlevel platform
240  * @privilege http://tizen.org/privilege/peripheralio
241  *
242  * @param[in] gpio The GPIO handle
243  *
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
249  *
250  * @pre peripheral_gpio_set_interrupted_cb()
251  */
252 EXPORT_API int peripheral_gpio_unset_interrupted_cb(peripheral_gpio_h gpio);
253
254 /**
255  * @platform
256  * @brief Gets the current value of the GPIO pin.
257  * @since_tizen 4.0
258  * @privlevel platform
259  * @privilege http://tizen.org/privilege/peripheralio
260  *
261  * @param[in] gpio The GPIO handle
262  * @param[out] value The value to get
263  *
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
272  *
273  * @see peripheral_gpio_write()
274  */
275 EXPORT_API int peripheral_gpio_read(peripheral_gpio_h gpio, uint32_t *value);
276
277 /**
278  * @platform
279  * @brief Sets the value of the GPIO pin.
280  * @since_tizen 4.0
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.
284  *
285  * @param[in] gpio The GPIO handle
286  * @param[in] value The value to set (must be 0 or 1)
287  *
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
296  *
297  * @see peripheral_gpio_read()
298  * @see peripheral_gpio_set_direction()
299  */
300 EXPORT_API int peripheral_gpio_write(peripheral_gpio_h gpio, uint32_t value);
301
302 /**
303 * @}
304 */
305
306 /**
307  * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_I2C_MODULE
308  * @{
309  */
310
311 /**
312  * @brief The handle of the I2C slave device.
313  * @since_tizen 4.0
314  */
315 typedef struct _peripheral_i2c_s *peripheral_i2c_h;
316
317 /**
318  * @platform
319  * @brief Opens an I2C slave device.
320  * @since_tizen 4.0
321  * @privlevel platform
322  * @privilege http://tizen.org/privilege/peripheralio
323  * @remarks @a i2c should be released with peripheral_i2c_close()
324  *
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
328  *
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
339  *
340  * @post peripheral_i2c_close()
341  */
342 EXPORT_API int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c);
343
344 /**
345  * @brief Enumeration for open flags (bitmask).
346  * @since_tizen 6.5
347  *
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
351  *
352  * The #PERIPHERAL_OPEN_FLAGS_NONBLOCK can be used with all other available flags.
353  */
354 typedef enum {
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;
360
361 /**
362  * @platform
363  * @brief Opens an I2C slave device.
364  * @since_tizen 6.5
365  * @privlevel platform
366  * @privilege http://tizen.org/privilege/peripheralio
367  * @remarks @a i2c should be released with peripheral_i2c_close()
368  *
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
373  *
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
384  *
385  * @post peripheral_i2c_close()
386  */
387 EXPORT_API int peripheral_i2c_open_flags(int bus, int address, peripheral_open_flags_e flags, peripheral_i2c_h *i2c);
388
389 /**
390  * @platform
391  * @brief Closes an I2C slave device.
392  * @since_tizen 4.0
393  * @privlevel platform
394  * @privilege http://tizen.org/privilege/peripheralio
395  *
396  * @param[in] i2c The I2C handle
397  *
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
404  *
405  * @pre peripheral_i2c_open()
406  */
407 EXPORT_API int peripheral_i2c_close(peripheral_i2c_h i2c);
408
409 /**
410  * @platform
411  * @brief Reads the bytes data from the I2C slave device.
412  * @since_tizen 4.0
413  * @privlevel platform
414  * @privilege http://tizen.org/privilege/peripheralio
415  *
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)
419  *
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
427  *
428  * @see peripheral_i2c_write()
429  */
430 EXPORT_API int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length);
431
432 /**
433  * @platform
434  * @brief Writes the bytes data to the I2C slave device.
435  * @since_tizen 4.0
436  * @privlevel platform
437  * @privilege http://tizen.org/privilege/peripheralio
438  *
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)
442  *
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
450  *
451  * @see peripheral_i2c_read()
452  */
453 EXPORT_API int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length);
454
455 /**
456  * @platform
457  * @brief Reads single byte data from the register of the I2C slave device.
458  * @since_tizen 4.0
459  * @privlevel platform
460  * @privilege http://tizen.org/privilege/peripheralio
461  *
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
465  *
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
473  *
474  * @see peripheral_i2c_write_register_byte()
475  */
476 EXPORT_API int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data);
477
478 /**
479  * @platform
480  * @brief Writes single byte data to the register of the I2C slave device.
481  * @since_tizen 4.0
482  * @privlevel platform
483  * @privilege http://tizen.org/privilege/peripheralio
484  *
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
488  *
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
496  *
497  * @see peripheral_i2c_read_register_byte()
498  */
499 EXPORT_API int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data);
500
501 /**
502  * @platform
503  * @brief Reads word data from the register of the I2C slave device.
504  * @since_tizen 4.0
505  * @privlevel platform
506  * @privilege http://tizen.org/privilege/peripheralio
507  *
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
511  *
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
519  *
520  * @see peripheral_i2c_write_register_word()
521  */
522 EXPORT_API int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data);
523
524 /**
525  * @platform
526  * @brief Writes word data to the register of the I2C slave device.
527  * @since_tizen 4.0
528  * @privlevel platform
529  * @privilege http://tizen.org/privilege/peripheralio
530  *
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
534  *
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
542  *
543  * @see peripheral_i2c_read_register_word()
544  */
545 EXPORT_API int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data);
546
547 /**
548 * @}
549 */
550
551 /**
552  * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_PWM_MODULE
553  * @{
554  */
555
556 /**
557  * @brief The handle of the PWM peripherals.
558  * @since_tizen 4.0
559  */
560 typedef struct _peripheral_pwm_s *peripheral_pwm_h;
561
562 /**
563  * @brief Enumeration for Polarity.
564  * @since_tizen 4.0
565  */
566 typedef enum {
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;
570
571 /**
572  * @platform
573  * @brief Opens the PWM pin.
574  * @since_tizen 4.0
575  * @privlevel platform
576  * @privilege http://tizen.org/privilege/peripheralio
577  * @remarks @a pwm should be released with peripheral_pwm_close()
578  *
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
582  *
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
593  *
594  * @post peripheral_pwm_close()
595  */
596 EXPORT_API int peripheral_pwm_open(int chip, int pin, peripheral_pwm_h *pwm);
597
598 /**
599  * @platform
600  * @brief Closes the PWM pin.
601  * @since_tizen 4.0
602  * @privlevel platform
603  * @privilege http://tizen.org/privilege/peripheralio
604  *
605  * @param[in] pwm The PWM handle
606  *
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
615  *
616  * @pre peripheral_pwm_open()
617  */
618 EXPORT_API int peripheral_pwm_close(peripheral_pwm_h pwm);
619
620 /**
621  * @platform
622  * @brief Sets period of the PWM pin.
623  * @since_tizen 4.0
624  * @privlevel platform
625  * @privilege http://tizen.org/privilege/peripheralio
626  *
627  * @param[in] pwm The PWM handle
628  * @param[in] period_ns The total period of the PWM pin (in nanoseconds)
629  *
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
638  */
639 EXPORT_API int peripheral_pwm_set_period(peripheral_pwm_h pwm, uint32_t period_ns);
640
641 /**
642  * @platform
643  * @brief Sets duty cycle of the PWM pin.
644  * @since_tizen 4.0
645  * @privlevel platform
646  * @privilege http://tizen.org/privilege/peripheralio
647  *
648  * @param[in] pwm The PWM handle
649  * @param[in] duty_cycle_ns The duty cycle of the PWM pin (in nanoseconds)
650  *
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
659  */
660 EXPORT_API int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, uint32_t duty_cycle_ns);
661
662 /**
663  * @platform
664  * @brief Sets polarity of the PWM pin.
665  * @since_tizen 4.0
666  * @privlevel platform
667  * @privilege http://tizen.org/privilege/peripheralio
668  *
669  * @param[in] pwm The PWM handle
670  * @param[in] polarity The polarity of the PWM pin
671  *
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
680  *
681  * @see peripheral_pwm_polarity_e
682  */
683 EXPORT_API int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity);
684
685 /**
686  * @platform
687  * @brief Enables the PWM pin.
688  * @since_tizen 4.0
689  * @privlevel platform
690  * @privilege http://tizen.org/privilege/peripheralio
691  *
692  * @param[in] pwm The PWM handle
693  * @param[in] enabled Enable/disable the PWM pin
694  *
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
703  */
704 EXPORT_API int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, bool enabled);
705
706 /**
707 * @}
708 */
709
710 /**
711  * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_ADC_MODULE
712  * @{
713  */
714
715 /**
716  * @brief The handle of the ADC peripherals.
717  * @since_tizen 5.0
718  */
719 typedef struct _peripheral_adc_s *peripheral_adc_h;
720
721 /**
722  * @platform
723  * @brief Opens the ADC pin.
724  * @since_tizen 5.0
725  * @privlevel platform
726  * @privilege http://tizen.org/privilege/peripheralio
727  * @remarks @a adc should be released with peripheral_adc_close()
728  *
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
732  *
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
743  *
744  * @post peripheral_adc_close()
745  */
746 EXPORT_API int peripheral_adc_open(int device, int channel, peripheral_adc_h *adc);
747
748 /**
749  * @platform
750  * @brief Closes the ADC pin.
751  * @since_tizen 5.0
752  * @privlevel platform
753  * @privilege http://tizen.org/privilege/peripheralio
754  *
755  * @param[in] adc The ADC handle
756  *
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
765  *
766  * @pre peripheral_adc_open()
767  */
768 EXPORT_API int peripheral_adc_close(peripheral_adc_h adc);
769
770 /**
771  * @platform
772  * @brief Gets the current value of the ADC pin.
773  * @since_tizen 5.0
774  * @privlevel platform
775  * @privilege http://tizen.org/privilege/peripheralio
776  *
777  * @param[in] adc The ADC handle
778  * @param[out] value The value to get
779  *
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
788  *
789  */
790 EXPORT_API int peripheral_adc_read(peripheral_adc_h adc, uint32_t *value);
791
792 /**
793 * @}
794 */
795
796 /**
797  * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_UART_MODULE
798  * @{
799  */
800
801 /**
802  * @brief The handle to the UART peripherals.
803  * @since_tizen 4.0
804  */
805 typedef struct _peripheral_uart_s *peripheral_uart_h;
806
807 /**
808  * @brief Enumeration for baud rate.
809  * @since_tizen 4.0
810  */
811 typedef enum {
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;
832
833 /**
834  * @brief Enumeration for byte size.
835  * @since_tizen 4.0
836  */
837 typedef enum {
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;
843
844 /**
845  * @brief Enumeration for parity bit.
846  * @since_tizen 4.0
847  */
848 typedef enum {
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;
853
854 /**
855  * @brief Enumeration for stop bits.
856  * @since_tizen 4.0
857  */
858 typedef enum {
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;
862
863 /**
864  * @brief Enumeration for hardware flow control.
865  * @since_tizen 4.0
866  */
867 typedef enum {
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;
871
872 /**
873  * @brief Enumeration for software flow control.
874  * @since_tizen 4.0
875  */
876 typedef enum {
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;
880
881 /**
882  * @platform
883  * @brief Opens the UART slave device.
884  * @since_tizen 4.0
885  * @privlevel platform
886  * @privilege http://tizen.org/privilege/peripheralio
887  * @remarks @a uart should be released with peripheral_uart_close()
888  *
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
891  *
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
902  *
903  * @post peripheral_uart_close()
904  */
905 EXPORT_API int peripheral_uart_open(int port, peripheral_uart_h *uart);
906
907 /**
908  * @platform
909  * @brief Opens the UART slave device.
910  * @since_tizen 6.5
911  * @privlevel platform
912  * @privilege http://tizen.org/privilege/peripheralio
913  * @remarks @a uart should be released with peripheral_uart_close()
914  *
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
918  *
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
929  *
930  * @post peripheral_uart_close()
931  */
932 EXPORT_API int peripheral_uart_open_flags(int port, peripheral_open_flags_e flags, peripheral_uart_h *uart);
933
934 /**
935  * @platform
936  * @brief Closes the UART slave device.
937  * @since_tizen 4.0
938  * @privlevel platform
939  * @privilege http://tizen.org/privilege/peripheralio
940  *
941  * @param[in] uart The UART handle
942  *
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
949  *
950  * @pre peripheral_uart_open()
951  */
952 EXPORT_API int peripheral_uart_close(peripheral_uart_h uart);
953
954 /**
955  * @platform
956  * @brief Sets baud rate of the UART slave device.
957  * @since_tizen 4.0
958  * @privlevel platform
959  * @privilege http://tizen.org/privilege/peripheralio
960  *
961  * @param[in] uart The UART handle
962  * @param[in] baud Baud rate of the UART slave device
963  *
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
972  *
973  * @see peripheral_uart_baud_rate_e
974  */
975 EXPORT_API int peripheral_uart_set_baud_rate(peripheral_uart_h uart, peripheral_uart_baud_rate_e baud);
976
977 /**
978  * @platform
979  * @brief Sets byte size of the UART slave device.
980  * @since_tizen 4.0
981  * @privlevel platform
982  * @privilege http://tizen.org/privilege/peripheralio
983  *
984  * @param[in] uart The UART handle
985  * @param[in] byte_size Byte size of the UART slave device
986  *
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
995  *
996  * @see peripheral_uart_byte_size_e
997  */
998 EXPORT_API int peripheral_uart_set_byte_size(peripheral_uart_h uart, peripheral_uart_byte_size_e byte_size);
999
1000 /**
1001  * @platform
1002  * @brief Sets parity bit of the UART slave device.
1003  * @since_tizen 4.0
1004  * @privlevel platform
1005  * @privilege http://tizen.org/privilege/peripheralio
1006  *
1007  * @param[in] uart The UART handle
1008  * @param[in] parity Parity bit of the UART slave device
1009  *
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
1018  *
1019  * @see peripheral_uart_parity_e
1020  */
1021 EXPORT_API int peripheral_uart_set_parity(peripheral_uart_h uart, peripheral_uart_parity_e parity);
1022
1023 /**
1024  * @platform
1025  * @brief Sets stop bits of the UART slave device.
1026  * @since_tizen 4.0
1027  * @privlevel platform
1028  * @privilege http://tizen.org/privilege/peripheralio
1029  *
1030  * @param[in] uart The UART handle
1031  * @param[in] stop_bits Stop bits of the UART slave device
1032  *
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
1041  *
1042  * @see peripheral_uart_stop_bits_e
1043  */
1044 EXPORT_API int peripheral_uart_set_stop_bits(peripheral_uart_h uart, peripheral_uart_stop_bits_e stop_bits);
1045
1046 /**
1047  * @platform
1048  * @brief Sets flow control of the UART slave device.
1049  * @since_tizen 4.0
1050  * @privlevel platform
1051  * @privilege http://tizen.org/privilege/peripheralio
1052  *
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)
1056  *
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
1065  *
1066  * @see peripheral_uart_software_flow_control_e
1067  * @see peripheral_uart_hardware_flow_control_e
1068  */
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);
1072
1073 /**
1074  * @platform
1075  * @brief Reads data from the UART slave device.
1076  * @since_tizen 4.0
1077  * @privlevel platform
1078  * @privilege http://tizen.org/privilege/peripheralio
1079  *
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)
1083  *
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
1092  *
1093  * @see peripheral_uart_write()
1094  */
1095 EXPORT_API int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, uint32_t length);
1096
1097
1098 /**
1099  * @platform
1100  * @brief Discards data queued for writing to UART slave device, but not yet transmitted.
1101  * @since_tizen 7.5
1102  * @privlevel platform
1103  * @privilege http://tizen.org/privilege/peripheralio
1104  *
1105  * @param[in] uart The UART handle
1106  *
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
1115  *
1116  */
1117 EXPORT_API int peripheral_uart_flush(peripheral_uart_h uart);
1118
1119 /**
1120  * @platform
1121  * @brief Waits for all data queued for UART to be transmitted.
1122  * @since_tizen 7.5
1123  * @privlevel platform
1124  * @privilege http://tizen.org/privilege/peripheralio
1125  *
1126  * @param[in] uart The UART handle
1127  *
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
1136  *
1137  */
1138 EXPORT_API int peripheral_uart_drain(peripheral_uart_h uart);
1139
1140 /**
1141  * @platform
1142  * @brief Writes data to the UART slave device.
1143  * @since_tizen 4.0
1144  * @privlevel platform
1145  * @privilege http://tizen.org/privilege/peripheralio
1146  *
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)
1150  *
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
1159  *
1160  * @see peripheral_uart_read()
1161  */
1162 EXPORT_API int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, uint32_t length);
1163
1164 /**
1165 * @}
1166 */
1167
1168 /**
1169  * @addtogroup CAPI_SYSTEM_PERIPHERAL_IO_SPI_MODULE
1170  * @{
1171  */
1172
1173 /**
1174  * @brief The handle of a SPI peripherals.
1175  * @since_tizen 4.0
1176  */
1177 typedef struct _peripheral_spi_s *peripheral_spi_h;
1178
1179 /**
1180  * @brief Enumeration of SPI transfer modes.
1181  * @since_tizen 4.0
1182  */
1183 typedef enum {
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;
1189
1190 /**
1191  * @brief Enumeration of bit orders.
1192  * @since_tizen 4.0
1193  */
1194 typedef enum {
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;
1198
1199 /**
1200  * @platform
1201  * @brief Opens a SPI slave device.
1202  * @since_tizen 4.0
1203  * @privlevel platform
1204  * @privilege http://tizen.org/privilege/peripheralio
1205  * @remarks @a spi should be released with peripheral_spi_close()
1206  *
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
1210  *
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
1221  *
1222  * @post peripheral_spi_close()
1223  */
1224 EXPORT_API int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi);
1225
1226 /**
1227  * @platform
1228  * @brief Closes the SPI slave device.
1229  * @since_tizen 4.0
1230  * @privlevel platform
1231  * @privilege http://tizen.org/privilege/peripheralio
1232  *
1233  * @param[in] spi The SPI slave device handle
1234  *
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
1243  *
1244  * @see peripheral_spi_open()
1245  */
1246 EXPORT_API int peripheral_spi_close(peripheral_spi_h spi);
1247
1248 /**
1249  * @platform
1250  * @brief Sets the SPI transfer mode.
1251  * @since_tizen 4.0
1252  * @privlevel platform
1253  * @privilege http://tizen.org/privilege/peripheralio
1254  *
1255  * @param[in] spi The SPI slave device handle
1256  * @param[in] mode The SPI transfer mode
1257  *
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
1266  *
1267  * @see peripheral_spi_mode_e
1268  */
1269 EXPORT_API int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode);
1270
1271 /**
1272  * @platform
1273  * @brief Sets the SPI bit order.
1274  * @since_tizen 4.0
1275  * @privlevel platform
1276  * @privilege http://tizen.org/privilege/peripheralio
1277  * @remarks ARTIK530 and Raspberry Pi 3 do not support LSB first bit order.
1278  *
1279  * @param[in] spi The SPI slave device handle
1280  * @param[in] bit_order The transfer bit order
1281  *
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
1290  *
1291  * @see peripheral_spi_bit_order_e
1292  */
1293 EXPORT_API int peripheral_spi_set_bit_order(peripheral_spi_h spi, peripheral_spi_bit_order_e bit_order);
1294
1295 /**
1296  * @platform
1297  * @brief Sets the number of bits per word.
1298  * @since_tizen 4.0
1299  * @privlevel platform
1300  * @privilege http://tizen.org/privilege/peripheralio
1301  *
1302  * @param[in] spi The SPI slave device handle
1303  * @param[in] bits The number of bits per word (in bits)
1304  *
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
1313  */
1314 EXPORT_API int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, uint8_t bits);
1315
1316 /**
1317  * @platform
1318  * @brief Sets the frequency of the SPI bus.
1319  * @since_tizen 4.0
1320  * @privlevel platform
1321  * @privilege http://tizen.org/privilege/peripheralio
1322  * @remarks The frequencies supported are board dependent.
1323  *
1324  * @param[in] spi The SPI slave device handle
1325  * @param[in] freq_hz Frequency to set (in Hz)
1326  *
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
1335  */
1336 EXPORT_API int peripheral_spi_set_frequency(peripheral_spi_h spi, uint32_t freq_hz);
1337
1338 /**
1339  * @platform
1340  * @brief Reads the bytes data from the SPI slave device.
1341  * @since_tizen 4.0
1342  * @privlevel platform
1343  * @privilege http://tizen.org/privilege/peripheralio
1344  *
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)
1348  *
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
1357  *
1358  * @see peripheral_spi_write()
1359  */
1360 EXPORT_API int peripheral_spi_read(peripheral_spi_h spi, uint8_t *data, uint32_t length);
1361
1362 /**
1363  * @platform
1364  * @brief Writes the bytes data to the SPI slave device.
1365  * @since_tizen 4.0
1366  * @privlevel platform
1367  * @privilege http://tizen.org/privilege/peripheralio
1368  *
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)
1372  *
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
1381  *
1382  * @see peripheral_spi_read()
1383  */
1384 EXPORT_API int peripheral_spi_write(peripheral_spi_h spi, uint8_t *data, uint32_t length);
1385
1386 /**
1387  * @platform
1388  * @brief Exchanges the bytes data to the SPI slave device.
1389  * @since_tizen 4.0
1390  * @privlevel platform
1391  * @privilege http://tizen.org/privilege/peripheralio
1392  *
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)
1397  *
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
1406  *
1407  * @see peripheral_spi_read()
1408  * @see peripheral_spi_write()
1409  */
1410 EXPORT_API int peripheral_spi_transfer(peripheral_spi_h spi, uint8_t *txdata, uint8_t *rxdata, uint32_t length);
1411
1412 /**
1413 * @}
1414 */
1415
1416 #ifdef __cplusplus
1417 }
1418 #endif
1419
1420 #endif /* __TIZEN_SYSTEM_PERIPHERAL_IO_H__ */