boards/stm32f411-minimum: add support for hx711 driver
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
This commit is contained in:
parent
84a2cab886
commit
d904a02392
@ -34,4 +34,53 @@ config STM32F411MINIMUM_FLASH_MINOR
|
||||
---help---
|
||||
Sets the minor number for the FLASH MTD /dev entry
|
||||
|
||||
menuconfig STM32F411MINIMUM_HX711
|
||||
bool "Enable hx711 scale sensor"
|
||||
default n
|
||||
select ADC_HX711
|
||||
|
||||
if STM32F411MINIMUM_HX711
|
||||
|
||||
choice
|
||||
prompt "Select GPIO port for clock pin"
|
||||
default STM32F411MINIMUM_HX711_CLK_PORTA
|
||||
|
||||
config STM32F411MINIMUM_HX711_CLK_PORTA
|
||||
bool "Port A"
|
||||
config STM32F411MINIMUM_HX711_CLK_PORTB
|
||||
bool "Port B"
|
||||
|
||||
endchoice # Select GPIO port for clock pin
|
||||
|
||||
config STM32F411MINIMUM_HX711_CLK_PIN
|
||||
int "Select GPIO pin number for clock pin"
|
||||
default 1
|
||||
range 0 15
|
||||
|
||||
choice
|
||||
prompt "Select GPIO port for data pin"
|
||||
default STM32F411MINIMUM_HX711_DATA_PORTA
|
||||
|
||||
config STM32F411MINIMUM_HX711_DATA_PORTA
|
||||
bool "Port A"
|
||||
config STM32F411MINIMUM_HX711_DATA_PORTB
|
||||
bool "Port B"
|
||||
|
||||
endchoice # Select GPIO port for data pin
|
||||
|
||||
config STM32F411MINIMUM_HX711_DATA_PIN
|
||||
int "Select GPIO pin number for data pin"
|
||||
default 2
|
||||
range 0 15
|
||||
|
||||
endif # STM32F411MINIMUM_HX711
|
||||
|
||||
menuconfig STM32F411MINIMUM_GPIO
|
||||
select DEV_GPIO
|
||||
bool "enable gpio subsystem"
|
||||
|
||||
if STM32F411MINIMUM_GPIO
|
||||
source boards/arm/stm32/stm32f411-minimum/Kconfig.gpio
|
||||
endif
|
||||
|
||||
endif
|
||||
|
@ -48,6 +48,10 @@ if(CONFIG_USBMSC)
|
||||
list(APPEND SRCS stm32_usbmsc.c)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ADC_HX711)
|
||||
list(APPEND SRCS stm32_hx711.c)
|
||||
endif()
|
||||
|
||||
target_sources(board PRIVATE ${SRCS})
|
||||
|
||||
set_property(GLOBAL PROPERTY LD_SCRIPT
|
||||
|
@ -30,6 +30,10 @@ ifeq ($(CONFIG_ARCH_LEDS),y)
|
||||
CSRCS += stm32_autoleds.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADC_HX711),y)
|
||||
CSRCS += stm32_hx711.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SPI),y)
|
||||
CSRCS += stm32_spi.c
|
||||
endif
|
||||
|
@ -84,6 +84,14 @@ int stm32_bringup(void)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
#ifdef CONFIG_ADC_HX711
|
||||
ret = stm32_hx711_initialize();
|
||||
if (ret != OK)
|
||||
{
|
||||
aerr("ERROR: Failed to initialize hx711: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST)
|
||||
/* Initialize USB host operation. stm32_usbhost_initialize() starts a
|
||||
* thread will monitor for USB connection and disconnection events.
|
||||
|
102
boards/arm/stm32/stm32f411-minimum/src/stm32_hx711.c
Normal file
102
boards/arm/stm32/stm32f411-minimum/src/stm32_hx711.c
Normal file
@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/stm32f411-minimum/src/stm32_hx711.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 <nuttx/analog/hx711.h>
|
||||
#include <nuttx/compiler.h>
|
||||
#include <arch/board/board.h>
|
||||
#include <arch/stm32/chip.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32f411-minimum.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int stm32_hx711_clock_set(unsigned char minor, int value);
|
||||
static int stm32_hx711_data_read(unsigned char minor);
|
||||
static int stm32_hx711_data_irq(unsigned char minor,
|
||||
xcpt_t handler, void *arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
struct hx711_lower_s g_lower =
|
||||
{
|
||||
.data_read = stm32_hx711_data_read,
|
||||
.clock_set = stm32_hx711_clock_set,
|
||||
.data_irq = stm32_hx711_data_irq,
|
||||
.cleanup = NULL
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static int stm32_hx711_clock_set(unsigned char minor, int value)
|
||||
{
|
||||
UNUSED(minor);
|
||||
|
||||
stm32_gpiowrite(HX711_CLK_PIN, value);
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int stm32_hx711_data_read(unsigned char minor)
|
||||
{
|
||||
UNUSED(minor);
|
||||
|
||||
return stm32_gpioread(HX711_DATA_PIN);
|
||||
}
|
||||
|
||||
static int stm32_hx711_data_irq(unsigned char minor,
|
||||
xcpt_t handler, void *arg)
|
||||
{
|
||||
UNUSED(minor);
|
||||
|
||||
return stm32_gpiosetevent(HX711_DATA_PIN, false, true, true, handler, arg);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_hx711_initialize(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
stm32_configgpio(HX711_DATA_PIN);
|
||||
stm32_configgpio(HX711_CLK_PIN);
|
||||
|
||||
ret = hx711_register(0, &g_lower);
|
||||
if (ret != 0)
|
||||
{
|
||||
aerr("ERROR: Failed to register hx711 device: %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
@ -76,6 +76,29 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* HX711 pins */
|
||||
|
||||
#ifdef CONFIG_ADC_HX711
|
||||
# ifdef CONFIG_STM32F411MINIMUM_HX711_CLK_PORTB
|
||||
# define HX711_CLK_PORT GPIO_PORTB
|
||||
# else
|
||||
# define HX711_CLK_PORT GPIO_PORTA
|
||||
# endif
|
||||
|
||||
# ifdef CONFIG_STM32F411MINIMUM_HX711_DATA_PORTB
|
||||
# define HX711_DATA_PORT GPIO_PORTB
|
||||
# else
|
||||
# define HX711_DATA_PORT GPIO_PORTA
|
||||
# endif
|
||||
|
||||
#define HX711_CLK_PIN (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_OUTPUT_SET|\
|
||||
GPIO_SPEED_2MHz|GPIO_PULLUP|\
|
||||
HX711_CLK_PORT|CONFIG_STM32F411MINIMUM_HX711_CLK_PIN)
|
||||
#define HX711_DATA_PIN (GPIO_INPUT|GPIO_SPEED_2MHz|GPIO_PULLUP|GPIO_EXTI|\
|
||||
HX711_DATA_PORT|CONFIG_STM32F411MINIMUM_HX711_DATA_PIN)
|
||||
|
||||
#endif /* CONFIG_HX711 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
@ -99,6 +122,18 @@ extern struct spi_dev_s *g_spi2;
|
||||
|
||||
void stm32_spidev_initialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_hx711_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize hx711 chip
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADC_HX711
|
||||
int stm32_hx711_initialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_mmcsd_initialize
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user