1 /* 2 * Copyright (C) 2020-2021 Alibaba Group Holding Limited 3 */ 4 5 #ifndef AOS_GPIOC_H 6 #define AOS_GPIOC_H 7 8 #include <aos/device.h> 9 #include <aos/gpio.h> 10 11 typedef aos_dev_ref_t aos_gpioc_ref_t; 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /** 18 * @brief Get a GPIO controller device. 19 * @param[out] ref GPIO controller ref to operate 20 * @param[in] id GPIO controller device ID 21 * @return 0: on success; < 0: on failure 22 */ 23 aos_status_t aos_gpioc_get(aos_gpioc_ref_t *ref, uint32_t id); 24 /** 25 * @brief Release a GPIO controller device. 26 * @param[in] ref GPIO controller ref to operate 27 * @return None 28 */ 29 void aos_gpioc_put(aos_gpioc_ref_t *ref); 30 /** 31 * @brief Get number of pins on a GPIO controller device. 32 * @param[in] ref GPIO controller ref to operate 33 * @return >= 0: on success; < 0: on failure 34 */ 35 aos_status_t aos_gpioc_get_num_pins(aos_gpioc_ref_t *ref); 36 /** 37 * @brief Get the parameters associated with a GPIO pin. 38 * @param[in] ref GPIO controller ref to operate 39 * @param[in] pin pin to operate 40 * @param[out] mode pin mode 41 * @return 0: on success; < 0: on failure 42 */ 43 aos_status_t aos_gpioc_get_mode(aos_gpioc_ref_t *ref, uint32_t pin, uint32_t *mode); 44 /** 45 * @brief Set the parameters associated with a GPIO pin. 46 * @param[in] ref GPIO controller ref to operate 47 * @param[in] pin pin to operate 48 * @param[in] mode pin mode 49 * @return 0: on success; < 0: on failure 50 */ 51 aos_status_t aos_gpioc_set_mode(aos_gpioc_ref_t *ref, uint32_t pin, uint32_t mode); 52 /** 53 * @brief Set the parameters and IRQ settings associated with a GPIO pin. 54 * @param[in] ref GPIO controller ref to operate 55 * @param[in] pin pin to operate 56 * @param[in] mode pin mode 57 * @param[in] irq_handler IRQ handler 58 * @param[in] irq_arg argument passed to IRQ handler 59 * @return 0: on success; < 0: on failure 60 */ 61 aos_status_t aos_gpioc_set_mode_irq(aos_gpioc_ref_t *ref, uint32_t pin, uint32_t mode, 62 aos_gpio_irq_handler_t irq_handler, void *irq_arg); 63 /** 64 * @brief Get the input or output level of a GPIO pin. 65 * @param[in] ref GPIO controller ref to operate 66 * @param[in] pin pin to operate 67 * @return 0: low level; > 0: high level; < 0: on failure 68 */ 69 aos_status_t aos_gpioc_get_value(aos_gpioc_ref_t *ref, uint32_t pin); 70 /** 71 * @brief Set the output level of a GPIO pin. 72 * @param[in] ref GPIO controller ref to operate 73 * @param[in] pin pin to operate 74 * @param[in] val output level 75 * @return 0: on success; < 0: on failure 76 */ 77 aos_status_t aos_gpioc_set_value(aos_gpioc_ref_t *ref, uint32_t pin, int val); 78 /** 79 * @brief Toggle the output level of a GPIO pin. 80 * @param[in] ref GPIO controller ref to operate 81 * @param[in] pin pin to operate 82 * @return 0: on success; < 0: on failure 83 */ 84 aos_status_t aos_gpioc_toggle(aos_gpioc_ref_t *ref, uint32_t pin); 85 86 #ifdef __cplusplus 87 } 88 #endif 89 90 #endif /* AOS_GPIOC_H */ 91