From 64f962d15c96ee5260522d62e5f82a1972e06334 Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Tue, 24 Mar 2015 16:48:06 +0000 Subject: [PATCH] pwm: add calls for getting PWM max and min period Resolves #176 Signed-off-by: Thomas Ingleby --- api/mraa/pwm.h | 14 ++++++++++++++ api/mraa/pwm.hpp | 20 ++++++++++++++++++++ src/pwm/pwm.c | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/api/mraa/pwm.h b/api/mraa/pwm.h index bbc9049..ef78110 100644 --- a/api/mraa/pwm.h +++ b/api/mraa/pwm.h @@ -186,6 +186,20 @@ mraa_result_t mraa_pwm_config_ms(mraa_pwm_context dev, int period, float duty); */ mraa_result_t mraa_pwm_config_percent(mraa_pwm_context dev, int period, float duty); +/** + * Get the maximum pwm period in us + * + * @return max pwm in us + */ +int mraa_pwm_get_max_period(); + +/** + * Get the minimum pwm period in us + * + * @return min pwm in us + */ +int mraa_pwm_get_min_period(); + #ifdef __cplusplus } #endif diff --git a/api/mraa/pwm.hpp b/api/mraa/pwm.hpp index 2a18a7b..e7ada7a 100644 --- a/api/mraa/pwm.hpp +++ b/api/mraa/pwm.hpp @@ -204,6 +204,26 @@ class Pwm { return mraa_pwm_config_percent(m_pwm, period, duty); } + /** + * Get the maximum pwm period in us + * + * @return max pwm in us + */ + int + max_period() + { + return mraa_pwm_get_max_period(); + } + /** + * Get the minimum pwm period in us + * + * @return min pwm in us + */ + int + min_period() + { + return mraa_pwm_get_min_period(); + } private: mraa_pwm_context m_pwm; diff --git a/src/pwm/pwm.c b/src/pwm/pwm.c index ab5978c..e5ca3fd 100644 --- a/src/pwm/pwm.c +++ b/src/pwm/pwm.c @@ -452,3 +452,21 @@ mraa_pwm_config_percent(mraa_pwm_context dev, int ms, float percentage) } return MRAA_SUCCESS; } + +int +mraa_pwm_get_max_period() +{ + if (plat == NULL) { + return -1; + } + return plat->pwm_max_period; +} + +int +mraa_pwm_get_min_period() +{ + if (plat == NULL) { + return -1; + } + return plat->pwm_min_period; +}