boards/stm32/common: add 3-phase Hall effect sensor common logic
This commit is contained in:
parent
78962165d8
commit
dbe4cd88dd
@ -70,4 +70,12 @@ endif # BOARD_STM32_IHM16M1
|
||||
|
||||
endif # STM32_FOC
|
||||
|
||||
if SENSORS_HALL3PHASE
|
||||
|
||||
config BOARD_STM32_HALL3PHASE_SAMPLES
|
||||
int "3-phase Hall effect sensor number of samples"
|
||||
default 10
|
||||
|
||||
endif # SENSORS_HALL3PHASE
|
||||
|
||||
endif # BOARD_STM32_COMMON
|
||||
|
67
boards/arm/stm32/common/include/board_hall3ph.h
Normal file
67
boards/arm/stm32/common/include/board_hall3ph.h
Normal file
@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/include/board_hall3ph.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 __BOARD_HALL3PH_H
|
||||
#define __BOARD_HALL3PH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_hall3ph_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the 3-phase Hall effect sensor driver for the given timer
|
||||
*
|
||||
* Input Parameters:
|
||||
* devno - The device number, used to build the device path as /dev/hallN
|
||||
* pha - phase A Hall effect sensor pin configuration
|
||||
* phb - phase B Hall effect sensor pin configuration
|
||||
* phc - phase C Hall effect sensor pin configuration
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_hall3ph_initialize(int devno, int pha, int phb, int phc);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __BOARD_HALL3PH_H
|
@ -78,6 +78,10 @@ ifeq ($(CONFIG_SENSORS_QENCODER),y)
|
||||
CSRCS += stm32_qencoder.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_HALL3PHASE),y)
|
||||
CSRCS += board_hall3ph.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_INA219),y)
|
||||
CSRCS += stm32_ina219.c
|
||||
endif
|
||||
|
75
boards/arm/stm32/common/src/board_hall3ph.c
Normal file
75
boards/arm/stm32/common/src/board_hall3ph.c
Normal file
@ -0,0 +1,75 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/src/board_hall3ph.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 <errno.h>
|
||||
#include <debug.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/sensors/hall3ph.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "stm32_hall3ph.h"
|
||||
#include "board_hall3ph.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_hall3ph_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the 3-phase Hall effect sensor driver
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_hall3ph_initialize(int devno, int pha, int phb, int phc)
|
||||
{
|
||||
struct stm32_hall3ph_cfg_s cfg;
|
||||
char devpath[12];
|
||||
int ret = OK;
|
||||
|
||||
/* Get configuration */
|
||||
|
||||
cfg.gpio_pha = pha;
|
||||
cfg.gpio_phb = phb;
|
||||
cfg.gpio_phc = phc;
|
||||
cfg.samples = CONFIG_BOARD_STM32_HALL3PHASE_SAMPLES;
|
||||
|
||||
/* Initialize a Hall effect sensor interface. */
|
||||
|
||||
snprintf(devpath, 12, "/dev/hall%d", devno);
|
||||
|
||||
ret = stm32_hall3ph_initialize(devpath, &cfg);
|
||||
if (ret < 0)
|
||||
{
|
||||
snerr("ERROR: stm32_hall3ph_initialize failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user