diff --git a/boards/arm/stm32/common/Kconfig b/boards/arm/stm32/common/Kconfig index 4eef44c53cb..e029254339a 100644 --- a/boards/arm/stm32/common/Kconfig +++ b/boards/arm/stm32/common/Kconfig @@ -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 diff --git a/boards/arm/stm32/common/include/board_hall3ph.h b/boards/arm/stm32/common/include/board_hall3ph.h new file mode 100644 index 00000000000..4b1431a5558 --- /dev/null +++ b/boards/arm/stm32/common/include/board_hall3ph.h @@ -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 + +/**************************************************************************** + * 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 diff --git a/boards/arm/stm32/common/src/Make.defs b/boards/arm/stm32/common/src/Make.defs index 45e91b6f3f1..8fee81a4e8b 100644 --- a/boards/arm/stm32/common/src/Make.defs +++ b/boards/arm/stm32/common/src/Make.defs @@ -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 diff --git a/boards/arm/stm32/common/src/board_hall3ph.c b/boards/arm/stm32/common/src/board_hall3ph.c new file mode 100644 index 00000000000..913d0fc3d71 --- /dev/null +++ b/boards/arm/stm32/common/src/board_hall3ph.c @@ -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 + +#include +#include +#include +#include + +#include +#include +#include + +#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; +}