aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-11-21 11:12:54 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-11-21 11:12:54 +0000
commit66c5a970fa52e53e643ef1f3365b4d30debd5bfe (patch)
tree6cea71ea231f0a27ebef680a0f60f19bc9175280
parent297a1cefa8e045e68c6b12d1cb31525a086ae4ec (diff)
downloadChibiOS-66c5a970fa52e53e643ef1f3365b4d30debd5bfe.tar.gz
ChibiOS-66c5a970fa52e53e643ef1f3365b4d30debd5bfe.tar.bz2
ChibiOS-66c5a970fa52e53e643ef1f3365b4d30debd5bfe.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2406 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/hal/platforms/STM32/pwm_lld.h23
-rw-r--r--os/hal/templates/pwm_lld.h21
-rw-r--r--readme.txt1
3 files changed, 39 insertions, 6 deletions
diff --git a/os/hal/platforms/STM32/pwm_lld.h b/os/hal/platforms/STM32/pwm_lld.h
index b22e3a315..a1a6c905e 100644
--- a/os/hal/platforms/STM32/pwm_lld.h
+++ b/os/hal/platforms/STM32/pwm_lld.h
@@ -270,6 +270,23 @@ struct PWMDriver {
((uint16_t)(((pwmclk) / (1000000 / (pwmperiod))) - 1))
/**
+ * @brief Converts from fraction to pulse width.
+ * @note Be careful with rounding errors, this is integer math not magic.
+ * You can specify tenths of thousandth but make sure you have the
+ * proper hardware resolution by carefully choosing the clock source
+ * and prescaler settings, see @p PWM_COMPUTE_PSC.
+ *
+ * @param[in] numerator numerator of the fraction
+ * @param[in] denominator percentage as an integer between 0 and numerator
+ * @return The pulse width to be passed to @p pwmEnableChannel().
+ *
+ * @api
+ */
+#define PWM_FRACTION_TO_WIDTH(pwmp, numerator, denominator) \
+ ((uint16_t)(((((uint32_t)(pwmp)->pd_config->pc_arr + 1UL) * \
+ (uint32_t)(denominator)) / (uint32_t)(numerator)) - 1UL))
+
+/**
* @brief Converts from degrees to pulse width.
* @note Be careful with rounding errors, this is integer math not magic.
* You can specify hundredths of degrees but make sure you have the
@@ -283,8 +300,7 @@ struct PWMDriver {
* @api
*/
#define PWM_DEGREES_TO_WIDTH(pwmp, degrees) \
- ((uint16_t)(((((uint32_t)(pwmp)->pd_config->pc_arr + 1UL) * \
- (uint32_t)(degrees)) / 36000UL) - 1UL))
+ PWM_FRACTION_TO_WIDTH(pwmp, 36000, degrees)
/**
* @brief Converts from percentage to pulse width.
@@ -300,8 +316,7 @@ struct PWMDriver {
* @api
*/
#define PWM_PERCENTAGE_TO_WIDTH(pwmp, percentage) \
- ((uint16_t)(((((uint32_t)(pwmp)->pd_config->pc_arr + 1UL) * \
- (uint32_t)(percentage)) / 10000UL) - 1UL))
+ PWM_FRACTION_TO_WIDTH(pwmp, 10000, percentage)
/*===========================================================================*/
/* External declarations. */
diff --git a/os/hal/templates/pwm_lld.h b/os/hal/templates/pwm_lld.h
index 1b0b38f75..2b8cf294f 100644
--- a/os/hal/templates/pwm_lld.h
+++ b/os/hal/templates/pwm_lld.h
@@ -138,6 +138,21 @@ struct PWMDriver {
/*===========================================================================*/
/**
+ * @brief Converts from fraction to pulse width.
+ * @note Be careful with rounding errors, this is integer math not magic.
+ * You can specify tenths of thousandth but make sure you have the
+ * proper hardware resolution by carefully choosing the clock source
+ * and prescaler settings, see @p PWM_COMPUTE_PSC.
+ *
+ * @param[in] numerator numerator of the fraction
+ * @param[in] denominator percentage as an integer between 0 and numerator
+ * @return The pulse width to be passed to @p pwmEnableChannel().
+ *
+ * @api
+ */
+#define PWM_FRACTION_TO_WIDTH(pwmp, numerator, denominator) 0
+
+/**
* @brief Converts from degrees to pulse width.
* @note Be careful with rounding errors, this is integer math not magic.
* You can specify hundredths of degrees but make sure you have the
@@ -150,7 +165,8 @@ struct PWMDriver {
*
* @api
*/
-#define PWM_DEGREES_TO_WIDTH(pwmp, degrees) 0
+#define PWM_DEGREES_TO_WIDTH(pwmp, degrees) \
+ PWM_FRACTION_TO_WIDTH(pwmp, 36000, degrees)
/**
* @brief Converts from percentage to pulse width.
@@ -165,7 +181,8 @@ struct PWMDriver {
*
* @api
*/
-#define PWM_PERCENTAGE_TO_WIDTH(pwmp, percentage) 0
+#define PWM_PERCENTAGE_TO_WIDTH(pwmp, percentage) \
+ PWM_FRACTION_TO_WIDTH(pwmp, 10000, percentage)
/*===========================================================================*/
/* External declarations. */
diff --git a/readme.txt b/readme.txt
index 0ed03f9fc..cc4740a7a 100644
--- a/readme.txt
+++ b/readme.txt
@@ -70,6 +70,7 @@
- FIX: Fixed typo in board name (bug 3113574)(backported to 2.0.7).
- FIX: Fixed defective event wait functions with timeout (bug 3113443)
(backported to 2.0.7).
+- NEW: Added new macro PWM_FRACTION_TO_WIDTH() to the PWM driver model.
- NEW: ARM7 port reorganization following the same pattern of the ARMCMx
one, on now the port is also supports the ARM9 architecture (but not
tested yet hardware). Removed the dependencies between the port layer