2011-09-23 20:45:28 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* examples/lcdrw/lcdrw_main.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
2012-09-13 16:14:18 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-09-23 20:45:28 +02: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 <stdlib.h>
|
|
|
|
|
2015-04-04 19:49:15 +02:00
|
|
|
#include <nuttx/board.h>
|
2011-09-23 20:45:28 +02:00
|
|
|
#include <nuttx/lcd/lcd.h>
|
|
|
|
#include <nuttx/nx/nxglib.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
/* Configuration ************************************************************/
|
|
|
|
/* Most of the NX configuration settings are probbably *not* needed by this
|
|
|
|
* example. But, presumeably you are using NX too and so the checks might
|
|
|
|
* be good for you.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NX
|
|
|
|
# error "CONFIG_NX must be defined to use this test"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NX_LCDDRIVER
|
|
|
|
# error "CONFIG_NX_LCDDRIVER must be defined to use this test"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_LCDRW_BPP
|
|
|
|
# define CONFIG_EXAMPLES_LCDRW_BPP 16
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_EXAMPLES_LCDRW_BPP != 16
|
|
|
|
# error "Currently only RGB565 is supported -- feel free to extend"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NX_DISABLE_16BPP
|
|
|
|
# error "CONFIG_NX_DISABLE_16BPP disables 16-bit support"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_LDCRW_DEVNO
|
|
|
|
# define CONFIG_EXAMPLES_LDCRW_DEVNO 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_LDCRW_XRES
|
|
|
|
# define CONFIG_EXAMPLES_LDCRW_XRES 240
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_LDCRW_YRES
|
|
|
|
# define CONFIG_EXAMPLES_LDCRW_YRES 320
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct lcdrw_instance_s
|
|
|
|
{
|
|
|
|
/* LCD device handle and planeinfo */
|
|
|
|
|
|
|
|
FAR struct lcd_dev_s *dev;
|
|
|
|
struct lcd_planeinfo_s pinfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: lcdrw_initialize
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline int lcdrw_initialize(FAR struct lcdrw_instance_s *inst)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Initialize the LCD device */
|
|
|
|
|
|
|
|
printf("screens_initialize: Initializing LCD\n");
|
2015-04-04 19:49:15 +02:00
|
|
|
ret = board_lcd_initialize();
|
2011-09-23 20:45:28 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2015-04-04 19:49:15 +02:00
|
|
|
fprintf(stderr, "screens_initialize: board_lcd_initialize failed: %d\n", -ret);
|
2011-09-23 20:45:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the device instance. */
|
|
|
|
|
|
|
|
printf("Get LCD instance\n");
|
2015-04-04 19:49:15 +02:00
|
|
|
inst->dev = board_lcd_getdev(CONFIG_EXAMPLES_LDCRW_DEVNO);
|
2011-09-23 20:45:28 +02:00
|
|
|
if (!inst->dev)
|
|
|
|
{
|
2015-04-04 19:49:15 +02:00
|
|
|
fprintf(stderr, "board_lcd_getdev failed, devno=%d\n",
|
|
|
|
CONFIG_EXAMPLES_LDCRW_DEVNO);
|
2011-09-23 20:45:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Turn the LCD on at 75% power. This should not be necessary. */
|
|
|
|
|
|
|
|
(void)inst->dev->setpower(inst->dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
|
|
|
|
|
|
|
|
/* Get the planeinfo structure */
|
|
|
|
|
|
|
|
ret = inst->dev->getplaneinfo(inst->dev, 0, &inst->pinfo);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "getplaneinfo failed: %d\n", ret);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-08-30 22:13:50 +02:00
|
|
|
* Name: lcdrw_main
|
2011-09-23 20:45:28 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-06 17:19:15 +02:00
|
|
|
#ifdef CONFIG_BUILD_KERNEL
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2014-09-06 17:19:15 +02:00
|
|
|
#else
|
2012-08-30 22:13:50 +02:00
|
|
|
int lcdrw_main(int argc, char *argv[])
|
2014-09-06 17:19:15 +02:00
|
|
|
#endif
|
2011-09-23 20:45:28 +02:00
|
|
|
{
|
|
|
|
struct lcdrw_instance_s inst;
|
|
|
|
nxgl_coord_t row;
|
|
|
|
nxgl_coord_t col;
|
|
|
|
uint16_t value;
|
|
|
|
uint32_t offset;
|
|
|
|
FAR uint16_t *ptr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Initialize the LCD driver */
|
|
|
|
|
|
|
|
ret = lcdrw_initialize(&inst);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-05-07 03:40:39 +02:00
|
|
|
/* Loop, writing all possible values to the LCD */
|
2011-09-23 20:45:28 +02:00
|
|
|
|
|
|
|
value = 0;
|
|
|
|
for (row = 0; row < CONFIG_EXAMPLES_LDCRW_YRES; row++)
|
|
|
|
{
|
|
|
|
/* Create a dummy row. The important thing is to try all
|
|
|
|
* bit combinations in a predictable way.
|
|
|
|
*/
|
2014-04-14 00:24:28 +02:00
|
|
|
|
2011-09-23 20:45:28 +02:00
|
|
|
ptr = (FAR uint16_t*)inst.pinfo.buffer;
|
|
|
|
for (col = 0; col < CONFIG_EXAMPLES_LDCRW_XRES; col++)
|
|
|
|
{
|
|
|
|
*ptr++ = value++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the row to the LCD */
|
|
|
|
|
|
|
|
ret = inst.pinfo.putrun(row, 0, inst.pinfo.buffer,
|
|
|
|
CONFIG_EXAMPLES_LDCRW_XRES);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "putrun failed: %d\n", ret);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print a header */
|
|
|
|
|
|
|
|
printf(" ");
|
|
|
|
for (col = 0; col < 15; col++)
|
|
|
|
{
|
|
|
|
printf("---%x ", col);
|
|
|
|
}
|
|
|
|
printf("---f\n");
|
|
|
|
|
2012-05-07 03:40:39 +02:00
|
|
|
/* Then read each line back from the LCD. */
|
2011-09-23 20:45:28 +02:00
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
for (row = 0; row < CONFIG_EXAMPLES_LDCRW_YRES; row++)
|
|
|
|
{
|
|
|
|
/* Read the row */
|
2014-04-14 00:24:28 +02:00
|
|
|
|
2011-09-23 20:45:28 +02:00
|
|
|
ret = inst.pinfo.getrun(row, 0, inst.pinfo.buffer,
|
|
|
|
CONFIG_EXAMPLES_LDCRW_XRES);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "getrun failed: %d\n", ret);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then dump the row to the display */
|
|
|
|
|
|
|
|
ptr = (FAR uint16_t*)inst.pinfo.buffer;
|
|
|
|
for (col = 0; col < CONFIG_EXAMPLES_LDCRW_XRES; col++)
|
|
|
|
{
|
|
|
|
if ((offset & 15) == 0)
|
|
|
|
{
|
|
|
|
printf("%06x ", offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
value = *ptr++;
|
|
|
|
offset++;
|
|
|
|
|
|
|
|
if ((offset & 15) == 0)
|
|
|
|
{
|
|
|
|
printf("%04x\n", value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("%04x ", value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|