first commit
This commit is contained in:
5
application/samples/peripheral/pwm/CMakeLists.txt
Executable file
5
application/samples/peripheral/pwm/CMakeLists.txt
Executable file
@ -0,0 +1,5 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
set(SOURCES "${SOURCES}" "${CMAKE_CURRENT_SOURCE_DIR}/pwm_demo.c" PARENT_SCOPE)
|
28
application/samples/peripheral/pwm/Kconfig
Executable file
28
application/samples/peripheral/pwm/Kconfig
Executable file
@ -0,0 +1,28 @@
|
||||
#===============================================================================
|
||||
# @brief Kconfig file.
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
config PWM_CHANNEL
|
||||
int
|
||||
prompt "Choose PWM Test Channel."
|
||||
depends on SAMPLE_SUPPORT_PWM
|
||||
default 0
|
||||
|
||||
config PWM_GROUP_ID
|
||||
int
|
||||
prompt "Choose PWM Test Group ID."
|
||||
depends on SAMPLE_SUPPORT_PWM && PWM_USING_V151
|
||||
default 0
|
||||
|
||||
config PWM_PIN
|
||||
int
|
||||
prompt "Choose PWM pin."
|
||||
depends on SAMPLE_SUPPORT_PWM
|
||||
default 20
|
||||
|
||||
config PWM_PIN_MODE
|
||||
int
|
||||
prompt "Choose PWM pin mode."
|
||||
default 3
|
||||
depends on SAMPLE_SUPPORT_PWM
|
||||
|
11
application/samples/peripheral/pwm/pwm.code-workspace
Executable file
11
application/samples/peripheral/pwm/pwm.code-workspace
Executable file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "../../../../"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"debug.onTaskErrors": "debugAnyway",
|
||||
"workspace.samplePath": "./samples/peripheral/pwm"
|
||||
}
|
||||
}
|
84
application/samples/peripheral/pwm/pwm_demo.c
Executable file
84
application/samples/peripheral/pwm/pwm_demo.c
Executable file
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
*
|
||||
* Description: PWM Sample Source. \n
|
||||
*
|
||||
* History: \n
|
||||
* 2023-06-27, Create file. \n
|
||||
*/
|
||||
#if defined(CONFIG_PWM_SUPPORT_LPM)
|
||||
#include "pm_veto.h"
|
||||
#endif
|
||||
#include "common_def.h"
|
||||
#include "pinctrl.h"
|
||||
#include "pwm.h"
|
||||
#include "tcxo.h"
|
||||
#include "soc_osal.h"
|
||||
#include "app_init.h"
|
||||
|
||||
#define TEST_TCXO_DELAY_1000MS 1000
|
||||
|
||||
#define PWM_TASK_PRIO 24
|
||||
#define PWM_TASK_STACK_SIZE 0x1000
|
||||
|
||||
static errcode_t pwm_sample_callback(uint8_t channel)
|
||||
{
|
||||
osal_printk("PWM %d, cycle done. \r\n", channel);
|
||||
return ERRCODE_SUCC;
|
||||
}
|
||||
|
||||
static void *pwm_task(const char *arg)
|
||||
{
|
||||
UNUSED(arg);
|
||||
pwm_config_t cfg_no_repeat = {
|
||||
100,
|
||||
100,
|
||||
0,
|
||||
0xFF,
|
||||
false
|
||||
};
|
||||
|
||||
uapi_pin_set_mode(CONFIG_PWM_PIN, CONFIG_PWM_PIN_MODE);
|
||||
uapi_pwm_deinit();
|
||||
uapi_pwm_init();
|
||||
uapi_pwm_open(CONFIG_PWM_CHANNEL, &cfg_no_repeat);
|
||||
|
||||
uapi_tcxo_delay_ms((uint32_t)TEST_TCXO_DELAY_1000MS);
|
||||
uapi_pwm_unregister_interrupt(CONFIG_PWM_CHANNEL);
|
||||
uapi_pwm_register_interrupt(CONFIG_PWM_CHANNEL, pwm_sample_callback);
|
||||
#ifdef CONFIG_PWM_USING_V151
|
||||
uint8_t channel_id = CONFIG_PWM_CHANNEL;
|
||||
/* channel_id can also choose to configure multiple channels, and the third parameter also needs to be adjusted
|
||||
accordingly. */
|
||||
uapi_pwm_set_group(CONFIG_PWM_GROUP_ID, &channel_id, 1);
|
||||
/* Here you can also call the uapi_pwm_start interface to open each channel individually. */
|
||||
uapi_pwm_start_group(CONFIG_PWM_GROUP_ID);
|
||||
#else
|
||||
uapi_pwm_start(CONFIG_PWM_CHANNEL);
|
||||
#endif
|
||||
|
||||
uapi_tcxo_delay_ms((uint32_t)TEST_TCXO_DELAY_1000MS);
|
||||
#ifdef CONFIG_PWM_USING_V151
|
||||
uapi_pwm_close(CONFIG_PWM_GROUP_ID);
|
||||
#else
|
||||
uapi_pwm_close(CONFIG_PWM_CHANNEL);
|
||||
#endif
|
||||
|
||||
uapi_tcxo_delay_ms((uint32_t)TEST_TCXO_DELAY_1000MS);
|
||||
uapi_pwm_deinit();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void pwm_entry(void)
|
||||
{
|
||||
osal_task *task_handle = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle = osal_kthread_create((osal_kthread_handler)pwm_task, 0, "PwmTask", PWM_TASK_STACK_SIZE);
|
||||
if (task_handle != NULL) {
|
||||
osal_kthread_set_priority(task_handle, PWM_TASK_PRIO);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
}
|
||||
|
||||
/* Run the pwm_entry. */
|
||||
app_run(pwm_entry);
|
Reference in New Issue
Block a user