From c7d0301cedae71ff339f76a69c61bb1e0db3d2bc Mon Sep 17 00:00:00 2001
From: Philippe Coval
Date: Fri, 24 May 2019 21:18:05 +0200
Subject: [PATCH] nuttx: Register PWM device only if device file is not present
If configured from menuconfig, device inode is already there
there is no need to register it again.
It was observed on STM32F7 using a config with those options:
```
CONFIG_STM32F7_TIM1=y
CONFIG_STM32F7_TIM1_PWM=y
```
Relate-to: https://github.com/rzr/webthing-iotjs/issues/3
Forwarded: https://github.com/pando-project/iotjs/pull/1886
Change-Id: I6134f15ead43babe3e5de6a9f0d185f6629f62d2
IoT.js-DCO-1.0-Signed-off-by: Philippe Coval p.coval@samsung.com
---
src/modules/nuttx/iotjs_module_pwm-nuttx.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/modules/nuttx/iotjs_module_pwm-nuttx.c b/src/modules/nuttx/iotjs_module_pwm-nuttx.c
index 40be7350b5..7993fa56f2 100644
--- a/src/modules/nuttx/iotjs_module_pwm-nuttx.c
+++ b/src/modules/nuttx/iotjs_module_pwm-nuttx.c
@@ -89,13 +89,15 @@ bool iotjs_pwm_open(iotjs_pwm_t* pwm) {
return false;
}
- struct pwm_lowerhalf_s* pwm_lowerhalf =
- iotjs_pwm_config_nuttx(timer, pwm->pin);
+ if (access(path, F_OK) != 0) {
+ struct pwm_lowerhalf_s* pwm_lowerhalf =
+ iotjs_pwm_config_nuttx(timer, pwm->pin);
- DDDLOG("%s - path: %s, timer: %d\n", __func__, path, timer);
+ DDDLOG("%s - path: %s, timer: %d\n", __func__, path, timer);
- if (pwm_register(path, pwm_lowerhalf) != 0) {
- return false;
+ if (pwm_register(path, pwm_lowerhalf) != 0) {
+ return false;
+ }
}
// File open