From e918b7cc7f4c80b8c23e8b5fe71cc557217c86b8 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Mon, 4 Jan 2021 09:31:58 +0800 Subject: [PATCH 1/4] Create pwm branch for testing PWM --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index c98351f42..58e74e73d 100755 --- a/README.rst +++ b/README.rst @@ -1,3 +1,5 @@ +This is the "pwm" branch for testing PWM. + Pine64 BL602 SDK modded for the articles... - `"Flashing Firmware to PineCone BL602" `_ From 5495334dd1b2da6ea8b5462cbefde9af3d4d1001 Mon Sep 17 00:00:00 2001 From: lupyuen Date: Mon, 4 Jan 2021 09:56:24 +0800 Subject: [PATCH 2/4] Add commands to set duty and frequency --- customer_app/sdk_app_pwm/sdk_app_pwm/main.c | 60 +++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/customer_app/sdk_app_pwm/sdk_app_pwm/main.c b/customer_app/sdk_app_pwm/sdk_app_pwm/main.c index c6fab6269..0911da65c 100755 --- a/customer_app/sdk_app_pwm/sdk_app_pwm/main.c +++ b/customer_app/sdk_app_pwm/sdk_app_pwm/main.c @@ -142,6 +142,63 @@ void cmd_pwm_init(char *buf, int len, int argc, char **argv) bl_pwm_init(id, pin, 6000000); } +/* +int32_t bl_pwm_set_duty(uint8_t id, float duty); +int32_t bl_pwm_get_duty(uint8_t id, float *p_duty); +int32_t bl_pwm_set_freq(uint8_t id, uint32_t freq); +*/ + +// pwm_duty_set 0 20000 +void cmd_pwm_duty_set(char *buf, int len, int argc, char **argv) +{ + uint8_t id; + float duty; + + if (argc != 3) { + log_error("arg err.\r\n"); + return; + } + + id = atoi(argv[1]); + duty = atof(argv[2]); + + bl_pwm_set_duty(id, duty); +} + +// pwm_duty_get 0 +void cmd_pwm_duty_get(char *buf, int len, int argc, char **argv) +{ + uint8_t id; + float duty; + + if (argc != 2) { + log_error("arg err.\r\n"); + return; + } + + id = atoi(argv[1]); + + bl_pwm_get_duty(id, &duty); + printf("pwm duty %f\r\n", duty); +} + +// pwm_freq_set 0 3000 +void cmd_pwm_freq_set(char *buf, int len, int argc, char **argv) +{ + uint8_t id; + uint32_t freq; + + if (argc != 3) { + log_error("arg err.\r\n"); + return; + } + + id = atoi(argv[1]); + freq = atoi(argv[2]); + + bl_pwm_set_freq(id, freq); +} + void cmd_pwm_start(char *buf, int len, int argc, char **argv) { uint8_t id; @@ -219,6 +276,9 @@ void cmd_pwm_test(char *buf, int len, int argc, char **argv) const static struct cli_command cmds_user[] STATIC_CLI_CMD_ATTRIBUTE = { { "pwm_init", "pwm_init 0 0", cmd_pwm_init}, + { "pwm_duty_set", "pwm_duty_set 0 20000", cmd_pwm_duty_set}, + { "pwm_duty_get", "pwm_duty_get 0", cmd_pwm_duty_get}, + { "pwm_freq_set", "pwm_freq_set 0 3000", cmd_pwm_freq_set}, { "pwm_start", "pwm_start 0", cmd_pwm_start}, { "pwm_stop", "pwm_stop 0", cmd_pwm_stop}, { "pwm_task", "pwm_task", cmd_pwm_task}, From 6c064f76ecec7b68a444d203b275aa5f42fda42b Mon Sep 17 00:00:00 2001 From: lupyuen Date: Mon, 4 Jan 2021 13:11:07 +0800 Subject: [PATCH 3/4] PWM tested OK --- customer_app/sdk_app_pwm/sdk_app_pwm/main.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/customer_app/sdk_app_pwm/sdk_app_pwm/main.c b/customer_app/sdk_app_pwm/sdk_app_pwm/main.c index 0911da65c..a389be181 100755 --- a/customer_app/sdk_app_pwm/sdk_app_pwm/main.c +++ b/customer_app/sdk_app_pwm/sdk_app_pwm/main.c @@ -130,24 +130,21 @@ void cmd_pwm_init(char *buf, int len, int argc, char **argv) { uint8_t id; uint8_t pin; + uint32_t freq; - if (argc != 3) { + if (argc != 4) { log_error("arg err.\r\n"); return; } id = atoi(argv[1]); pin = atoi(argv[2]); + freq = atoi(argv[3]); - bl_pwm_init(id, pin, 6000000); + // Frequency must be between 2000 and 800000 + bl_pwm_init(id, pin, freq); } -/* -int32_t bl_pwm_set_duty(uint8_t id, float duty); -int32_t bl_pwm_get_duty(uint8_t id, float *p_duty); -int32_t bl_pwm_set_freq(uint8_t id, uint32_t freq); -*/ - // pwm_duty_set 0 20000 void cmd_pwm_duty_set(char *buf, int len, int argc, char **argv) { @@ -275,7 +272,7 @@ void cmd_pwm_test(char *buf, int len, int argc, char **argv) } const static struct cli_command cmds_user[] STATIC_CLI_CMD_ATTRIBUTE = { - { "pwm_init", "pwm_init 0 0", cmd_pwm_init}, + { "pwm_init", "pwm_init 0 0 3000", cmd_pwm_init}, { "pwm_duty_set", "pwm_duty_set 0 20000", cmd_pwm_duty_set}, { "pwm_duty_get", "pwm_duty_get 0", cmd_pwm_duty_get}, { "pwm_freq_set", "pwm_freq_set 0 3000", cmd_pwm_freq_set}, From de60959338d5470d6753693264a4cbf1c029fba1 Mon Sep 17 00:00:00 2001 From: lupyuen Date: Mon, 4 Jan 2021 13:19:09 +0800 Subject: [PATCH 4/4] Clean up --- customer_app/sdk_app_pwm/sdk_app_pwm/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/customer_app/sdk_app_pwm/sdk_app_pwm/main.c b/customer_app/sdk_app_pwm/sdk_app_pwm/main.c index a389be181..8a32e7f32 100755 --- a/customer_app/sdk_app_pwm/sdk_app_pwm/main.c +++ b/customer_app/sdk_app_pwm/sdk_app_pwm/main.c @@ -145,7 +145,7 @@ void cmd_pwm_init(char *buf, int len, int argc, char **argv) bl_pwm_init(id, pin, freq); } -// pwm_duty_set 0 20000 +// Set the Duty Cycle (percentage from 0 to 100): pwm_duty_set 0 50 void cmd_pwm_duty_set(char *buf, int len, int argc, char **argv) { uint8_t id; @@ -162,7 +162,7 @@ void cmd_pwm_duty_set(char *buf, int len, int argc, char **argv) bl_pwm_set_duty(id, duty); } -// pwm_duty_get 0 +// Display the Duty Cycle (percentage from 0 to 100): pwm_duty_get 0 void cmd_pwm_duty_get(char *buf, int len, int argc, char **argv) { uint8_t id; @@ -179,7 +179,7 @@ void cmd_pwm_duty_get(char *buf, int len, int argc, char **argv) printf("pwm duty %f\r\n", duty); } -// pwm_freq_set 0 3000 +// Set the Frequency (2000 to 800000): pwm_freq_set 0 3000 void cmd_pwm_freq_set(char *buf, int len, int argc, char **argv) { uint8_t id; @@ -273,7 +273,7 @@ void cmd_pwm_test(char *buf, int len, int argc, char **argv) const static struct cli_command cmds_user[] STATIC_CLI_CMD_ATTRIBUTE = { { "pwm_init", "pwm_init 0 0 3000", cmd_pwm_init}, - { "pwm_duty_set", "pwm_duty_set 0 20000", cmd_pwm_duty_set}, + { "pwm_duty_set", "pwm_duty_set 0 50", cmd_pwm_duty_set}, { "pwm_duty_get", "pwm_duty_get 0", cmd_pwm_duty_get}, { "pwm_freq_set", "pwm_freq_set 0 3000", cmd_pwm_freq_set}, { "pwm_start", "pwm_start 0", cmd_pwm_start},