summaryrefslogtreecommitdiff
path: root/nuttx/configs/stm3240g-eval/src/up_pwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/configs/stm3240g-eval/src/up_pwm.c')
-rw-r--r--nuttx/configs/stm3240g-eval/src/up_pwm.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/nuttx/configs/stm3240g-eval/src/up_pwm.c b/nuttx/configs/stm3240g-eval/src/up_pwm.c
index 503e26073..d0701b2b2 100644
--- a/nuttx/configs/stm3240g-eval/src/up_pwm.c
+++ b/nuttx/configs/stm3240g-eval/src/up_pwm.c
@@ -40,6 +40,7 @@
#include <nuttx/config.h>
+#include <errno.h>
#include <debug.h>
#include <nuttx/pwm.h>
@@ -102,27 +103,40 @@
*
************************************************************************************/
-void pwm_devinit(void)
+int pwm_devinit(void)
{
+ static bool initialized = false;
struct pwm_lowerhalf_s *pwm;
int ret;
- /* Call stm32_pwminitialize() to get an instance of the PWM interface */
+ /* Have we already initialized? */
- pwm = stm32_pwminitialize(STM3240G_EVAL_PWMTIMER);
- if (!pwm)
+ if (!initialized)
{
- dbg("Failed to get the STM32 PWM lower half\n");
- return;
- }
+ /* Call stm32_pwminitialize() to get an instance of the PWM interface */
- /* Register the PWM driver at "/dev/pwm0" */
+ pwm = stm32_pwminitialize(STM3240G_EVAL_PWMTIMER);
+ if (!pwm)
+ {
+ dbg("Failed to get the STM32 PWM lower half\n");
+ return -ENODEV;
+ }
- ret = pwm_register("/dev/pwm0", pwm);
- if (ret < 0)
- {
- adbg("pwm_register failed: %d\n", ret);
+ /* Register the PWM driver at "/dev/pwm0" */
+
+ ret = pwm_register("/dev/pwm0", pwm);
+ if (ret < 0)
+ {
+ adbg("pwm_register failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Now we are initialized */
+
+ initialized = true;
}
+
+ return OK;
}
#endif /* HAVE_PWM */