mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
STM32F4-Discovery: Add SSD1351 SPI 4-wire interface
This commit is contained in:
@@ -104,6 +104,10 @@ CSRCS += stm32_ssd1289.c
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LCD_SSD1351),y)
|
||||
CSRCS += stm32_ssd1351.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LCD_UG2864AMBAG01),y)
|
||||
CSRCS += stm32_ug2864ambag01.c
|
||||
endif
|
||||
|
||||
@@ -100,12 +100,13 @@ void weak_function stm32_spiinitialize(void)
|
||||
#if defined(CONFIG_STM32_SPI2) && defined(CONFIG_MAX31855)
|
||||
(void)stm32_configgpio(GPIO_MAX31855_CS); /* MAX31855 chip select */
|
||||
#endif
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01)
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01) || \
|
||||
defined(CONFIG_LCD_SSD1351)
|
||||
(void)stm32_configgpio(GPIO_OLED_CS); /* OLED chip select */
|
||||
# if defined(CONFIG_LCD_UG2864AMBAG01)
|
||||
(void)stm32_configgpio(GPIO_OLED_A0); /* OLED Command/Data */
|
||||
# endif
|
||||
# if defined(CONFIG_LCD_UG2864HSWEG01)
|
||||
# if defined(CONFIG_LCD_UG2864HSWEG01) || defined(CONFIG_LCD_SSD1351)
|
||||
(void)stm32_configgpio(GPIO_OLED_DC); /* OLED Command/Data */
|
||||
# endif
|
||||
#endif
|
||||
@@ -141,7 +142,8 @@ void stm32_spi1select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool sele
|
||||
{
|
||||
spidbg("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
|
||||
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01)
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01) || \
|
||||
defined(CONFIG_LCD_SSD1351)
|
||||
if (devid == SPIDEV_DISPLAY)
|
||||
{
|
||||
stm32_gpiowrite(GPIO_OLED_CS, !selected);
|
||||
@@ -217,7 +219,8 @@ uint8_t stm32_spi3status(FAR struct spi_dev_s *dev, enum spi_dev_e devid)
|
||||
#ifdef CONFIG_STM32_SPI1
|
||||
int stm32_spi1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd)
|
||||
{
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01)
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01) || \
|
||||
defined(CONFIG_LCD_SSD1351)
|
||||
if (devid == SPIDEV_DISPLAY)
|
||||
{
|
||||
/* "This is the Data/Command control pad which determines whether the
|
||||
@@ -231,7 +234,7 @@ int stm32_spi1cmddata(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool cmd)
|
||||
# if defined(CONFIG_LCD_UG2864AMBAG01)
|
||||
(void)stm32_gpiowrite(GPIO_OLED_A0, !cmd);
|
||||
# endif
|
||||
# if defined(CONFIG_LCD_UG2864HSWEG01)
|
||||
# if defined(CONFIG_LCD_UG2864HSWEG01) || defined(CONFIG_LCD_SSD1351)
|
||||
(void)stm32_gpiowrite(GPIO_OLED_DC, !cmd);
|
||||
# endif
|
||||
return OK;
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/****************************************************************************
|
||||
* configs/stm32f4discovery/src/stm32_ssd1351.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
|
||||
* Authors: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||
*
|
||||
* 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 <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/board.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/lcd/lcd.h>
|
||||
#include <nuttx/lcd/ssd1351.h>
|
||||
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32f4discovery.h"
|
||||
|
||||
#ifdef CONFIG_LCD_SSD1351
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
/* The pin configurations here require that SPI1 is selected */
|
||||
|
||||
#ifndef CONFIG_STM32_SPI1
|
||||
# error "The OLED driver requires CONFIG_STM32_SPI1 in the configuration"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SSD1351_SPI4WIRE
|
||||
# error "The configuration requires the SPI 4-wire interface"
|
||||
#endif
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
#ifdef CONFIG_DEBUG_LCD
|
||||
# define lcddbg(format, ...) dbg(format, ##__VA_ARGS__)
|
||||
# define lcdvdbg(format, ...) vdbg(format, ##__VA_ARGS__)
|
||||
#else
|
||||
# define lcddbg(x...)
|
||||
# define lcdvdbg(x...)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_graphics_setup
|
||||
*
|
||||
* Description:
|
||||
* Called by NX initialization logic to configure the OLED.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno)
|
||||
{
|
||||
FAR struct spi_dev_s *spi;
|
||||
FAR struct lcd_dev_s *dev;
|
||||
|
||||
/* Configure the OLED GPIOs. This initial configuration is RESET low,
|
||||
* putting the OLED into reset state.
|
||||
*/
|
||||
|
||||
(void)stm32_configgpio(GPIO_OLED_RESET);
|
||||
|
||||
/* Wait a bit then release the OLED from the reset state */
|
||||
|
||||
up_mdelay(20);
|
||||
stm32_gpiowrite(GPIO_OLED_RESET, true);
|
||||
|
||||
/* Get the SPI1 port interface */
|
||||
|
||||
spi = up_spiinitialize(1);
|
||||
if (spi == NULL)
|
||||
{
|
||||
lcddbg("Failed to initialize SPI port 1\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bind the SPI port to the OLED */
|
||||
|
||||
dev = ssd1351_initialize(spi, devno);
|
||||
if (dev == NULL)
|
||||
{
|
||||
lcddbg("Failed to bind SPI port 1 to OLED %d: %d\n", devno);
|
||||
}
|
||||
else
|
||||
{
|
||||
lcdvdbg("Bound SPI port 1 to OLED %d\n", devno);
|
||||
|
||||
/* And turn the OLED on */
|
||||
|
||||
(void)dev->setpower(dev, LCD_FULL_ON);
|
||||
return dev;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_LCD_SSD1351 */
|
||||
@@ -252,7 +252,8 @@
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01)
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01) || \
|
||||
defined(CONFIG_LCD_SSD1351)
|
||||
# define GPIO_OLED_RESET (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN6)
|
||||
# define GPIO_OLED_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
|
||||
|
||||
Reference in New Issue
Block a user