You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "acassis (via GitHub)" <gi...@apache.org> on 2023/02/07 16:01:33 UTC

[GitHub] [nuttx] acassis commented on a diff in pull request #8446: esp32s3: Add pwm support using LEDC peripheral

acassis commented on code in PR #8446:
URL: https://github.com/apache/nuttx/pull/8446#discussion_r1098862970


##########
boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_ledc.c:
##########
@@ -0,0 +1,134 @@
+/****************************************************************************
+ * boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_ledc.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/board.h>
+#include <nuttx/timers/pwm.h>
+
+#include <arch/board/board.h>
+
+#include "chip.h"
+#include "esp32s3_ledc.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32s3_pwm_setup
+ *
+ * Description:
+ *   Initialize LEDC PWM and register the PWM device.
+ *
+ ****************************************************************************/
+
+int esp32s3_pwm_setup(void)
+{
+  int ret;
+  struct pwm_lowerhalf_s *pwm;
+
+#ifdef CONFIG_ESP32S3_LEDC_TIM0
+  pwm = esp32s3_ledc_init(0);
+  if (!pwm)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 0 lower half\n");
+      return -ENODEV;
+    }
+
+  /* Register the PWM driver at "/dev/pwm0" */
+
+  ret = pwm_register("/dev/pwm0", pwm);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+#ifdef CONFIG_ESP32S3_LEDC_TIM1
+  pwm = esp32s3_ledc_init(1);
+  if (!pwm)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 1 lower half\n");
+      return -ENODEV;
+    }
+
+  /* Register the PWM driver at "/dev/pwm1" */
+
+  ret = pwm_register("/dev/pwm1", pwm);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+#ifdef CONFIG_ESP32S3_LEDC_TIM2
+  pwm = esp32s3_ledc_init(2);
+  if (!pwm)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 2 lower half\n");
+      return -ENODEV;
+    }
+
+  /* Register the PWM driver at "/dev/pwm2" */
+
+  ret = pwm_register("/dev/pwm2", pwm);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+#ifdef CONFIG_ESP32S3_LEDC_TIM3
+  pwm = esp32s3_ledc_init(3);
+  if (!pwm)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 3 lower half\n");
+      return -ENODEV;
+    }
+
+  /* Register the PWM driver at "/dev/pwm3" */
+
+  ret = pwm_register("/dev/pwm3", pwm);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+  return OK;
+}

Review Comment:
   Good point, fixed! Thank you!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org