diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-11-21 21:31:35 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-11-21 21:31:35 +0000 |
commit | 955425572d170dc100034ce991911854bf600a30 (patch) | |
tree | 29cdb46b02e87de9cad84f3674df6da851dfb9cb | |
parent | 2018975c3ebca410dd2f8b9a35fe510f4996fa77 (diff) | |
download | ChibiOS-955425572d170dc100034ce991911854bf600a30.tar.gz ChibiOS-955425572d170dc100034ce991911854bf600a30.tar.bz2 ChibiOS-955425572d170dc100034ce991911854bf600a30.zip |
Had to go back...
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2416 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | os/hal/include/pwm.h | 4 | ||||
-rw-r--r-- | os/hal/platforms/STM32/pwm_lld.c | 167 | ||||
-rw-r--r-- | os/hal/platforms/STM32/pwm_lld.h | 7 | ||||
-rw-r--r-- | os/hal/src/pwm.c | 7 | ||||
-rw-r--r-- | os/hal/templates/pwm_lld.c | 24 | ||||
-rw-r--r-- | os/hal/templates/pwm_lld.h | 7 | ||||
-rw-r--r-- | readme.txt | 2 |
7 files changed, 115 insertions, 103 deletions
diff --git a/os/hal/include/pwm.h b/os/hal/include/pwm.h index 5d36e49b5..6570e9fdf 100644 --- a/os/hal/include/pwm.h +++ b/os/hal/include/pwm.h @@ -82,7 +82,7 @@ typedef enum { * @iclass
*/
#define pwmEnableChannelI(pwmp, channel, width) \
- pwm_lld_set_channel(pwmp, channel, width)
+ pwm_lld_enable_channel(pwmp, channel, width)
/**
* @brief Disables a PWM channel.
@@ -96,7 +96,7 @@ typedef enum { * @iclass
*/
#define pwmDisableChannelI(pwmp, channel) \
- pwm_lld_set_channel(pwmp, channel, 0)
+ pwm_lld_disable_channel(pwmp, channel)
/*===========================================================================*/
/* External declarations. */
diff --git a/os/hal/platforms/STM32/pwm_lld.c b/os/hal/platforms/STM32/pwm_lld.c index f3588123a..4ef49ebca 100644 --- a/os/hal/platforms/STM32/pwm_lld.c +++ b/os/hal/platforms/STM32/pwm_lld.c @@ -87,9 +87,8 @@ static void stop_channels(PWMDriver *pwmp) { pwmp->pd_tim->CCR2 = 0; /* Comparator 2 disabled. */
pwmp->pd_tim->CCR3 = 0; /* Comparator 3 disabled. */
pwmp->pd_tim->CCR4 = 0; /* Comparator 4 disabled. */
- /* Channels forced to idle.*/
- pwmp->pd_tim->CCMR1 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC2M_2;
- pwmp->pd_tim->CCMR2 = TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC4M_2;
+ pwmp->pd_tim->CCMR1 = 0; /* Channels 1 and 2 frozen. */
+ pwmp->pd_tim->CCMR2 = 0; /* Channels 3 and 4 frozen. */
}
#if STM32_PWM_USE_TIM2 || STM32_PWM_USE_TIM3 || STM32_PWM_USE_TIM4 || \
@@ -414,102 +413,106 @@ void pwm_lld_stop(PWMDriver *pwmp) { }
/**
- * @brief Disables, enables or reprograms a PWM channel.
+ * @brief Enables a PWM channel.
*
* @param[in] pwmp pointer to a @p PWMDriver object
* @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1)
- * @param[in] width PWM pulse width as clock pulses number, note that
- * specifying zero disables the channel and enforces
- * the output to the idle state.
+ * @param[in] width PWM pulse width as clock pulses number
*
* @notapi
*/
-void pwm_lld_set_channel(PWMDriver *pwmp,
- pwmchannel_t channel,
- pwmcnt_t width) {
-
- if (width == 0) {
- /* Channel disable mode.*/
- pwmp->pd_enabled_channels &= ~(1 << channel);
- switch (channel) {
- case 0:
- pwmp->pd_tim->CCR1 = 0;
- pwmp->pd_tim->CCMR1 = (pwmp->pd_tim->CCMR1 & 0xFF00) | TIM_CCMR1_OC1M_2;
- pwmp->pd_tim->DIER &= ~TIM_DIER_CC1IE;
- break;
- case 1:
- pwmp->pd_tim->CCR2 = 0;
- pwmp->pd_tim->CCMR1 = (pwmp->pd_tim->CCMR1 & 0x00FF) | TIM_CCMR1_OC2M_2;
- pwmp->pd_tim->DIER &= ~TIM_DIER_CC2IE;
- break;
- case 2:
- pwmp->pd_tim->CCR3 = 0;
- pwmp->pd_tim->CCMR2 = (pwmp->pd_tim->CCMR2 & 0xFF00) | TIM_CCMR2_OC3M_2;
- pwmp->pd_tim->DIER &= ~TIM_DIER_CC3IE;
- break;
- case 3:
- pwmp->pd_tim->CCR4 = 0;
- pwmp->pd_tim->CCMR2 = (pwmp->pd_tim->CCMR2 & 0x00FF) | TIM_CCMR2_OC4M_2;
- pwmp->pd_tim->DIER &= ~TIM_DIER_CC4IE;
- break;
- }
+void pwm_lld_enable_channel(PWMDriver *pwmp,
+ pwmchannel_t channel,
+ pwmcnt_t width) {
+
+ switch (channel) {
+ case 0:
+ pwmp->pd_tim->CCR1 = width;
+ break;
+ case 1:
+ pwmp->pd_tim->CCR2 = width;
+ break;
+ case 2:
+ pwmp->pd_tim->CCR3 = width;
+ break;
+ case 3:
+ pwmp->pd_tim->CCR4 = width;
+ break;
}
- else {
- /* Channel enable or reprogram mode.*/
+ if ((pwmp->pd_enabled_channels & (1 << channel)) == 0) {
+ /* The channel is not enabled yet.*/
+ pwmp->pd_enabled_channels |= (1 << channel);
+ /* Setup the comparator, the channel is configured as PWM mode 1 with
+ preload enabled.*/
switch (channel) {
case 0:
- pwmp->pd_tim->CCR1 = width;
+ pwmp->pd_tim->CCMR1 = (pwmp->pd_tim->CCMR1 & 0xFF00) |
+ TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 |
+ TIM_CCMR1_OC1PE;
+ pwmp->pd_tim->SR = ~TIM_SR_CC1IF;
+ pwmp->pd_tim->DIER |= pwmp->pd_config->pc_channels[0].pcc_callback == NULL
+ ? 0 : TIM_DIER_CC1IE;
break;
case 1:
- pwmp->pd_tim->CCR2 = width;
+ pwmp->pd_tim->CCMR1 = (pwmp->pd_tim->CCMR1 & 0x00FF) |
+ TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 |
+ TIM_CCMR1_OC2PE;
+ pwmp->pd_tim->SR = ~TIM_SR_CC2IF;
+ pwmp->pd_tim->DIER |= pwmp->pd_config->pc_channels[1].pcc_callback == NULL
+ ? 0 : TIM_DIER_CC2IE;
break;
case 2:
- pwmp->pd_tim->CCR3 = width;
+ pwmp->pd_tim->CCMR2 = (pwmp->pd_tim->CCMR2 & 0xFF00) |
+ TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_2 |
+ TIM_CCMR2_OC3PE;
+ pwmp->pd_tim->SR = ~TIM_SR_CC3IF;
+ pwmp->pd_tim->DIER |= pwmp->pd_config->pc_channels[2].pcc_callback == NULL
+ ? 0 : TIM_DIER_CC3IE;
break;
case 3:
- pwmp->pd_tim->CCR4 = width;
+ pwmp->pd_tim->CCMR2 = (pwmp->pd_tim->CCMR2 & 0x00FF) |
+ TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 |
+ TIM_CCMR2_OC4PE;
+ pwmp->pd_tim->SR = ~TIM_SR_CC4IF;
+ pwmp->pd_tim->DIER |= pwmp->pd_config->pc_channels[3].pcc_callback == NULL
+ ? 0 : TIM_DIER_CC4IE;
break;
}
- if ((pwmp->pd_enabled_channels & (1 << channel)) == 0) {
- /* The channel is not enabled yet.*/
- pwmp->pd_enabled_channels |= (1 << channel);
- /* Setup the comparator, the channel is configured as PWM mode 1 with
- preload enabled.*/
- switch (channel) {
- case 0:
- pwmp->pd_tim->CCMR1 = (pwmp->pd_tim->CCMR1 & 0xFF00) |
- TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 |
- TIM_CCMR1_OC1PE;
- pwmp->pd_tim->SR = ~TIM_SR_CC1IF;
- pwmp->pd_tim->DIER |= pwmp->pd_config->pc_channels[0].pcc_callback == NULL
- ? 0 : TIM_DIER_CC1IE;
- break;
- case 1:
- pwmp->pd_tim->CCMR1 = (pwmp->pd_tim->CCMR1 & 0x00FF) |
- TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 |
- TIM_CCMR1_OC2PE;
- pwmp->pd_tim->SR = ~TIM_SR_CC2IF;
- pwmp->pd_tim->DIER |= pwmp->pd_config->pc_channels[1].pcc_callback == NULL
- ? 0 : TIM_DIER_CC2IE;
- break;
- case 2:
- pwmp->pd_tim->CCMR2 = (pwmp->pd_tim->CCMR2 & 0xFF00) |
- TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_2 |
- TIM_CCMR2_OC3PE;
- pwmp->pd_tim->SR = ~TIM_SR_CC3IF;
- pwmp->pd_tim->DIER |= pwmp->pd_config->pc_channels[2].pcc_callback == NULL
- ? 0 : TIM_DIER_CC3IE;
- break;
- case 3:
- pwmp->pd_tim->CCMR2 = (pwmp->pd_tim->CCMR2 & 0x00FF) |
- TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 |
- TIM_CCMR2_OC4PE;
- pwmp->pd_tim->SR = ~TIM_SR_CC4IF;
- pwmp->pd_tim->DIER |= pwmp->pd_config->pc_channels[3].pcc_callback == NULL
- ? 0 : TIM_DIER_CC4IE;
- break;
- }
- }
+ }
+}
+
+/**
+ * @brief Disables a PWM channel.
+ * @details The channel is disabled and its output line returned to the
+ * idle state.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1)
+ */
+void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel) {
+
+ pwmp->pd_enabled_channels &= ~(1 << channel);
+ switch (channel) {
+ case 0:
+ pwmp->pd_tim->CCR1 = 0;
+ pwmp->pd_tim->CCMR1 = pwmp->pd_tim->CCMR1 & 0xFF00;
+ pwmp->pd_tim->DIER &= ~TIM_DIER_CC1IE;
+ break;
+ case 1:
+ pwmp->pd_tim->CCR2 = 0;
+ pwmp->pd_tim->CCMR1 = pwmp->pd_tim->CCMR1 & 0x00FF;
+ pwmp->pd_tim->DIER &= ~TIM_DIER_CC2IE;
+ break;
+ case 2:
+ pwmp->pd_tim->CCR3 = 0;
+ pwmp->pd_tim->CCMR2 = pwmp->pd_tim->CCMR2 & 0xFF00;
+ pwmp->pd_tim->DIER &= ~TIM_DIER_CC3IE;
+ break;
+ case 3:
+ pwmp->pd_tim->CCR4 = 0;
+ pwmp->pd_tim->CCMR2 = pwmp->pd_tim->CCMR2 & 0x00FF;
+ pwmp->pd_tim->DIER &= ~TIM_DIER_CC4IE;
+ break;
}
}
diff --git a/os/hal/platforms/STM32/pwm_lld.h b/os/hal/platforms/STM32/pwm_lld.h index 4c3b99e4d..194e60b48 100644 --- a/os/hal/platforms/STM32/pwm_lld.h +++ b/os/hal/platforms/STM32/pwm_lld.h @@ -344,9 +344,10 @@ extern "C" { void pwm_lld_init(void);
void pwm_lld_start(PWMDriver *pwmp);
void pwm_lld_stop(PWMDriver *pwmp);
- void pwm_lld_set_channel(PWMDriver *pwmp,
- pwmchannel_t channel,
- pwmcnt_t width);
+ void pwm_lld_enable_channel(PWMDriver *pwmp,
+ pwmchannel_t channel,
+ pwmcnt_t width);
+ void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/src/pwm.c b/os/hal/src/pwm.c index ecf9eba3f..ec5bd65be 100644 --- a/os/hal/src/pwm.c +++ b/os/hal/src/pwm.c @@ -118,8 +118,7 @@ void pwmStop(PWMDriver *pwmp) { *
* @param[in] pwmp pointer to a @p PWMDriver object
* @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1)
- * @param[in] width PWM pulse width as clock pulses number, setting the
- * width at zero is equivalent to disabling the channel
+ * @param[in] width PWM pulse width as clock pulses number
*
* @api
*/
@@ -133,7 +132,7 @@ void pwmEnableChannel(PWMDriver *pwmp, chSysLock();
chDbgAssert(pwmp->pd_state == PWM_READY,
"pwmEnableChannel(), #1", "not ready");
- pwm_lld_set_channel(pwmp, channel, width);
+ pwm_lld_enable_channel(pwmp, channel, width);
chSysUnlock();
}
@@ -155,7 +154,7 @@ void pwmDisableChannel(PWMDriver *pwmp, pwmchannel_t channel) { chSysLock();
chDbgAssert(pwmp->pd_state == PWM_READY,
"pwmDisableChannel(), #1", "not ready");
- pwm_lld_set_channel(pwmp, channel, 0);
+ pwm_lld_disable_channel(pwmp, channel);
chSysUnlock();
}
diff --git a/os/hal/templates/pwm_lld.c b/os/hal/templates/pwm_lld.c index 5a4838ade..7e904765a 100644 --- a/os/hal/templates/pwm_lld.c +++ b/os/hal/templates/pwm_lld.c @@ -102,19 +102,29 @@ bool_t pwm_lld_is_enabled(PWMDriver *pwmp, pwmchannel_t channel) { }
/**
- * @brief Disables, enables or reprograms a PWM channel.
+ * @brief Enables a PWM channel.
*
* @param[in] pwmp pointer to a @p PWMDriver object
* @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1)
- * @param[in] width PWM pulse width as clock pulses number, note that
- * specifying zero disables the channel and enforces
- * the output to the idle state.
+ * @param[in] width PWM pulse width as clock pulses number
*
* @notapi
*/
-void pwm_lld_set_channel(PWMDriver *pwmp,
- pwmchannel_t channel,
- pwmcnt_t width) {
+void pwm_lld_enable_channel(PWMDriver *pwmp,
+ pwmchannel_t channel,
+ pwmcnt_t width) {
+
+}
+
+/**
+ * @brief Disables a PWM channel.
+ * @details The channel is disabled and its output line returned to the
+ * idle state.
+ *
+ * @param[in] pwmp pointer to a @p PWMDriver object
+ * @param[in] channel PWM channel identifier (0...PWM_CHANNELS-1)
+ */
+void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel) {
}
diff --git a/os/hal/templates/pwm_lld.h b/os/hal/templates/pwm_lld.h index 3e81959e7..2b8cf294f 100644 --- a/os/hal/templates/pwm_lld.h +++ b/os/hal/templates/pwm_lld.h @@ -195,9 +195,10 @@ extern "C" { void pwm_lld_start(PWMDriver *pwmp);
void pwm_lld_stop(PWMDriver *pwmp);
bool_t pwm_lld_is_enabled(PWMDriver *pwmp, pwmchannel_t channel);
- void pwm_lld_set_channel(PWMDriver *pwmp,
- pwmchannel_t channel,
- pwmcnt_t width);
+ void pwm_lld_enable_channel(PWMDriver *pwmp,
+ pwmchannel_t channel,
+ pwmcnt_t width);
+ void pwm_lld_disable_channel(PWMDriver *pwmp, pwmchannel_t channel);
#ifdef __cplusplus
}
#endif
diff --git a/readme.txt b/readme.txt index 46c281fd0..6b3aafc53 100644 --- a/readme.txt +++ b/readme.txt @@ -85,8 +85,6 @@ - NEW: Added demo for the ST STM8L-Discovery kit.
- NEW: Added support for the STM32 Value Line to the HAL.
- NEW: Added demo for the ST STM32VL-Discovery kit.
-- NEW: Simplified the interface between the PWM high level driver and the
- low level driver, now there is a single channels-interacting function.
- CHANGE: Improved the STM32 HAL to support multiple sub-families, at compile
time now it is possible to test the presence of any single peripheral into
the specified STM32 device.
|