mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 14:53:47 +08:00
stm32: moved all remaining sensor initialization to common board logic
This commit is contained in:
committed by
Alin Jerpelea
parent
05e005c58e
commit
5fd9bd5837
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* /home/v01d/coding/nuttx_latest/nuttx/boards/arm/stm32/common/include/stm32_bh1750.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_BH1750_H
|
||||
#define __STM32_BH1750_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: board_bh1750_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the MPL115A Pressure Sensor driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/lightN
|
||||
* busno - The I2C bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_bh1750_initialize(int devno, int busno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __STM32_BH1750_H
|
||||
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
* /home/v01d/coding/nuttx_latest/nuttx/boards/arm/stm32/common/include/stm32_dhtxx.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_DHTXX_H
|
||||
#define __STM32_DHTXX_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: board_dhtxx_initialize
|
||||
*
|
||||
* Description:
|
||||
* This function is called by application-specific, setup logic to
|
||||
* configure the DHTxx sensor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/humN.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) returned on success;
|
||||
* a negated errno value is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_dhtxx_initialize(int devno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __STM32_DHTXX_H
|
||||
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* /home/v01d/coding/nuttx_latest/nuttx/boards/arm/stm32/common/include/stm32_l3gd20.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_L3GD20_H
|
||||
#define __STM32_L3GD20_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: board_l3gd20_initialize()
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the L3GD20 3 axis gyroscope sensor driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/gyroN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_l3gd20_initialize(int devno, int busno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __STM32_L3GD20_H
|
||||
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/include/stm32_lis3dsh.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_LIS3DSH_H
|
||||
#define __STM32_LIS3DSH_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: board_lis3dsh_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the LIS3DSH 3-axis accelerometer.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/accN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_lis3dsh_initialize(int devno, int busno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __STM32_LIS3DSH_H
|
||||
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/include/stm32_max31855.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_MAX31855_H
|
||||
#define __STM32_MAX31855_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: board_max31855_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the MAX31855 Temperature Sensor driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/tempN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_max31855_initialize(int devno, int busno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __STM32_MAX31855_H
|
||||
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/include/stm32_mlx90614.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_MLX90614_H
|
||||
#define __STM32_MLX90614_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: board_mlx90614_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the MLX90614 Infrared Thermometer.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/thermN
|
||||
* busno - The I2C bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_mlx90614_initialize(int devno, int busno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __STM32_MLX90614_H
|
||||
@@ -0,0 +1,80 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/include/stm32_mpl115a.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_MPL115A_H
|
||||
#define __STM32_MPL115A_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: board_mpl115a_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the MPL115A Pressure Sensor driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/pressN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_mpl115a_initialize(int devno, int busno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __STM32_MPL115A_H
|
||||
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/include/stm32_xen1210.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_XEN1210_H
|
||||
#define __STM32_XEN1210_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: xen1210_archinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the XEN1210 device driver
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/accelN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_xen1210_initialize(int devno, int busno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __STM32_XEN1210_H
|
||||
@@ -74,6 +74,38 @@ ifeq ($(CONFIG_SENSORS_INA219),y)
|
||||
CSRCS += stm32_ina219.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_L3GD20),y)
|
||||
CSRCS += stm32_l3gd20.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_MPL115A),y)
|
||||
CSRCS += stm32_mpl115a.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_DHTXX),y)
|
||||
CSRCS += stm32_dhtxx.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_XEN1210),y)
|
||||
CSRCS += stm32_xen1210.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_BH1750FVI),y)
|
||||
CSRCS += stm32_bh1750.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_MLX90614),y)
|
||||
CSRCS += stm32_mlx90614.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_MAX31855),y)
|
||||
CSRCS += stm32_max31855.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LIS3DSH),y)
|
||||
CSRCS += stm32_lis3dsh.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)
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/src/stm32_bh1750fvi.c
|
||||
*
|
||||
* Copyright (C) 2016 Alan Carvalho de Assis. 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 <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <arch/board/board.h>
|
||||
#include <nuttx/sensors/bh1750fvi.h>
|
||||
|
||||
#include "stm32.h"
|
||||
#include "stm32_i2c.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_bh1750initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the MPL115A Pressure Sensor driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/lightN
|
||||
* busno - The I2C bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_bh1750_initialize(int devno, int busno)
|
||||
{
|
||||
FAR struct i2c_master_s *i2c;
|
||||
int ret;
|
||||
|
||||
sninfo("Initializing BH1750FVI!\n");
|
||||
|
||||
/* Initialize I2C */
|
||||
|
||||
i2c = stm32_i2cbus_initialize(busno);
|
||||
|
||||
if (!i2c)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Then register the barometer sensor */
|
||||
|
||||
ret = bh1750fvi_register(devpath, i2c, BH1750FVI_I2C_ADDR);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Error registering BM180\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
#include <stdio.h>
|
||||
#include "stm32_i2c.h"
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_BMP180)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
@@ -103,4 +101,3 @@ int board_bmp180_initialize(int devno, int busno)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/olimex-stm32-p407/src/stm32_dhtxx.c
|
||||
*
|
||||
* Copyright (C) 2014 Abdelatif GUETTOUCHE. All rights reserved.
|
||||
* Author: Abdelatif GUETTOUCHE <abdelatif.guettouche@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 <nuttx/arch.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/sensors/dhtxx.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "stm32.h"
|
||||
#include "stm32_freerun.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void dhtxx_config_data_pin(FAR struct dhtxx_config_s *state, bool mode);
|
||||
static void dhtxx_set_data_pin(FAR struct dhtxx_config_s *state, bool value);
|
||||
static bool dhtxx_read_data_pin(FAR struct dhtxx_config_s *state);
|
||||
static int64_t dhtxx_get_clock(FAR struct dhtxx_config_s *state);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct dhtxx_config_s g_dhtxx_config =
|
||||
{
|
||||
.config_data_pin = dhtxx_config_data_pin,
|
||||
.set_data_pin = dhtxx_set_data_pin,
|
||||
.read_data_pin = dhtxx_read_data_pin,
|
||||
.get_clock = dhtxx_get_clock,
|
||||
.type = DHTXX_DHT11
|
||||
};
|
||||
|
||||
struct stm32_freerun_s g_freerun;
|
||||
struct timespec ts;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void dhtxx_config_data_pin(FAR struct dhtxx_config_s *state, bool mode)
|
||||
{
|
||||
if (mode)
|
||||
{
|
||||
stm32_configgpio(BOARD_DHTXX_GPIO_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
stm32_configgpio(BOARD_DHTXX_GPIO_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
static void dhtxx_set_data_pin(FAR struct dhtxx_config_s *state, bool value)
|
||||
{
|
||||
stm32_gpiowrite(BOARD_DHTXX_GPIO_OUTPUT, value);
|
||||
}
|
||||
|
||||
static bool dhtxx_read_data_pin(FAR struct dhtxx_config_s *state)
|
||||
{
|
||||
return stm32_gpioread(BOARD_DHTXX_GPIO_INPUT);
|
||||
}
|
||||
|
||||
static int64_t dhtxx_get_clock(FAR struct dhtxx_config_s *state)
|
||||
{
|
||||
/* Get the time from free running timer */
|
||||
|
||||
stm32_freerun_counter(&g_freerun, &ts);
|
||||
|
||||
/* Return time in microseconds */
|
||||
|
||||
return ((ts.tv_sec * 1000000) + (ts.tv_nsec / 1000));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_dhtxx_initialize
|
||||
*
|
||||
* Description:
|
||||
* This function is called by application-specific, setup logic to
|
||||
* configure the DHTxx sensor.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/humN.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) returned on success;
|
||||
* a negated errno value is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_dhtxx_initialize(int devno)
|
||||
{
|
||||
int ret;
|
||||
char devpath[12];
|
||||
|
||||
stm32_configgpio(BOARD_DHTXX_GPIO_OUTPUT);
|
||||
|
||||
stm32_gpiowrite(BOARD_DHTXX_GPIO_OUTPUT, false);
|
||||
|
||||
/* Initialize the free-running timer with 1uS resolution */
|
||||
|
||||
ret = stm32_freerun_initialize(&g_freerun, BOARD_DHTXX_FRTIMER, 1);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("Failed to initialize the free running timer! Err = %d\n", ret);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
snprintf(devpath, 12, "/dev/hum%d", devno);
|
||||
ret = dhtxx_register(devpath, &g_dhtxx_config);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Error registering Dhtxx\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/src/stm32_l3gd20.c
|
||||
*
|
||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Mateusz Szafoni <raiden00@railab.me>
|
||||
*
|
||||
* 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 <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/sensors/l3gd20.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "stm32.h"
|
||||
#include "stm32_spi.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int l3gd20_attach(FAR struct l3gd20_config_s * cfg, xcpt_t irq);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Only one L3GD20 device on board */
|
||||
|
||||
static struct l3gd20_config_s g_l3gd20_config =
|
||||
{
|
||||
.attach = l3gd20_attach,
|
||||
.irq = BOARD_L3GD20_IRQ,
|
||||
.spi_devid = SPIDEV_ACCELEROMETER(0)
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: l3gd20_attach()
|
||||
*
|
||||
* Description: Attach the l3gd20 interrupt handler to the GPIO interrupt
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int l3gd20_attach(FAR struct l3gd20_config_s *cfg, xcpt_t irq)
|
||||
{
|
||||
return stm32_gpiosetevent(BOARD_L3GD20_GPIO_DREADY, true, false,
|
||||
true, irq, NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_l3gd20_initialize()
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the L3GD20 3 axis gyroscope sensor driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/gyroN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_l3gd20_initialize(int devno, int busno)
|
||||
{
|
||||
int ret = 0;
|
||||
struct spi_dev_s *spi;
|
||||
char devpath[12];
|
||||
|
||||
/* Configure DREADY IRQ input */
|
||||
|
||||
stm32_configgpio(BOARD_L3GD20_GPIO_DREADY);
|
||||
|
||||
/* Initialize SPI */
|
||||
|
||||
spi = stm32_spibus_initialize(busno);
|
||||
|
||||
if (!spi)
|
||||
{
|
||||
ret = -ENODEV;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Then register the gyro */
|
||||
|
||||
snprintf(devpath, 12, "/dev/gyro%d", devno);
|
||||
ret = l3gd20_register(devpath, spi, &g_l3gd20_config);
|
||||
if (ret != OK)
|
||||
{
|
||||
goto errout;
|
||||
}
|
||||
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/src/stm32_lis3dsh.c
|
||||
*
|
||||
* Copyright (C) 2017 Florian Olbrich. All rights reserved.
|
||||
* Author: Florian Olbrich <flox@posteo.de>
|
||||
*
|
||||
* 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 <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/sensors/lis3dsh.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "stm32.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: attach_disc_lis3dsh
|
||||
*
|
||||
* Description:
|
||||
* Attach the lis3dsh interrupt handler to PE0/EXT0 on the STM32F4 as wired
|
||||
* on STM32F4Discovery
|
||||
*
|
||||
* Input Parameters:
|
||||
* *config - The lis3dsh instance configuration data containing the IRQ number,
|
||||
* device ID and interrupt handler
|
||||
* interrupt_handler - The interrupt handler to attach
|
||||
* arg -
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
int attach_disc_lis3dsh(FAR struct lis3dsh_config_s *config,
|
||||
xcpt_t interrupt_handler)
|
||||
{
|
||||
return stm32_gpiosetevent(BOARD_LIS3DSH_GPIO_EXT0, true, false, false,
|
||||
interrupt_handler, NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_lis3dsh_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the LIS3DSH 3-axis accelerometer.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/accN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_lis3dsh_initialize(int devno, int busno)
|
||||
{
|
||||
static struct lis3dsh_config_s acc0_config;
|
||||
char devpath[12];
|
||||
struct spi_dev_s *spi;
|
||||
int ret;
|
||||
|
||||
sninfo("Initializing LIS3DSH\n");
|
||||
|
||||
acc0_config.irq = 22;
|
||||
acc0_config.spi_devid = 0;
|
||||
acc0_config.attach = &attach_disc_lis3dsh;
|
||||
|
||||
spi = stm32_spibus_initialize(1);
|
||||
if (!spi)
|
||||
{
|
||||
spiinfo("Failed to initialize SPI port\n");
|
||||
ret = -ENODEV;
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(devpath, 12, "/dev/acc%d", devno);
|
||||
ret = lis3dsh_register(devpath, spi, &acc0_config);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/src/stm32_max31855.c
|
||||
*
|
||||
* Copyright (C) 2015 Alan Carvalho de Assis. 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 <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <arch/board/board.h>
|
||||
#include <nuttx/sensors/max31855.h>
|
||||
|
||||
#include "stm32.h"
|
||||
#include "stm32_spi.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_max31855_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the MAX31855 Temperature Sensor driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/tempN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_max31855_initialize(int devno, int busno)
|
||||
{
|
||||
FAR struct spi_dev_s *spi;
|
||||
char devpath[12];
|
||||
int ret;
|
||||
|
||||
spi = stm32_spibus_initialize(busno);
|
||||
|
||||
if (!spi)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Then register the barometer sensor */
|
||||
|
||||
snprintf(devpath, 12, "/dev/temp%d", devno);
|
||||
ret = max31855_register(devpath, spi, devno);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Error registering MAX31855\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/src/stm32_mlx90614.c
|
||||
*
|
||||
* Copyright (C) 2016 Alan Carvalho de Assis. 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 <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
#include <nuttx/sensors/mlx90614.h>
|
||||
|
||||
#include "stm32.h"
|
||||
#include "stm32_i2c.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define MLX90614_ADDRESS 0x5a /* Default I2C Address, can be chanced in EEPROM */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_mlx90614_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the MLX90614 Infrared Thermometer.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/thermN
|
||||
* busno - The I2C bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_mlx90614_initialize(int devno, int busno)
|
||||
{
|
||||
FAR struct i2c_master_s *i2c;
|
||||
char devpath[12];
|
||||
int ret;
|
||||
|
||||
sninfo("Initializing MLX90614!\n");
|
||||
|
||||
/* Initialize I2C */
|
||||
|
||||
i2c = stm32_i2cbus_initialize(busno);
|
||||
|
||||
if (!i2c)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Then register the light sensor */
|
||||
|
||||
snprintf(devpath, 12, "/dev/therm%d", devno);
|
||||
ret = mlx90614_register(devpath, i2c, MLX90614_ADDRESS);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Error registering BM180\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/src/stm32_mpl115a.c
|
||||
*
|
||||
* Copyright (C) 2015 Alan Carvalho de Assis. 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 <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/sensors/mpl115a.h>
|
||||
|
||||
#include "stm32.h"
|
||||
#include "stm32_spi.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_mpl115a_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the MPL115A Pressure Sensor driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/pressN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_mpl115a_initialize(int devno, int busno)
|
||||
{
|
||||
FAR struct spi_dev_s *spi;
|
||||
char devpath[12];
|
||||
int ret;
|
||||
|
||||
spi = stm32_spibus_initialize(busno);
|
||||
|
||||
if (!spi)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Then register the barometer sensor */
|
||||
|
||||
snprintf(devpath, 12, "/dev/press%d", devno);
|
||||
ret = mpl115a_register(devpath, spi);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Error registering MPL115A\n");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/src/stm32_xen1210.c
|
||||
*
|
||||
* Copyright (C) 2016 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 <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/sensors/xen1210.h>
|
||||
|
||||
#include <nuttx/timers/pwm.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_spi.h"
|
||||
#include "stm32_pwm.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct stm32_xen1210config_s
|
||||
{
|
||||
/* Configuration structure as seen by the XEN1210 driver */
|
||||
|
||||
struct xen1210_config_s config;
|
||||
|
||||
/* Additional private definitions only known to this driver */
|
||||
|
||||
XEN1210_HANDLE handle; /* The XEN1210 driver handle */
|
||||
xen1210_handler_t handler; /* The XEN1210 interrupt handler */
|
||||
FAR void *arg; /* Argument to pass to the interrupt handler */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Static Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* IRQ/GPIO access callbacks. These operations all hidden behind callbacks
|
||||
* to isolate the XEN1210 driver from differences in GPIO interrupt handling
|
||||
* by varying boards and MCUs.
|
||||
*
|
||||
* attach - Attach the XEN1210 interrupt handler to the GPIO interrupt
|
||||
* enable - Enable or disable the GPIO interrupt
|
||||
* clear - Acknowledge/clear any pending GPIO interrupt
|
||||
*/
|
||||
|
||||
static int xen1210_attach(FAR struct xen1210_config_s *state,
|
||||
xen1210_handler_t handler, FAR void *arg);
|
||||
static void xen1210_enable(FAR struct xen1210_config_s *state, bool enable);
|
||||
static void xen1210_clear(FAR struct xen1210_config_s *state);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* A reference to a structure of this type must be passed to the XEN1210
|
||||
* driver. This structure provides information about the configuration
|
||||
* of the XEN1210 and provides some board-specific hooks.
|
||||
*
|
||||
* Memory for this structure is provided by the caller. It is not copied
|
||||
* by the driver and is presumed to persist while the driver is active. The
|
||||
* memory must be writable because, under certain circumstances, the driver
|
||||
* may modify frequency or X plate resistance values.
|
||||
*/
|
||||
|
||||
static struct stm32_xen1210config_s g_xen1210config =
|
||||
{
|
||||
.config =
|
||||
{
|
||||
.frequency = XEN1210_SPI_MAXFREQUENCY,
|
||||
.attach = xen1210_attach,
|
||||
.enable = xen1210_enable,
|
||||
.clear = xen1210_clear,
|
||||
},
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/* This is the XEN1210 Interrupt handler */
|
||||
|
||||
static int xen1210_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
{
|
||||
/* Verify that we have a handler attached */
|
||||
|
||||
if (g_xen1210config.handler)
|
||||
{
|
||||
/* Yes.. forward with interrupt along with its argument */
|
||||
|
||||
g_xen1210config.handler(&g_xen1210config.config, g_xen1210config.arg);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* IRQ/GPIO access callbacks. These operations all hidden behind
|
||||
* callbacks to isolate the XEN1210 driver from differences in GPIO
|
||||
* interrupt handling by varying boards and MCUs.
|
||||
*
|
||||
* attach - Attach the XEN1210 interrupt handler to the GPIO interrupt
|
||||
* enable - Enable or disable the GPIO interrupt
|
||||
* clear - Acknowledge/clear any pending GPIO interrupt
|
||||
*/
|
||||
|
||||
static int xen1210_attach(FAR struct xen1210_config_s *state,
|
||||
xen1210_handler_t handler, FAR void *arg)
|
||||
{
|
||||
FAR struct stm32_xen1210config_s *priv =
|
||||
(FAR struct stm32_xen1210config_s *)state;
|
||||
|
||||
sninfo("Saving handler %p\n", handler);
|
||||
DEBUGASSERT(priv);
|
||||
|
||||
/* Just save the handler and its argument. We will use it when interrupts
|
||||
* are enabled
|
||||
*/
|
||||
|
||||
priv->handler = handler;
|
||||
priv->arg = arg;
|
||||
return OK;
|
||||
}
|
||||
|
||||
static void xen1210_enable(FAR struct xen1210_config_s *state, bool enable)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
/* Attach and enable, or detach and disable. Enabling and disabling GPIO
|
||||
* interrupts is a multi-step process so the safest thing is to keep
|
||||
* interrupts disabled during the reconfiguration.
|
||||
*/
|
||||
|
||||
flags = enter_critical_section();
|
||||
if (enable)
|
||||
{
|
||||
/* Configure the interrupt using the SAVED handler */
|
||||
|
||||
stm32_configgpio(BOARD_XEN1210_GPIO_INT);
|
||||
stm32_gpiosetevent(BOARD_XEN1210_GPIO_INT, false, true,
|
||||
true, xen1210_interrupt, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Configure the interrupt with a NULL handler to disable it */
|
||||
|
||||
stm32_gpiosetevent(BOARD_XEN1210_GPIO_INT, false, false, false,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
static void xen1210_clear(FAR struct xen1210_config_s *state)
|
||||
{
|
||||
/* Does nothing */
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xen1210_pwm_setup
|
||||
*
|
||||
* Description:
|
||||
* All STM32 architectures must provide the following interface to work with
|
||||
* examples/pwm.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int xen1210_pwm_setup(void)
|
||||
{
|
||||
static bool initialized = false;
|
||||
struct pwm_lowerhalf_s *pwm;
|
||||
struct pwm_info_s info;
|
||||
|
||||
/* Have we already initialized? */
|
||||
|
||||
if (!initialized)
|
||||
{
|
||||
/* Call stm32_pwminitialize() to get an instance of the PWM interface */
|
||||
|
||||
pwm = stm32_pwminitialize(BOARD_XEN1210_PWMTIMER);
|
||||
if (!pwm)
|
||||
{
|
||||
_err("ERROR: Failed to get the STM32 PWM lower half\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Define frequency and duty cycle: 2MHz @ 50% */
|
||||
|
||||
info.frequency = 2000000; /* 2MHz */
|
||||
info.duty = 32768; /* This value means 50% */
|
||||
|
||||
/* Initialize PWM */
|
||||
|
||||
pwm->ops->setup(pwm);
|
||||
pwm->ops->start(pwm, &info);
|
||||
|
||||
/* Now we are initialized */
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: xen1210_archinitialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the XEN1210 device driver
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/accelN
|
||||
* busno - The SPI bus number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_xen1210_initialize(int devno, int busno)
|
||||
{
|
||||
FAR struct spi_dev_s *dev;
|
||||
int ret;
|
||||
|
||||
/* Check if we are already initialized */
|
||||
|
||||
if (!g_xen1210config.handle)
|
||||
{
|
||||
sninfo("Initializing\n");
|
||||
|
||||
/* XEN1210 needs an external clock 1-4MHz
|
||||
* We are using PWM on TIM1 CH1 to do it!
|
||||
*/
|
||||
|
||||
xen1210_pwm_setup();
|
||||
|
||||
/* Configure the XEN1210 interrupt pin as an input */
|
||||
|
||||
stm32_configgpio(BOARD_XEN1210_GPIO_INT);
|
||||
|
||||
/* Get an instance of the I2C interface */
|
||||
|
||||
dev = stm32_spibus_initialize(busno);
|
||||
if (!dev)
|
||||
{
|
||||
snerr("ERROR: Failed to initialize SPI bus %d\n", busno);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Instantiate the XEN1210 driver */
|
||||
|
||||
g_xen1210config.handle =
|
||||
xen1210_instantiate(dev, (FAR struct xen1210_config_s *)&g_xen1210config);
|
||||
if (!g_xen1210config.handle)
|
||||
{
|
||||
snerr("ERROR: Failed to instantiate the XEN1210 driver\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Initialize and register the XEN1210 driver */
|
||||
|
||||
ret = xen1210_register(g_xen1210config.handle, devno);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: Failed to register XEN1210 driver: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
Reference in New Issue
Block a user