You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2020/06/08 01:53:40 UTC

[incubator-nuttx] 02/02: boards/risc-v/k210/maix-bit: Add initial autoled support

This is an automated email from the ASF dual-hosted git repository.

masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 2b0324c3bfe7425a32e8cac846f1d463b46ec507
Author: Huang Qi <hu...@xiaomi.com>
AuthorDate: Sat Jun 6 13:18:14 2020 +0800

    boards/risc-v/k210/maix-bit: Add initial autoled support
    
    Signed-off-by: Huang Qi <hu...@xiaomi.com>
---
 arch/risc-v/src/k210/Make.defs              |  1 +
 arch/risc-v/src/k210/k210_fpioa.h           |  4 +-
 boards/Kconfig                              |  1 +
 boards/risc-v/k210/maix-bit/include/board.h | 22 +++++++++++
 boards/risc-v/k210/maix-bit/src/Makefile    |  4 ++
 boards/risc-v/k210/maix-bit/src/k210_boot.c |  2 +
 boards/risc-v/k210/maix-bit/src/k210_leds.c | 59 +++++++++++++++++++++++++++++
 7 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/arch/risc-v/src/k210/Make.defs b/arch/risc-v/src/k210/Make.defs
index c8ad47e..718a785 100644
--- a/arch/risc-v/src/k210/Make.defs
+++ b/arch/risc-v/src/k210/Make.defs
@@ -47,6 +47,7 @@ CMN_CSRCS  += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c
 CMN_CSRCS  += riscv_releasepending.c riscv_reprioritizertr.c
 CMN_CSRCS  += riscv_releasestack.c riscv_stackframe.c k210_schedulesigaction.c
 CMN_CSRCS  += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c
+CMN_CSRCS  += riscv_mdelay.c
 
 ifeq ($(CONFIG_STACK_COLORATION),y)
 CMN_CSRCS += riscv_checkstack.c
diff --git a/arch/risc-v/src/k210/k210_fpioa.h b/arch/risc-v/src/k210/k210_fpioa.h
index 5b13884..b3c7349 100644
--- a/arch/risc-v/src/k210/k210_fpioa.h
+++ b/arch/risc-v/src/k210/k210_fpioa.h
@@ -80,8 +80,8 @@
 #define K210_IO_SL             (1 << 19)
 #define K210_IO_ST             (1 << 23)
 
-#define K210_FLAG_GPIOHS  (K210_IO_DS(0xf) | K210_IO_OUTPUT_ENABLE | \
-                           K210_IO_INPUT_ENABLE | K210_IO_ST)
+#define K210_IOFLAG_GPIOHS (K210_IO_DS(0xf) | K210_IO_OUTPUT_ENABLE | \
+                            K210_IO_INPUT_ENABLE | K210_IO_ST)
 
 /****************************************************************************
  * Public Functions Prototypes
diff --git a/boards/Kconfig b/boards/Kconfig
index 860f3ec..917903f 100644
--- a/boards/Kconfig
+++ b/boards/Kconfig
@@ -549,6 +549,7 @@ config ARCH_BOARD_LX_CPU
 config ARCH_BOARD_MAIX_BIT
 	bool "Sipeed Maix Bit board"
 	depends on ARCH_CHIP_K210
+	select ARCH_HAVE_LEDS
 	---help---
 		This is the board configuration for the port of NuttX to the
 		Sipeed Maix Bit board. This board features the RISC-V K210
diff --git a/boards/risc-v/k210/maix-bit/include/board.h b/boards/risc-v/k210/maix-bit/include/board.h
index b0127c3..c3862bc 100644
--- a/boards/risc-v/k210/maix-bit/include/board.h
+++ b/boards/risc-v/k210/maix-bit/include/board.h
@@ -48,6 +48,28 @@
 
 #include "k210.h"
 
+#include "k210_fpioa.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define BOARD_LED_PAD     14 /* Connected to red led */
+
+/* Map pad 14 to gpiohs io 0 */
+
+#define BOARD_LED_IO_FUNC K210_IO_FUNC_GPIOHS0
+#define BOARD_LED_IO      0
+
+#define LED_STARTED       0  /* N/C */
+#define LED_HEAPALLOCATE  1  /* N/C */
+#define LED_IRQSENABLED   2  /* N/C */
+#define LED_STACKCREATED  3  /* N/C */
+#define LED_INIRQ         4  /* N/C */
+#define LED_SIGNAL        5  /* N/C */
+#define LED_ASSERTION     6  /* N/C */
+#define LED_PANIC         7  /* blink */
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
diff --git a/boards/risc-v/k210/maix-bit/src/Makefile b/boards/risc-v/k210/maix-bit/src/Makefile
index dc91ae4..cbb092e 100644
--- a/boards/risc-v/k210/maix-bit/src/Makefile
+++ b/boards/risc-v/k210/maix-bit/src/Makefile
@@ -41,4 +41,8 @@ ifeq ($(CONFIG_LIB_BOARDCTL),y)
 CSRCS += k210_appinit.c
 endif
 
+ifeq ($(CONFIG_ARCH_LEDS),y)
+CSRCS += k210_leds.c
+endif
+
 include $(TOPDIR)/boards/Board.mk
diff --git a/boards/risc-v/k210/maix-bit/src/k210_boot.c b/boards/risc-v/k210/maix-bit/src/k210_boot.c
index fe08418..8c6f42c 100644
--- a/boards/risc-v/k210/maix-bit/src/k210_boot.c
+++ b/boards/risc-v/k210/maix-bit/src/k210_boot.c
@@ -41,6 +41,7 @@
 
 #include <debug.h>
 
+#include <nuttx/board.h>
 #include <arch/board/board.h>
 
 /****************************************************************************
@@ -68,4 +69,5 @@
 
 void k210_boardinitialize(void)
 {
+  board_autoled_initialize();
 }
diff --git a/boards/risc-v/k210/maix-bit/src/k210_leds.c b/boards/risc-v/k210/maix-bit/src/k210_leds.c
new file mode 100644
index 0000000..15442cb
--- /dev/null
+++ b/boards/risc-v/k210/maix-bit/src/k210_leds.c
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * boards/risc-v/k210/maix-bit/src/k210_leds.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 <nuttx/board.h>
+
+#include <arch/board/board.h>
+
+#include "k210_fpioa.h"
+#include "k210_gpiohs.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+void board_autoled_initialize(void)
+{
+  k210_fpioa_config(BOARD_LED_PAD, BOARD_LED_IO_FUNC | K210_IOFLAG_GPIOHS);
+  k210_gpiohs_set_direction(BOARD_LED_IO, true);
+  k210_gpiohs_set_value(BOARD_LED_IO, true); /* LED off */
+}
+
+void board_autoled_on(int led)
+{
+  if (led == LED_PANIC)
+    {
+      k210_gpiohs_set_value(BOARD_LED_IO, false);
+    }
+}
+
+void board_autoled_off(int led)
+{
+  if (led == LED_PANIC)
+    {
+      k210_gpiohs_set_value(BOARD_LED_IO, true);
+    }
+}