73 lines
2.6 KiB
C
73 lines
2.6 KiB
C
/**
|
|
* @file imp_comp_sg90.c
|
|
* @author Alvin Young (impressionyang@outlook.com)
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2025-04-14
|
|
*
|
|
* _ _
|
|
* (_)_ _ ___ _______ ___ ___ (_)__ ___ __ _____ ____ ___ _
|
|
* / / ' \/ _ \/ __/ -_|_-<(_-</ / _ \/ _ \/ // / _ `/ _ \/ _ `/
|
|
* /_/_/_/_/ .__/_/ \__/___/___/_/\___/_//_/\_, /\_,_/_//_/\_, /
|
|
* /_/ /___/ /___/
|
|
* @copyright Copyright (c) 2025 impressionyang
|
|
*
|
|
* @par 修改日志:
|
|
* <table>
|
|
* <tr><th>Date <th>Version <th>Author <th>Description
|
|
* <tr><td>2025-04-14 <td>v1.0 <td>Alvin Young <td>首次创建
|
|
* </table>
|
|
*
|
|
*/
|
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "imp_comp_sg90.h"
|
|
/* define --------------------------------------------------------------------*/
|
|
/* typedef -------------------------------------------------------------------*/
|
|
/* variables -----------------------------------------------------------------*/
|
|
/* Private function(only *.c) -----------------------------------------------*/
|
|
/* Exported functions --------------------------------------------------------*/
|
|
|
|
uint8_t imp_comp_sg90_init(imp_comp_sg90_t* handle, uint8_t gpio,
|
|
uint8_t pwm_ch)
|
|
{
|
|
handle->is_init = 1;
|
|
handle->servo_pin = gpio;
|
|
handle->servo_pwm_channel = pwm_ch;
|
|
handle->speed_mode = LEDC_LOW_SPEED_MODE;
|
|
handle->servo_config.channel_number = 1;
|
|
handle->servo_config.channels.servo_pin[0] = handle->servo_pin;
|
|
handle->servo_config.channels.ch[0] =
|
|
pwm_ch > LEDC_CHANNEL_MAX ? LEDC_CHANNEL_MAX : pwm_ch;
|
|
handle->servo_config.max_angle = 180;
|
|
handle->servo_config.min_width_us = 500;
|
|
handle->servo_config.max_width_us = 2500;
|
|
handle->servo_config.freq = 50;
|
|
handle->servo_config.timer_number = LEDC_TIMER_0;
|
|
|
|
iot_servo_init(handle->speed_mode, &handle->servo_config);
|
|
|
|
return 0;
|
|
}
|
|
|
|
uint8_t imp_comp_sg90_set_angle(imp_comp_sg90_t* handle, float angle)
|
|
{
|
|
iot_servo_write_angle(handle->speed_mode, handle->servo_pwm_channel, angle);
|
|
return 0;
|
|
}
|
|
|
|
uint8_t imp_comp_sg90_get_angle(imp_comp_sg90_t* handle, float* angle)
|
|
{
|
|
iot_servo_read_angle(handle->speed_mode, handle->servo_pwm_channel, angle);
|
|
return 0;
|
|
}
|
|
|
|
uint8_t imp_comp_sg90_deinit(imp_comp_sg90_t* handle)
|
|
{
|
|
iot_servo_deinit(handle->speed_mode);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* EOF
|
|
*/ |