bba13cad6bb343f3078bc180eb82699c084ae329
[platform/core/api/peripheral-io.git] / include / peripheral_io.h
1 /*
2  * Copyright (c) 2016-2017 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 __PERIPHERAL_IO_H__
18 #define __PERIPHERAL_IO_H__
19
20 #include <stdint.h>
21 #include <tizen.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /**
28  * @file peripheral_io.h
29  * @brief This file contains the peripheral-io API
30  */
31
32 /**
33  * @brief Enumeration for peripheral-io error.
34  * @since_tizen
35  */
36 typedef enum {
37         PERIPHERAL_ERROR_NONE                = TIZEN_ERROR_NONE,                /**< Successful */
38         PERIPHERAL_ERROR_IO_ERROR            = TIZEN_ERROR_IO_ERROR,            /**< I/O error */
39         PERIPHERAL_ERROR_NO_DEVICE           = TIZEN_ERROR_NO_SUCH_DEVICE,      /**< No such device */
40         PERIPHERAL_ERROR_OUT_OF_MEMORY       = TIZEN_ERROR_OUT_OF_MEMORY,       /**< Out of memory */
41         PERIPHERAL_ERROR_PERMISSION_DENIED   = TIZEN_ERROR_PERMISSION_DENIED,   /**< Permission denied */
42         PERIPHERAL_ERROR_RESOURCE_BUSY       = TIZEN_ERROR_RESOURCE_BUSY,       /**< Device or resource busy */
43         PERIPHERAL_ERROR_INVALID_PARAMETER   = TIZEN_ERROR_INVALID_PARAMETER,   /**< Invalid parameter */
44         PERIPHERAL_ERROR_NO_DATA             = TIZEN_ERROR_NO_DATA,             /**< No data available */
45         PERIPHERAL_ERROR_INVALID_OPERATION   = TIZEN_ERROR_INVALID_OPERATION,   /**< Function not implemented */
46         PERIPHERAL_ERROR_TIMED_OUT           = TIZEN_ERROR_TIMED_OUT,           /**< Time out */
47         PERIPHERAL_ERROR_NOT_SUPPORTED       = TIZEN_ERROR_NOT_SUPPORTED,       /**< Not supported */
48         PERIPHERAL_ERROR_UNKNOWN             = TIZEN_ERROR_UNKNOWN,             /**< Unknown error */
49 } peripheral_error_e;
50
51 /**
52  * @addtogroup CAPI_SYSTEM_PERIPHERAL_GPIO_MODULE
53  * @{
54  */
55
56 /**
57  * @brief Enumeration of gpio direction
58  */
59 typedef enum {
60         PERIPHERAL_GPIO_DIRECTION_IN = 0,    /**< Input Mode */
61         PERIPHERAL_GPIO_DIRECTION_OUT,       /**< Output mode with low value */
62         PERIPHERAL_GPIO_DIRECTION_OUT_LOW = PERIPHERAL_GPIO_DIRECTION_OUT, /**< Same as above */
63         PERIPHERAL_GPIO_DIRECTION_OUT_HIGH,  /**< Output mode with high value */
64 } peripheral_gpio_direction_e;
65
66 /**
67  * @brief Enumeration of edge type for gpio interrupt
68  */
69 typedef enum {
70         PERIPHERAL_GPIO_EDGE_NONE = 0,  /**< No interrupt on Gpio */
71         PERIPHERAL_GPIO_EDGE_RISING,    /**< Interrupt on rising only */
72         PERIPHERAL_GPIO_EDGE_FALLING,   /**< Interrupt on falling only */
73         PERIPHERAL_GPIO_EDGE_BOTH,      /**< Interrupt on rising & falling */
74 } peripheral_gpio_edge_e;
75
76 /**
77  * @brief The handle to the gpio pin
78  * @since_tizen 4.0
79  */
80 typedef struct _peripheral_gpio_s* peripheral_gpio_h;
81
82 /**
83  * @brief Initializes(export) gpio pin and creates gpio handle.
84  * @since_tizen 4.0
85  *
86  * @param[in] gpio_pin The gpio pin number
87  * @param[out] gpio The gpio handle is created on success
88  *
89  * @return 0 on success, otherwise a negative error value
90  * @retval #PERIPHERAL_ERROR_NONE Successful
91  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
92  * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
93  * @retval #PERIPHERAL_ERROR_PERMISSION_DENIED Permission denied
94  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
95  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
96  *
97  * @see peripheral_gpio_close()
98  */
99 int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio);
100
101 /**
102  * @brief Releases the gpio handle and finalize(unexport) the gpio pin.
103  * @since_tizen 4.0
104  *
105  * @param[in] gpio The handle to the gpio pin to release
106  *
107  * @return 0 on success, otherwise a negative error value
108  * @retval #PERIPHERAL_ERROR_NONE Successful
109  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
110  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
111  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
112  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
113  *
114  * @see peripheral_gpio_open()
115  */
116 int peripheral_gpio_close(peripheral_gpio_h gpio);
117
118 /**
119  * @brief Gets direction of the gpio.
120  * @since_tizen 4.0
121  *
122  * @param[in] gpio The handle to the gpio pin
123  * @param[out] value The direction(value) type of the gpio
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_INVALID_PARAMETER Invalid parameter
129  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
130  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
131  *
132  * @see peripheral_gpio_set_direction()
133  */
134 int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction);
135
136 /**
137  * @brief Sets direction of the gpio pin.
138  * @since_tizen 4.0
139  *
140  * @param[in] gpio The handle to the gpio pin to set
141  * @param[in] direction Direction(value) type of the gpio pin
142  *
143  * @return 0 on success, otherwise a negative error value
144  * @retval #PERIPHERAL_ERROR_NONE Successful
145  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
146  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
147  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
148  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
149  */
150 int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
151
152 /**
153  * @brief Reads value of the gpio.
154  * @since_tizen 4.0
155  *
156  * @param[in] gpio The handle to the gpio pin
157  * @param[out] value The value of the gpio (zero or non-zero)
158  *
159  * @return 0 on success, otherwise a negative error value
160  * @retval #PERIPHERAL_ERROR_NONE Successful
161  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
162  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
163  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
164  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
165  *
166  * @see peripheral_gpio_write()
167  */
168 int peripheral_gpio_read(peripheral_gpio_h gpio, int *value);
169
170 /**
171  * @brief Writes value to the gpio.
172  * @since_tizen 4.0
173  *
174  * @param[in] gpio The handle to the gpio pin
175  * @param[in] value Value to be written to the gpio (muse be zero or non-zero)
176  *
177  * @return 0 on success, otherwise a negative error value
178  * @retval #PERIPHERAL_ERROR_NONE Successful
179  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
180  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
181  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
182  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
183  *
184  * @see peripheral_gpio_read()
185  */
186 int peripheral_gpio_write(peripheral_gpio_h gpio, int value);
187
188 /**
189  * @brief Gets the edge mode of the gpio.
190  * @since_tizen 4.0
191  *
192  * @param[in] gpio The handle to the gpio pin
193  * @param[out] gpio_pin The edge mode of the gpio
194  *
195  * @return 0 on success, otherwise a negative error value
196  * @retval #PERIPHERAL_ERROR_NONE Successful
197  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
198  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
199  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
200  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
201  *
202  * @see peripheral_gpio_set_edge_mode()
203  */
204 int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge);
205
206 /**
207  * @brief Sets the edge mode of the gpio pin.
208  * @since_tizen 4.0
209  *
210  * @param[in] gpio The handle to the gpio pin to set
211  * @param[in] edge The edge mode of the gpio pin
212  *
213  * @return 0 on success, otherwise a negative error value
214  * @retval #PERIPHERAL_ERROR_NONE Successful
215  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
216  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
217  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
218  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
219  *
220  * @see peripheral_gpio_get_edge_mode()
221  */
222 int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
223
224 /**
225  * @brief Called when the gpio interrupt is triggered.
226  * @since_tizen 4.0
227  *
228  * @param[in] user_data The user data passed from the callback registration function
229  *
230  * @see peripheral_gpio_register_cb()
231  * @see peripheral_gpio_unregister_cb()
232  */
233 typedef void(*gpio_isr_cb)(void *user_data);
234
235 /**
236  * @brief Registers a callback function to be invoked when the gpio interrupt is triggered.
237  * @since_tizen 4.0
238  *
239  * @param[in] gpio The handle to the gpio pin to set
240  * @param[in] edge The edge type of the gpio pin
241  * @param[in] callback The callback function to register
242  * @param[in] user_data The user data to be passed to the callback function
243  *
244  * @return 0 on success, otherwise a negative error value
245  * @retval #PERIPHERAL_ERROR_NONE Successful
246  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
247  *
248  * @see peripheral_gpio_set_edge_mode()
249  * @see peripheral_gpio_unregister_cb()
250  */
251 int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data);
252
253 /**
254  * @brief Unregisters the callback function for the gpio handler.
255  * @since_tizen 4.0
256  *
257  * @param[in] gpio The handle to the gpio pin
258  *
259  * @return 0 on success, otherwise a negative error value
260  * @retval #PERIPHERAL_ERROR_NONE Successful
261  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
262  *
263  * @see peripheral_gpio_register_cb()
264  */
265 int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio);
266
267 /**
268  * @brief Gets pin number of the gpio handle.
269  * @since_tizen 4.0
270  *
271  * @param[in] gpio The handle to the gpio pin
272  * @param[out] gpio_pin The pin number of the gpio
273  *
274  * @return 0 on success, otherwise a negative error value
275  * @retval #PERIPHERAL_ERROR_NONE Successful
276  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
277  */
278 int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin);
279
280 /**
281 * @}
282 */
283
284 /**
285  * @addtogroup CAPI_SYSTEM_PERIPHERAL_I2C_MODULE
286  * @{
287  */
288
289 /**
290  * @brief The handle to the i2c device
291  * @since_tizen 4.0
292  */
293 typedef struct _peripheral_i2c_s *peripheral_i2c_h;
294
295 /**
296  * @brief Initializes i2c communication and creates i2c handle.
297  * @since_tizen 4.0
298  *
299  * @param[in] bus The i2c bus number that the slave device is connected
300  * @param[in] address The address of the slave device
301  * @param[out] i2c The i2c handle is created on success
302  *
303  * @return 0 on success, otherwise a negative error value
304  * @retval #PERIPHERAL_ERROR_NONE Successful
305  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
306  * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
307  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
308  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
309  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
310  *
311  * @see peripheral_i2c_close()
312  */
313 int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c);
314
315 /**
316  * @brief Destory the i2c handle and release the communication.
317  * @since_tizen 4.0
318  *
319  * @param[in] i2c The i2c handle
320  *
321  * @return 0 on success, otherwise a negative error value
322  * @retval #PERIPHERAL_ERROR_NONE Successful
323  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
324  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
325  *
326  * @see peripheral_i2c_open()
327  */
328 int peripheral_i2c_close(peripheral_i2c_h i2c);
329
330 /**
331  * @brief Reads data from the i2c slave device.
332  * @since_tizen 4.0
333  *
334  * @param[in] i2c The handle to the i2c device
335  * @param[out] data The address of data buffer to read
336  * @param[in] length The size of data buffer (in bytes)
337  *
338  * @return 0 on success, otherwise a negative error value
339  * @retval #PERIPHERAL_ERROR_NONE Successful
340  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
341  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
342  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
343  */
344 int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
345
346 /**
347  * @brief Write data to the i2c slave device.
348  * @since_tizen 4.0
349  *
350  * @param[in] i2c The handle to the i2c device
351  * @param[in] data The address of data buffer to write
352  * @param[in] length The size of data buffer (in bytes)
353  *
354  * @return 0 on success, otherwise a negative error value
355  * @retval #PERIPHERAL_ERROR_NONE Successful
356  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
357  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
358  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
359  */
360 int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
361
362 /**
363  * @brief Reads single byte data from the i2c slave device.
364  * @since_tizen 4.0
365  *
366  * @param[in] i2c The handle to the i2c device
367  * @param[out] data The address of data buffer to read
368  *
369  * @return 0 on success, otherwise a negative error value
370  * @retval #PERIPHERAL_ERROR_NONE Successful
371  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
372  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
373  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
374  */
375 int peripheral_i2c_read_byte(peripheral_i2c_h i2c, uint8_t *data);
376
377 /**
378  * @brief Write single byte data to the i2c slave device.
379  * @since_tizen 4.0
380  *
381  * @param[in] i2c The handle to the i2c device
382  * @param[in] data The byte value to write
383  *
384  * @return 0 on success, otherwise a negative error value
385  * @retval #PERIPHERAL_ERROR_NONE Successful
386  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
387  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
388  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
389  */
390 int peripheral_i2c_write_byte(peripheral_i2c_h i2c, uint8_t data);
391
392 /**
393  * @brief Reads byte data from the register of i2c slave device.
394  * @since_tizen 4.0
395  *
396  * @param[in] i2c The handle to the i2c device
397  * @param[in] address The register address of the i2c slave device to read
398  * @param[out] data The byte output of slave device(register value)
399  *
400  * @return 0 on success, otherwise a negative error value
401  * @retval #PERIPHERAL_ERROR_NONE Successful
402  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
403  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
404  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
405  */
406 int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t *data);
407
408 /**
409  * @brief Write byte data to the register of i2c slave device.
410  * @since_tizen 4.0
411  *
412  * @param[in] i2c The handle to the i2c device
413  * @param[in] address The register address of the i2c slave device to write
414  * @param[in] data The byte value to write
415  *
416  * @return 0 on success, otherwise a negative error value
417  * @retval #PERIPHERAL_ERROR_NONE Successful
418  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
419  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
420  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
421  */
422 int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t data);
423
424 /**
425  * @brief Reads word data from the register of i2c slave device.
426  * @since_tizen 4.0
427  *
428  * @param[in] i2c The handle to the i2c device
429  * @param[in] address The register address of the i2c slave device to read
430  * @param[out] data The word output(2 bytes) of slave device(register value)
431  *
432  * @return 0 on success, otherwise a negative error value
433  * @retval #PERIPHERAL_ERROR_NONE Successful
434  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
435  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
436  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
437  */
438 int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t *data);
439
440 /**
441  * @brief Write byte data to the register of i2c slave device.
442  * @since_tizen 4.0
443  *
444  * @param[in] i2c The handle to the i2c device
445  * @param[in] address The register address of the i2c slave device to write
446  * @param[in] data The word(2 bytes) value to write
447  *
448  * @return 0 on success, otherwise a negative error value
449  * @retval #PERIPHERAL_ERROR_NONE Successful
450  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
451  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
452  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
453  */
454 int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t data);
455
456 /**
457 * @}
458 */
459
460 /**
461  * @addtogroup CAPI_SYSTEM_PERIPHERAL_PWM_MODULE
462  * @{
463  */
464
465 /**
466  * @brief The handle to the pwm device
467  * @since_tizen 4.0
468  */
469 typedef struct _peripheral_pwm_s *peripheral_pwm_h;
470
471 /**
472  * @brief Enumeration for Polarity.
473  */
474 typedef enum {
475         PERIPHERAL_PWM_POLARITY_NORMAL = 0,
476         PERIPHERAL_PWM_POLARITY_INVERSED,
477 } peripheral_pwm_polarity_e;
478
479 /**
480  * @brief Initializes(export) pwm device and creates pwm handle.
481  * @since_tizen 4.0
482  *
483  * @param[in] device The pwm chip number
484  * @param[in] channel The pwm channel number to control
485  * @param[out] pwm The pwm handle is created on success
486  *
487  * @return 0 on success, otherwise a negative error value
488  * @retval #PERIPHERAL_ERROR_NONE Successful
489  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
490  * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
491  * @retval #PERIPHERAL_ERROR_RESOURCE_BUSY Device is in use
492  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
493  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
494  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
495  *
496  * @see peripheral_pwm_close()
497  */
498 int peripheral_pwm_open(int device, int channel, peripheral_pwm_h *pwm);
499
500 /**
501  * @brief Destory the pwm handle and finalize(unexport) the pwm device.
502  * @since_tizen 4.0
503  *
504  * @param[in] pwm The handle to the pwm device
505  *
506  * @return 0 on success, otherwise a negative error value
507  * @retval #PERIPHERAL_ERROR_NONE Successful
508  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
509  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
510  * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access
511  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
512  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
513  *
514  * @see peripheral_pwm_open()
515  */
516 int peripheral_pwm_close(peripheral_pwm_h pwm);
517
518 /**
519  * @brief Sets Period of the pwm device.
520  * @since_tizen 4.0
521  *
522  * @param[in] pwm The handle to the pwm device
523  * @param[in] period The total period of the PWM signal (in nanoseconds)
524  *
525  * @return 0 on success, otherwise a negative error value
526  * @retval #PERIPHERAL_ERROR_NONE Successful
527  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
528  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
529  * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access
530  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
531  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
532  */
533 int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period);
534
535 /**
536  * @brief Gets Period of the pwm device.
537  * @since_tizen 4.0
538  *
539  * @param[in] pwm The handle to the pwm device
540  * @param[out] period The total period of the PWM signal (in nanoseconds)
541  *
542  * @return 0 on success, otherwise a negative error value
543  * @retval #PERIPHERAL_ERROR_NONE Successful
544  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
545  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
546  * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access
547  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
548  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
549  */
550 int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period);
551
552 /**
553  * @brief Sets Duty Cycle of the pwm device.
554  * @since_tizen 4.0
555  *
556  * @param[in] pwm The handle to the pwm device
557  * @param[in] duty_cycle The active time of the pwm signal (in nanoseconds)
558  *
559  * @return 0 on success, otherwise a negative error value
560  * @retval #PERIPHERAL_ERROR_NONE Successful
561  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
562  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
563  * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access
564  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
565  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
566  */
567 int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle);
568
569 /**
570  * @brief Gets Duty Cycle of the pwm device.
571  * @since_tizen 4.0
572  *
573  * @param[in] pwm The handle to the pwm device
574  * @param[out] duty_cycle The active time of the pwm signal (in nanoseconds)
575  *
576  * @return 0 on success, otherwise a negative error value
577  * @retval #PERIPHERAL_ERROR_NONE Successful
578  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
579  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
580  * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access
581  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
582  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
583  */
584 int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle);
585
586 /**
587  * @brief Sets Polarity of the pwm device.
588  * @since_tizen 4.0
589  *
590  * @param[in] pwm The handle to the pwm device
591  * @param[in] polarity The polarity of the pwm signal
592  *
593  * @return 0 on success, otherwise a negative error value
594  * @retval #PERIPHERAL_ERROR_NONE Successful
595  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
596  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
597  * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access
598  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
599  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
600  */
601 int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity);
602
603 /**
604  * @brief Gets Polarity of the pwm device.
605  * @since_tizen 4.0
606  *
607  * @param[in] pwm The handle to the pwm device
608  * @param[out] polarity The polarity of the pwm signal
609  *
610  * @return 0 on success, otherwise a negative error value
611  * @retval #PERIPHERAL_ERROR_NONE Successful
612  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
613  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
614  * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access
615  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
616  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
617  */
618 int peripheral_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity);
619
620 /**
621  * @brief Enable of the pwm device.
622  * @since_tizen 4.0
623  *
624  * @param[in] pwm The handle to the pwm device
625  * @param[in] enable Enable/disable the pwm signal
626  *            true - enable
627  *            false - disable
628  * @return 0 on success, otherwise a negative error value
629  * @retval #PERIPHERAL_ERROR_NONE Successful
630  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
631  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
632  * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access
633  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
634  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
635  */
636 int peripheral_pwm_set_enable(peripheral_pwm_h pwm, bool enable);
637
638 /**
639  * @brief Gets Enable status of the pwm device.
640  * @since_tizen 4.0
641  *
642  * @param[in] pwm The handle to the pwm device
643  * @param[out] enable Enable/disable the pwm signal
644  *
645  * @return 0 on success, otherwise a negative error value
646  * @retval #PERIPHERAL_ERROR_NONE Successful
647  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
648  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
649  * @retval #PERIPHERAL_ERROR_INVALID_OPERATION Invalid access
650  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
651  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
652  */
653 int peripheral_pwm_get_enable(peripheral_pwm_h pwm, bool *enable);
654
655 /**
656 * @}
657 */
658
659 /**
660  * @addtogroup CAPI_SYSTEM_PERIPHERAL_ADC_MODULE
661  * @{
662  */
663
664 /**
665  * @brief Reads data from the adc device.
666  * @since_tizen 4.0
667  *
668  * @param[in] device The device number of the adc device
669  * @param[in] channel The channel number to read
670  * @param[out] data The address of buffer to read
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_INVALID_PARAMETER Invalid parameter
676  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
677  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
678  */
679 int peripheral_adc_read(unsigned int device, unsigned int channel, int *data);
680
681 /**
682 * @}
683 */
684
685 /**
686  * @addtogroup CAPI_SYSTEM_PERIPHERAL_UART_MODULE
687  * @{
688  */
689
690 /**
691  * @brief The handle to the uart device
692  * @since_tizen 4.0
693  */
694 typedef struct _peripheral_uart_s *peripheral_uart_h;
695
696 /**
697  * @brief Enumeration for Baud Rate.
698  */
699 typedef enum {
700         PERIPHERAL_UART_BAUDRATE_0 = 0,
701         PERIPHERAL_UART_BAUDRATE_50,
702         PERIPHERAL_UART_BAUDRATE_75,
703         PERIPHERAL_UART_BAUDRATE_110,
704         PERIPHERAL_UART_BAUDRATE_134,
705         PERIPHERAL_UART_BAUDRATE_150,
706         PERIPHERAL_UART_BAUDRATE_200,
707         PERIPHERAL_UART_BAUDRATE_300,
708         PERIPHERAL_UART_BAUDRATE_600,
709         PERIPHERAL_UART_BAUDRATE_1200,
710         PERIPHERAL_UART_BAUDRATE_1800,
711         PERIPHERAL_UART_BAUDRATE_2400,
712         PERIPHERAL_UART_BAUDRATE_4800,
713         PERIPHERAL_UART_BAUDRATE_9600,
714         PERIPHERAL_UART_BAUDRATE_19200,
715         PERIPHERAL_UART_BAUDRATE_38400,
716         PERIPHERAL_UART_BAUDRATE_57600,
717         PERIPHERAL_UART_BAUDRATE_115200,
718         PERIPHERAL_UART_BAUDRATE_230400
719 } peripheral_uart_baudrate_e;
720
721 /**
722  * @brief Enumeration for Byte Size.
723  */
724 typedef enum {
725         PERIPHERAL_UART_BYTESIZE_5BIT = 0,
726         PERIPHERAL_UART_BYTESIZE_6BIT,
727         PERIPHERAL_UART_BYTESIZE_7BIT,
728         PERIPHERAL_UART_BYTESIZE_8BIT
729 } peripheral_uart_bytesize_e;
730
731 /**
732  * @brief Enumeration for Parity Bit.
733  */
734 typedef enum {
735         PERIPHERAL_UART_PARITY_NONE = 0,
736         PERIPHERAL_UART_PARITY_EVEN,
737         PERIPHERAL_UART_PARITY_ODD
738 } peripheral_uart_parity_e;
739
740 /**
741  * @brief Enumeration for Stop Bits.
742  */
743 typedef enum {
744         PERIPHERAL_UART_STOPBITS_1BIT = 0,
745         PERIPHERAL_UART_STOPBITS_2BIT
746 } peripheral_uart_stopbits_e;
747
748 /**
749  * @brief Initializes uart communication and creates uart handle.
750  * @since_tizen 4.0
751  *
752  * @param[in] port The uart port number that the slave device is connected
753  * @param[out] uart The uart handle is created on success
754  *
755  * @return 0 on success, otherwise a negative error value
756  * @retval #PERIPHERAL_ERROR_NONE Successful
757  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
758  * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
759  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
760  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
761  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
762  *
763  * @see peripheral_uart_close()
764  */
765 int peripheral_uart_open(int port, peripheral_uart_h *uart);
766
767 /**
768  * @brief Destory the uart handle and release the communication.
769  * @since_tizen 4.0
770  *
771  * @param[in] uart The handle to the uart device
772  *
773  * @return 0 on success, otherwise a negative error value
774  * @retval #PERIPHERAL_ERROR_NONE Successful
775  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
776  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
777  *
778  * @see peripheral_uart_open()
779  */
780 int peripheral_uart_close(peripheral_uart_h uart);
781
782 /**
783  * @brief Flush all input that has received but not yet been read by the uart
784  *        device, or all output written but not transmitted to the uart device.
785  * @since_tizen 4.0
786  *
787  * @param[in] uart The uart handle
788  *
789  * @return 0 on success, otherwise a negative error value
790  * @retval #PERIPHERAL_ERROR_NONE Successful
791  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
792  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
793  */
794 int peripheral_uart_flush(peripheral_uart_h uart);
795
796 /**
797  * @brief Sets baudrate of the uart device.
798  * @since_tizen 4.0
799  *
800  * @param[in] uart The handle to the uart device to set
801  * @param[in] baud Baudrate of the uart device
802  *
803  * @return 0 on success, otherwise a negative error value
804  * @retval #PERIPHERAL_ERROR_NONE Successful
805  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
806  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
807  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
808  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
809  */
810 int peripheral_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud);
811
812 /**
813  * @brief Sets mode of the uart device.
814  * @since_tizen 4.0
815  *
816  * @param[in] uart The handle to the uart device to set
817  * @param[in] bytesize Byte size of the uart device
818  * @param[in] parity Parity bits of the uart device
819  * @param[in] stopbits Stop bits of the uart device
820  *
821  * @return 0 on success, otherwise a negative error value
822  * @retval #PERIPHERAL_ERROR_NONE Successful
823  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
824  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
825  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
826  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
827  */
828 int peripheral_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits);
829
830 /**
831  * @brief Sets flow control of the uart device.
832  * @since_tizen 4.0
833  *
834  * @param[in] uart The handle to the uart device to set
835  * @param[in] xonxoff Turns a transmitter on or off
836  * @param[in] rtscts Turns "Request to Send/Clear to Send" on or off
837  *
838  * @return 0 on success, otherwise a negative error value
839  * @retval #PERIPHERAL_ERROR_NONE Successful
840  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
841  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
842  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
843  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
844  */
845 int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts);
846
847 /**
848  * @brief Reads data from the uart device.
849  * @since_tizen 4.0
850  *
851  * @param[in] uart The handle to the uart device
852  * @param[out] data The address of read buffer
853  * @param[out] length The size of data buffer (in bytes)
854  *
855  * @return the number of bytes read on success, otherwise a negative error value
856  * @retval #PERIPHERAL_ERROR_NONE Successful
857  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
858  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
859  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
860  */
861 int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length);
862
863 /**
864  * @brief Write data to the uart device.
865  * @since_tizen 4.0
866  *
867  * @param[in] uart The handle to the uart device
868  * @param[in] data The address of buffer to write
869  * @param[in] length The size of data (in bytes)
870  *
871  * @return the number of bytes write on success, otherwise a negative error value
872  * @retval #PERIPHERAL_ERROR_NONE Successful
873  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
874  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
875  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
876  */
877 int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, int length);
878
879 /**
880 * @}
881 */
882
883 /**
884  * @addtogroup CAPI_SYSTEM_PERIPHERAL_SPI_MODULE
885  * @{
886  */
887
888 /**
889  * @brief The handle to the spi device
890  * @since_tizen 4.0
891  */
892 typedef struct _peripheral_spi_s* peripheral_spi_h;
893
894 /**
895  * @brief Enumeration for SPI mode.
896  */
897 typedef enum {
898         PERIPHERAL_SPI_MODE_0 = 0,
899         PERIPHERAL_SPI_MODE_1,
900         PERIPHERAL_SPI_MODE_2,
901         PERIPHERAL_SPI_MODE_3
902 } peripheral_spi_mode_e;
903
904 /**
905  * @brief Initializes spi communication and creates spi handle.
906  * @since_tizen 4.0
907  *
908  * @param[in] bus The spi bus number that the slave device is connected
909  * @param[in] cs The spi chip select number that the slave device is connected
910  * @param[out] spi The spi handle is created on success
911  *
912  * @return 0 on success, otherwise a negative error value
913  * @retval #PERIPHERAL_ERROR_NONE Successful
914  *
915  * @see peripheral_spi_close()
916  */
917 int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi);
918
919 /**
920  * @brief Destory the spi handle and release the communication.
921  * @since_tizen 4.0
922  *
923  * @param[in] spi The handle to the spi device
924  *
925  * @return 0 on success, otherwise a negative error value
926  * @retval #PERIPHERAL_ERROR_NONE Successful
927  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
928  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
929  *
930  * @see peripheral_spi_open()
931  */
932 int peripheral_spi_close(peripheral_spi_h spi);
933
934 /**
935  * @brief Sets mode of the spi device.
936  * @since_tizen 4.0
937  *
938  * @param[in] spi The handle to the spi device
939  * @param[in] mode The mode of the spi device
940  *
941  * @return 0 on success, otherwise a negative error value
942  * @retval #PERIPHERAL_ERROR_NONE Successful
943  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
944  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
945  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
946  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
947  */
948 int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode);
949
950 /**
951  * @brief Gets mode of the spi device.
952  * @since_tizen 4.0
953  *
954  * @param[in] spi The handle to the spi device
955  * @param[out] mode The mode of the spi device
956  *
957  * @return 0 on success, otherwise a negative error value
958  * @retval #PERIPHERAL_ERROR_NONE Successful
959  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
960  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
961  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
962  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
963  */
964 int peripheral_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode);
965
966 /**
967  * @brief Sets bits justification of the spi device.
968  * @since_tizen 4.0
969  *
970  * @param[in] spi The handle to the spi device
971  * @param[in] lsb The bit position to be transmitted first
972  *            true - LSB first
973  *            false - MSB first
974  *
975  * @return 0 on success, otherwise a negative error value
976  * @retval #PERIPHERAL_ERROR_NONE Successful
977  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
978  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
979  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
980  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
981  */
982 int peripheral_spi_set_lsb_first(peripheral_spi_h spi, bool lsb);
983
984 /**
985  * @brief Gets bits justification of the spi device.
986  * @since_tizen 4.0
987  *
988  * @param[in] spi The handle to the spi device
989  * @param[out] lsb The bit position to be transmitted first
990  *
991  * @return 0 on success, otherwise a negative error value
992  * @retval #PERIPHERAL_ERROR_NONE Successful
993  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
994  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
995  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
996  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
997  */
998 int peripheral_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb);
999
1000 /**
1001  * @brief Sets the number of bits per word of the spi device
1002  * @since_tizen 4.0
1003  *
1004  * @param[in] spi The handle to the spi device
1005  * @param[in] bits The number of bits per word (in bits)
1006  *
1007  * @return 0 on success, otherwise a negative error value
1008  * @retval #PERIPHERAL_ERROR_NONE Successful
1009  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1010  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1011  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1012  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
1013  */
1014 int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits);
1015
1016 /**
1017  * @brief Gets the number of bits per word of the spi device
1018  * @since_tizen 4.0
1019  *
1020  * @param[in] spi The handle to the spi device
1021  * @param[out] bits The number of bits per word (in bits)
1022  *
1023  * @return 0 on success, otherwise a negative error value
1024  * @retval #PERIPHERAL_ERROR_NONE Successful
1025  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1026  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1027  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1028  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
1029  */
1030 int peripheral_spi_get_bits_per_word(peripheral_spi_h spi, unsigned char *bits);
1031
1032 /**
1033  * @brief Sets default max speed of the spi device.
1034  * @since_tizen 4.0
1035  *
1036  * @param[in] spi The handle to the spi device
1037  * @param[in] freq Max speed (in hz)
1038  *
1039  * @return 0 on success, otherwise a negative error value
1040  * @retval #PERIPHERAL_ERROR_NONE Successful
1041  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1042  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1043  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1044  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
1045  */
1046 int peripheral_spi_set_frequency(peripheral_spi_h spi, unsigned int freq);
1047
1048 /**
1049  * @brief Gets default max speed of the spi device.
1050  * @since_tizen 4.0
1051  *
1052  * @param[in] spi The handle to the spi device
1053  * @param[out] freq Max speed (in hz)
1054  *
1055  * @return 0 on success, otherwise a negative error value
1056  * @retval #PERIPHERAL_ERROR_NONE Successful
1057  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1058  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1059  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1060  * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
1061  */
1062
1063 int peripheral_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq);
1064
1065 /**
1066  * @brief Reads data from the slave device.
1067  * @since_tizen 4.0
1068  *
1069  * @param[in] spi The handle to the spi device
1070  * @param[out] data The address of buffer to read
1071  * @param[in] length The size of data buffer (in bytes)
1072  *
1073  * @return 0 on success, otherwise a negative error value
1074  * @retval #PERIPHERAL_ERROR_NONE Successful
1075  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1076  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1077  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1078  */
1079 int peripheral_spi_read(peripheral_spi_h spi, unsigned char *data, int length);
1080
1081 /**
1082  * @brief Write data to the slave device.
1083  * @since_tizen 4.0
1084  *
1085  * @param[in] spi The handle to the spi device
1086  * @param[in] data The address of buffer to write
1087  * @param[in] length The size of data (in bytes)
1088  *
1089  * @return 0 on success, otherwise a negative error value
1090  * @retval #PERIPHERAL_ERROR_NONE Successful
1091  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1092  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1093  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1094  */
1095 int peripheral_spi_write(peripheral_spi_h spi, unsigned char *data, int length);
1096
1097 /**
1098  * @brief Exchange data with the slave device.
1099  * @since_tizen 4.0
1100  *
1101  * @param[in] spi The handle to the spi device
1102  * @param[in] txdata The address of buffer to write
1103  * @param[out] rxdata The address of buffer to read
1104  * @param[in] length The size of data (in bytes)
1105  *
1106  * @return 0 on success, otherwise a negative error value
1107  * @retval #PERIPHERAL_ERROR_NONE Successful
1108  * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1109  * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1110  * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1111  */
1112 int peripheral_spi_read_write(peripheral_spi_h spi, unsigned char *txdata, unsigned char *rxdata, int length);
1113
1114 /**
1115 * @}
1116 */
1117
1118 #ifdef __cplusplus
1119 }
1120 #endif
1121
1122 #endif /* __PERIPHERAL_IO_H__ */