2008-03-12 20:35:42 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "lcd.h"
|
|
|
|
#include "scroll_engine.h"
|
|
|
|
|
|
|
|
/* The LCD in the iAudio M3/M5/X5 remote control is a Tomato LSI 0350 */
|
|
|
|
|
|
|
|
#define LCD_SET_DUTY_RATIO 0x48
|
|
|
|
#define LCD_SELECT_ADC 0xa0
|
|
|
|
#define LCD_SELECT_SHL 0xc0
|
|
|
|
#define LCD_SET_COM0 0x44
|
|
|
|
#define LCD_OSC_ON 0xab
|
|
|
|
#define LCD_SELECT_DCDC 0x64
|
|
|
|
#define LCD_SELECT_RES 0x20
|
|
|
|
#define LCD_SET_VOLUME 0x81
|
|
|
|
#define LCD_SET_BIAS 0x50
|
|
|
|
#define LCD_CONTROL_POWER 0x28
|
|
|
|
#define LCD_DISPLAY_ON 0xae
|
|
|
|
#define LCD_SET_INITLINE 0x40
|
|
|
|
#define LCD_SET_COLUMN 0x10
|
|
|
|
#define LCD_SET_PAGE 0xb0
|
|
|
|
#define LCD_SET_GRAY 0x88
|
|
|
|
#define LCD_SET_PWM_FRC 0x90
|
|
|
|
#define LCD_SET_POWER_SAVE 0xa8
|
|
|
|
#define LCD_REVERSE 0xa6
|
|
|
|
|
|
|
|
#define CS_LO and_l(~0x00010000, &GPIO1_OUT)
|
|
|
|
#define CS_HI or_l( 0x00010000, &GPIO1_OUT)
|
|
|
|
#define CLK_LO and_l(~0x20000000, &GPIO_OUT)
|
|
|
|
#define CLK_HI or_l( 0x20000000, &GPIO_OUT)
|
|
|
|
#define DATA_LO and_l(~0x04000000, &GPIO_OUT)
|
|
|
|
#define DATA_HI or_l( 0x04000000, &GPIO_OUT)
|
|
|
|
#define RS_LO and_l(~0x00001000, &GPIO1_OUT)
|
|
|
|
#define RS_HI or_l( 0x00001000, &GPIO1_OUT)
|
|
|
|
|
|
|
|
/* cached settings values */
|
|
|
|
static bool cached_invert = false;
|
|
|
|
static bool cached_flip = false;
|
|
|
|
static int cached_contrast = DEFAULT_CONTRAST_SETTING;
|
|
|
|
|
|
|
|
bool initialized = false;
|
|
|
|
|
|
|
|
|
|
|
|
int lcd_default_contrast(void)
|
|
|
|
{
|
|
|
|
return DEFAULT_CONTRAST_SETTING;
|
|
|
|
}
|
|
|
|
|
2008-03-12 23:08:33 +00:00
|
|
|
void lcd_set_contrast(int val)
|
2008-03-12 20:35:42 +00:00
|
|
|
{
|
|
|
|
if (val < 0)
|
|
|
|
val = 0;
|
|
|
|
else if (val > 63)
|
|
|
|
val = 63;
|
|
|
|
|
|
|
|
cached_contrast = val;
|
|
|
|
if (initialized)
|
|
|
|
lcd_write_command_e(LCD_SET_VOLUME, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool remote_detect(void)
|
|
|
|
{
|
|
|
|
return (GPIO_READ & 0x40000000) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_on(void)
|
|
|
|
{
|
|
|
|
CS_HI;
|
|
|
|
CLK_HI;
|
2008-03-12 23:08:33 +00:00
|
|
|
sleep(HZ/100);
|
2008-03-12 20:35:42 +00:00
|
|
|
|
|
|
|
lcd_write_command(LCD_SET_DUTY_RATIO);
|
|
|
|
lcd_write_command(0x70); /* 1/128 */
|
|
|
|
|
|
|
|
lcd_write_command(LCD_OSC_ON);
|
|
|
|
|
|
|
|
lcd_write_command(LCD_SELECT_DCDC | 2); /* DC/DC 5xboost */
|
|
|
|
|
|
|
|
lcd_write_command(LCD_SELECT_RES | 7); /* Regulator resistor: 7.2 */
|
|
|
|
|
|
|
|
lcd_write_command(LCD_SET_BIAS | 6); /* 1/11 */
|
|
|
|
|
|
|
|
lcd_write_command(LCD_CONTROL_POWER | 7); /* All circuits ON */
|
|
|
|
|
2008-03-12 23:08:33 +00:00
|
|
|
sleep(3*HZ/100);
|
2008-03-12 20:35:42 +00:00
|
|
|
|
|
|
|
lcd_write_command_e(LCD_SET_GRAY | 0, 0x00);
|
|
|
|
lcd_write_command_e(LCD_SET_GRAY | 1, 0x00);
|
|
|
|
lcd_write_command_e(LCD_SET_GRAY | 2, 0x0c);
|
|
|
|
lcd_write_command_e(LCD_SET_GRAY | 3, 0x00);
|
|
|
|
lcd_write_command_e(LCD_SET_GRAY | 4, 0xcc);
|
|
|
|
lcd_write_command_e(LCD_SET_GRAY | 5, 0x00);
|
|
|
|
lcd_write_command_e(LCD_SET_GRAY | 6, 0xcc);
|
|
|
|
lcd_write_command_e(LCD_SET_GRAY | 7, 0x0c);
|
|
|
|
|
2008-03-24 00:35:53 +00:00
|
|
|
lcd_write_command(LCD_SET_PWM_FRC | 6); /* 3FRC + 12PWM */
|
2008-03-12 20:35:42 +00:00
|
|
|
|
|
|
|
lcd_write_command(LCD_DISPLAY_ON | 1); /* display on */
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
|
|
|
|
lcd_set_flip(cached_flip);
|
|
|
|
lcd_set_contrast(cached_contrast);
|
|
|
|
lcd_set_invert_display(cached_invert);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_off(void)
|
|
|
|
{
|
|
|
|
initialized = false;
|
|
|
|
CS_HI;
|
|
|
|
RS_HI;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_poweroff(void)
|
|
|
|
{
|
|
|
|
/* Set power save -> Power OFF (VDD - VSS) .. that's it */
|
2008-03-13 19:36:58 +00:00
|
|
|
if (initialized)
|
2008-03-12 20:35:42 +00:00
|
|
|
lcd_write_command(LCD_SET_POWER_SAVE | 1);
|
|
|
|
}
|
|
|
|
|
2008-03-12 23:08:33 +00:00
|
|
|
#ifndef BOOTLOADER
|
2008-03-12 20:35:42 +00:00
|
|
|
/* Monitor remote hotswap */
|
|
|
|
static void lcd_tick(void)
|
|
|
|
{
|
|
|
|
static bool last_status = false;
|
|
|
|
static int countdown = 0;
|
|
|
|
bool current_status;
|
|
|
|
|
|
|
|
current_status = remote_detect();
|
|
|
|
|
|
|
|
/* Only report when the status has changed */
|
|
|
|
if (current_status != last_status)
|
|
|
|
{
|
|
|
|
last_status = current_status;
|
|
|
|
countdown = current_status ? 20*HZ : 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Count down until it gets negative */
|
|
|
|
if (countdown >= 0)
|
|
|
|
countdown--;
|
|
|
|
|
|
|
|
if (current_status)
|
|
|
|
{
|
|
|
|
if (!(countdown % 48))
|
|
|
|
{
|
|
|
|
queue_broadcast(SYS_REMOTE_PLUGGED, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (countdown == 0)
|
|
|
|
{
|
|
|
|
queue_broadcast(SYS_REMOTE_UNPLUGGED, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-12 23:08:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void lcd_init_device(void)
|
|
|
|
{
|
|
|
|
or_l(0x24000000, &GPIO_OUT);
|
|
|
|
or_l(0x24000000, &GPIO_ENABLE);
|
|
|
|
or_l(0x24000000, &GPIO_FUNCTION);
|
|
|
|
|
|
|
|
or_l(0x00011000, &GPIO1_OUT);
|
|
|
|
or_l(0x00011000, &GPIO1_ENABLE);
|
|
|
|
or_l(0x00011000, &GPIO1_FUNCTION);
|
|
|
|
|
|
|
|
and_l(~0x40000000, &GPIO_OUT);
|
|
|
|
and_l(~0x40000000, &GPIO_ENABLE);
|
|
|
|
or_l(0x40000000, &GPIO_FUNCTION);
|
|
|
|
|
|
|
|
lcd_clear_display();
|
2008-03-13 19:36:58 +00:00
|
|
|
if (remote_detect())
|
|
|
|
lcd_on();
|
|
|
|
#ifndef BOOTLOADER
|
2008-03-12 23:08:33 +00:00
|
|
|
tick_add_task(lcd_tick);
|
|
|
|
#endif
|
|
|
|
}
|
2008-03-12 20:35:42 +00:00
|
|
|
|
2008-03-25 23:21:36 +00:00
|
|
|
/* Helper function. */
|
|
|
|
void lcd_mono_data(const unsigned char *data, int count);
|
|
|
|
|
2008-03-14 08:54:54 +00:00
|
|
|
/* Performance function that works with an external buffer
|
|
|
|
note that by and bheight are in 8-pixel units! */
|
2008-03-24 00:35:53 +00:00
|
|
|
void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
|
|
|
|
int bheight, int stride)
|
2008-03-14 08:54:54 +00:00
|
|
|
{
|
2008-03-24 00:35:53 +00:00
|
|
|
if (initialized)
|
|
|
|
{
|
|
|
|
/* COM48-COM63 are not connected, so we need to skip those */
|
|
|
|
while (bheight--)
|
|
|
|
{
|
|
|
|
lcd_write_command(LCD_SET_PAGE | ((by > 5 ? by + 2 : by) & 0xf));
|
|
|
|
lcd_write_command_e(LCD_SET_COLUMN | ((x >> 4) & 0xf), x & 0xf);
|
|
|
|
|
|
|
|
lcd_mono_data(data, width);
|
|
|
|
data += stride;
|
|
|
|
by++;
|
|
|
|
}
|
|
|
|
}
|
2008-03-14 08:54:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 23:21:36 +00:00
|
|
|
/* Helper function for lcd_grey_phase_blit(). */
|
|
|
|
void lcd_grey_data(unsigned char *values, unsigned char *phases, int count);
|
2008-03-24 00:35:53 +00:00
|
|
|
|
2008-03-14 08:54:54 +00:00
|
|
|
/* Performance function that works with an external buffer
|
|
|
|
note that by and bheight are in 8-pixel units! */
|
2008-03-24 00:35:53 +00:00
|
|
|
void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
|
2008-03-14 08:54:54 +00:00
|
|
|
int x, int by, int width, int bheight, int stride)
|
|
|
|
{
|
2008-03-25 23:21:36 +00:00
|
|
|
if (initialized)
|
|
|
|
{
|
|
|
|
stride <<= 3; /* 8 pixels per block */
|
|
|
|
while (bheight--)
|
|
|
|
{
|
|
|
|
lcd_write_command(LCD_SET_PAGE | ((by > 5 ? by + 2 : by) & 0xf));
|
|
|
|
lcd_write_command_e(LCD_SET_COLUMN | ((x >> 4) & 0xf), x & 0xf);
|
|
|
|
|
|
|
|
lcd_grey_data(values, phases, width);
|
|
|
|
values += stride;
|
|
|
|
phases += stride;
|
|
|
|
by++;
|
|
|
|
}
|
|
|
|
}
|
2008-03-14 08:54:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-12 20:35:42 +00:00
|
|
|
/* Update the display.
|
|
|
|
This must be called after all other LCD functions that change the display. */
|
|
|
|
void lcd_update(void)
|
|
|
|
{
|
|
|
|
int y;
|
2008-03-24 00:35:53 +00:00
|
|
|
if (initialized)
|
|
|
|
{
|
2008-03-25 23:21:36 +00:00
|
|
|
for(y = 0;y < LCD_FBHEIGHT;y++)
|
|
|
|
{
|
2008-03-12 20:35:42 +00:00
|
|
|
/* Copy display bitmap to hardware.
|
|
|
|
The COM48-COM63 lines are not connected so we have to skip
|
|
|
|
them. Further, the column address doesn't wrap, so we
|
|
|
|
have to update one page at a time. */
|
2008-03-25 23:21:36 +00:00
|
|
|
lcd_write_command(LCD_SET_PAGE | (y > 5 ? y + 2 : y));
|
2008-03-12 20:35:42 +00:00
|
|
|
lcd_write_command_e(LCD_SET_COLUMN | 0, 0);
|
|
|
|
lcd_write_data(lcd_framebuffer[y], LCD_WIDTH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update a fraction of the display. */
|
|
|
|
void lcd_update_rect(int x, int y, int width, int height)
|
|
|
|
{
|
2008-03-24 00:35:53 +00:00
|
|
|
if (initialized)
|
|
|
|
{
|
2008-03-12 20:35:42 +00:00
|
|
|
int ymax;
|
|
|
|
|
|
|
|
/* The Y coordinates have to work on even 8 pixel rows */
|
|
|
|
ymax = (y + height-1) >> 3;
|
|
|
|
y >>= 3;
|
|
|
|
|
|
|
|
if(x + width > LCD_WIDTH)
|
|
|
|
width = LCD_WIDTH - x;
|
|
|
|
if (width <= 0)
|
|
|
|
return; /* nothing left to do, 0 is harmful to lcd_write_data() */
|
|
|
|
if(ymax >= LCD_FBHEIGHT)
|
|
|
|
ymax = LCD_FBHEIGHT-1;
|
|
|
|
|
|
|
|
/* Copy specified rectangle bitmap to hardware
|
|
|
|
COM48-COM63 are not connected, so we need to skip those */
|
|
|
|
for (; y <= ymax; y++)
|
|
|
|
{
|
2008-03-25 23:21:36 +00:00
|
|
|
lcd_write_command(LCD_SET_PAGE | ((y > 5 ? y + 2 : y) & 0xf));
|
2008-03-12 20:35:42 +00:00
|
|
|
lcd_write_command_e(LCD_SET_COLUMN | ((x >> 4) & 0xf), x & 0xf);
|
|
|
|
|
|
|
|
lcd_write_data(&lcd_framebuffer[y][x], width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_set_invert_display(bool yesno)
|
|
|
|
{
|
|
|
|
cached_invert = yesno;
|
2008-03-25 23:21:36 +00:00
|
|
|
if (initialized)
|
2008-03-12 20:35:42 +00:00
|
|
|
lcd_write_command(LCD_REVERSE | yesno);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_set_flip(bool yesno)
|
|
|
|
{
|
|
|
|
cached_flip = yesno;
|
2008-03-25 23:21:36 +00:00
|
|
|
if (initialized)
|
|
|
|
{
|
|
|
|
if(yesno)
|
|
|
|
{
|
2008-03-12 20:35:42 +00:00
|
|
|
lcd_write_command(LCD_SELECT_ADC | 0);
|
|
|
|
lcd_write_command(LCD_SELECT_SHL | 0);
|
|
|
|
lcd_write_command_e(LCD_SET_COM0, 16);
|
2008-03-25 23:21:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-12 20:35:42 +00:00
|
|
|
lcd_write_command(LCD_SELECT_ADC | 1);
|
|
|
|
lcd_write_command(LCD_SELECT_SHL | 8);
|
|
|
|
lcd_write_command_e(LCD_SET_COM0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|