Skip to content

Commit 091af20

Browse files
ArcaneNibbledlech
authored andcommitted
pbio/drv/pwm/pwm_ev3: Reimplement using PRU
1 parent 3db3b91 commit 091af20

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/pbio/drv/pwm/pwm_ev3.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#if PBDRV_CONFIG_PWM_TIAM1808
77

88
#include <stdio.h>
9+
#include <string.h>
910

1011
#include <pbdrv/pwm.h>
1112
#include <pbdrv/gpio.h>
@@ -19,6 +20,7 @@
1920
#include <tiam1808/timer.h>
2021

2122
#include "../drv/pwm/pwm.h"
23+
#include "../../drv/led/led_pwm.h"
2224
#include "../../drv/pwm/pwm_ev3.h"
2325
#include "../../drv/gpio/gpio_ev3.h"
2426

@@ -32,7 +34,12 @@ typedef struct shared_ram {
3234
static volatile shared_ram *const pru1_shared_ram = (volatile shared_ram *)PRU1_SHARED_RAM_ADDR;
3335

3436
static pbio_error_t pbdrv_pwm_tiam1808_set_duty(pbdrv_pwm_dev_t *dev, uint32_t ch, uint32_t value) {
35-
// TODO: Reimplement this function to use the PRU
37+
// Blue not available.
38+
if (ch == PBDRV_LED_PWM_CHANNEL_INVALID) {
39+
return PBIO_SUCCESS;
40+
}
41+
42+
pru1_shared_ram->pwms[ch] = value;
3643
return PBIO_SUCCESS;
3744
}
3845

@@ -52,11 +59,8 @@ void pbdrv_pwm_tiam1808_init(pbdrv_pwm_dev_t *devs) {
5259
TimerPeriodSet(SOC_TMR_0_REGS, TMR_TIMER34, 256 * 256 - 1);
5360
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER34, TMR_ENABLE_CONT);
5461

55-
// TODO: Remove this test code
56-
pru1_shared_ram->pwms[0] = 0x20; // R
57-
pru1_shared_ram->pwms[1] = 0xc0; // G
58-
pru1_shared_ram->pwms[2] = 0x10; // R
59-
pru1_shared_ram->pwms[3] = 0xf0; // G
62+
// Clear shared command memory
63+
memset((void *)pru1_shared_ram, 0, sizeof(shared_ram));
6064

6165
// Enable PRU1 and load its firmware
6266
PSCModuleControl(SOC_PSC_0_REGS, HW_PSC_PRU, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);

lib/pbio/platform/ev3/platform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const pbdrv_led_dual_platform_data_t pbdrv_led_dual_platform_data[PBDRV_CONFIG_L
8686
};
8787

8888
static const pbdrv_led_pwm_platform_color_t pbdrv_led_pwm_color = {
89-
// TODO: PWM not yet implemented, so these values not used.
89+
// TODO: Calibrate these numbers, as well as .scale_factor
9090
.r_factor = 1000,
9191
.g_factor = 170,
9292
.b_factor = 200,

0 commit comments

Comments
 (0)