mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
boards/risc-v/k210/maix-bit: Add userled support
Build Documentation / build-html (push) Has been cancelled
Build Documentation / build-html (push) Has been cancelled
Replace GPIO driver with userled driver for Pin 12 and 13 LEDs. The red LED on Pin 14 remains as system LED. - Add user LED definitions in board.h (BOARD_LED1, BOARD_LED2) - Add k210_userleds.c implementing board_userled_* functions - Remove k210_gpio.c (GPIO driver no longer needed) - Update CMakeLists.txt and Makefile for userled build - Update k210_bringup.c to initialize userled instead of GPIO Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
@@ -37,10 +37,16 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#define BOARD_LED_PAD 14 /* Connected to red led */
|
/* GPIOHS allocation:
|
||||||
|
*
|
||||||
|
* GPIOHS0 - System LED (pad 14, red) - k210_leds.c
|
||||||
|
* GPIOHS1 - User LED 1 (pad 12) - k210_userleds.c
|
||||||
|
* GPIOHS2 - User LED 2 (pad 13) - k210_userleds.c
|
||||||
|
*/
|
||||||
|
|
||||||
/* Map pad 14 to gpiohs io 0 */
|
/* System LED (CONFIG_ARCH_LEDS) */
|
||||||
|
|
||||||
|
#define BOARD_LED_PAD 14
|
||||||
#define BOARD_LED_IO_FUNC K210_IO_FUNC_GPIOHS0
|
#define BOARD_LED_IO_FUNC K210_IO_FUNC_GPIOHS0
|
||||||
#define BOARD_LED_IO 0
|
#define BOARD_LED_IO 0
|
||||||
|
|
||||||
@@ -53,10 +59,16 @@
|
|||||||
#define LED_ASSERTION 6 /* N/C */
|
#define LED_ASSERTION 6 /* N/C */
|
||||||
#define LED_PANIC 7 /* blink */
|
#define LED_PANIC 7 /* blink */
|
||||||
|
|
||||||
/* GPIO pins used by the GPIO Subsystem */
|
/* User LED definitions */
|
||||||
|
|
||||||
#define BOARD_NGPIOOUT 2 /* Amount of GPIO Output pins */
|
#define BOARD_LEDS 2
|
||||||
#define BOARD_NGPIOINT 0 /* Amount of GPIO Input */
|
|
||||||
|
/* User LED pin mappings */
|
||||||
|
|
||||||
|
#define BOARD_USERLED1_PAD 12
|
||||||
|
#define BOARD_USERLED1_IO 1
|
||||||
|
#define BOARD_USERLED2_PAD 13
|
||||||
|
#define BOARD_USERLED2_IO 2
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ if(CONFIG_ARCH_LEDS)
|
|||||||
list(APPEND SRCS k210_leds.c)
|
list(APPEND SRCS k210_leds.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CONFIG_DEV_GPIO)
|
if(CONFIG_USERLED_LOWER)
|
||||||
list(APPEND SRCS k210_gpio.c)
|
list(APPEND SRCS k210_userleds.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_sources(board PRIVATE ${SRCS})
|
target_sources(board PRIVATE ${SRCS})
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ ifeq ($(CONFIG_ARCH_LEDS),y)
|
|||||||
CSRCS += k210_leds.c
|
CSRCS += k210_leds.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_DEV_GPIO),y)
|
ifeq ($(CONFIG_USERLED_LOWER),y)
|
||||||
CSRCS += k210_gpio.c
|
CSRCS += k210_userleds.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
include $(TOPDIR)/boards/Board.mk
|
include $(TOPDIR)/boards/Board.mk
|
||||||
|
|||||||
@@ -34,6 +34,10 @@
|
|||||||
#include <nuttx/board.h>
|
#include <nuttx/board.h>
|
||||||
#include <nuttx/fs/fs.h>
|
#include <nuttx/fs/fs.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_USERLED_LOWER
|
||||||
|
# include <nuttx/leds/userled.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "k210.h"
|
#include "k210.h"
|
||||||
#include "k210_wdt.h"
|
#include "k210_wdt.h"
|
||||||
#include "maix-bit.h"
|
#include "maix-bit.h"
|
||||||
@@ -60,12 +64,11 @@ int k210_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_DEV_GPIO
|
#ifdef CONFIG_USERLED_LOWER
|
||||||
ret = k210_gpio_init();
|
ret = userled_lower_initialize("/dev/userleds");
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret);
|
syslog(LOG_ERR, "ERROR: userled_lower_initialize() failed: %d\n", ret);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,175 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* boards/risc-v/k210/maix-bit/src/k210_gpio.c
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* 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 <syslog.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <debug.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <nuttx/irq.h>
|
|
||||||
#include <arch/irq.h>
|
|
||||||
|
|
||||||
#include <nuttx/ioexpander/gpio.h>
|
|
||||||
|
|
||||||
#include <arch/board/board.h>
|
|
||||||
|
|
||||||
#include "k210_fpioa.h"
|
|
||||||
#include "k210_gpiohs.h"
|
|
||||||
|
|
||||||
#if defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF)
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* Pin 1 and 2 are used for this example as GPIO outputs. */
|
|
||||||
|
|
||||||
#define GPIO_OUT1 12
|
|
||||||
#define GPIO_OUT2 13
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
struct k210gpio_dev_s
|
|
||||||
{
|
|
||||||
struct gpio_dev_s gpio;
|
|
||||||
uint8_t id;
|
|
||||||
};
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#if BOARD_NGPIOOUT > 0
|
|
||||||
static int gpout_read(struct gpio_dev_s *dev, bool *value);
|
|
||||||
static int gpout_write(struct gpio_dev_s *dev, bool value);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#if BOARD_NGPIOOUT > 0
|
|
||||||
static const struct gpio_operations_s gpout_ops =
|
|
||||||
{
|
|
||||||
.go_read = gpout_read,
|
|
||||||
.go_write = gpout_write,
|
|
||||||
.go_attach = NULL,
|
|
||||||
.go_enable = NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* This array maps the GPIO pins used as OUTPUT */
|
|
||||||
|
|
||||||
static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] =
|
|
||||||
{
|
|
||||||
GPIO_OUT1, GPIO_OUT2
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct k210gpio_dev_s g_gpout[BOARD_NGPIOOUT];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: gpout_read
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#if BOARD_NGPIOOUT > 0
|
|
||||||
static int gpout_read(struct gpio_dev_s *dev, bool *value)
|
|
||||||
{
|
|
||||||
struct k210gpio_dev_s *k210gpio =
|
|
||||||
(struct k210gpio_dev_s *)dev;
|
|
||||||
|
|
||||||
DEBUGASSERT(k210gpio != NULL && value != NULL);
|
|
||||||
DEBUGASSERT(k210gpio->id < BOARD_NGPIOOUT);
|
|
||||||
gpioinfo("Reading...\n");
|
|
||||||
|
|
||||||
*value = (int) k210_gpiohs_get_value(k210gpio->id + 1);
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: gpout_write
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static int gpout_write(struct gpio_dev_s *dev, bool value)
|
|
||||||
{
|
|
||||||
struct k210gpio_dev_s *k210gpio =
|
|
||||||
(struct k210gpio_dev_s *)dev;
|
|
||||||
|
|
||||||
DEBUGASSERT(k210gpio != NULL);
|
|
||||||
DEBUGASSERT(k210gpio->id < BOARD_NGPIOOUT);
|
|
||||||
gpioinfo("Writing %d\n", (int)value);
|
|
||||||
|
|
||||||
k210_gpiohs_set_value(k210gpio->id + 1, !value);
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: k210_gpio_init
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int k210_gpio_init(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int pincount = 0;
|
|
||||||
|
|
||||||
#if BOARD_NGPIOOUT > 0
|
|
||||||
for (i = 0; i < BOARD_NGPIOOUT; i++)
|
|
||||||
{
|
|
||||||
/* Setup and register the GPIO pin */
|
|
||||||
|
|
||||||
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
|
|
||||||
g_gpout[i].gpio.gp_ops = &gpout_ops;
|
|
||||||
g_gpout[i].id = i;
|
|
||||||
gpio_pin_register(&g_gpout[i].gpio, pincount);
|
|
||||||
|
|
||||||
/* Configure the pins that will be used as output */
|
|
||||||
|
|
||||||
k210_fpioa_config(g_gpiooutputs[i],
|
|
||||||
(K210_IO_FUNC_GPIOHS1 + i) | K210_IOFLAG_GPIOHS);
|
|
||||||
k210_gpiohs_set_direction(i + 1, true);
|
|
||||||
k210_gpiohs_set_value(i + 1, true);
|
|
||||||
|
|
||||||
pincount++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
#endif /* CONFIG_DEV_GPIO && !CONFIG_GPIO_LOWER_HALF */
|
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/risc-v/k210/maix-bit/src/k210_userleds.c
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* 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 <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <nuttx/board.h>
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
|
#include "k210_fpioa.h"
|
||||||
|
#include "k210_gpiohs.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* LED configuration table */
|
||||||
|
|
||||||
|
struct k210_led_cfg_s
|
||||||
|
{
|
||||||
|
uint32_t pad; /* FPIOA physical pad number */
|
||||||
|
uint32_t func; /* FPIOA function + flags */
|
||||||
|
uint32_t io; /* GPIOHS IO number */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct k210_led_cfg_s g_led_cfg[BOARD_LEDS] =
|
||||||
|
{
|
||||||
|
{ BOARD_USERLED1_PAD, K210_IO_FUNC_GPIOHS1 | K210_IOFLAG_GPIOHS,
|
||||||
|
BOARD_USERLED1_IO },
|
||||||
|
{ BOARD_USERLED2_PAD, K210_IO_FUNC_GPIOHS2 | K210_IOFLAG_GPIOHS,
|
||||||
|
BOARD_USERLED2_IO }
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_userled_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This function may called from application-specific logic during its
|
||||||
|
* to perform board-specific initialization of LED resources. This
|
||||||
|
* includes such things as, for example, configure GPIO pins to drive the
|
||||||
|
* LEDs and also putting the LEDs in their correct initial state.
|
||||||
|
*
|
||||||
|
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
|
||||||
|
* LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be
|
||||||
|
* available to control the LEDs directly from user board logic or
|
||||||
|
* indirectly user applications (via the common LED character driver).
|
||||||
|
*
|
||||||
|
* Most boards have only a few LEDs and in those cases all LEDs may be
|
||||||
|
* used by the NuttX LED logic exclusively and may not be available for
|
||||||
|
* use by user logic if CONFIG_ARCH_LEDS=y.
|
||||||
|
*
|
||||||
|
* NOTE: The LED number is returned.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Number of LEDs on board
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
uint32_t board_userled_initialize(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Configure the LED GPIO for output.
|
||||||
|
* LEDs are active low (false=on, true=off), so set them
|
||||||
|
* high (off) initially.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (i = 0; i < BOARD_LEDS; i++)
|
||||||
|
{
|
||||||
|
/* Configure pin for GPIOHS function */
|
||||||
|
|
||||||
|
k210_fpioa_config(g_led_cfg[i].pad, g_led_cfg[i].func);
|
||||||
|
|
||||||
|
/* Set direction to output, initial value high (LED off) */
|
||||||
|
|
||||||
|
k210_gpiohs_set_direction(g_led_cfg[i].io, true);
|
||||||
|
k210_gpiohs_set_value(g_led_cfg[i].io, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return BOARD_LEDS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_userled
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This interface may be used by application specific logic to set the
|
||||||
|
* state of a single LED. Definitions for the led identification are
|
||||||
|
* provided in the board-specific board.h header file that may be included
|
||||||
|
* like:
|
||||||
|
*
|
||||||
|
* #included <arch/board/board.h>
|
||||||
|
*
|
||||||
|
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
|
||||||
|
* LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be
|
||||||
|
* available to control the LEDs directly from user board logic or
|
||||||
|
* indirectly user applications (via the common LED character driver).
|
||||||
|
*
|
||||||
|
* Most boards have only a few LEDs and in those cases all LEDs may be
|
||||||
|
* used by the NuttX LED logic exclusively and may not be available for
|
||||||
|
* use by user logic if CONFIG_ARCH_LEDS=y.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* led - LED number
|
||||||
|
* ledon - True if LED should be turned on; False to turn off
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void board_userled(int led, bool ledon)
|
||||||
|
{
|
||||||
|
if ((unsigned)led < BOARD_LEDS)
|
||||||
|
{
|
||||||
|
/* LEDs are active low: false = on, true = off */
|
||||||
|
|
||||||
|
k210_gpiohs_set_value(g_led_cfg[led].io, !ledon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_userled_all
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This interface may be used by application specific logic to set the
|
||||||
|
* state of all board LED. Definitions for the led set member
|
||||||
|
* identification is provided in the board-specific board.h header file
|
||||||
|
* that may be includedlike:
|
||||||
|
*
|
||||||
|
* #included <arch/board/board.h>
|
||||||
|
*
|
||||||
|
* If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
|
||||||
|
* LEDs. If CONFIG_ARCH_LEDS is not defined, then this interfaces may be
|
||||||
|
* available to control the LEDs directly from user board logic or
|
||||||
|
* indirectly user applications (via the common LED character driver).
|
||||||
|
*
|
||||||
|
* Most boards have only a few LEDs and in those cases all LEDs may be
|
||||||
|
* used by the NuttX LED logic exclusively and may not be available for
|
||||||
|
* use by user logic if CONFIG_ARCH_LEDS=y.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* ledset - Bitset of LEDs to be turned on and off
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void board_userled_all(uint32_t ledset)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < BOARD_LEDS; i++)
|
||||||
|
{
|
||||||
|
board_userled(i, (ledset & (1 << i)) != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,8 +31,4 @@
|
|||||||
|
|
||||||
int k210_bringup(void);
|
int k210_bringup(void);
|
||||||
|
|
||||||
#ifdef CONFIG_DEV_GPIO
|
|
||||||
int k210_gpio_init(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __BOARDS_RISCV_K210_MAIX_BIT_SRC_MAIX_BIT_H */
|
#endif /* __BOARDS_RISCV_K210_MAIX_BIT_SRC_MAIX_BIT_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user