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 Struct for peripheral_gpio_s
668 #define DEVICE_NAME_SIZE 20
670 struct _peripheral_adc_s {
671 char device_name[DEVICE_NAME_SIZE];
676 * @brief Pointer definition to the internal struct peripheral_adc_s
678 typedef struct _peripheral_adc_s* peripheral_adc_context_h;
680 peripheral_adc_context_h peripheral_adc_open(int channel);
682 int peripheral_adc_read(peripheral_adc_context_h dev, int *data);
684 int peripheral_adc_close(peripheral_adc_context_h dev);
691 * @addtogroup CAPI_SYSTEM_PERIPHERAL_UART_MODULE
696 * @brief The handle to the uart device
699 typedef struct _peripheral_uart_s *peripheral_uart_h;
702 * @brief Enumeration for Baud Rate.
705 PERIPHERAL_UART_BAUDRATE_0 = 0,
706 PERIPHERAL_UART_BAUDRATE_50,
707 PERIPHERAL_UART_BAUDRATE_75,
708 PERIPHERAL_UART_BAUDRATE_110,
709 PERIPHERAL_UART_BAUDRATE_134,
710 PERIPHERAL_UART_BAUDRATE_150,
711 PERIPHERAL_UART_BAUDRATE_200,
712 PERIPHERAL_UART_BAUDRATE_300,
713 PERIPHERAL_UART_BAUDRATE_600,
714 PERIPHERAL_UART_BAUDRATE_1200,
715 PERIPHERAL_UART_BAUDRATE_1800,
716 PERIPHERAL_UART_BAUDRATE_2400,
717 PERIPHERAL_UART_BAUDRATE_4800,
718 PERIPHERAL_UART_BAUDRATE_9600,
719 PERIPHERAL_UART_BAUDRATE_19200,
720 PERIPHERAL_UART_BAUDRATE_38400,
721 PERIPHERAL_UART_BAUDRATE_57600,
722 PERIPHERAL_UART_BAUDRATE_115200,
723 PERIPHERAL_UART_BAUDRATE_230400
724 } peripheral_uart_baudrate_e;
727 * @brief Enumeration for Byte Size.
730 PERIPHERAL_UART_BYTESIZE_5BIT = 0,
731 PERIPHERAL_UART_BYTESIZE_6BIT,
732 PERIPHERAL_UART_BYTESIZE_7BIT,
733 PERIPHERAL_UART_BYTESIZE_8BIT
734 } peripheral_uart_bytesize_e;
737 * @brief Enumeration for Parity Bit.
740 PERIPHERAL_UART_PARITY_NONE = 0,
741 PERIPHERAL_UART_PARITY_EVEN,
742 PERIPHERAL_UART_PARITY_ODD
743 } peripheral_uart_parity_e;
746 * @brief Enumeration for Stop Bits.
749 PERIPHERAL_UART_STOPBITS_1BIT = 0,
750 PERIPHERAL_UART_STOPBITS_2BIT
751 } peripheral_uart_stopbits_e;
754 * @brief Initializes uart communication and creates uart handle.
757 * @param[in] port The uart port number that the slave device is connected
758 * @param[out] uart The uart handle is created on success
760 * @return 0 on success, otherwise a negative error value
761 * @retval #PERIPHERAL_ERROR_NONE Successful
762 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
763 * @retval #PERIPHERAL_ERROR_OUT_OF_MEMORY Memory allocation failed
764 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
765 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
766 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
768 * @see peripheral_uart_close()
770 int peripheral_uart_open(int port, peripheral_uart_h *uart);
773 * @brief Destory the uart handle and release the communication.
776 * @param[in] uart The handle to the uart device
778 * @return 0 on success, otherwise a negative error value
779 * @retval #PERIPHERAL_ERROR_NONE Successful
780 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
781 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
783 * @see peripheral_uart_open()
785 int peripheral_uart_close(peripheral_uart_h uart);
788 * @brief Flush all input that has received but not yet been read by the uart
789 * device, or all output written but not transmitted to the uart device.
792 * @param[in] uart The uart handle
794 * @return 0 on success, otherwise a negative error value
795 * @retval #PERIPHERAL_ERROR_NONE Successful
796 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
797 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
799 int peripheral_uart_flush(peripheral_uart_h uart);
802 * @brief Sets baudrate of the uart device.
805 * @param[in] uart The handle to the uart device to set
806 * @param[in] baud Baudrate of the uart device
808 * @return 0 on success, otherwise a negative error value
809 * @retval #PERIPHERAL_ERROR_NONE Successful
810 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
811 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
812 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
813 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
815 int peripheral_uart_set_baudrate(peripheral_uart_h uart, peripheral_uart_baudrate_e baud);
818 * @brief Sets mode of the uart device.
821 * @param[in] uart The handle to the uart device to set
822 * @param[in] bytesize Byte size of the uart device
823 * @param[in] parity Parity bits of the uart device
824 * @param[in] stopbits Stop bits of the uart device
826 * @return 0 on success, otherwise a negative error value
827 * @retval #PERIPHERAL_ERROR_NONE Successful
828 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
829 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
830 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
831 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
833 int peripheral_uart_set_mode(peripheral_uart_h uart, peripheral_uart_bytesize_e bytesize, peripheral_uart_parity_e parity, peripheral_uart_stopbits_e stopbits);
836 * @brief Sets flow control of the uart device.
839 * @param[in] uart The handle to the uart device to set
840 * @param[in] xonxoff Turns a transmitter on or off
841 * @param[in] rtscts Turns "Request to Send/Clear to Send" on or off
843 * @return 0 on success, otherwise a negative error value
844 * @retval #PERIPHERAL_ERROR_NONE Successful
845 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
846 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
847 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
848 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
850 int peripheral_uart_set_flowcontrol(peripheral_uart_h uart, bool xonxoff, bool rtscts);
853 * @brief Reads data from the uart device.
856 * @param[in] uart The handle to the uart device
857 * @param[out] data The address of read buffer
858 * @param[out] length The size of data buffer (in bytes)
860 * @return the number of bytes read on success, otherwise a negative error value
861 * @retval #PERIPHERAL_ERROR_NONE Successful
862 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
863 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
864 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
866 int peripheral_uart_read(peripheral_uart_h uart, uint8_t *data, int length);
869 * @brief Write data to the uart device.
872 * @param[in] uart The handle to the uart device
873 * @param[in] data The address of buffer to write
874 * @param[in] length The size of data (in bytes)
876 * @return the number of bytes write on success, otherwise a negative error value
877 * @retval #PERIPHERAL_ERROR_NONE Successful
878 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
879 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
880 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
882 int peripheral_uart_write(peripheral_uart_h uart, uint8_t *data, int length);
889 * @addtogroup CAPI_SYSTEM_PERIPHERAL_SPI_MODULE
894 * @brief The handle to the spi device
897 typedef struct _peripheral_spi_s* peripheral_spi_h;
900 * @brief Enumeration for SPI mode.
903 PERIPHERAL_SPI_MODE_0 = 0,
904 PERIPHERAL_SPI_MODE_1,
905 PERIPHERAL_SPI_MODE_2,
906 PERIPHERAL_SPI_MODE_3
907 } peripheral_spi_mode_e;
910 * @brief Initializes spi communication and creates spi handle.
913 * @param[in] bus The spi bus number that the slave device is connected
914 * @param[in] cs The spi chip select number that the slave device is connected
915 * @param[out] spi The spi handle is created on success
917 * @return 0 on success, otherwise a negative error value
918 * @retval #PERIPHERAL_ERROR_NONE Successful
920 * @see peripheral_spi_close()
922 int peripheral_spi_open(int bus, int cs, peripheral_spi_h *spi);
925 * @brief Destory the spi handle and release the communication.
928 * @param[in] spi The handle to the spi device
930 * @return 0 on success, otherwise a negative error value
931 * @retval #PERIPHERAL_ERROR_NONE Successful
932 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
933 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
935 * @see peripheral_spi_open()
937 int peripheral_spi_close(peripheral_spi_h spi);
940 * @brief Sets mode of the spi device.
943 * @param[in] spi The handle to the spi device
944 * @param[in] mode The mode of the spi device
946 * @return 0 on success, otherwise a negative error value
947 * @retval #PERIPHERAL_ERROR_NONE Successful
948 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
949 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
950 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
951 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
953 int peripheral_spi_set_mode(peripheral_spi_h spi, peripheral_spi_mode_e mode);
956 * @brief Gets mode of the spi device.
959 * @param[in] spi The handle to the spi device
960 * @param[out] mode The mode of the spi device
962 * @return 0 on success, otherwise a negative error value
963 * @retval #PERIPHERAL_ERROR_NONE Successful
964 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
965 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
966 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
967 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
969 int peripheral_spi_get_mode(peripheral_spi_h spi, peripheral_spi_mode_e *mode);
972 * @brief Sets bits justification of the spi device.
975 * @param[in] spi The handle to the spi device
976 * @param[in] lsb The bit position to be transmitted first
980 * @return 0 on success, otherwise a negative error value
981 * @retval #PERIPHERAL_ERROR_NONE Successful
982 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
983 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
984 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
985 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
987 int peripheral_spi_set_lsb_first(peripheral_spi_h spi, bool lsb);
990 * @brief Gets bits justification of the spi device.
993 * @param[in] spi The handle to the spi device
994 * @param[out] lsb The bit position to be transmitted first
996 * @return 0 on success, otherwise a negative error value
997 * @retval #PERIPHERAL_ERROR_NONE Successful
998 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
999 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1000 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1001 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
1003 int peripheral_spi_get_lsb_first(peripheral_spi_h spi, bool *lsb);
1006 * @brief Sets the number of bits per word of the spi device
1009 * @param[in] spi The handle to the spi device
1010 * @param[in] bits The number of bits per word (in bits)
1012 * @return 0 on success, otherwise a negative error value
1013 * @retval #PERIPHERAL_ERROR_NONE Successful
1014 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1015 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1016 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1017 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
1019 int peripheral_spi_set_bits_per_word(peripheral_spi_h spi, unsigned char bits);
1022 * @brief Gets the number of bits per word of the spi device
1025 * @param[in] spi The handle to the spi device
1026 * @param[out] bits The number of bits per word (in bits)
1028 * @return 0 on success, otherwise a negative error value
1029 * @retval #PERIPHERAL_ERROR_NONE Successful
1030 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1031 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1032 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1033 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
1035 int peripheral_spi_get_bits_per_word(peripheral_spi_h spi, unsigned char *bits);
1038 * @brief Sets default max speed of the spi device.
1041 * @param[in] spi The handle to the spi device
1042 * @param[in] freq Max speed (in hz)
1044 * @return 0 on success, otherwise a negative error value
1045 * @retval #PERIPHERAL_ERROR_NONE Successful
1046 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1047 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1048 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1049 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
1051 int peripheral_spi_set_frequency(peripheral_spi_h spi, unsigned int freq);
1054 * @brief Gets default max speed of the spi device.
1057 * @param[in] spi The handle to the spi device
1058 * @param[out] freq Max speed (in hz)
1060 * @return 0 on success, otherwise a negative error value
1061 * @retval #PERIPHERAL_ERROR_NONE Successful
1062 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1063 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1064 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1065 * @retval #PERIPHERAL_ERROR_NO_DEVICE Device is not exist or removed
1068 int peripheral_spi_get_frequency(peripheral_spi_h spi, unsigned int *freq);
1071 * @brief Reads data from the slave device.
1074 * @param[in] spi The handle to the spi device
1075 * @param[out] data The address of buffer to read
1076 * @param[in] length The size of data buffer (in bytes)
1078 * @return 0 on success, otherwise a negative error value
1079 * @retval #PERIPHERAL_ERROR_NONE Successful
1080 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1081 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1082 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1084 int peripheral_spi_read(peripheral_spi_h spi, unsigned char *data, int length);
1087 * @brief Write data to the slave device.
1090 * @param[in] spi The handle to the spi device
1091 * @param[in] data The address of buffer to write
1092 * @param[in] length The size of data (in bytes)
1094 * @return 0 on success, otherwise a negative error value
1095 * @retval #PERIPHERAL_ERROR_NONE Successful
1096 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1097 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1098 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1100 int peripheral_spi_write(peripheral_spi_h spi, unsigned char *data, int length);
1103 * @brief Exchange data with the slave device.
1106 * @param[in] spi The handle to the spi device
1107 * @param[in] txdata The address of buffer to write
1108 * @param[out] rxdata The address of buffer to read
1109 * @param[in] length The size of data (in bytes)
1111 * @return 0 on success, otherwise a negative error value
1112 * @retval #PERIPHERAL_ERROR_NONE Successful
1113 * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
1114 * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
1115 * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
1117 int peripheral_spi_read_write(peripheral_spi_h spi, unsigned char *txdata, unsigned char *rxdata, int length);
1127 #endif /* __PERIPHERAL_IO_H__ */