2011-04-17 16:16:28 +00:00
|
|
|
/****************************************************************************
|
2015-03-21 10:29:46 -06:00
|
|
|
* config/lpcxpresso-lpc1768/src/lpc17_oled.c
|
2011-04-17 16:16:28 +00:00
|
|
|
*
|
2015-03-31 16:20:21 -06:00
|
|
|
* Copyright (C) 2011, 2013, 2015 Gregory Nutt. All rights reserved.
|
2012-09-13 18:32:24 +00:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-04-17 16:16:28 +00:00
|
|
|
*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2015-03-31 16:20:21 -06:00
|
|
|
#include <nuttx/board.h>
|
2013-07-01 08:11:54 -06:00
|
|
|
#include <nuttx/spi/spi.h>
|
2011-04-17 16:16:28 +00:00
|
|
|
#include <nuttx/lcd/lcd.h>
|
2011-04-18 17:16:24 +00:00
|
|
|
#include <nuttx/lcd/ug-9664hswag01.h>
|
2011-04-17 16:16:28 +00:00
|
|
|
|
2013-01-18 19:16:44 +00:00
|
|
|
#include "lpc17_gpio.h"
|
|
|
|
#include "lpc17_ssp.h"
|
2015-12-29 15:44:56 -06:00
|
|
|
#include "lpcxpresso-lpc1768.h"
|
2011-04-17 16:16:28 +00:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-03-21 10:29:46 -06:00
|
|
|
* Pre-processor Definitions
|
2011-04-17 16:16:28 +00:00
|
|
|
****************************************************************************/
|
|
|
|
/* Configuration ************************************************************/
|
|
|
|
/* This module is only built if CONFIG_NX_LCDDRIVER is selected. In this
|
|
|
|
* case, it would be an error if SSP1 is not also enabled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_LPC17_SSP1
|
2011-04-18 17:16:24 +00:00
|
|
|
# error "The OLED driver requires CONFIG_LPC17_SSP1 in the configuration"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_UG9664HSWAG01_POWER
|
|
|
|
# error "This logic requires CONFIG_UG9664HSWAG01_POWER in the configuration"
|
2011-04-17 16:16:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Debug ********************************************************************/
|
|
|
|
|
2012-11-08 01:28:32 +00:00
|
|
|
#ifdef CONFIG_DEBUG_LCD
|
2014-05-22 09:01:51 -06:00
|
|
|
# define oleddc_dumpgpio(m) lpc17_dumpgpio(LPCXPRESSO_OLED_POWER, m)
|
|
|
|
# define oledcs_dumpgpio(m) lpc17_dumpgpio(LPCXPRESSO_OLED_CS, m)
|
2011-04-17 16:16:28 +00:00
|
|
|
#else
|
|
|
|
# define oleddc_dumpgpio(m)
|
|
|
|
# define oledcs_dumpgpio(m)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-03-31 16:20:21 -06:00
|
|
|
* Name: board_graphics_setup
|
2011-04-17 16:16:28 +00:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called by NX initialization logic to configure the OLED.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-03-31 16:20:21 -06:00
|
|
|
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno)
|
2011-04-17 16:16:28 +00:00
|
|
|
{
|
|
|
|
FAR struct spi_dev_s *spi;
|
|
|
|
FAR struct lcd_dev_s *dev;
|
|
|
|
|
|
|
|
/* Configure the OLED GPIOs. For the SPI interface, insert jumpers in J42,
|
|
|
|
* J43, J45 pin1-2 and J46 pin 1-2.
|
|
|
|
*/
|
2014-04-13 16:22:22 -06:00
|
|
|
|
2015-03-31 16:20:21 -06:00
|
|
|
oledcs_dumpgpio("board_graphics_setup: After OLED CS setup");
|
|
|
|
oleddc_dumpgpio("board_graphics_setup: On entry");
|
2011-04-17 16:16:28 +00:00
|
|
|
|
|
|
|
(void)lpc17_configgpio(LPCXPRESSO_OLED_POWER); /* OLED 11V power */
|
|
|
|
(void)lpc17_configgpio(LPCXPRESSO_OLED_DC); /* OLED Command/Data */
|
|
|
|
|
2015-03-31 16:20:21 -06:00
|
|
|
oleddc_dumpgpio("board_graphics_setup: After OLED Power/DC setup");
|
2011-04-17 16:16:28 +00:00
|
|
|
|
2013-04-01 15:02:22 +00:00
|
|
|
/* Get the SPI1 port (configure as a Freescale SPI port) */
|
2011-04-17 16:16:28 +00:00
|
|
|
|
2016-02-04 10:24:32 -06:00
|
|
|
spi = lpc17_sspbus_initialize(1);
|
2011-04-17 16:16:28 +00:00
|
|
|
if (!spi)
|
|
|
|
{
|
2016-06-20 12:44:38 -06:00
|
|
|
gerr("ERROR: Failed to initialize SPI port 1\n");
|
2011-04-17 16:16:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-01 15:02:22 +00:00
|
|
|
/* Bind the SPI port to the OLED */
|
2011-04-17 16:16:28 +00:00
|
|
|
|
2011-04-18 17:16:24 +00:00
|
|
|
dev = ug_initialize(spi, devno);
|
2011-04-17 16:16:28 +00:00
|
|
|
if (!dev)
|
|
|
|
{
|
2016-06-20 12:44:38 -06:00
|
|
|
gerr("ERROR: Failed to bind SPI port 1 to OLED %d: %d\n", devno);
|
2011-04-17 16:16:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-20 11:59:15 -06:00
|
|
|
ginfo("Bound SPI port 1 to OLED %d\n", devno);
|
2011-04-17 16:16:28 +00:00
|
|
|
|
2011-04-18 17:16:24 +00:00
|
|
|
/* And turn the OLED on (dim) */
|
2011-04-17 16:16:28 +00:00
|
|
|
|
2011-04-18 17:16:24 +00:00
|
|
|
(void)dev->setpower(dev, UG_POWER_DIM);
|
2011-04-17 16:16:28 +00:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-18 20:13:54 +00:00
|
|
|
/****************************************************************************
|
2011-04-18 17:16:24 +00:00
|
|
|
* Name: lpc17_ssp1cmddata
|
2011-04-17 16:16:28 +00:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set or clear the SD1329 D/Cn bit to select data (true) or command
|
|
|
|
* (false). This function must be provided by platform-specific logic.
|
|
|
|
* This is an implementation of the cmddata method of the SPI
|
2013-07-01 08:11:54 -06:00
|
|
|
* interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h).
|
2011-04-17 16:16:28 +00:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* spi - SPI device that controls the bus the device that requires the CMD/
|
|
|
|
* DATA selection.
|
|
|
|
* devid - If there are multiple devices on the bus, this selects which one
|
|
|
|
* to select cmd or data. NOTE: This design restricts, for example,
|
|
|
|
* one one SPI display per SPI bus.
|
|
|
|
* cmd - true: select command; false: select data
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
2011-04-18 20:13:54 +00:00
|
|
|
****************************************************************************/
|
2011-04-17 16:16:28 +00:00
|
|
|
|
2017-04-28 18:29:43 +02:00
|
|
|
int lpc17_ssp1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
|
2011-04-17 16:16:28 +00:00
|
|
|
{
|
|
|
|
if (devid == SPIDEV_DISPLAY)
|
|
|
|
{
|
|
|
|
/* Set GPIO to 1 for data, 0 for command */
|
|
|
|
|
2011-04-17 23:48:01 +00:00
|
|
|
(void)lpc17_gpiowrite(LPCXPRESSO_OLED_DC, !cmd);
|
2011-04-17 16:16:28 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2011-04-18 17:16:24 +00:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ug_power
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* If the hardware supports a controllable OLED a power supply, this
|
|
|
|
* interface should be provided. It may be called by the driver to turn
|
|
|
|
* the OLED power on and off as needed.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* devno - A value in the range of 0 throuh CONFIG_UG9664HSWAG01_NINTERFACES-1.
|
|
|
|
* This allows support for multiple OLED devices.
|
|
|
|
* on - true:turn power on, false: turn power off.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
2011-04-18 20:13:54 +00:00
|
|
|
****************************************************************************/
|
2011-04-18 17:16:24 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_UG9664HSWAG01_POWER
|
|
|
|
void ug_power(unsigned int devno, bool on)
|
|
|
|
{
|
2016-06-20 11:59:15 -06:00
|
|
|
ginfo("power %s\n", on ? "ON" : "OFF");
|
2011-04-18 17:16:24 +00:00
|
|
|
(void)lpc17_gpiowrite(LPCXPRESSO_OLED_POWER, on);
|
|
|
|
}
|
|
|
|
#endif
|