board/stm32f401rc-rs485: Add support to MAX7219 8x8 LED Matrix

Signed-off-by: Rodrigo Sim rcsim10@gmail.com
This commit is contained in:
Rodrigo Sim 2024-07-14 18:42:27 -03:00 committed by Xiang Xiao
parent b8561558e7
commit 17aec1328a
9 changed files with 349 additions and 2 deletions

View File

@ -632,3 +632,35 @@ Now you will be able to access the Device Configuration over Telnet::
help, ? - show help
reset - reset the board
exit - exit shell
max7219
-------
Configures the NuttShell (nsh) over USB Serial (check usbserial configuration) and enables LCD driver with
MAX7219 for 8x8 LED matrix::
NuttShell (NSH) NuttX-12.5.1
nsh>
nsh> nxhello
nxhello_main: NX handle=0x20005420
nxhello_main: Set background color=0
nxhello_listener: Connected
nxhello_main: Screen resolution (32,8)
nxhello_hello: Position (3,0)
nxhello_main: Disconnect from the server
nsh>
======= ====
MAX7219 PINS
======= ====
CS PC4
DIN PA7
Clk PA5
======= ====
As this LED matrix can be combined either horizontally or vetically,
you can configure this using menuconfig::
Number of 8x8 LEDs matrices in the horizontal (width)
Number of 8x8 LEDs matrices in the vertical (height)

View File

@ -0,0 +1,79 @@
/****************************************************************************
* boards/arm/stm32/common/include/stm32_max7219_matrix.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 __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_MAX7219_H
#define __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_MAX7219_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_max7219_matrix_initialize
*
* Description:
* Initialize and register the MAX7219 Matrix.
*
* Input Parameters:
* busno - The SPI bus number
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_max7219_matrix_initialize(int busno);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_MAX7219_H */

View File

@ -116,6 +116,10 @@ if(CONFIG_SENSORS_MAX31855)
list(APPEND SRCS stm32_max31855.c)
endif()
if(CONFIG_LCD_MAX7219)
list(APPEND SRCS stm32_max7219_matrix.c)
endif()
if(CONFIG_LIS3DSH)
list(APPEND SRCS stm32_lis3dsh.c)
endif()

View File

@ -124,6 +124,10 @@ ifeq ($(CONFIG_SENSORS_MAX31855),y)
CSRCS += stm32_max31855.c
endif
ifeq ($(CONFIG_LCD_MAX7219),y)
CSRCS += stm32_max7219_matrix.c
endif
ifeq ($(CONFIG_LIS3DSH),y)
CSRCS += stm32_lis3dsh.c
endif

View File

@ -0,0 +1,118 @@
/****************************************************************************
* boards/arm/stm32/common/src/stm32_max7219_matrix.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 <stdio.h>
#include <stdbool.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/max7219.h>
#include "stm32_gpio.h"
#include "stm32_spi.h"
#ifndef CONFIG_NX_LCDDRIVER
# error "You need to enable CONFIG_NX_LCDDRIVER to use MAX7219 Matrix"
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef CONFIG_LCD_CONTRAST
# define CONFIG_LCD_CONTRAST 60
#endif
/****************************************************************************
* Private Data
****************************************************************************/
struct spi_dev_s *g_spidev;
struct lcd_dev_s *g_lcddev;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_max7219_matrix_initialize
****************************************************************************/
int board_max7219_matrix_initialize(int busno)
{
g_spidev = stm32_spibus_initialize(busno);
if (g_spidev == NULL)
{
lcderr("ERROR: Failed to initialize SPI port %d\n", busno);
return -ENODEV;
}
return OK;
}
/****************************************************************************
* Name: board_lcd_initialize
****************************************************************************/
int board_lcd_initialize(void)
{
return OK;
}
/****************************************************************************
* Name: board_lcd_getdev
****************************************************************************/
struct lcd_dev_s *board_lcd_getdev(int lcddev)
{
g_lcddev = max7219_initialize(g_spidev, lcddev);
if (!g_lcddev)
{
lcderr("ERROR: Failed to bind SPI port 1 to LCD %d\n", lcddev);
}
else
{
lcdinfo("SPI port 1 bound to LCD %d\n", lcddev);
return g_lcddev;
}
return NULL;
}
/****************************************************************************
* Name: board_lcd_uninitialize
****************************************************************************/
void board_lcd_uninitialize(void)
{
/* TO-FIX */
}

View File

@ -0,0 +1,74 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ARCH_FPU is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NX_DISABLE_1BPP is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f401rc-rs485"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_STM32F401RC_RS485=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F401RC=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_IRQBUTTONS=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_USBDEVCTRL=y
CONFIG_BOARD_LOOPSPERMSEC=8499
CONFIG_BUILTIN=y
CONFIG_CDCACM=y
CONFIG_CDCACM_CONSOLE=y
CONFIG_EXAMPLES_BUTTONS=y
CONFIG_EXAMPLES_BUTTONS_NAME0="SW3"
CONFIG_EXAMPLES_BUTTONS_NAME1="SW4"
CONFIG_EXAMPLES_BUTTONS_NAME2="SW5"
CONFIG_EXAMPLES_BUTTONS_NAMES=y
CONFIG_EXAMPLES_BUTTONS_QTD=3
CONFIG_EXAMPLES_NXHELLO=y
CONFIG_EXAMPLES_NXHELLO_BPP=1
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INPUT=y
CONFIG_INPUT_BUTTONS=y
CONFIG_INPUT_BUTTONS_LOWER=y
CONFIG_INTELHEX_BINARY=y
CONFIG_LCD=y
CONFIG_LCD_FRAMEBUFFER=y
CONFIG_LCD_MAX7219=y
CONFIG_LCD_NOGETRUN=y
CONFIG_MQ_MAXMSGSIZE=64
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_NX=y
CONFIG_NXFONT_MONO5X8=y
CONFIG_NX_BLOCKING=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=98304
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=5
CONFIG_START_MONTH=5
CONFIG_START_YEAR=2014
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_OTGFS=y
CONFIG_STM32_PWR=y
CONFIG_STM32_SPI1=y
CONFIG_STM32_USART6=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_USBDEV=y

View File

@ -335,6 +335,11 @@ extern "C"
#define GPIO_SPI2_MOSI GPIO_SPI2_MOSI_1
#define GPIO_SPI2_SCK GPIO_SPI2_SCK_2
/* MAX7219 */
#define STM32_LCD_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN4)
/* LEDs
*
* The STM32F401RC-RS485 boards provide 4 blue user LEDs. LD1, LD2, LD3

View File

@ -63,6 +63,10 @@
#include "stm32_hcsr04.h"
#endif
#ifdef CONFIG_LCD_MAX7219
#include "stm32_max7219_matrix.h"
#endif
#ifdef CONFIG_STEPPER_DRV8825
#include "stm32_drv8266.h"
#endif
@ -205,6 +209,17 @@ int stm32_bringup(void)
}
#endif
#ifdef CONFIG_LCD_MAX7219
/* Configure and initialize the MAX7219 driver */
ret = board_max7219_matrix_initialize(1);
if (ret < 0)
{
syslog(LOG_ERR, \
"ERROR: board_max7219_matrix_initialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_VIDEO_FB
/* Initialize and register the framebuffer driver */

View File

@ -55,9 +55,13 @@
void weak_function stm32_spidev_initialize(void)
{
#ifdef CONFIG_STM32_SPI1
#ifdef CONFIG_LCD_SSD1306
stm32_configgpio(GPIO_OLED_CS); /* OLED chip select */
#endif
#ifdef CONFIG_LCD_MAX7219
stm32_configgpio(STM32_LCD_CS); /* MAX7219 chip select */
#endif
}
/****************************************************************************
@ -93,7 +97,19 @@ void stm32_spi1select(struct spi_dev_s *dev,
spiinfo("devid: %d CS: %s\n",
(int)devid, selected ? "assert" : "de-assert");
stm32_gpiowrite(GPIO_OLED_CS, !selected);
#ifdef CONFIG_LCD_SSD1306
if (devid == SPIDEV_DISPLAY(0))
{
stm32_gpiowrite(GPIO_OLED_CS, !selected);
}
#endif
#ifdef CONFIG_LCD_MAX7219
if (devid == SPIDEV_DISPLAY(0))
{
stm32_gpiowrite(STM32_LCD_CS, !selected);
}
#endif
}
uint8_t stm32_spi1status(struct spi_dev_s *dev, uint32_t devid)