You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.3 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2021-2021. All rights reserved.
* Description: pwm sample
* Author: Hisilicon
* Create: 2021.12.10
*/
/********************************************************************************************/
/* Includes */
/********************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "uapi_pwm.h"
#include "sample_pwm.h"
/*********************************************************************************************
Function Implementation
*********************************************************************************************/
static td_void printf_help(td_void)
{
printf("\nUsage: sample_moto_pwm pwm_num | freq | duty_ratio | time_us\n");
printf(" pwm_num - The moto pwm number should be 47(GPIO5_7).\n");
printf(" freq - The frequency in Hz.\n");
printf(" duty_ratio - The value of duty ratio is from 0 to 1000.\n");
printf(" time_us - The duration time in microsecond.\n");
printf("Example: sample_moto_pwm 47 36000 500 1000000\n");
printf("Note: The moto pwm sample can only be ran on type_v1.\n");
}
td_s32 main(td_s32 argc, td_char *argv[])
{
td_s32 ret, ret1, i;
td_u32 pwm_no, freq, duty_ratio, time_us;
uapi_pwm_attr attr = {0};
sample_pwm_check_param(ret, TD_FAILURE, argc != 0x5, goto help);
pwm_no = (td_u32)strtoul(argv[0x1], TD_NULL, 0);
freq = (td_u32)strtoul(argv[0x2], TD_NULL, 0);
duty_ratio = (td_u32)strtoul(argv[0x3], TD_NULL, 0);
time_us = (td_u32)strtoul(argv[0x4], TD_NULL, 0);
sample_pwm_check_param(ret, TD_FAILURE, duty_ratio > 1000, goto help); /* 1000: max duty ratio */
sample_pwm_func_call(ret, uapi_pwm_init(), goto out);
attr.pwm_frequency = freq;
attr.pwm_duty_ratio = duty_ratio;
sample_pwm_func_call(ret, uapi_pwm_moto_trigger(pwm_no, &attr, time_us), goto deinit);
while (1) {
printf("enter q to quit\n");
i = getchar();
if (i == 'q') {
break;
}
}
sample_pwm_func_call(ret, uapi_pwm_set_enable(pwm_no, TD_FALSE), goto deinit);
deinit:
sample_pwm_func_call(ret1, uapi_pwm_deinit(), goto out);
goto out;
help:
printf_help();
out:
return ret;
}