Skip to content

Commit 998c862

Browse files
committed
drivers/pca9685: PWM extension API code removed
1 parent e1ec5b5 commit 998c862

File tree

6 files changed

+18
-156
lines changed

6 files changed

+18
-156
lines changed

drivers/include/pca9685.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,8 @@
3838
* - functions require an additional parameter, the pointer to the PWM
3939
* device of type #pca9685_t.
4040
*
41-
* The driver is also compatible with the PWM extension API so that PCA9685
42-
* PWM devices can be used as PWM extensions with the standard peripheral
43-
* PWM interface.
44-
*
4541
* Please refer the test application in `tests/driver_pca9685` for an example
46-
* on how to use the driver either directly or through the PWM extension
47-
* interface.
42+
* on how to use the driver.
4843
*
4944
* ## SAUL Capabilities
5045
*

drivers/pca9685/pca9685.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ static int _read(const pca9685_t *dev, uint8_t reg, uint8_t *data, uint32_t len)
9090
static int _write(const pca9685_t *dev, uint8_t reg, const uint8_t *data, uint32_t len);
9191
static int _update(const pca9685_t *dev, uint8_t reg, uint8_t mask, uint8_t data);
9292

93-
inline static int _read_word(const pca9685_t *dev, uint8_t reg, uint16_t *word);
9493
inline static int _write_word(const pca9685_t *dev, uint8_t reg, uint16_t word);
9594

9695
int pca9685_init(pca9685_t *dev, const pca9685_params_t *params)
@@ -317,15 +316,6 @@ static int _read(const pca9685_t *dev, uint8_t reg, uint8_t *data, uint32_t len)
317316
return PCA9685_OK;
318317
}
319318

320-
inline static int _read_word(const pca9685_t *dev, uint8_t reg, uint16_t *word)
321-
{
322-
uint8_t bytes[2];
323-
EXEC_RET(_read (dev, reg, bytes, 2));
324-
*word = (bytes[1] << 8) + (bytes[0]);
325-
326-
return PCA9685_OK;
327-
}
328-
329319
static int _write(const pca9685_t *dev, uint8_t reg, const uint8_t *data, uint32_t len)
330320
{
331321
DEBUG_DEV("reg=%02x data=%p len=%"PRIu32"", dev, reg, data, len);

tests/driver_pca9685/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
include ../Makefile.tests_common
22

3+
# These boards are blacklisted since efm32 CPU dosn't support PWM_RIGHT
4+
BOARD_BLACKLIST := slstk3401a slstk3402a sltb001a slwstk6000b stk3600 stk3700
5+
6+
# Boards with insufficient memory
7+
BOARD_INSUFFICIENT_MEMORY := arduino-duemilanove arduino-nano arduino-uno
8+
39
USEMODULE += pca9685
410
USEMODULE += shell
511

6-
INCLUDES += -I$(APPDIR)/include
7-
812
include $(RIOTBASE)/Makefile.include

tests/driver_pca9685/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ Please check the default configuration parameters in
2222
`$(RIOTBASE)/drivers/pca9685/include/pca9685_params.h` and adopt them
2323
if necessary.
2424

25-
To use it with the PWM extension API, use module `extend_pwm` as following
26-
```
27-
USEMODULE=extend_pwm make -C tests/driver_pca9685 BOARD=...
28-
```
2925
If the active LOW output enable pin /OE is used, the GPIO has to be defined
3026
as parameter, e.g.
3127
```
3228
CFLAGS="-DPCA9685_PARAM_INT_PIN=\(GPIO\(0,6\)\)" \
33-
USEMODULE=extend_pwm make -C tests/driver_pca9685 BOARD=...
29+
make -C tests/driver_pca9685 BOARD=...
3430
```

tests/driver_pca9685/include/pwm_ext_conf.h

Lines changed: 0 additions & 59 deletions
This file was deleted.

tests/driver_pca9685/main.c

Lines changed: 10 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@
3434
* `$(RIOTBASE)/drivers/pca9685/include/pca9685_params.h` and adopt them
3535
* if necessary.
3636
*
37-
* To use it with the PWM extension API, use module `extend_pwm` as following
38-
*
39-
* USEMODULE=extend_pwm make -C tests/driver_pca9685 BOARD=...
40-
*
4137
* If the active LOW output enable pin /OE is used, the GPIO has to be defined
4238
* as parameter, e.g.
4339
*
4440
* CFLAGS="-DPCA9685_PARAM_INT_PIN=\(GPIO\(0,6\)\)" \
45-
* USEMODULE=extend_pwm make -C tests/driver_pca9685 BOARD=...
41+
* make -C tests/driver_pca9685 BOARD=...
4642
*/
4743

4844
#include <stdio.h>
@@ -57,11 +53,6 @@
5753
#include "pca9685.h"
5854
#include "pca9685_params.h"
5955

60-
#if MODULE_EXTEND_PWM
61-
#include "extend/pwm.h"
62-
#include "pwm_ext_conf.h"
63-
#endif
64-
6556
#define OSC_INTERVAL (10LU * US_PER_MS) /* 10 ms */
6657
#define OSC_STEP (10)
6758
#define OSC_MODE PWM_LEFT
@@ -70,34 +61,18 @@
7061
#define PWR_SLEEP (1U)
7162

7263
/* Number of configured PCA9685 I/O expander devices */
73-
#define PCA9685_NUMOF (sizeof(pca9685_params) / sizeof(pca9685_params[0]))
64+
#define PCA9685_NUMOF ARRAY_SIZE(pca9685_params)
7465

7566
/* PCA9685 devices allocation */
7667
pca9685_t pca9685_dev[PCA9685_NUMOF];
7768

78-
#if MODULE_EXTEND_PWM
79-
/* PCA9685 PWM extension driver definition */
80-
const pwm_ext_driver_t pca9685_extend_pwm_driver = {
81-
.init = (pwm_ext_init_t)pca9685_pwm_init,
82-
.channels = (pwm_ext_channels_t)pca9685_pwm_channels,
83-
.set = (pwm_ext_set_t)pca9685_pwm_set,
84-
.poweron = (pwm_ext_poweron_t)pca9685_pwm_poweron,
85-
.poweroff = (pwm_ext_poweroff_t)pca9685_pwm_poweroff,
86-
};
87-
#endif /* MODULE_EXTEND_PWM */
88-
8969
static uint32_t initiated;
9070

9171
static unsigned _get_dev(const char *dev_str)
9272
{
9373
unsigned dev = atoi(dev_str);
94-
#if MODULE_EXTEND_PWM
95-
if (dev >= PWM_EXT_NUMOF) {
96-
printf("Error: device PWM_EXT_DEV(%u) is unknown\n", dev);
97-
#else
9874
if (dev >= PCA9685_NUMOF) {
99-
printf("Error: device PWM_DEV(%u) is unknown\n", dev);
100-
#endif
75+
printf("Error: PWM device %u is unknown\n", dev);
10176
return UINT_MAX;
10277
}
10378

@@ -108,7 +83,7 @@ static int _init(int argc, char** argv)
10883
{
10984
if (argc != 5) {
11085
printf("usage: %s <dev> <mode> <frequency> <resolution>\n", argv[0]);
111-
printf("\tdev: device by number between 0 and %u\n", PWM_NUMOF - 1);
86+
printf("\tdev: device by number between 0 and %u\n", PCA9685_NUMOF - 1);
11287
puts("\tmode:\n");
11388
puts("\t\t0: left aligned\n");
11489
puts("\t\t1: right aligned\n");
@@ -139,11 +114,7 @@ static int _init(int argc, char** argv)
139114
return 1;
140115
}
141116

142-
#if MODULE_EXTEND_PWM
143-
uint32_t pwm_freq = pwm_init(PWM_EXT_DEV(dev), pwm_mode,
144-
#else
145117
uint32_t pwm_freq = pca9685_pwm_init(&pca9685_dev[dev], pwm_mode,
146-
#endif
147118
(uint32_t)atoi(argv[3]),
148119
(uint16_t)atoi(argv[4]));
149120
if (pwm_freq != 0) {
@@ -160,7 +131,7 @@ static int _set(int argc, char**argv)
160131
{
161132
if (argc != 4) {
162133
printf("usage: %s <dev> <ch> <val>\n", argv[0]);
163-
printf("\tdev: device by number between 0 and %d\n", PWM_NUMOF - 1);
134+
printf("\tdev: device by number between 0 and %d\n", PCA9685_NUMOF - 1);
164135
puts("\tch: channel of device (if 16, all channels are set)\n");
165136
puts("\tval: duty cycle\n");
166137
return 1;
@@ -178,20 +149,12 @@ static int _set(int argc, char**argv)
178149
}
179150

180151
uint8_t chan = atoi(argv[2]);
181-
#if MODULE_EXTEND_PWM
182-
if (chan > pwm_channels(PWM_EXT_DEV(dev))) {
183-
#else
184152
if (chan > pca9685_pwm_channels(&pca9685_dev[dev])) {
185-
#endif
186153
printf("Error: channel %d is unknown.\n", chan);
187154
return 1;
188155
}
189156

190-
#if MODULE_EXTEND_PWM
191-
pwm_set(PWM_EXT_DEV(dev), chan, (uint16_t)atoi(argv[3]));
192-
#else
193157
pca9685_pwm_set(&pca9685_dev[dev], chan, (uint16_t)atoi(argv[3]));
194-
#endif
195158
return 0;
196159
}
197160

@@ -207,34 +170,23 @@ static int _oscillate(int argc, char** argv)
207170
puts("\nRIOT PWM test");
208171
puts("Connect an LED or scope to PWM pins to see something.\n");
209172

210-
printf("Available PWM device between 0 and %d\n", PWM_NUMOF - 1);
211-
#if MODULE_EXTEND_PWM
212-
for (unsigned i = 0; i < PWM_NUMOF; i++) {
213-
uint32_t real_f = pwm_init(PWM_EXT_DEV(i), OSC_MODE, OSC_FREQU, OSC_STEPS);
214-
#else
173+
printf("Available PWM device between 0 and %d\n", PCA9685_NUMOF - 1);
215174
for (unsigned i = 0; i < PCA9685_NUMOF; i++) {
216175
uint32_t real_f = pca9685_pwm_init(&pca9685_dev[i], OSC_MODE, OSC_FREQU, OSC_STEPS);
217-
#endif
218176
if (real_f == 0) {
219-
printf("Error: initializing PWM_%u.\n", i);
177+
printf("Error: initializing PWM device %u.\n", i);
220178
return 1;
221179
}
222180
else {
223-
printf("Initialized PWM_%u @ %" PRIu32 "Hz.\n", i, real_f);
181+
printf("Initialized PWM device %u @ %" PRIu32 "Hz.\n", i, real_f);
224182
}
225183
}
226184

227185
puts("\nLetting the PWM pins oscillate now...");
228186
while (1) {
229-
#if MODULE_EXTEND_PWM
230-
for (unsigned i = 0; i < PWM_EXT_NUMOF; i++) {
231-
for (uint8_t chan = 0; chan < pwm_channels(PWM_EXT_DEV(i)); chan++) {
232-
pwm_set(PWM_EXT_DEV(i), chan, state);
233-
#else
234187
for (unsigned i = 0; i < PCA9685_NUMOF; i++) {
235188
for (uint8_t chan = 0; chan < pca9685_pwm_channels(&pca9685_dev[i]); chan++) {
236189
pca9685_pwm_set(&pca9685_dev[i], chan, state);
237-
#endif
238190
}
239191
}
240192

@@ -253,7 +205,7 @@ static int _power(int argc, char** argv)
253205
{
254206
if (argc != 3) {
255207
printf("usage: %s <dev> <state>\n", argv[0]);
256-
printf("\tdev: device by number between 0 and %d\n", PWM_NUMOF - 1);
208+
printf("\tdev: device by number between 0 and %d\n", PCA9685_NUMOF - 1);
257209
puts("\tstate:\n");
258210
puts("\t\t0: power off\n");
259211
puts("\t\t1: power on\n");
@@ -268,19 +220,11 @@ static int _power(int argc, char** argv)
268220
switch (atoi(argv[2])) {
269221
case (0):
270222
puts("Powering down PWM device.\n");
271-
#if MODULE_EXTEND_PWM
272-
pwm_poweroff(PWM_EXT_DEV(dev));
273-
#else
274223
pca9685_pwm_poweroff(&pca9685_dev[dev]);
275-
#endif
276224
break;
277225
case (1):
278226
puts("Powering up PWM device.\n");
279-
#if MODULE_EXTEND_PWM
280-
pwm_poweron(PWM_EXT_DEV(dev));
281-
#else
282227
pca9685_pwm_poweron(&pca9685_dev[dev]);
283-
#endif
284228
break;
285229
default:
286230
puts("Error: power state not available.\n");
@@ -293,7 +237,7 @@ static int _power_test(int argc, char** argv)
293237
{
294238
if (argc != 2) {
295239
printf("usage: %s <dev>\n", argv[0]);
296-
printf("\tdev: device by number between 0 and %d\n", PWM_NUMOF - 1);
240+
printf("\tdev: device by number between 0 and %d\n", PCA9685_NUMOF - 1);
297241
return 1;
298242
}
299243

@@ -304,20 +248,12 @@ static int _power_test(int argc, char** argv)
304248

305249
printf("Powering down PWM device and sleeping for %u second(s)...\n",
306250
PWR_SLEEP);
307-
#if MODULE_EXTEND_PWM
308-
pwm_poweroff(PWM_EXT_DEV(dev));
309-
#else
310251
pca9685_pwm_poweroff(&pca9685_dev[dev]);
311-
#endif
312252

313253
xtimer_sleep(PWR_SLEEP);
314254

315255
puts("Powering up PWM device.\n");
316-
#if MODULE_EXTEND_PWM
317-
pwm_poweron(PWM_EXT_DEV(dev));
318-
#else
319256
pca9685_pwm_poweron(&pca9685_dev[dev]);
320-
#endif
321257

322258
return 0;
323259
}

0 commit comments

Comments
 (0)