/** * @file hal_pwm.h * @author XRADIO IOT WLAN Team */ /* * Copyright (C) 2017 XRADIO TECHNOLOGY CO., LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * 3. Neither the name of XRADIO TECHNOLOGY CO., LTD. nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _DRIVER_CHIP_HAL_PWM_H_ #define _DRIVER_CHIP_HAL_PWM_H_ #include "driver/chip/hal_def.h" #include "driver/chip/hal_gpio.h" #include "driver/chip/hal_clock.h" #ifdef __cplusplus extern "C" { #endif /** * @brief PWM group id. */ typedef enum { PWM_GROUP_0, /*!clk:The source clk of this group. * @arg param->div:The division for source clk. * @retval HAL_Status: The status of driver */ HAL_Status HAL_PWM_GroupClkCfg(PWM_GROUP_ID group_id, PWM_ClkParam *param); /** * @brief Init the pwm channel. * @note This function is used to configure the channel pin(IO mode), output frequency , * polarity and rum mode. * @param ch_id: The pwm channel id. * @param param: * @arg param->mode:The channels run mode. * @arg param->polarity:The channels polarity. * @arg param->hz:The channels output frequency. * @retval max_duty_ratio: The channel max duty cycle value. if the mode is * capture, the return value is 0. error return -1; */ int HAL_PWM_ChInit(PWM_CH_ID ch_id, PWM_ChInitParam *param); /** * @brief Deinit the pwm channel. * @note This function is used to deinit the channel pin, reduce power consumption. * @param ch_id: The pwm channel id. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_ChDeinit(PWM_CH_ID ch_id); /** * @brief Init the complementary mode. * @note This function is used to configure the groups pin(IO mode), output frequency , * polarity. * This mode is two channel output complementart waveform, the channel run in * cycle mode. * @param group_id: The pwm group id. * @param param: * @arg param->polarity:The channels polarity. * @arg param->hz:The channels output frequency. * @retval HAL_Status: The channel max duty cycle value. */ int HAL_PWM_ComplementaryInit(PWM_GROUP_ID group_id, PWM_CompInitParam *param); /** * @brief Deinit the pwm complementary. * @note This function is used to deinit the groupl pin, reduce power consumption. * @param group_id: The pwm group id. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_ComplementaryDeInit(PWM_GROUP_ID group_id); /** * @brief Enable the pwm channel. * @param ch_id: The pwm channel id. * @param mode: The pwm channel run mode. * @param en: set 1 enable , 0 disable. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_EnableCh(PWM_CH_ID ch_id, PWM_Mode mode, uint8_t en); /** * @brief Output one pluse.Use this function you need already enable the channel. * @param ch_id: The pwm channel id. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_OutputPluse(PWM_CH_ID ch_id); /** * @brief Enable the complementary. * @param group_id: The pwm group id. * @param en: set 1 enable , 0 disable. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_EnableComplementary(PWM_GROUP_ID group_id, uint8_t en); /** * @brief Enable the pwm channel's interrupt. * @param ch_id: The pwm channel id. * @param param: * @arg param->event:The interrupt event. * @arg param->callback:The interrupt callback. * @arg param->arg: The param for callback. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_EnableIRQ(PWM_CH_ID ch_id, const PWM_IrqParam *param); /** * @brief Disable the pwm channel's interrupt. * @param ch_id: The pwm channel id. * @retval HAL_Status: The status of driver. */ void HAL_PWM_DisableIRQ(PWM_CH_ID ch_id); /** * @brief Set channel's duty ratio. * @param ch_id: The pwm channel id. * @param value: The duty ratio value. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_ChSetDutyRatio(PWM_CH_ID ch_id, uint16_t value); /** * @brief Set Complementary duty ratio. * @param group_id: The pwm group id. * @param value: The duty ratio value. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_ComplementarySetDutyRatio(PWM_GROUP_ID group_id, uint16_t value); /** * @brief Set dead zone for complementary mode. * @param group_id: The pwm group id. * @param value: The dead zone value. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_SetDeadZoneTime(PWM_GROUP_ID group_id, uint8_t dead_zone_value); /** * @brief Enable the dead zone. * @param group_id: The pwm group id. * @param en: set 1 enable, 0 disable. * @retval HAL_Status: The status of driver. */ HAL_Status HAL_PWM_EnableDeadZone(PWM_GROUP_ID group_id, uint8_t en); /** * @brief The pwm channel capture result. * @param mode: * @arg PWM_CAP_PLUSE: used for capture pluse. Run in the mode, * only the highLevlTime is valid. * @arg PWM_CAP_CYCLE: used for cycle signal. capture the signal's period, * high level time and low level time. * @param ch_id: The pwm channel id. * @retval PWM_CapResult: The result of capture. */ PWM_CapResult HAL_PWM_CaptureResult(PWM_CaptureMode mode, PWM_CH_ID ch_id); #ifdef __cplusplus } #endif #endif /* _DRIVER_CHIP_HAL_PWM_H_ */