Merge pull request #1466 from haukepetersen/fix_periph_pwmif

drivers: improvements to the low-level pwm driver interface
dev/timer
Hauke Petersen 9 years ago
commit 60886c240f

@ -28,6 +28,7 @@
#define PWM_0_EN (1)
/* PWM_0 device configuration */
#define PWM_0_CHANNELS (3)
#define PWM_0_CH0 (3)
#define PWM_0_CH0_MR PWM1MR3
#define PWM_0_CH1 (4)

@ -23,6 +23,8 @@
#include "periph/pwm.h"
#include "periph_conf.h"
/* guard file in case no PWM device is defined */
#if PWM_NUMOF
#define PCPWM1 BIT6
@ -47,7 +49,7 @@ int pwm_init(pwm_t dev, pwm_mode_t mode, unsigned int frequency, unsigned int re
(PWM_0_FUNC << PWM_0_CH2_PIN * 2);
/* power on PWM1 */
PCONP |= BIT6;
pwm_poweron(dev);
/* select PWM1 clock */
PCLKSEL0 &= ~(BIT13);
@ -78,9 +80,6 @@ int pwm_init(pwm_t dev, pwm_mode_t mode, unsigned int frequency, unsigned int re
PWM1LER = BIT0 | (1 << PWM_0_CH0) | (1 << PWM_0_CH1) | (1 << PWM_0_CH2);
break;
#endif
case PWM_UNDEFINED:
default:
return -1;
}
return 0;
@ -110,42 +109,53 @@ int pwm_set(pwm_t dev, int channel, unsigned int value)
}
break;
#endif
case PWM_UNDEFINED:
default:
return -1;
}
return 0;
}
int pwm_start(pwm_t dev)
void pwm_start(pwm_t dev)
{
switch (dev) {
#if PWM_0_EN
case PWM_0:
PCONP |= PCPWM1; /* enable PWM1 device */
PWM1TCR |= BIT0;
break;
#endif
case PWM_UNDEFINED:
default:
return -1;
}
}
return 0;
void pwm_stop(pwm_t dev)
{
switch (dev) {
#if PWM_0_EN
case PWM_0:
PWM1TCR &= ~(BIT0);
break;
#endif
}
}
int pwm_stop(pwm_t dev)
void pwm_poweron(pwm_t dev)
{
switch (dev) {
#if PWM_0_EN
case PWM_0:
PCONP &= ~PCPWM1; /* disable PWM1 device */
PCONP |= PCPWM1;
break;
#endif
case PWM_UNDEFINED:
default:
return -1;
}
}
return 0;
void pwm_poweroff(pwm_t dev)
{
switch (dev) {
#if PWM_0_EN
case PWM_0:
PCONP &= ~(PCPWM1);
break;
#endif
}
}
#endif /* PWM_NUMOF */

@ -22,6 +22,8 @@
#include "periph_conf.h"
/* ignore file in case no PWM devices are defined */
#if PWM_NUMOF
/**
* @brief Definition of available PWM devices
@ -41,7 +43,6 @@ typedef enum {
#if PWM_3_EN
PWM_3, /*< 4th PWM device */
#endif
PWM_UNDEFINED
} pwm_t;
/**
@ -71,8 +72,8 @@ typedef enum {
* @param[in] resolution the PWM resolution
*
* @return 0 on success
* @return -1 on invalid device
* @return -2 on requested mode and/or frequency and resolution not applicable
* @return -1 on mode not applicable
* @return -2 on frequency and resolution not applicable
*/
int pwm_init(pwm_t dev, pwm_mode_t mode, unsigned int frequency, unsigned int resolution);
@ -87,8 +88,7 @@ int pwm_init(pwm_t dev, pwm_mode_t mode, unsigned int frequency, unsigned int re
* @param[in] value the desired duty-cycle to set
*
* @return 0 on success
* @return -1 on invalid device
* @return -2 on invalid channel
* @return -1 on invalid channel
*/
int pwm_set(pwm_t dev, int channel, unsigned int value);
@ -96,21 +96,37 @@ int pwm_set(pwm_t dev, int channel, unsigned int value);
* @brief Start PWM generation on the given device
*
* @param[in] dev device to start
*
* @return 0 on success
* @return -1 if invalid device given
*/
int pwm_start(pwm_t dev);
void pwm_start(pwm_t dev);
/**
* @brief Stop PWM generation on the given device
*
* @param[in] dev device to stop
*/
void pwm_stop(pwm_t dev);
/**
* @brief Power on the PWM device
*
* @return 0 on success
* @return -1 if invalid device given
* The PWM deice is powered on. It is dependent on the implementing platform,
* if the previously set configuration is still available after power on.
*
* @param[in] dev device to power on
*/
int pwm_stop(pwm_t dev);
void pwm_poweron(pwm_t dev);
/**
* @brief Power off the given PWM device
*
* The given PWM is completely powered off. On most platform this means, that
* the clock for the PWM device is disabled.
*
* @param[in] dev device to power off
*/
void pwm_poweroff(pwm_t dev);
#endif /* PWM_NUMOF */
#endif /* __PWM_H */
/** @} */

Loading…
Cancel
Save