mlaz closed pull request #821: Adding blinking to pwm_test, fixing os_dev_close 
URL: https://github.com/apache/mynewt-core/pull/821
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/apps/pwm_test/src/main.c b/apps/pwm_test/src/main.c
index 09d5a4c8b..34d5cf727 100755
--- a/apps/pwm_test/src/main.c
+++ b/apps/pwm_test/src/main.c
@@ -24,9 +24,10 @@
 
 struct pwm_dev *pwm;
 uint16_t max_val;
+static struct os_callout my_callout;
 
 int
-main(int argc, char **argv)
+pwm_init(void)
 {
     struct pwm_chan_cfg chan_conf = {
         .pin = LED_BLINK_PIN,
@@ -36,8 +37,6 @@ main(int argc, char **argv)
     uint32_t base_freq;
     int rc;
 
-    sysinit();
-
 #if MYNEWT_VAL(SOFT_PWM)
     pwm = (struct pwm_dev *) os_dev_open("spwm", 0, NULL);
 #else
@@ -84,6 +83,35 @@ main(int argc, char **argv)
     assert(rc == 0);
 #endif
 
+    return rc;
+}
+
+static void
+pwm_toggle(struct os_event *ev)
+{
+    int rc;
+
+    if(pwm!=0){
+        rc = os_dev_close((struct os_dev *)pwm);
+        assert(rc == 0);
+        pwm = NULL;
+    }else{
+        rc = pwm_init();
+        assert(rc == 0);
+    }
+    os_callout_reset(&my_callout, OS_TICKS_PER_SEC * 5);
+}
+
+int
+main(int argc, char **argv)
+{
+    sysinit();
+
+    os_callout_init(&my_callout, os_eventq_dflt_get(),
+                    pwm_toggle, NULL);
+
+    os_callout_reset(&my_callout, OS_TICKS_PER_SEC * 5);
+
     while (1) {
         os_eventq_run(os_eventq_dflt_get());
     }
diff --git a/hw/drivers/pwm/pwm_nrf52/src/pwm_nrf52.c 
b/hw/drivers/pwm/pwm_nrf52/src/pwm_nrf52.c
index ae0615f06..09fe5ef0e 100644
--- a/hw/drivers/pwm/pwm_nrf52/src/pwm_nrf52.c
+++ b/hw/drivers/pwm/pwm_nrf52/src/pwm_nrf52.c
@@ -24,7 +24,6 @@
 #include <errno.h>
 #include <pwm/pwm.h>
 #include <string.h>
-#include <bsp/cmsis_nvic.h>
 
 /* Nordic headers */
 #include <nrfx.h>
@@ -118,16 +117,6 @@ init_instance(int inst_id, nrfx_pwm_config_t* init_conf)
     return (0);
 }
 
-/**
- * Cleanup a driver instance.
- */
-static void
-cleanup_instance(int inst_id)
-{
-    instances[inst_id].playing = false;
-    instances[inst_id].in_use = false;
-}
-
 /**
  * Open the NRF52 PWM device
  *
@@ -190,8 +179,7 @@ nrf52_pwm_close(struct os_dev *odev)
     inst_id = dev->pwm_instance_id;
 
     nrfx_pwm_uninit(&instances[inst_id].drv_instance);
-
-    cleanup_instance(inst_id);
+    instances[inst_id].playing = false;
 
     if (os_started()) {
         os_mutex_release(&dev->pwm_lock);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to