mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 13:13:08 +08:00
Generic SPI interface for controlling an LCD display
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
6ad906488e
commit
e99a8d192d
+186
-131
File diff suppressed because it is too large
Load Diff
@@ -1134,6 +1134,23 @@ config LCD_ILI9341_IFACE1_RGB565
|
||||
endchoice
|
||||
endif
|
||||
|
||||
config LCD_LCDDRV_SPIIF
|
||||
bool "Generic SPI Interface Driver (for ILI9341 or others)"
|
||||
default n
|
||||
depends on LCD_ILI9341
|
||||
---help---
|
||||
SPI Interface shim to allow LCD and ePaper to be bound to
|
||||
a normal SPI port.
|
||||
|
||||
config LCD_LCDDRV_SPEED
|
||||
int "Generic SPI Interface speed"
|
||||
default 10000000
|
||||
depends on LCD_LCDDRV_SPIIF
|
||||
---help---
|
||||
SPI Interface speed. According to the specification this is generally
|
||||
quite limited, but people have had success with much faster
|
||||
speeds than the spec sheets say. YMMV.
|
||||
|
||||
config LCD_RA8875
|
||||
bool "RA8875 LCD Display Controller"
|
||||
default n
|
||||
|
||||
@@ -124,6 +124,10 @@ ifeq ($(CONFIG_LCD_ILI9341),y)
|
||||
CSRCS += ili9341.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LCD_LCDDRV_SPIIF),y)
|
||||
CSRCS += lcddrv_spiif.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LCD_RA8875),y)
|
||||
CSRCS += ra8875.c
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,347 @@
|
||||
/****************************************************************************
|
||||
* drivers/lcd/lcddrv_spiif.c
|
||||
*
|
||||
* Generic Driver interface for the Single Chip LCD driver connected
|
||||
* via spi driver
|
||||
*
|
||||
* Copyright (C) 2019 Greg Nutt. All rights reserved.
|
||||
* Author: Dave Marples <dave@marples.net>
|
||||
* Based on work from Marco Krahl <ocram.lhark@gmail.com>
|
||||
*
|
||||
* 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 writen 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 <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/lcd/lcddrv_spiif.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Definition
|
||||
****************************************************************************/
|
||||
|
||||
struct lcddrv_spiif_lcd_s
|
||||
{
|
||||
/* Publically visible device structure */
|
||||
|
||||
struct lcddrv_lcd_s dev;
|
||||
|
||||
/* Reference to spi device structure */
|
||||
|
||||
struct spi_dev_s *spi;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Protototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddrv_spiif_backlight
|
||||
*
|
||||
* Description:
|
||||
* Set the backlight level of the connected display.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - Reference to the public driver structure
|
||||
* level - backlight level
|
||||
*
|
||||
* Returned Value:
|
||||
* OK - On Success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lcddrv_spiif_backlight(struct lcddrv_lcd_s *lcd, int level)
|
||||
{
|
||||
return spiif_backlight(lcd, level);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddrv_spiif_select
|
||||
*
|
||||
* Description:
|
||||
* Select the SPI, locking and re-configuring if necessary
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - Reference to the public driver structure
|
||||
* isCommand - Flag indicating is command mode
|
||||
*
|
||||
* Returned Value:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void lcddrv_spiif_select(FAR struct lcddrv_lcd_s *lcd)
|
||||
{
|
||||
FAR struct lcddrv_spiif_lcd_s *priv = (FAR struct lcddrv_spiif_lcd_s *)lcd;
|
||||
|
||||
SPI_LOCK(priv->spi, true);
|
||||
SPI_SELECT(priv->spi, SPIDEV_DISPLAY(0), true);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddrv_spiif_deselect
|
||||
*
|
||||
* Description:
|
||||
* De-select the SPI
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - Reference to the public driver structure
|
||||
*
|
||||
* Returned Value:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void lcddrv_spiif_deselect(FAR struct lcddrv_lcd_s *lcd)
|
||||
{
|
||||
FAR struct lcddrv_spiif_lcd_s *priv = (FAR struct lcddrv_spiif_lcd_s *)lcd;
|
||||
|
||||
SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY(0), false);
|
||||
SPI_SELECT(priv->spi, SPIDEV_DISPLAY(0), false);
|
||||
SPI_LOCK(priv->spi, false);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddrv_spiif_sendmulti
|
||||
*
|
||||
* Description:
|
||||
* Send a number of pixel words to the lcd driver gram.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lcd - Reference to the lcddrv_lcd_s driver structure
|
||||
* wd - Reference to the words to send
|
||||
* nwords - number of words to send
|
||||
*
|
||||
* Returned Value:
|
||||
* OK - On Success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lcddrv_spiif_sendmulti(FAR struct lcddrv_lcd_s *lcd,
|
||||
FAR const uint16_t *wd, uint32_t nwords)
|
||||
{
|
||||
FAR struct lcddrv_spiif_lcd_s *priv = (FAR struct lcddrv_spiif_lcd_s *)lcd;
|
||||
|
||||
SPI_SETBITS(priv->spi, 16);
|
||||
for (uint32_t t = 0; t < nwords; t++)
|
||||
{
|
||||
SPI_SEND(priv->spi, *wd++);
|
||||
}
|
||||
|
||||
SPI_SETBITS(priv->spi, 8);
|
||||
|
||||
return OK;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddrv_spiif_recv
|
||||
*
|
||||
* Description:
|
||||
* Receive a parameter from the lcd driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lcd - Reference to the lcddrv_lcd_s driver structure
|
||||
* param - Reference to where parameter receive
|
||||
*
|
||||
* Returned Value:
|
||||
* OK - On Success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lcddrv_spiif_recv(FAR struct lcddrv_lcd_s *lcd,
|
||||
uint8_t *param)
|
||||
{
|
||||
FAR struct lcddrv_spiif_lcd_s *priv = (FAR struct lcddrv_spiif_lcd_s *)lcd;
|
||||
|
||||
lcdinfo("param=%04x\n", param);
|
||||
SPI_RECVBLOCK(priv->spi, param, 1);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddrv_spiif_send
|
||||
*
|
||||
* Description:
|
||||
* Send to the lcd
|
||||
*
|
||||
* Input Parameters:
|
||||
* lcd - Reference to the lcddrv_lcd_s driver structure
|
||||
* param - Reference to where parameter to send is located
|
||||
*
|
||||
* Returned Value:
|
||||
* OK - On Success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lcddrv_spiif_send(FAR struct lcddrv_lcd_s *lcd,
|
||||
const uint8_t param)
|
||||
{
|
||||
uint8_t r;
|
||||
FAR struct lcddrv_spiif_lcd_s *priv = (FAR struct lcddrv_spiif_lcd_s *)lcd;
|
||||
|
||||
r = SPI_SEND(priv->spi, param);
|
||||
return r;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddrv_spiif_sendcmd
|
||||
*
|
||||
* Description:
|
||||
* Send command to the lcd
|
||||
*
|
||||
* Input Parameters:
|
||||
* lcd - Reference to the lcddrv_lcd_s driver structure
|
||||
* param - Reference to where parameter to send is located
|
||||
*
|
||||
* Returned Value:
|
||||
* OK - On Success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lcddrv_spiif_sendcmd(FAR struct lcddrv_lcd_s *lcd,
|
||||
const uint8_t param)
|
||||
{
|
||||
uint8_t r;
|
||||
FAR struct lcddrv_spiif_lcd_s *priv = (FAR struct lcddrv_spiif_lcd_s *)lcd;
|
||||
|
||||
lcdinfo("param=%04x\n", param);
|
||||
SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY(0), true);
|
||||
r = SPI_SEND(priv->spi, param);
|
||||
SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY(0), false);
|
||||
return r;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lcddrv_spiif_recvmulti
|
||||
*
|
||||
* Description:
|
||||
* Receive pixel words from the lcd driver gram.
|
||||
*
|
||||
* Input Parameters:
|
||||
* lcd - Reference to the public driver structure
|
||||
* wd - Reference to where the pixel words receive
|
||||
* nwords - number of pixel words to receive
|
||||
*
|
||||
* Returned Value:
|
||||
* OK - On Success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lcddrv_spiif_recvmulti(FAR struct lcddrv_lcd_s *lcd,
|
||||
FAR uint16_t *wd, uint32_t nwords)
|
||||
{
|
||||
FAR struct lcddrv_spiif_lcd_s *priv = (FAR struct lcddrv_spiif_lcd_s *)lcd;
|
||||
|
||||
lcdinfo("wd=%p, nwords=%d\n", wd, nwords);
|
||||
SPI_SETBITS(priv->spi, 16);
|
||||
SPI_RECVBLOCK(priv->spi, wd, nwords);
|
||||
SPI_SETBITS(priv->spi, 8);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: FAR struct lcddrv_lcd_s *lcddrv_spiif_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the device structure to control the LCD Single chip driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi : handle to the spi to use
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, this function returns a reference to the LCD control object
|
||||
* for the specified LCDDRV LCD Single chip driver.
|
||||
* NULL is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct lcddrv_lcd_s *lcddrv_spiif_initialize(struct spi_dev_s *spi)
|
||||
{
|
||||
FAR struct lcddrv_spiif_lcd_s *priv =
|
||||
(struct lcddrv_spiif_lcd_s *)kmm_zalloc(sizeof(struct lcddrv_spiif_lcd_s));
|
||||
|
||||
if (!priv)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lcdinfo("initialize lcddrv spi subdriver\n");
|
||||
|
||||
priv->spi = spi;
|
||||
|
||||
if (!priv->spi)
|
||||
{
|
||||
kmm_free(priv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPI_SETFREQUENCY(spi, CONFIG_LCD_LCDDRV_SPEED);
|
||||
SPI_SETBITS(spi, 8);
|
||||
|
||||
/* Hook in our driver routines */
|
||||
|
||||
priv->dev.select = lcddrv_spiif_select;
|
||||
priv->dev.deselect = lcddrv_spiif_deselect;
|
||||
priv->dev.sendparam = lcddrv_spiif_send;
|
||||
priv->dev.sendcmd = lcddrv_spiif_sendcmd;
|
||||
priv->dev.recvparam = lcddrv_spiif_recv;
|
||||
priv->dev.sendgram = lcddrv_spiif_sendmulti;
|
||||
priv->dev.recvgram = lcddrv_spiif_recvmulti;
|
||||
priv->dev.backlight = lcddrv_spiif_backlight;
|
||||
|
||||
return &priv->dev;
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*****************************************************************************
|
||||
* include/nuttx/lcd/lcddrv_spiif.h
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Authors: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Dave Marples <dave@marples.net>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_LCD_LCDDRV_SPIIF_H
|
||||
#define __INCLUDE_NUTTX_LCD_LCDDRV_SPIIF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/spi/spi.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct lcddrv_lcd_s
|
||||
{
|
||||
/* Interface to control the ILI9341 lcd driver
|
||||
*
|
||||
* - select Select the device (as neccessary) before performing
|
||||
* any operations.
|
||||
* - deselect Deselect the device (as necessary).
|
||||
* - send Send specific parameter to the LCD driver.
|
||||
* - recv Receive specific parameter from the LCD driver.
|
||||
* - sendmulti Send pixel data to the LCD drivers gram.
|
||||
* - recvmulti Receive pixel data from the LCD drivers gram.
|
||||
* - backlight Change the backlight level of the connected display.
|
||||
* In the context of the ili9341 that means change the
|
||||
* backlight level of the connected LED driver.
|
||||
* The implementation in detail is part of the platform
|
||||
* specific sub driver.
|
||||
*/
|
||||
|
||||
CODE void (*select)(FAR struct lcddrv_lcd_s *lcd);
|
||||
CODE void (*deselect)(FAR struct lcddrv_lcd_s *lcd);
|
||||
CODE int (*sendcmd)(FAR struct lcddrv_lcd_s *lcd, const uint8_t cmd);
|
||||
CODE int (*sendparam)(FAR struct lcddrv_lcd_s *lcd, const uint8_t param);
|
||||
CODE int (*recvparam)(FAR struct lcddrv_lcd_s *lcd, uint8_t *param);
|
||||
CODE int (*recvgram)(FAR struct lcddrv_lcd_s *lcd,
|
||||
uint16_t *wd, uint32_t nwords);
|
||||
CODE int (*sendgram)(FAR struct lcddrv_lcd_s *lcd,
|
||||
const uint16_t *wd, uint32_t nwords);
|
||||
CODE int (*backlight)(FAR struct lcddrv_lcd_s *lcd, int level);
|
||||
|
||||
/* mcu interface specific data following */
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
* Public Data
|
||||
*****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
* Public Function Prototypes
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Name: spiif_backlight
|
||||
* (Provided by integrating platform)
|
||||
*
|
||||
* Description:
|
||||
* Set the backlight level of the connected display.
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - Reference to the public driver structure
|
||||
* level - backlight level
|
||||
*
|
||||
* Returned Value:
|
||||
* OK - On Success
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
extern int spiif_backlight(struct lcddrv_lcd_s *lcd, int level);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: FAR struct lcddrv_lcd_s *lcddrv_spiif_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the device structure to control the LCD Single chip driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* path : path to spi device to use
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, this function returns a reference to the LCD control object
|
||||
* for the specified LCDDRV LCD Single chip driver.
|
||||
* NULL is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct lcddrv_lcd_s *lcddrv_spiif_initialize(struct spi_dev_s *spi);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_LCD_LCDDRV_SPIIF_H */
|
||||
Reference in New Issue
Block a user