2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* drivers/lcd/memlcd.c
|
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* 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
|
2013-12-23 23:03:54 +01:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-12-23 23:03:54 +01:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* 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.
|
2013-12-23 23:03:54 +01:00
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Included Files
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2013-12-23 23:03:54 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/spi/spi.h>
|
|
|
|
#include <nuttx/lcd/lcd.h>
|
|
|
|
#include <nuttx/lcd/memlcd.h>
|
|
|
|
|
|
|
|
#include <arch/irq.h>
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Pre-processor Definitions
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2016-08-08 19:54:13 +02:00
|
|
|
/* Bit order H/W feature must be enabled in order to support LSB first
|
|
|
|
* operation.
|
|
|
|
*/
|
2016-08-08 16:28:13 +02:00
|
|
|
|
2016-08-08 19:54:13 +02:00
|
|
|
#if !defined(CONFIG_SPI_HWFEATURES) || !defined(CONFIG_SPI_BITORDER)
|
|
|
|
# error CONFIG_SPI_HWFEATURES=y and CONFIG_SPI_BITORDER=y required by this driver
|
2016-08-08 16:28:13 +02:00
|
|
|
#endif
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2016-08-08 20:21:20 +02:00
|
|
|
#ifndef CONFIG_ARCH_HAVE_SPI_BITORDER
|
|
|
|
# warning This platform does not support SPI LSB-bit order
|
|
|
|
#endif
|
|
|
|
|
2020-11-08 16:56:19 +01:00
|
|
|
/* Display resolution */
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
#if defined CONFIG_MEMLCD_LS013B7DH01
|
|
|
|
# define MEMLCD_XRES 144
|
|
|
|
# define MEMLCD_YRES 168
|
|
|
|
#elif defined CONFIG_MEMLCD_LS013B7DH03
|
|
|
|
# define MEMLCD_XRES 128
|
|
|
|
# define MEMLCD_YRES 128
|
|
|
|
#else
|
|
|
|
# error "This Memory LCD model is not supported yet."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* lcd command */
|
|
|
|
|
|
|
|
#define MEMLCD_CMD_UPDATE (0x01)
|
|
|
|
#define MEMLCD_CMD_ALL_CLEAR (0x04)
|
|
|
|
#define MEMLCD_CONTROL_BYTES (0)
|
|
|
|
|
|
|
|
/* Dolor depth and format */
|
|
|
|
|
|
|
|
#define MEMLCD_BPP 1
|
|
|
|
#define MEMLCD_COLORFMT FB_FMT_Y1
|
|
|
|
|
|
|
|
/* Bytes per logical row and column */
|
|
|
|
|
|
|
|
#define MEMLCD_XSTRIDE (MEMLCD_XRES >> 3)
|
|
|
|
#define MEMLCD_YSTRIDE (MEMLCD_YRES >> 3)
|
|
|
|
|
|
|
|
/* display memory allocation */
|
|
|
|
#define MEMLCD_FBSIZE (MEMLCD_XSTRIDE*MEMLCD_YRES)
|
|
|
|
|
2020-11-08 16:56:19 +01:00
|
|
|
/* Contrast setting, related to VCOM toggle frequency.
|
|
|
|
* Higher frequency gives better contrast, lower instead saves power.
|
2013-12-23 23:03:54 +01:00
|
|
|
*/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
#define MEMLCD_CONTRAST 24
|
|
|
|
#define MEMLCD_MAXCONTRAST 60
|
|
|
|
#define MEMLCD_MINCONTRAST 1
|
|
|
|
|
|
|
|
/* Other misc settings */
|
|
|
|
|
|
|
|
#define MEMLCD_SPI_FREQUENCY 2250000
|
2016-08-08 16:28:13 +02:00
|
|
|
#define MEMLCD_SPI_BITS 8
|
2013-12-23 23:03:54 +01:00
|
|
|
#define MEMLCD_SPI_MODE SPIDEV_MODE0
|
|
|
|
|
|
|
|
#define LS_BIT (1 << 0)
|
|
|
|
#define MS_BIT (1 << 7)
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Private Type Definition
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
struct memlcd_dev_s
|
|
|
|
{
|
2020-02-22 19:31:14 +01:00
|
|
|
/* Publicly visible device structure */
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
struct lcd_dev_s dev;
|
|
|
|
|
|
|
|
/* Private lcd-specific information follows */
|
|
|
|
|
|
|
|
FAR struct spi_dev_s *spi; /* Cached SPI device reference */
|
|
|
|
FAR struct memlcd_priv_s *priv; /* Board specific structure */
|
|
|
|
uint8_t contrast; /* Current contrast setting */
|
|
|
|
uint8_t power; /* Current power setting */
|
|
|
|
|
|
|
|
/* The memlcds does not support reading the display memory in SPI mode.
|
|
|
|
* Since there is 1 BPP and is byte access, it is necessary to keep a
|
|
|
|
* shadow copy of the framebuffer. At 128x128, it amounts to 2KB.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t fb[MEMLCD_FBSIZE];
|
|
|
|
};
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Private Function Protototypes
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
/* Low-level spi helpers */
|
|
|
|
|
|
|
|
static void memlcd_select(FAR struct spi_dev_s *spi);
|
|
|
|
static void memlcd_deselect(FAR struct spi_dev_s *spi);
|
|
|
|
|
|
|
|
/* lcd data transfer methods */
|
|
|
|
|
|
|
|
static int memlcd_putrun(fb_coord_t row, fb_coord_t col,
|
|
|
|
FAR const uint8_t * buffer, size_t npixels);
|
2020-11-08 16:56:19 +01:00
|
|
|
static int memlcd_getrun(fb_coord_t row, fb_coord_t col,
|
|
|
|
FAR uint8_t * buffer, size_t npixels);
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
/* lcd configuration */
|
|
|
|
|
|
|
|
static int memlcd_getvideoinfo(FAR struct lcd_dev_s *dev,
|
|
|
|
FAR struct fb_videoinfo_s *vinfo);
|
2020-11-08 16:56:19 +01:00
|
|
|
static int memlcd_getplaneinfo(FAR struct lcd_dev_s *dev,
|
|
|
|
unsigned int planeno,
|
2013-12-23 23:03:54 +01:00
|
|
|
FAR struct lcd_planeinfo_s *pinfo);
|
|
|
|
|
|
|
|
/* lcd specific controls */
|
|
|
|
|
|
|
|
static int memlcd_getpower(struct lcd_dev_s *dev);
|
|
|
|
static int memlcd_setpower(struct lcd_dev_s *dev, int power);
|
|
|
|
static int memlcd_getcontrast(struct lcd_dev_s *dev);
|
|
|
|
static int memlcd_setcontrast(struct lcd_dev_s *dev, unsigned int contrast);
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Private Data
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static uint8_t g_runbuffer[MEMLCD_BPP * MEMLCD_XRES / 8];
|
|
|
|
|
|
|
|
/* This structure describes the overall lcd video controller */
|
|
|
|
|
|
|
|
static const struct fb_videoinfo_s g_videoinfo =
|
|
|
|
{
|
|
|
|
.fmt = MEMLCD_COLORFMT, /* Color format: rgb16-565: rrrr rggg gggb bbbb */
|
|
|
|
.xres = MEMLCD_XRES, /* Horizontal resolution in pixel columns */
|
|
|
|
.yres = MEMLCD_YRES, /* Vertical resolution in pixel rows */
|
|
|
|
.nplanes = 1, /* Number of color planes supported */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This is the standard, nuttx plane information object */
|
|
|
|
|
|
|
|
static const struct lcd_planeinfo_s g_planeinfo =
|
|
|
|
{
|
|
|
|
.putrun = memlcd_putrun, /* Put a run into lcd memory */
|
|
|
|
.getrun = memlcd_getrun, /* Get a run from lcd memory */
|
|
|
|
.buffer = (uint8_t *) g_runbuffer, /* Run scratch buffer */
|
|
|
|
.bpp = MEMLCD_BPP, /* Bits-per-pixel */
|
|
|
|
};
|
|
|
|
|
2020-11-08 16:56:19 +01:00
|
|
|
/* This is the oled driver instance (only a single device is supported
|
|
|
|
* for now).
|
|
|
|
*/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static struct memlcd_dev_s g_memlcddev =
|
|
|
|
{
|
|
|
|
.dev =
|
|
|
|
{
|
|
|
|
/* lcd configuration */
|
|
|
|
|
|
|
|
.getvideoinfo = memlcd_getvideoinfo,
|
|
|
|
.getplaneinfo = memlcd_getplaneinfo,
|
|
|
|
|
|
|
|
/* lcd specific controls */
|
|
|
|
|
|
|
|
.getpower = memlcd_getpower,
|
|
|
|
.setpower = memlcd_setpower,
|
|
|
|
.getcontrast = memlcd_getcontrast,
|
|
|
|
.setcontrast = memlcd_setcontrast,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Private Functions
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* __set_bit - Set a bit in memory
|
|
|
|
*
|
|
|
|
* @nr: the bit to set
|
|
|
|
* @addr: the address to start counting from
|
|
|
|
*
|
2020-11-08 16:56:19 +01:00
|
|
|
* This function is not atomic and may be reordered. If it's called on the
|
|
|
|
* same region of memory simultaneously, the effect may be that only one
|
|
|
|
* operation succeeds.
|
2013-12-23 23:03:54 +01:00
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
#define BIT(nr) (1 << (nr))
|
2020-11-08 16:56:19 +01:00
|
|
|
#define BITS_PER_BYTE 8
|
|
|
|
#define BIT_MASK(nr) (1 << ((nr) % BITS_PER_BYTE))
|
|
|
|
#define BIT_BYTE(nr) ((nr) / BITS_PER_BYTE)
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static inline void __set_bit(int nr, uint8_t * addr)
|
|
|
|
{
|
|
|
|
uint8_t mask = BIT_MASK(nr);
|
|
|
|
uint8_t *p = ((uint8_t *) addr) + BIT_BYTE(nr);
|
|
|
|
*p |= mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __clear_bit(int nr, uint8_t * addr)
|
|
|
|
{
|
|
|
|
uint8_t mask = BIT_MASK(nr);
|
|
|
|
uint8_t *p = ((uint8_t *) addr) + BIT_BYTE(nr);
|
|
|
|
*p &= ~mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __test_bit(int nr, const volatile uint8_t * addr)
|
|
|
|
{
|
|
|
|
return 1 & (addr[BIT_BYTE(nr)] >> (nr & (BITS_PER_BYTE - 1)));
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_select
|
|
|
|
*
|
|
|
|
* Description:
|
2020-11-08 16:56:19 +01:00
|
|
|
* Select the SPI, locking and re-configuring if necessary
|
2013-12-23 23:03:54 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* spi - Reference to the SPI driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static void memlcd_select(FAR struct spi_dev_s *spi)
|
|
|
|
{
|
2016-08-08 16:40:37 +02:00
|
|
|
int ret;
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
/* Select memlcd (locking the SPI bus in case there are multiple
|
2013-12-23 23:03:54 +01:00
|
|
|
* devices competing for the SPI bus
|
|
|
|
*/
|
2016-01-24 01:54:36 +01:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
SPI_LOCK(spi, true);
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_DISPLAY(0), true);
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
/* Now make sure that the SPI bus is configured for the memlcd (it
|
2013-12-23 23:03:54 +01:00
|
|
|
* might have gotten configured for a different device while unlocked)
|
|
|
|
*/
|
2016-01-24 01:54:36 +01:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
SPI_SETMODE(spi, MEMLCD_SPI_MODE);
|
|
|
|
SPI_SETBITS(spi, MEMLCD_SPI_BITS);
|
2016-08-08 16:40:37 +02:00
|
|
|
|
|
|
|
ret = SPI_HWFEATURES(spi, HWFEAT_LSBFIRST);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
lcderr("ERROR: SPI_HWFEATURES failed to set bit order: %d\n", ret);
|
|
|
|
}
|
|
|
|
|
2016-08-08 16:28:13 +02:00
|
|
|
#ifdef CONFIG_MEMLCD_SPI_FREQUENCY
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SETFREQUENCY(spi, CONFIG_MEMLCD_SPI_FREQUENCY);
|
2016-08-08 16:28:13 +02:00
|
|
|
#else
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SETFREQUENCY(spi, MEMLCD_SPI_FREQUENCY);
|
2016-08-08 16:28:13 +02:00
|
|
|
#endif
|
2013-12-23 23:03:54 +01:00
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_deselect
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* De-select the SPI
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* spi - Reference to the SPI driver structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static void memlcd_deselect(FAR struct spi_dev_s *spi)
|
|
|
|
{
|
2016-01-24 01:54:36 +01:00
|
|
|
/* De-select memlcd and relinquish the spi bus. */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(spi, SPIDEV_DISPLAY(0), false);
|
2013-12-23 23:03:54 +01:00
|
|
|
SPI_LOCK(spi, false);
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_clear
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This method can be used to clear the entire display.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* mlcd - Reference to private driver structure
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static inline void memlcd_clear(FAR struct memlcd_dev_s *mlcd)
|
|
|
|
{
|
|
|
|
uint16_t cmd = MEMLCD_CMD_ALL_CLEAR;
|
2016-06-12 17:26:00 +02:00
|
|
|
|
|
|
|
lcdinfo("Clear display\n");
|
2013-12-23 23:03:54 +01:00
|
|
|
memlcd_select(mlcd->spi);
|
2020-11-08 16:56:19 +01:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
/* XXX Ensure 2us here */
|
2020-11-08 16:56:19 +01:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
SPI_SNDBLOCK(mlcd->spi, &cmd, 2);
|
2020-11-08 16:56:19 +01:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
/* XXX Ensure 6us here */
|
2020-11-08 16:56:19 +01:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
memlcd_deselect(mlcd->spi);
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_extcominisr
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This method enables/disables the polarity (VCOM) toggling behavior for
|
|
|
|
* the Memory LCD. Which is always used within setpower() call.
|
|
|
|
* Basically, the frequency shall be 1Hz~60Hz.
|
2020-11-08 16:56:19 +01:00
|
|
|
* If use hardware mode to toggle VCOM, we need to send specific command at
|
|
|
|
* a constant frequency to trigger the LCD internal hardware logic.
|
|
|
|
* While use software mode, we set up a timer to toggle EXTCOMIN connected
|
|
|
|
* IO, basically, it is a hardware timer to ensure a constant frequency.
|
2013-12-23 23:03:54 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* mlcd - Reference to private driver structure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Board specific logic needs to be provided to support it.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2017-03-01 15:52:58 +01:00
|
|
|
static int memlcd_extcominisr(int irq, FAR void *context, void *arg)
|
2013-12-23 23:03:54 +01:00
|
|
|
{
|
|
|
|
static bool pol = 0;
|
|
|
|
struct memlcd_dev_s *mlcd = &g_memlcddev;
|
|
|
|
#ifdef CONFIG_MEMLCD_EXTCOMIN_MODE_HW
|
|
|
|
# error "CONFIG_MEMLCD_EXTCOMIN_MODE_HW unsupported yet!"
|
2015-10-10 18:41:00 +02:00
|
|
|
/* Start a worker thread, do it in bottom half? */
|
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
#else
|
|
|
|
pol = !pol;
|
|
|
|
mlcd->priv->setpolarity(pol);
|
|
|
|
#endif
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_putrun
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This method can be used to write a partial raster line to the LCD.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* row - Starting row to write to (range: 0 <= row < yres)
|
|
|
|
* col - Starting column to write to (range: 0 <= col <= xres-npixels)
|
2020-02-22 19:31:14 +01:00
|
|
|
* buffer - The buffer containing the run to be written to the LCD
|
2013-12-23 23:03:54 +01:00
|
|
|
* npixels - The number of pixels to write to the LCD
|
|
|
|
* (range: 0 < npixels <= xres-col)
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static int memlcd_putrun(fb_coord_t row, fb_coord_t col,
|
|
|
|
FAR const uint8_t * buffer, size_t npixels)
|
|
|
|
{
|
|
|
|
FAR struct memlcd_dev_s *mlcd = (FAR struct memlcd_dev_s *)&g_memlcddev;
|
|
|
|
uint16_t cmd;
|
|
|
|
uint8_t *p;
|
|
|
|
uint8_t *pfb;
|
|
|
|
uint8_t usrmask;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DEBUGASSERT(buffer);
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("row: %d col: %d npixels: %d\n", row, col, npixels);
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2017-11-25 20:13:30 +01:00
|
|
|
#ifdef CONFIG_LCD_PACKEDMSFIRST
|
2013-12-23 23:03:54 +01:00
|
|
|
usrmask = MS_BIT;
|
|
|
|
#else
|
|
|
|
usrmask = LS_BIT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pfb = &mlcd->fb[row * MEMLCD_XSTRIDE];
|
|
|
|
p = pfb + (col >> 3);
|
|
|
|
for (i = 0; i < npixels; i++)
|
|
|
|
{
|
|
|
|
if ((*buffer & usrmask) != 0)
|
|
|
|
{
|
|
|
|
__set_bit(col % 8 + i, p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__clear_bit(col % 8 + i, p);
|
|
|
|
}
|
|
|
|
|
2017-11-25 20:13:30 +01:00
|
|
|
#ifdef CONFIG_LCD_PACKEDMSFIRST
|
2013-12-23 23:03:54 +01:00
|
|
|
if (usrmask == LS_BIT)
|
|
|
|
{
|
|
|
|
buffer++;
|
|
|
|
usrmask = MS_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usrmask >>= 1;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (usrmask == MS_BIT)
|
|
|
|
{
|
|
|
|
buffer++;
|
|
|
|
usrmask = LS_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usrmask <<= 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Need to adjust start row by one because Memory LCD starts counting
|
|
|
|
* lines from 1, while the display interface starts from 0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
row++;
|
|
|
|
|
|
|
|
memlcd_select(mlcd->spi);
|
|
|
|
|
|
|
|
/* XXX Ensure 6us here */
|
|
|
|
|
|
|
|
cmd = MEMLCD_CMD_UPDATE | row << 8;
|
|
|
|
SPI_SNDBLOCK(mlcd->spi, &cmd, 2);
|
|
|
|
SPI_SNDBLOCK(mlcd->spi, pfb, MEMLCD_YRES / 8 + MEMLCD_CONTROL_BYTES);
|
|
|
|
cmd = 0xffff;
|
|
|
|
SPI_SNDBLOCK(mlcd->spi, &cmd, 2);
|
|
|
|
|
|
|
|
/* XXX Ensure 2us here */
|
|
|
|
|
|
|
|
memlcd_deselect(mlcd->spi);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_getrun
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This method can be used to read a partial raster line from the LCD.
|
|
|
|
*
|
|
|
|
* row - Starting row to read from (range: 0 <= row < yres)
|
|
|
|
* col - Starting column to read read (range: 0 <= col <= xres-npixels)
|
|
|
|
* buffer - The buffer in which to return the run read from the LCD
|
|
|
|
* npixels - The number of pixels to read from the LCD
|
|
|
|
* (range: 0 < npixels <= xres-col)
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2020-11-08 16:56:19 +01:00
|
|
|
static int memlcd_getrun(fb_coord_t row, fb_coord_t col,
|
|
|
|
FAR uint8_t * buffer, size_t npixels)
|
2013-12-23 23:03:54 +01:00
|
|
|
{
|
|
|
|
FAR struct memlcd_dev_s *mlcd = (FAR struct memlcd_dev_s *)&g_memlcddev;
|
|
|
|
uint8_t *p;
|
|
|
|
uint8_t *pfb;
|
|
|
|
uint8_t usrmask;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DEBUGASSERT(buffer);
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("row: %d col: %d npixels: %d\n", row, col, npixels);
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2017-11-25 20:13:30 +01:00
|
|
|
#ifdef CONFIG_LCD_PACKEDMSFIRST
|
2013-12-23 23:03:54 +01:00
|
|
|
usrmask = MS_BIT;
|
|
|
|
#else
|
|
|
|
usrmask = LS_BIT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pfb = &mlcd->fb[row * MEMLCD_XSTRIDE];
|
|
|
|
p = pfb + (col >> 3);
|
|
|
|
for (i = 0; i < npixels; i++)
|
|
|
|
{
|
|
|
|
if (__test_bit(col % 8 + i, p))
|
|
|
|
{
|
|
|
|
*buffer |= usrmask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*buffer &= ~usrmask;
|
|
|
|
}
|
|
|
|
|
2017-11-25 20:13:30 +01:00
|
|
|
#ifdef CONFIG_LCD_PACKEDMSFIRST
|
2013-12-23 23:03:54 +01:00
|
|
|
if (usrmask == LS_BIT)
|
|
|
|
{
|
|
|
|
buffer++;
|
|
|
|
usrmask = MS_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usrmask >>= 1;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (usrmask == MS_BIT)
|
|
|
|
{
|
|
|
|
buffer++;
|
|
|
|
usrmask = LS_BIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usrmask <<= 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_getvideoinfo
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get information about the LCD video controller configuration.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2016-08-29 15:53:57 +02:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
static int memlcd_getvideoinfo(FAR struct lcd_dev_s *dev,
|
|
|
|
FAR struct fb_videoinfo_s *vinfo)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(dev && vinfo);
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("fmt: %d xres: %d yres: %d nplanes: %d\n",
|
2013-12-23 23:03:54 +01:00
|
|
|
g_videoinfo.fmt, g_videoinfo.xres, g_videoinfo.yres,
|
|
|
|
g_videoinfo.nplanes);
|
|
|
|
memcpy(vinfo, &g_videoinfo, sizeof(struct fb_videoinfo_s));
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_getplaneinfo
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get information about the configuration of each LCD color plane.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2020-11-08 16:56:19 +01:00
|
|
|
static int memlcd_getplaneinfo(FAR struct lcd_dev_s *dev,
|
|
|
|
unsigned int planeno,
|
2013-12-23 23:03:54 +01:00
|
|
|
FAR struct lcd_planeinfo_s *pinfo)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(pinfo && planeno == 0);
|
2016-06-11 19:59:51 +02:00
|
|
|
lcdinfo("planeno: %d bpp: %d\n", planeno, g_planeinfo.bpp);
|
2013-12-23 23:03:54 +01:00
|
|
|
memcpy(pinfo, &g_planeinfo, sizeof(struct lcd_planeinfo_s));
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_getpower
|
|
|
|
*
|
|
|
|
* Description:
|
2020-11-08 16:56:19 +01:00
|
|
|
* Get the LCD panel power status (0: full off - CONFIG_LCD_MAXPOWER: full
|
|
|
|
* on. On backlit LCDs, this setting may correspond to the backlight
|
|
|
|
* setting.
|
2013-12-23 23:03:54 +01:00
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static int memlcd_getpower(FAR struct lcd_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct memlcd_dev_s *mlcd = (FAR struct memlcd_dev_s *)dev;
|
2016-06-12 17:26:00 +02:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
DEBUGASSERT(mlcd);
|
2016-06-12 17:26:00 +02:00
|
|
|
lcdinfo("%d\n", mlcd->power);
|
2013-12-23 23:03:54 +01:00
|
|
|
return mlcd->power;
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_setpower
|
|
|
|
*
|
|
|
|
* Description:
|
2020-11-08 16:56:19 +01:00
|
|
|
* Enable/disable LCD panel power (0: full off - CONFIG_LCD_MAXPOWER: full
|
|
|
|
* on). On backlit LCDs, this setting may correspond to the backlight
|
|
|
|
* setting.
|
2013-12-23 23:03:54 +01:00
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static int memlcd_setpower(FAR struct lcd_dev_s *dev, int power)
|
|
|
|
{
|
|
|
|
struct memlcd_dev_s *mlcd = (struct memlcd_dev_s *)dev;
|
2016-06-12 17:26:00 +02:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
DEBUGASSERT(mlcd && (unsigned)power <= CONFIG_LCD_MAXPOWER && mlcd->spi);
|
2016-06-12 17:26:00 +02:00
|
|
|
lcdinfo("%d\n", power);
|
2013-12-23 23:03:54 +01:00
|
|
|
mlcd->power = power;
|
|
|
|
|
|
|
|
if (power > 0)
|
|
|
|
{
|
|
|
|
mlcd->priv->dispcontrol(1);
|
|
|
|
memlcd_clear(mlcd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mlcd->priv->dispcontrol(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_getcontrast
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the current contrast setting (0-CONFIG_LCD_MAXCONTRAST).
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static int memlcd_getcontrast(struct lcd_dev_s *dev)
|
|
|
|
{
|
|
|
|
struct memlcd_dev_s *mlcd = (struct memlcd_dev_s *)dev;
|
2016-06-12 17:26:00 +02:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
DEBUGASSERT(mlcd);
|
2016-06-12 17:26:00 +02:00
|
|
|
lcdinfo("contrast: %d\n", mlcd->contrast);
|
2013-12-23 23:03:54 +01:00
|
|
|
return mlcd->contrast;
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_setcontrast
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set LCD panel contrast (0-CONFIG_LCD_MAXCONTRAST).
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
|
|
|
static int memlcd_setcontrast(struct lcd_dev_s *dev, unsigned int contrast)
|
|
|
|
{
|
|
|
|
struct memlcd_dev_s *mlcd = (struct memlcd_dev_s *)dev;
|
2016-06-12 17:26:00 +02:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
DEBUGASSERT(mlcd);
|
2016-06-12 17:26:00 +02:00
|
|
|
lcdinfo("contrast: %d\n", contrast);
|
2013-12-23 23:03:54 +01:00
|
|
|
if (contrast > MEMLCD_MAXCONTRAST)
|
|
|
|
{
|
|
|
|
contrast = MEMLCD_MAXCONTRAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contrast < MEMLCD_MINCONTRAST)
|
|
|
|
{
|
|
|
|
contrast = MEMLCD_MINCONTRAST;
|
|
|
|
}
|
|
|
|
|
|
|
|
mlcd->contrast = contrast;
|
|
|
|
mlcd->priv->setvcomfreq(contrast);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Public Functions
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2015-10-03 15:25:53 +02:00
|
|
|
/****************************************************************************
|
2013-12-23 23:03:54 +01:00
|
|
|
* Name: memlcd_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initialize the Sharp Memory LCD hardware. The initial state of the
|
|
|
|
* OLED is fully initialized, display memory cleared, and the OLED ready
|
|
|
|
* to use, but with the power setting at 0 (full off == sleep mode).
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* spi - A reference to the SPI driver instance.
|
2020-11-08 16:56:19 +01:00
|
|
|
* priv - Board specific structure
|
|
|
|
* devno - A value in the range of 0 through CONFIG_MEMLCD_NINTERFACES-1.
|
2013-12-23 23:03:54 +01:00
|
|
|
* This allows support for multiple OLED devices.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
* On success, this function returns a reference to the LCD object for
|
|
|
|
* the specified LCD. NULL is returned on any failure.
|
|
|
|
*
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2016-08-29 15:53:57 +02:00
|
|
|
|
2013-12-23 23:03:54 +01:00
|
|
|
FAR struct lcd_dev_s *memlcd_initialize(FAR struct spi_dev_s *spi,
|
|
|
|
FAR struct memlcd_priv_s *priv,
|
|
|
|
unsigned int devno)
|
|
|
|
{
|
|
|
|
FAR struct memlcd_dev_s *mlcd = &g_memlcddev;
|
|
|
|
|
|
|
|
DEBUGASSERT(spi && priv && devno == 0);
|
|
|
|
|
2016-01-24 01:54:36 +01:00
|
|
|
/* Register board specific functions */
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2016-01-24 01:54:36 +01:00
|
|
|
mlcd->priv = priv;
|
2013-12-23 23:03:54 +01:00
|
|
|
mlcd->spi = spi;
|
|
|
|
|
2017-03-01 15:52:58 +01:00
|
|
|
mlcd->priv->attachirq(memlcd_extcominisr, mlcd);
|
2013-12-23 23:03:54 +01:00
|
|
|
|
2016-06-12 17:26:00 +02:00
|
|
|
lcdinfo("done\n");
|
2013-12-23 23:03:54 +01:00
|
|
|
return &mlcd->dev;
|
|
|
|
}
|