From 8d4b4aa7a3615df712b9ed42f358e05dfb9fb3c0 Mon Sep 17 00:00:00 2001
From: Sashka <github@durdom.com>
Date: Fri, 23 Feb 2018 12:29:42 -0500
Subject: [PATCH] Multi-Channel Soft PWM library (#579)

---
 .gitmodules                       |  3 ++
 examples/multipwm/Makefile        |  4 +++
 examples/multipwm/multipwm_test.c | 50 +++++++++++++++++++++++++++++++
 extras/multipwm                   |  1 +
 4 files changed, 58 insertions(+)
 create mode 100644 examples/multipwm/Makefile
 create mode 100644 examples/multipwm/multipwm_test.c
 create mode 160000 extras/multipwm

diff --git a/.gitmodules b/.gitmodules
index 6790fd5..2ebfb8a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -34,3 +34,6 @@
 [submodule "extras/libesphttpd/libesphttpd/lib/heatshrink"]
 	path = extras/libesphttpd/libesphttpd/lib/heatshrink
 	url = https://github.com/atomicobject/heatshrink
+[submodule "extras/multipwm"]
+	path = extras/multipwm
+	url = https://github.com/nochkin/multipwm
diff --git a/examples/multipwm/Makefile b/examples/multipwm/Makefile
new file mode 100644
index 0000000..4138f8b
--- /dev/null
+++ b/examples/multipwm/Makefile
@@ -0,0 +1,4 @@
+# Simple makefile for multipwm example
+PROGRAM=multipwm_test
+EXTRA_COMPONENTS = extras/multipwm
+include ../../common.mk
diff --git a/examples/multipwm/multipwm_test.c b/examples/multipwm/multipwm_test.c
new file mode 100644
index 0000000..46ddce8
--- /dev/null
+++ b/examples/multipwm/multipwm_test.c
@@ -0,0 +1,50 @@
+/* An example for the multipwm library
+ * Connect LEDs to pins 12, 13, 15 to see the light changes
+ *
+ * Part of esp-open-rtos
+ * Copyright (c) Sashka Nochkin (https://github.com/nochkin)
+ * MIT Licensed
+ */
+
+#include "espressif/esp_common.h"
+#include "esp/uart.h"
+#include "FreeRTOS.h"
+#include "task.h"
+
+#include "multipwm.h"
+
+void multipwm_task(void *pvParameters)
+{
+    uint32_t counts[] = {500, 2100, 3000};
+    int32_t   steps[] = {100,  300,  200};
+    uint8_t    pins[] = { 12,   13,   15};
+
+    pwm_info_t pwm_info;
+    pwm_info.channels = 3;
+
+    multipwm_init(&pwm_info);
+    for (uint8_t ii=0; ii<pwm_info.channels; ii++) {
+        multipwm_set_pin(&pwm_info, ii, pins[ii]);
+    }
+
+    while(1) {
+        multipwm_stop(&pwm_info);
+        for (uint8_t ii=0; ii<pwm_info.channels; ii++) {
+            multipwm_set_duty(&pwm_info, ii, counts[ii]);
+            counts[ii] += steps[ii];
+            if ((counts[ii] >= 10000) || (counts[ii] == 0)) {
+                steps[ii] = -steps[ii];
+            }
+        }
+        multipwm_start(&pwm_info);
+        vTaskDelay(1);
+    }
+}
+
+void user_init(void)
+{
+    uart_set_baud(0, 115200);
+    printf("SDK version:%s\n", sdk_system_get_sdk_version());
+
+    xTaskCreate(multipwm_task, "multipwm", 256, NULL, 2, NULL);
+}
diff --git a/extras/multipwm b/extras/multipwm
new file mode 160000
index 0000000..44ecea5
--- /dev/null
+++ b/extras/multipwm
@@ -0,0 +1 @@
+Subproject commit 44ecea5757bee0112c65f33eadb44e91a8923535