File tree Expand file tree Collapse file tree 7 files changed +55
-30
lines changed Expand file tree Collapse file tree 7 files changed +55
-30
lines changed Original file line number Diff line number Diff line change 55
66#include <pbdrv/battery.h>
77#include <pbdrv/led.h>
8- #include <pbdrv/pwm.h>
98
109#include "counter/counter.h"
10+ #include "pwm/pwm.h"
1111
1212/** Initializes all enabled drivers. */
1313void pbdrv_init () {
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: MIT
2+ // Copyright (c) 2020 The Pybricks Authors
3+
4+ // Pulse width modulation (PWM) drivers
5+
6+ #ifndef _PBDRV_PWM_PWM_H_
7+ #define _PBDRV_PWM_PWM_H_
8+
9+ #include <stdint.h>
10+
11+ #include <pbdrv/config.h>
12+ #include <pbdrv/pwm.h>
13+ #include <pbio/error.h>
14+
15+ /**
16+ * Driver callback functions.
17+ */
18+ typedef struct {
19+ /** Driver implementation of pbdrv_pwm_set_duty() */
20+ pbio_error_t (* set_duty )(pbdrv_pwm_dev_t * dev , uint32_t ch , uint32_t value );
21+ } pbdrv_pwm_driver_funcs_t ;
22+
23+ struct _pbdrv_pwm_dev_t {
24+ /** Platform data. */
25+ const void * pdata ;
26+ /** Driver callback functions. */
27+ const pbdrv_pwm_driver_funcs_t * funcs ;
28+ /** Private driver data */
29+ void * priv ;
30+ };
31+
32+ #if PBDRV_CONFIG_PWM
33+
34+ void pbdrv_pwm_init ();
35+
36+ #else // PBDRV_CONFIG_PWM
37+
38+ #define pbdrv_pwm_init ()
39+
40+ #endif // PBDRV_CONFIG_PWM
41+
42+ #endif // _PBDRV_PWM_PWM_H_
Original file line number Diff line number Diff line change 1111#include <pbdrv/pwm.h>
1212#include <pbio/error.h>
1313
14- #include "./pwm_stm32_tim.h"
15- #include "./pwm_test.h"
16- #include "./pwm_tlc5955_stm32.h"
14+ #include "pwm_stm32_tim.h"
15+ #include "pwm_test.h"
16+ #include "pwm_tlc5955_stm32.h"
17+ #include "pwm.h"
1718
1819
1920static pbdrv_pwm_dev_t pbdrv_pwm_dev [PBDRV_CONFIG_PWM_NUM_DEV ];
2021
21- /** @cond INTERNAL */
22-
2322/**
2423 * Initializes all PWM drivers.
2524 */
@@ -29,8 +28,6 @@ void pbdrv_pwm_init() {
2928 pbdrv_pwm_tlc5955_stm32_init (pbdrv_pwm_dev );
3029}
3130
32- /** @endcond */
33-
3431/**
3532 * Gets the PWM device with the given ID.
3633 * @param [in] id The ID of the PWM device.
Original file line number Diff line number Diff line change 1414#include <pbdrv/pwm.h>
1515#include <pbio/error.h>
1616
17- #include "./pwm_stm32_tim.h"
17+ #include "pwm_stm32_tim.h"
18+ #include "pwm.h"
1819
1920static pbio_error_t pbdrv_pwm_stm32_tim_set_duty (pbdrv_pwm_dev_t * dev , uint32_t ch , uint32_t value ) {
2021 const pbdrv_pwm_stm32_tim_platform_data_t * pdata = dev -> pdata ;
Original file line number Diff line number Diff line change 2020#include <pbio/error.h>
2121#include <pbio/util.h>
2222
23- #include "./pwm_tlc5955_stm32.h"
23+ #include "pwm_tlc5955_stm32.h"
24+ #include "pwm.h"
2425
2526// size in bytes to hold 769-bit shift register data
2627#define TLC5955_DATA_SIZE ((769 + 7) / 8)
Original file line number Diff line number Diff line change 2020 */
2121typedef struct _pbdrv_pwm_dev_t pbdrv_pwm_dev_t ;
2222
23- /**
24- * Driver callback functions.
25- */
26- typedef struct {
27- /** Driver implementation of pbdrv_pwm_set_duty() */
28- pbio_error_t (* set_duty )(pbdrv_pwm_dev_t * dev , uint32_t ch , uint32_t value );
29- } pbdrv_pwm_driver_funcs_t ;
30-
31- struct _pbdrv_pwm_dev_t {
32- /** Platform data. */
33- const void * pdata ;
34- /** Driver callback functions. */
35- const pbdrv_pwm_driver_funcs_t * funcs ;
36- /** Private driver data */
37- void * priv ;
38- };
39-
4023#if PBDRV_CONFIG_PWM
4124
42- void pbdrv_pwm_init ();
4325pbio_error_t pbdrv_pwm_get_dev (uint8_t id , pbdrv_pwm_dev_t * * dev );
4426pbio_error_t pbdrv_pwm_set_duty (pbdrv_pwm_dev_t * dev , uint32_t ch , uint32_t value );
4527
Original file line number Diff line number Diff line change 33
44#include <stdio.h>
55
6+ #include <tinytest.h>
7+ #include <tinytest_macros.h>
8+
69#include <pbdrv/pwm.h>
710#include <pbio/error.h>
811
9- #include <tinytest.h>
10- #include <tinytest_macros.h>
12+ #include "../drv/pwm/pwm.h"
1113
1214typedef struct {
1315 uint32_t duty_channel ;
You can’t perform that action at this time.
0 commit comments