boards/esp32s2-saola-1: Add button driver support
This commit is contained in:
parent
749d0dfe84
commit
89536c526b
@ -0,0 +1,52 @@
|
|||||||
|
#
|
||||||
|
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||||
|
#
|
||||||
|
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||||
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||||
|
# modifications.
|
||||||
|
#
|
||||||
|
# CONFIG_ARCH_LEDS is not set
|
||||||
|
# CONFIG_NSH_ARGCAT is not set
|
||||||
|
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||||
|
# CONFIG_NSH_CMDPARMS is not set
|
||||||
|
CONFIG_ARCH="xtensa"
|
||||||
|
CONFIG_ARCH_BOARD="esp32s2-saola-1"
|
||||||
|
CONFIG_ARCH_BOARD_COMMON=y
|
||||||
|
CONFIG_ARCH_BOARD_ESP32S2_SAOLA_1=y
|
||||||
|
CONFIG_ARCH_BUTTONS=y
|
||||||
|
CONFIG_ARCH_CHIP="esp32s2"
|
||||||
|
CONFIG_ARCH_CHIP_ESP32S2=y
|
||||||
|
CONFIG_ARCH_CHIP_ESP32S2WROVER=y
|
||||||
|
CONFIG_ARCH_IRQBUTTONS=y
|
||||||
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
|
CONFIG_ARCH_XTENSA=y
|
||||||
|
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||||
|
CONFIG_BUILTIN=y
|
||||||
|
CONFIG_ESP32S2_GPIO_IRQ=y
|
||||||
|
CONFIG_ESP32S2_UART0=y
|
||||||
|
CONFIG_EXAMPLES_BUTTONS=y
|
||||||
|
CONFIG_FS_PROCFS=y
|
||||||
|
CONFIG_HAVE_CXX=y
|
||||||
|
CONFIG_HAVE_CXXINITIALIZE=y
|
||||||
|
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||||
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
|
CONFIG_INPUT=y
|
||||||
|
CONFIG_INPUT_BUTTONS=y
|
||||||
|
CONFIG_INPUT_BUTTONS_LOWER=y
|
||||||
|
CONFIG_INTELHEX_BINARY=y
|
||||||
|
CONFIG_NSH_ARCHINIT=y
|
||||||
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
|
CONFIG_NSH_LINELEN=64
|
||||||
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
|
CONFIG_RAM_SIZE=114688
|
||||||
|
CONFIG_RAM_START=0x20000000
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_WAITPID=y
|
||||||
|
CONFIG_SPI=y
|
||||||
|
CONFIG_START_DAY=6
|
||||||
|
CONFIG_START_MONTH=12
|
||||||
|
CONFIG_START_YEAR=2011
|
||||||
|
CONFIG_SYSTEM_NSH=y
|
||||||
|
CONFIG_UART0_SERIAL_CONSOLE=y
|
@ -43,6 +43,13 @@
|
|||||||
# define BOARD_CLOCK_FREQUENCY 80000000
|
# define BOARD_CLOCK_FREQUENCY 80000000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Button definitions *******************************************************/
|
||||||
|
|
||||||
|
#define BUTTON_BTN1 0 /* BUTTON_BOOT */
|
||||||
|
#define BUTTON_BTN1_BIT (1 << BUTTON_BTN1)
|
||||||
|
|
||||||
|
#define NUM_BUTTONS 1
|
||||||
|
|
||||||
/* LED definitions **********************************************************/
|
/* LED definitions **********************************************************/
|
||||||
|
|
||||||
/* Define how many LEDs this board has (needed by userleds) */
|
/* Define how many LEDs this board has (needed by userleds) */
|
||||||
|
@ -49,6 +49,10 @@ ifeq ($(CONFIG_ESP32S2_SPI),y)
|
|||||||
CSRCS += esp32s2_board_spi.c
|
CSRCS += esp32s2_board_spi.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ARCH_BUTTONS),y)
|
||||||
|
CSRCS += esp32s2_buttons.c
|
||||||
|
endif
|
||||||
|
|
||||||
DEPPATH += --dep-path board
|
DEPPATH += --dep-path board
|
||||||
VPATH += :board
|
VPATH += :board
|
||||||
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
|
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)
|
||||||
|
@ -221,6 +221,16 @@ int esp32s2_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_INPUT_BUTTONS
|
||||||
|
/* Register the BUTTON driver */
|
||||||
|
|
||||||
|
ret = btn_lower_initialize("/dev/buttons");
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SENSORS_MAX6675
|
#ifdef CONFIG_SENSORS_MAX6675
|
||||||
ret = board_max6675_initialize(0, 2);
|
ret = board_max6675_initialize(0, 2);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
167
boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_buttons.c
Normal file
167
boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_buttons.c
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_buttons.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 <assert.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
#include <nuttx/board.h>
|
||||||
|
#include <nuttx/irq.h>
|
||||||
|
#include <arch/irq.h>
|
||||||
|
|
||||||
|
#include "esp32s2_gpio.h"
|
||||||
|
|
||||||
|
#include "esp32s2-saola-1.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_button_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* board_button_initialize() must be called to initialize button resources.
|
||||||
|
* After that, board_buttons() may be called to collect the current state
|
||||||
|
* of all buttons or board_button_irq() may be called to register button
|
||||||
|
* interrupt handlers.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
uint32_t board_button_initialize(void)
|
||||||
|
{
|
||||||
|
esp32s2_configgpio(BUTTON_BOOT, INPUT_FUNCTION_3 | PULLUP);
|
||||||
|
return NUM_BUTTONS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_buttons
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* After board_button_initialize() has been called, board_buttons() may be
|
||||||
|
* called to collect the state of all buttons. board_buttons() returns an
|
||||||
|
* 8-bit bit set with each bit associated with a button. See the
|
||||||
|
* BUTTON_*_BIT definitions in board.h for the meaning of each bit.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
uint32_t board_buttons(void)
|
||||||
|
{
|
||||||
|
uint8_t ret = 0;
|
||||||
|
int i = 0;
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
bool b0 = esp32s2_gpioread(BUTTON_BOOT);
|
||||||
|
|
||||||
|
for (i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
up_mdelay(1); /* TODO */
|
||||||
|
|
||||||
|
bool b1 = esp32s2_gpioread(BUTTON_BOOT);
|
||||||
|
|
||||||
|
if (b0 == b1)
|
||||||
|
{
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (3 == n)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
b0 = b1;
|
||||||
|
}
|
||||||
|
|
||||||
|
iinfo("b=%d n=%d\n", b0, n);
|
||||||
|
|
||||||
|
/* Low value means that the button is pressed */
|
||||||
|
|
||||||
|
if (!b0)
|
||||||
|
{
|
||||||
|
ret = 0x1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: board_button_irq
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* board_button_irq() may be called to register an interrupt handler that
|
||||||
|
* will be called when a button is depressed or released. The ID value is
|
||||||
|
* a button enumeration value that uniquely identifies a button resource.
|
||||||
|
* See the BUTTON_* definitions in board.h for the meaning of enumeration
|
||||||
|
* value.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_ARCH_IRQBUTTONS
|
||||||
|
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
DEBUGASSERT(id == 0);
|
||||||
|
|
||||||
|
int irq = ESP32S2_PIN2IRQ(BUTTON_BOOT);
|
||||||
|
|
||||||
|
if (NULL != irqhandler)
|
||||||
|
{
|
||||||
|
/* Make sure the interrupt is disabled */
|
||||||
|
|
||||||
|
esp32s2_gpioirqdisable(irq);
|
||||||
|
|
||||||
|
ret = irq_attach(irq, irqhandler, arg);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: irq_attach() failed: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpioinfo("Attach %p\n", irqhandler);
|
||||||
|
|
||||||
|
gpioinfo("Enabling the interrupt\n");
|
||||||
|
|
||||||
|
/* Configure the interrupt for rising and falling edges */
|
||||||
|
|
||||||
|
esp32s2_gpioirqenable(irq, GPIO_INTR_ANYEDGE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gpioinfo("Disable the interrupt\n");
|
||||||
|
esp32s2_gpioirqdisable(irq);
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user