2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __PERIPHERAL_IO_H__
18 #define __PERIPHERAL_IO_H__
28 * @file peripheral_io.h
29 * @brief This file contains the peripheral-io API
33 * @brief Enumeration for peripheral-io error.
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 */
52 * @addtogroup CAPI_SYSTEM_PERIPHERAL_GPIO_MODULE
57 * @brief Enumeration of gpio direction
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;
67 * @brief Enumeration of edge type for gpio interrupt
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;
77 * @brief The handle to the gpio pin
80 typedef struct _peripheral_gpio_s* peripheral_gpio_h;
83 * @brief Initializes(export) gpio pin and creates gpio handle.
86 * @param[in] gpio_pin The gpio pin number
87 * @param[out] gpio The gpio handle is created on success
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
97 * @see peripheral_gpio_close()
99 int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio);
102 * @brief Releases the gpio handle and finalize(unexport) the gpio pin.
105 * @param[in] gpio The handle to the gpio pin to release
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
114 * @see peripheral_gpio_open()
116 int peripheral_gpio_close(peripheral_gpio_h gpio);
119 * @brief Gets direction of the gpio.
122 * @param[in] gpio The handle to the gpio pin
123 * @param[out] value The direction(value) type of the gpio
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
132 * @see peripheral_gpio_set_direction()
134 int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction);
137 * @brief Sets direction of the gpio pin.
140 * @param[in] gpio The handle to the gpio pin to set
141 * @param[in] direction Direction(value) type of the gpio pin
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
150 int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
153 * @brief Reads value of the gpio.
156 * @param[in] gpio The handle to the gpio pin
157 * @param[out] value The value of the gpio (zero or non-zero)
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
166 * @see peripheral_gpio_write()
168 int peripheral_gpio_read(peripheral_gpio_h gpio, int *value);
171 * @brief Writes value to the gpio.
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)
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
184 * @see peripheral_gpio_read()
186 int peripheral_gpio_write(peripheral_gpio_h gpio, int value);
189 * @brief Gets the edge mode of the gpio.
192 * @param[in] gpio The handle to the gpio pin
193 * @param[out] gpio_pin The edge mode of the gpio
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
202 * @see peripheral_gpio_set_edge_mode()
204 int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge);
207 * @brief Sets the edge mode of the gpio pin.
210 * @param[in] gpio The handle to the gpio pin to set
211 * @param[in] edge The edge mode of the gpio pin
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
220 * @see peripheral_gpio_get_edge_mode()
222 int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
225 * @brief Called when the gpio interrupt is triggered.
228 * @param[in] user_data The user data passed from the callback registration function
230 * @see peripheral_gpio_register_cb()
231 * @see peripheral_gpio_unregister_cb()
233 typedef void(*gpio_isr_cb)(void *user_data);
236 * @brief Registers a callback function to be invoked when the gpio interrupt is triggered.
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
244 * @return 0 on success, otherwise a negative error value
245 * @retval #PERIPHERAL_ERROR_NONE Successful
246 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
248 * @see peripheral_gpio_set_edge_mode()
249 * @see peripheral_gpio_unregister_cb()
251 int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data);
254 * @brief Unregisters the callback function for the gpio handler.
257 * @param[in] gpio The handle to the gpio pin
259 * @return 0 on success, otherwise a negative error value
260 * @retval #PERIPHERAL_ERROR_NONE Successful
261 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
263 * @see peripheral_gpio_register_cb()
265 int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio);
268 * @brief Gets pin number of the gpio handle.
271 * @param[in] gpio The handle to the gpio pin
272 * @param[out] gpio_pin The pin number of the gpio
274 * @return 0 on success, otherwise a negative error value
275 * @retval #PERIPHERAL_ERROR_NONE Successful
276 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
278 int peripheral_gpio_get_pin(peripheral_gpio_h gpio, int *gpio_pin);
285 * @addtogroup CAPI_SYSTEM_PERIPHERAL_I2C_MODULE
290 * @brief The handle to the i2c device
293 typedef struct _peripheral_i2c_s *peripheral_i2c_h;
296 * @brief Initializes i2c communication and creates i2c handle.
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
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
311 * @see peripheral_i2c_close()
313 int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c);
316 * @brief Destory the i2c handle and release the communication.
319 * @param[in] i2c The i2c handle
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
326 * @see peripheral_i2c_open()
328 int peripheral_i2c_close(peripheral_i2c_h i2c);
331 * @brief Reads data from the i2c slave device.
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)
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
344 int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
347 * @brief Write data to the i2c slave device.
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)
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
360 int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
363 * @brief Reads single byte data from the i2c slave device.
366 * @param[in] i2c The handle to the i2c device
367 * @param[out] data The address of data buffer to read
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
375 int peripheral_i2c_read_byte(peripheral_i2c_h i2c, uint8_t *data);
378 * @brief Write single byte data to the i2c slave device.
381 * @param[in] i2c The handle to the i2c device
382 * @param[in] data The byte value to write
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
390 int peripheral_i2c_write_byte(peripheral_i2c_h i2c, uint8_t data);
393 * @brief Reads byte data from the register of i2c slave device.
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)
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
406 int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t *data);
409 * @brief Write byte data to the register of i2c slave device.
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
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
422 int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t data);
425 * @brief Reads word data from the register of i2c slave device.
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)
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
438 int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t *data);
441 * @brief Write byte data to the register of i2c slave device.
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
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
454 int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t data);
461 * @addtogroup CAPI_SYSTEM_PERIPHERAL_PWM_MODULE
466 * @brief The handle to the pwm device
469 typedef struct _peripheral_pwm_s *peripheral_pwm_h;
472 * @brief Enumeration for Polarity.
475 PERIPHERAL_PWM_POLARITY_NORMAL = 0,
476 PERIPHERAL_PWM_POLARITY_INVERSED,
477 } peripheral_pwm_polarity_e;
480 * @brief Initializes(export) pwm device and creates pwm handle.
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
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
496 * @see peripheral_pwm_close()
498 int peripheral_pwm_open(int device, int channel, peripheral_pwm_h *pwm);
501 * @brief Destory the pwm handle and finalize(unexport) the pwm device.
504 * @param[in] pwm The handle to the pwm device
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
514 * @see peripheral_pwm_open()
516 int peripheral_pwm_close(peripheral_pwm_h pwm);
519 * @brief Sets Period of the pwm device.
522 * @param[in] pwm The handle to the pwm device
523 * @param[in] period The total period of the PWM signal (in nanoseconds)
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
533 int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period);
536 * @brief Gets Period of the pwm device.
539 * @param[in] pwm The handle to the pwm device
540 * @param[out] period The total period of the PWM signal (in nanoseconds)
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
550 int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period);
553 * @brief Sets Duty Cycle of the pwm device.
556 * @param[in] pwm The handle to the pwm device
557 * @param[in] duty_cycle The active time of the pwm signal (in nanoseconds)
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
567 int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle);
570 * @brief Gets Duty Cycle of the pwm device.
573 * @param[in] pwm The handle to the pwm device
574 * @param[out] duty_cycle The active time of the pwm signal (in nanoseconds)
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
584 int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle);
587 * @brief Sets Polarity of the pwm device.
590 * @param[in] pwm The handle to the pwm device
591 * @param[in] polarity The polarity of the pwm signal
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
601 int peripheral_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity);
604 * @brief Gets Polarity of the pwm device.
607 * @param[in] pwm The handle to the pwm device
608 * @param[out] polarity The polarity of the pwm signal
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
618 int peripheral_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity);
621 * @brief Enable of the pwm device.
624 * @param[in] pwm The handle to the pwm device
625 * @param[in] enable Enable/disable the pwm signal
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
636 int peripheral_pwm_set_enable(peripheral_pwm_h pwm, bool enable);
639 * @brief Gets Enable status of the pwm device.
642 * @param[in] pwm The handle to the pwm device
643 * @param[out] enable Enable/disable the pwm signal
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
653 int peripheral_pwm_get_enable(peripheral_pwm_h pwm, bool *enable);
660 * @addtogroup CAPI_SYSTEM_PERIPHERAL_ADC_MODULE
665 * @brief Reads data from the adc device.
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
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
679 int peripheral_adc_read(unsigned int device, unsigned int channel, int *data);
686 * @addtogroup CAPI_SYSTEM_PERIPHERAL_UART_MODULE
691 * @brief The handle to the uart device
694 typedef struct _peripheral_uart_s *peripheral_uart_h;
697 * @brief Enumeration for Baud Rate.
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;
722 * @brief Enumeration for Byte Size.
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;
732 * @brief Enumeration for Parity Bit.
735 PERIPHERAL_UART_PARITY_NONE = 0,
736 PERIPHERAL_UART_PARITY_EVEN,
737 PERIPHERAL_UART_PARITY_ODD
738 } peripheral_uart_parity_e;
741 * @brief Enumeration for Stop Bits.
744 PERIPHERAL_UART_STOPBITS_1BIT = 0,
745 PERIPHERAL_UART_STOPBITS_2BIT
746 } peripheral_uart_stopbits_e;
749 * @brief Initializes uart communication and creates uart handle.
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
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
763 * @see peripheral_uart_close()
765 int peripheral_uart_open(int port, peripheral_uart_h *uart);
768 * @brief Destory the uart handle and release the communication.
771 * @param[in] uart The handle to the uart device
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
778 * @see peripheral_uart_open()
780 int peripheral_uart_close(peripheral_uart_h uart);
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.
787 * @param[in] uart The uart handle
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
794 int peripheral_uart_flush(peripheral_uart_h uart);
797 * @brief Sets baudrate of the uart device.
800 * @param[in] uart The handle to the uart device to set
801 * @param[in] baud Baudrate of the uart device
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
810 int peripheral_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud);
813 * @brief Sets mode of the uart device.
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
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
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);
831 * @brief Sets flow control of the uart device.
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
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
845 int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts);
848 * @brief Reads data from the uart device.
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)
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
861 int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length);
864 * @brief Write data to the uart device.
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)
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
877 int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, int length);
884 * @addtogroup CAPI_SYSTEM_PERIPHERAL_SPI_MODULE
889 * @brief The handle to the spi device
892 typedef struct _peripheral_spi_s* peripheral_spi_h;
895 * @brief Enumeration for SPI mode.
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;
905 * @brief Initializes spi communication and creates spi handle.
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
912 * @return 0 on success, otherwise a negative error value
913 * @retval #PERIPHERAL_ERROR_NONE Successful
915 * @see peripheral_spi_close()
917 int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi);
920 * @brief Destory the spi handle and release the communication.
923 * @param[in] spi The handle to the spi device
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
930 * @see peripheral_spi_open()
932 int peripheral_spi_close(peripheral_spi_h spi);
935 * @brief Sets mode of the spi device.
938 * @param[in] spi The handle to the spi device
939 * @param[in] mode The mode of the spi device
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
948 int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode);
951 * @brief Gets mode of the spi device.
954 * @param[in] spi The handle to the spi device
955 * @param[out] mode The mode of the spi device
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
964 int peripheral_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode);
967 * @brief Sets bits justification of the spi device.
970 * @param[in] spi The handle to the spi device
971 * @param[in] lsb The bit position to be transmitted first
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
982 int peripheral_spi_set_lsb_first(peripheral_spi_h spi, bool lsb);
985 * @brief Gets bits justification of the spi device.
988 * @param[in] spi The handle to the spi device
989 * @param[out] lsb The bit position to be transmitted first
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
998 int peripheral_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb);
1001 * @brief Sets the number of bits per word of the spi device
1004 * @param[in] spi The handle to the spi device
1005 * @param[in] bits The number of bits per word (in bits)
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
1014 int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits);
1017 * @brief Gets the number of bits per word of the spi device
1020 * @param[in] spi The handle to the spi device
1021 * @param[out] bits The number of bits per word (in bits)
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
1030 int peripheral_spi_get_bits_per_word(peripheral_spi_h spi, unsigned char *bits);
1033 * @brief Sets default max speed of the spi device.
1036 * @param[in] spi The handle to the spi device
1037 * @param[in] freq Max speed (in hz)
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
1046 int peripheral_spi_set_frequency(peripheral_spi_h spi, unsigned int freq);
1049 * @brief Gets default max speed of the spi device.
1052 * @param[in] spi The handle to the spi device
1053 * @param[out] freq Max speed (in hz)
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
1063 int peripheral_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq);
1066 * @brief Reads data from the slave device.
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)
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
1079 int peripheral_spi_read(peripheral_spi_h spi, unsigned char *data, int length);
1082 * @brief Write data to the slave device.
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)
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
1095 int peripheral_spi_write(peripheral_spi_h spi, unsigned char *data, int length);
1098 * @brief Exchange data with the slave device.
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)
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
1112 int peripheral_spi_read_write(peripheral_spi_h spi, unsigned char *txdata, unsigned char *rxdata, int length);
1122 #endif /* __PERIPHERAL_IO_H__ */