stm32: move zerocross sensor initialization to common board logic

This commit is contained in:
Matias Nitsche 2020-05-11 18:45:14 -03:00 committed by Alin Jerpelea
parent 562210a9bd
commit cf1ff36e0e
12 changed files with 103 additions and 237 deletions

View File

@ -0,0 +1,73 @@
/****************************************************************************
* /home/v01d/coding/nuttx_latest/nuttx/boards/arm/stm32/common/include/stm32_zerocross.h
*
* 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.
*
****************************************************************************/
#ifndef __STM32_ZEROCROSS_H
#define __STM32_ZEROCROSS_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Inline Functions
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: stm32_zerocross_initialize
*
* Description:
* Initialize and register the zero cross driver
*
****************************************************************************/
int board_zerocross_initialize(int devno);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif // __STM32_ZEROCROSS_H

View File

@ -62,6 +62,10 @@ ifeq ($(CONFIG_SENSORS_APDS9960),y)
CSRCS += stm32_apds9960.c
endif
ifeq ($(CONFIG_SENSORS_ZEROCROSS),y)
CSRCS += stm32_zerocross.c
endif
DEPPATH += --dep-path src
VPATH += :src
CFLAGS += $(shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src)

View File

@ -1,5 +1,5 @@
/****************************************************************************
* boards/arm/stm32/stm32f4discovery/src/stm32_zerocross.c
* boards/arm/stm32/common/src/stm32_zerocross.c
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -44,12 +44,10 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <arch/board/board.h>
#include <nuttx/sensors/zerocross.h>
#include "stm32_gpio.h"
#include "stm32f103_minimum.h"
#ifdef CONFIG_SENSORS_ZEROCROSS
/****************************************************************************
* Private Function Prototypes
@ -110,7 +108,7 @@ static void zcross_enable(FAR const struct zc_lowerhalf_s *lower,
g_zcrossarg = arg;
}
stm32_gpiosetevent(GPIO_ZEROCROSS, rising, falling,
stm32_gpiosetevent(BOARD_ZEROCROSS_GPIO, rising, falling,
true, zcross_interrupt, NULL);
leave_critical_section(flags);
@ -132,7 +130,7 @@ static void zcross_disable(void)
flags = enter_critical_section();
stm32_gpiosetevent(GPIO_ZEROCROSS, false, false, false, NULL, NULL);
stm32_gpiosetevent(BOARD_ZEROCROSS_GPIO, false, false, false, NULL, NULL);
leave_critical_section(flags);
@ -173,13 +171,13 @@ static int zcross_interrupt(int irq, FAR void *context, FAR void *arg)
*
****************************************************************************/
int stm32_zerocross_initialize(void)
int board_zerocross_initialize(int devno)
{
/* Configure the GPIO pin as input. NOTE: This is unnecessary for
* interrupting pins since it will also be done by stm32_gpiosetevent().
*/
stm32_configgpio(GPIO_ZEROCROSS);
stm32_configgpio(BOARD_ZEROCROSS_GPIO);
/* Make sure that all interrupts are disabled */
@ -189,5 +187,3 @@ int stm32_zerocross_initialize(void)
return zc_register("/dev/zc0", &g_zcrosslower);
}
#endif /* CONFIG_SENSORS_ZEROCROSS */

View File

@ -236,4 +236,9 @@
#define BOARD_APDS9960_GPIO_INT GPIO_APDS9960_INT
/* ZERO CROSS pin definition */
#define BOARD_ZEROCROSS_GPIO \
(GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTA|GPIO_PIN0)
#endif /* __BOARDS_ARM_STM32_STM32F103_MINIMUM_INCLUDE_BOARD_H */

View File

@ -65,10 +65,6 @@ ifeq ($(CONFIG_PWM),y)
CSRCS += stm32_pwm.c
endif
ifeq ($(CONFIG_SENSORS_ZEROCROSS),y)
CSRCS += stm32_zerocross.c
endif
ifeq ($(CONFIG_LCD_BACKPACK),y)
CSRCS += stm32_lcd_backpack.c
endif

View File

@ -125,6 +125,10 @@
#include "stm32_apds9960.h"
#endif
#ifdef CONFIG_SENSORS_ZEROCROSS
#include "stm32_zerocross.h"
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -219,7 +223,7 @@ int stm32_bringup(void)
#ifdef CONFIG_SENSORS_ZEROCROSS
/* Configure the zero-crossing driver */
ret = stm32_zerocross_initialize();
ret = board_zerocross_initialize(0);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize Zero-Cross, error %d\n", ret);

View File

@ -133,10 +133,6 @@
#define MAX_IRQBUTTON BUTTON_USER2
#define NUM_IRQBUTTONS (BUTTON_USER1 - BUTTON_USER2 + 1)
/* ZERO CROSS pin definition */
#define GPIO_ZEROCROSS (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTA|GPIO_PIN0)
/* SPI chip selects */
#define FLASH_SPI1_CS (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
@ -239,18 +235,6 @@ int stm32_bringup(void);
int stm32_gpio_initialize(void);
#endif
/****************************************************************************
* Name: stm32_zerocross_initialize
*
* Description:
* Initialize and register the zero cross driver
*
****************************************************************************/
#ifdef CONFIG_SENSORS_ZEROCROSS
int stm32_zerocross_initialize(void);
#endif
/****************************************************************************
* Name: stm32_adc_setup
*

View File

@ -420,4 +420,9 @@
#define DMAMAP_SDIO DMAMAP_SDIO_1
/* ZERO CROSS pin definition */
#define BOARD_ZEROCROSS_GPIO \
(GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN0)
#endif /* __BOARDS_ARM_STM32_STM32F4DISCOVERY_INCLUDE_BOARD_H */

View File

@ -152,10 +152,6 @@ ifeq ($(CONFIG_PM_BUTTONS),y)
CSRCS += stm32_pmbuttons.c
endif
ifeq ($(CONFIG_SENSORS_ZEROCROSS),y)
CSRCS += stm32_zerocross.c
endif
ifeq ($(CONFIG_ARCH_IDLE_CUSTOM),y)
CSRCS += stm32_idle.c
endif

View File

@ -94,6 +94,10 @@
#include "stm32_nunchuck.h"
#endif
#ifdef CONFIG_SENSORS_ZEROCROSS
#include "stm32_zerocross.h"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -198,7 +202,7 @@ int stm32_bringup(void)
#ifdef CONFIG_SENSORS_ZEROCROSS
/* Configure the zero-crossing driver */
stm32_zerocross_initialize();
board_zerocross_initialize(0);
#endif
#ifdef CONFIG_LEDS_MAX7219

View File

@ -1,197 +0,0 @@
/****************************************************************************
* boards/arm/stm32/stm32f4discovery/src/stm32_zerocross.c
*
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/sensors/zerocross.h>
#include "stm32_gpio.h"
#include "stm32f4discovery.h"
#ifdef CONFIG_SENSORS_ZEROCROSS
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static void zcross_enable(FAR const struct zc_lowerhalf_s *lower,
zc_interrupt_t handler, FAR void *arg);
static void zcross_disable(void);
static int zcross_interrupt(int irq, FAR void *context);
/****************************************************************************
* Private Data
****************************************************************************/
/* Current interrupt handler and argument */
static zc_interrupt_t g_zcrosshandler;
static FAR void *g_zcrossarg;
/* This is the zero cross lower half driver interface */
static const struct zc_lowerhalf_s g_zcrosslower =
{
.zc_enable = zcross_enable,
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: zcross_enable
*
* Description:
* Enable interrupts on the selected zero cross pin. And empty
* set will disable all interrupts.
*
****************************************************************************/
static void zcross_enable(FAR const struct zc_lowerhalf_s *lower,
zc_interrupt_t handler, FAR void *arg)
{
irqstate_t flags;
bool rising = false;
bool falling = true;
int i;
/* Start with all interrupts disabled */
flags = enter_critical_section();
zcross_disable();
sninfo("handler: %p arg: %p\n", handler, arg);
if (handler)
{
g_zcrosshandler = handler;
g_zcrossarg = arg;
}
stm32_gpiosetevent(GPIO_ZEROCROSS, rising, falling,
true, zcross_interrupt, NULL);
leave_critical_section(flags);
}
/****************************************************************************
* Name: zcross_disable
*
* Description:
* Disable all joystick interrupts
*
****************************************************************************/
static void zcross_disable(void)
{
irqstate_t flags;
int i;
/* Disable zero cross pin interrupt */
flags = enter_critical_section();
stm32_gpiosetevent(GPIO_ZEROCROSS, false, false, false, NULL);
leave_critical_section(flags);
/* Nullify the handler and argument */
g_zcrosshandler = NULL;
g_zcrossarg = NULL;
}
/****************************************************************************
* Name: zcross_interrupt
*
* Description:
* Zero Cross interrupt handler
*
****************************************************************************/
static int zcross_interrupt(int irq, FAR void *context)
{
DEBUGASSERT(g_zcrosshandler);
if (g_zcrosshandler)
{
g_zcrosshandler(&g_zcrosslower, g_zcrossarg);
}
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_zerocross_initialize
*
* Description:
* Initialize and register the zero cross driver
*
****************************************************************************/
int stm32_zerocross_initialize(void)
{
int i;
/* Configure the GPIO pin as input. NOTE: This is unnecessary for
* interrupting pins since it will also be done by stm32_gpiosetevent().
*/
stm32_configgpio(GPIO_ZEROCROSS);
/* Make sure that all interrupts are disabled */
zcross_disable();
/* Register the zero cross device as /dev/zc0 */
return zc_register("/dev/zc0", &g_zcrosslower);
}
#endif /* CONFIG_SENSORS_ZEROCROSS */

View File

@ -236,10 +236,6 @@
#define GPIO_BTN_USER (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTA|GPIO_PIN0)
/* ZERO CROSS pin definition */
#define GPIO_ZEROCROSS (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN0)
#define GPIO_CS43L22_RESET (GPIO_OUTPUT|GPIO_SPEED_50MHz|GPIO_PORTD|GPIO_PIN4)
/* LoRa SX127x */