Skip to content

Commit 04e2420

Browse files
committed
pbio/drv/pwm/pwm_ev3: Consolidate LEDs into one PWM device
1 parent 400ca7a commit 04e2420

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

lib/pbio/drv/pwm/pwm_ev3.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
// This needs to match the interface expected by the PRU firmware
2929
typedef struct shared_ram {
30-
uint8_t pwms[4];
30+
uint8_t pwms[PBDRV_PWM_EV3_NUM_CHANNELS];
3131
} shared_ram;
3232
static volatile shared_ram *const pru1_shared_ram = (volatile shared_ram *)PRU1_SHARED_RAM_ADDR;
3333

@@ -43,19 +43,15 @@ static const pbdrv_pwm_driver_funcs_t pbdrv_pwm_tiam1808_funcs = {
4343
extern char _pru1_start;
4444
extern char _pru1_end;
4545

46+
#define PINMUX_ALT_PRU1 4
47+
4648
void pbdrv_pwm_tiam1808_init(pbdrv_pwm_dev_t *devs) {
4749
// Enable Timer0 "34" half to count up to 256 * 256
4850
// This is used by the PRU to time the PWM
4951
TimerPreScalarCount34Set(SOC_TMR_0_REGS, 0);
5052
TimerPeriodSet(SOC_TMR_0_REGS, TMR_TIMER34, 256 * 256 - 1);
5153
TimerEnable(SOC_TMR_0_REGS, TMR_TIMER34, TMR_ENABLE_CONT);
5254

53-
// Set GPIO alt modes for the PRU
54-
pbdrv_gpio_alt(&pbdrv_pwm_tiam1808_platform_data[0].gpio_red, SYSCFG_PINMUX13_PINMUX13_11_8_PRU1_R30_12);
55-
pbdrv_gpio_alt(&pbdrv_pwm_tiam1808_platform_data[0].gpio_green, SYSCFG_PINMUX14_PINMUX14_3_0_PRU1_R30_10);
56-
pbdrv_gpio_alt(&pbdrv_pwm_tiam1808_platform_data[1].gpio_red, SYSCFG_PINMUX13_PINMUX13_15_12_PRU1_R30_11);
57-
pbdrv_gpio_alt(&pbdrv_pwm_tiam1808_platform_data[1].gpio_green, SYSCFG_PINMUX13_PINMUX13_7_4_PRU1_R30_13);
58-
5955
// TODO: Remove this test code
6056
pru1_shared_ram->pwms[0] = 0x20; // R
6157
pru1_shared_ram->pwms[1] = 0xc0; // G
@@ -76,6 +72,11 @@ void pbdrv_pwm_tiam1808_init(pbdrv_pwm_dev_t *devs) {
7672
for (int i = 0; i < PBDRV_CONFIG_PWM_TIAM1808_NUM_DEV; i++) {
7773
devs[i].funcs = &pbdrv_pwm_tiam1808_funcs;
7874
devs[i].priv = (pbdrv_pwm_tiam1808_platform_data_t *)&pbdrv_pwm_tiam1808_platform_data[i];
75+
76+
// Set GPIO alt modes for the PRU
77+
for (int j = 0; j < PBDRV_PWM_EV3_NUM_CHANNELS; j++) {
78+
pbdrv_gpio_alt(&pbdrv_pwm_tiam1808_platform_data[i].gpios[j], PINMUX_ALT_PRU1);
79+
}
7980
}
8081
}
8182

lib/pbio/drv/pwm/pwm_ev3.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#include <pbdrv/pwm.h>
1414
#include <pbdrv/gpio.h>
1515

16+
#define PBDRV_PWM_EV3_NUM_CHANNELS 4
17+
1618
/** Platform-specific device information. */
1719
typedef struct {
1820
uint8_t id;
19-
pbdrv_gpio_t gpio_red;
20-
pbdrv_gpio_t gpio_green;
21+
pbdrv_gpio_t gpios[PBDRV_PWM_EV3_NUM_CHANNELS];
2122
} pbdrv_pwm_tiam1808_platform_data_t;
2223

2324
// Defined in platform.c

lib/pbio/platform/ev3/pbdrvconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
#define PBDRV_CONFIG_PWM (1)
6767
#define PBDRV_CONFIG_PWM_NUM_DEV (2)
6868
#define PBDRV_CONFIG_PWM_TIAM1808 (1)
69-
#define PBDRV_CONFIG_PWM_TIAM1808_NUM_DEV (2)
69+
#define PBDRV_CONFIG_PWM_TIAM1808_NUM_DEV (1)
7070

7171
#define PBDRV_CONFIG_RESET (1)
7272
#define PBDRV_CONFIG_RESET_EV3 (1)

lib/pbio/platform/ev3/platform.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ enum {
7272
};
7373

7474
enum {
75-
PWM_DEV_0_TODO,
76-
PWM_DEV_1_TODO,
75+
PWM_DEV_0,
7776
};
7877

7978
// LED
@@ -100,26 +99,26 @@ const pbdrv_led_pwm_platform_data_t pbdrv_led_pwm_platform_data[PBDRV_CONFIG_LED
10099
{
101100
.color = &pbdrv_led_pwm_color,
102101
.id = LED_DEV_1_STATUS_LEFT,
103-
.r_id = PWM_DEV_0_TODO,
102+
.r_id = PWM_DEV_0,
104103
.r_ch = 0,
105-
.g_id = PWM_DEV_0_TODO,
104+
.g_id = PWM_DEV_0,
106105
.g_ch = 1,
107106
// Blue not available.
108-
.b_id = PWM_DEV_0_TODO,
109-
.b_ch = 2,
107+
.b_id = PWM_DEV_0,
108+
.b_ch = 0xff,
110109
// TODO: PWM not yet implemented, so these values not used.
111110
.scale_factor = 35,
112111
},
113112
{
114113
.color = &pbdrv_led_pwm_color,
115114
.id = LED_DEV_2_STATUS_RIGHT,
116-
.r_id = PWM_DEV_1_TODO,
117-
.r_ch = 0,
118-
.g_id = PWM_DEV_1_TODO,
119-
.g_ch = 1,
115+
.r_id = PWM_DEV_0,
116+
.r_ch = 2,
117+
.g_id = PWM_DEV_0,
118+
.g_ch = 3,
120119
// Blue not available.
121-
.b_id = PWM_DEV_1_TODO,
122-
.b_ch = 2,
120+
.b_id = PWM_DEV_0,
121+
.b_ch = 0xff,
123122
// TODO: PWM not yet implemented, so these values not used.
124123
.scale_factor = 35,
125124
},
@@ -128,14 +127,13 @@ const pbdrv_led_pwm_platform_data_t pbdrv_led_pwm_platform_data[PBDRV_CONFIG_LED
128127
const pbdrv_pwm_tiam1808_platform_data_t
129128
pbdrv_pwm_tiam1808_platform_data[PBDRV_CONFIG_PWM_TIAM1808_NUM_DEV] = {
130129
{
131-
.id = PWM_DEV_0_TODO,
132-
.gpio_red = PBDRV_GPIO_EV3_PIN(13, 11, 8, 6, 13),
133-
.gpio_green = PBDRV_GPIO_EV3_PIN(14, 3, 0, 6, 7),
134-
},
135-
{
136-
.id = PWM_DEV_1_TODO,
137-
.gpio_red = PBDRV_GPIO_EV3_PIN(13, 15, 12, 6, 12),
138-
.gpio_green = PBDRV_GPIO_EV3_PIN(13, 7, 4, 6, 14),
130+
.id = PWM_DEV_0,
131+
.gpios = {
132+
PBDRV_GPIO_EV3_PIN(13, 11, 8, 6, 13),
133+
PBDRV_GPIO_EV3_PIN(14, 3, 0, 6, 7),
134+
PBDRV_GPIO_EV3_PIN(13, 15, 12, 6, 12),
135+
PBDRV_GPIO_EV3_PIN(13, 7, 4, 6, 14),
136+
},
139137
},
140138
};
141139

0 commit comments

Comments
 (0)