Skip to content

Commit

Permalink
Merge pull request #1 from lupyuen/pwm
Browse files Browse the repository at this point in the history
Fix PWM demo for non-Device Tree
  • Loading branch information
lupyuen committed Jan 4, 2021
2 parents a1d8e15 + de60959 commit 4ab3010
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
This is the "pwm" branch for testing PWM.

Pine64 BL602 SDK modded for the articles...

- `"Flashing Firmware to PineCone BL602" <https://lupyuen.github.io/articles/flash>`_
Expand Down
63 changes: 60 additions & 3 deletions customer_app/sdk_app_pwm/sdk_app_pwm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,70 @@ 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]);

// Frequency must be between 2000 and 800000
bl_pwm_init(id, pin, freq);
}

// 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;
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);
}

// 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;
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);
}

// 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;
uint32_t freq;

if (argc != 3) {
log_error("arg err.\r\n");
return;
}

id = atoi(argv[1]);
freq = atoi(argv[2]);

bl_pwm_init(id, pin, 6000000);
bl_pwm_set_freq(id, freq);
}

void cmd_pwm_start(char *buf, int len, int argc, char **argv)
Expand Down Expand Up @@ -218,7 +272,10 @@ 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 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},
{ "pwm_stop", "pwm_stop 0", cmd_pwm_stop},
{ "pwm_task", "pwm_task", cmd_pwm_task},
Expand Down

0 comments on commit 4ab3010

Please sign in to comment.