stm32: move nunchuck driver to common board logic

This commit is contained in:
Matias Nitsche 2020-05-08 14:35:51 -03:00 committed by Alin Jerpelea
parent d444df59af
commit 717fa46a53
8 changed files with 210 additions and 204 deletions

View File

@ -0,0 +1,85 @@
/****************************************************************************
* boards/arm/stm32/common/include/stm32_nunchuck.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_NUNCHUCK_H
#define __STM32_NUNCHUCK_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Type Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Inline Functions
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: board_nunchuk_initialize
*
* Description:
* Initialize and register the Nunchuck joystick driver driver.
*
* Input Parameters:
* devno - The device number, used to build the device path as
* /dev/nunchuckN
* busno - The I2C bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_nunchuck_initialize(int devno, int busno);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif // __STM32_NUNCHUCK_H

View File

@ -34,6 +34,10 @@ ifeq ($(CONFIG_SENSORS_VEML6070),y)
CSRCS += stm32_veml6070.c
endif
ifeq ($(CONFIG_INPUT_NUNCHUCK),y)
CSRCS += stm32_nunchuck.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

@ -0,0 +1,111 @@
/****************************************************************************
* boards/arm/stm32/common/src/stm32_nunchuck.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 <stdint.h>
#include <fcntl.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/fs/fs.h>
#include <nuttx/input/nunchuck.h>
#include "stm32_i2c.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_nunchuk_initialize
*
* Description:
* Initialize and register the Nunchuck joystick driver driver.
*
* Input Parameters:
* devno - The device number, used to build the device path as
* /dev/nunchuckN
* busno - The I2C bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_nunchuck_initialize(int devno, int busno)
{
FAR struct i2c_master_s *i2c;
char devpath[14];
int ret;
iinfo("Initializing Wii Nunchuck!\n");
/* Initialize I2C */
i2c = stm32_i2cbus_initialize(busno);
if (i2c == NULL)
{
return -ENODEV;
}
/* Register the joystick device as /dev/nunchuck0 */
iinfo("Initialize joystick driver: %s\n", devname);
snprintf(devpath, 14, "/dev/nunchuck%d", devno);
ret = nunchuck_register(devname, i2c);
if (ret < 0)
{
ierr("ERROR: nunchuck_register failed: %d\n", ret);
}
return ret;
}

View File

@ -101,6 +101,10 @@
#include "stm32_veml6070.h"
#endif
#ifdef CONFIG_INPUT_NUNCHUCK
#include "stm32_nunchuck.h"
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -360,7 +364,7 @@ int stm32_bringup(void)
#ifdef CONFIG_INPUT_NUNCHUCK
/* Register the Nunchuck driver */
ret = nunchuck_initialize("/dev/nunchuck0");
ret = board_nunchuck_initialize(0, 1);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: nunchuck_initialize() failed: %d\n", ret);

View File

@ -1,99 +0,0 @@
/****************************************************************************
* boards/arm/stm32/stm32f4discovery/src/stm32_nunchuck.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Alan Carvalho de Assis <acassis@gmail.com>
*
* 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 <fcntl.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/fs/fs.h>
#include <nuttx/input/nunchuck.h>
#include "stm32_i2c.h"
#include "stm32f103_minimum.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define NUNCHUCK_I2C_PORTNO 1 /* On I2C1 */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nunchuck_initialize
*
* Description:
* Initialize and register the Nunchuck joystick driver
*
****************************************************************************/
int nunchuck_initialize(FAR char *devname)
{
FAR struct i2c_master_s *i2c;
int ret;
iinfo("Initializing Wii Nunchuck!\n");
/* Initialize I2C */
i2c = stm32_i2cbus_initialize(NUNCHUCK_I2C_PORTNO);
if (i2c == NULL)
{
return -ENODEV;
}
/* Register the joystick device as /dev/nunchuck0 */
iinfo("Initialize joystick driver: %s\n", devname);
ret = nunchuck_register(devname, i2c);
if (ret < 0)
{
ierr("ERROR: nunchuck_register failed: %d\n", ret);
}
return ret;
}

View File

@ -85,10 +85,6 @@ ifeq ($(CONFIG_LPWAN_SX127X),y)
CSRCS += stm32_sx127x.c
endif
ifeq ($(CONFIG_INPUT_NUNCHUCK),y)
CSRCS += stm32_nunchuck.c
endif
ifeq ($(CONFIG_SENSORS_MAX31855),y)
CSRCS += stm32_max31855.c
endif

View File

@ -90,6 +90,10 @@
#include "stm32_max6675.h"
#endif
#ifdef CONFIG_INPUT_NUNCHUCK
#include "stm32_nunchuck.h"
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -318,7 +322,7 @@ int stm32_bringup(void)
#ifdef CONFIG_INPUT_NUNCHUCK
/* Register the Nunchuck driver */
ret = nunchuck_initialize("/dev/nunchuck0");
ret = board_nunchuck_initialize(0, 1);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: nunchuck_initialize() failed: %d\n", ret);

View File

@ -1,99 +0,0 @@
/****************************************************************************
* boards/arm/stm32/stm32f4discovery/src/stm32_nunchuck.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Alan Carvalho de Assis <acassis@gmail.com>
*
* 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 <fcntl.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/fs/fs.h>
#include <nuttx/input/nunchuck.h>
#include "stm32_i2c.h"
#include "stm32f4discovery.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define NUNCHUCK_I2C_PORTNO 1 /* On I2C1 */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nunchuck_initialize
*
* Description:
* Initialize and register the Nunchuck joystick driver
*
****************************************************************************/
int nunchuck_initialize(FAR char *devname)
{
FAR struct i2c_master_s *i2c;
int ret;
iinfo("Initializing Wii Nunchuck!\n");
/* Initialize I2C */
i2c = stm32_i2cbus_initialize(NUNCHUCK_I2C_PORTNO);
if (i2c == NULL)
{
return -ENODEV;
}
/* Register the joystick device as /dev/nunchuck0 */
iinfo("Initialize joystick driver: %s\n", devname);
ret = nunchuck_register(devname, i2c);
if (ret < 0)
{
ierr("ERROR: nunchuck_register failed: %d\n", ret);
}
return ret;
}