2006-07-26 13:38:31 +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"
|
2007-07-28 08:12:05 +00:00
|
|
|
#include "file.h"
|
2006-07-28 12:41:13 +00:00
|
|
|
#include "lcd-remote.h"
|
2007-07-28 08:12:05 +00:00
|
|
|
#include "scroll_engine.h"
|
2006-07-26 13:38:31 +00:00
|
|
|
|
|
|
|
/* The LCD in the iAudio M3/M5/X5 remote control is a Tomato LSI 0350 */
|
|
|
|
|
2006-09-17 09:19:50 +00:00
|
|
|
#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
|
2006-07-28 12:41:13 +00:00
|
|
|
#define LCD_REVERSE 0xa6
|
2006-07-26 13:38:31 +00:00
|
|
|
|
|
|
|
#define CS_LO and_l(~0x00000020, &GPIO1_OUT)
|
|
|
|
#define CS_HI or_l(0x00000020, &GPIO1_OUT)
|
|
|
|
#define CLK_LO and_l(~0x00004000, &GPIO_OUT)
|
|
|
|
#define CLK_HI or_l(0x00004000, &GPIO_OUT)
|
|
|
|
#define DATA_LO and_l(~0x00002000, &GPIO_OUT)
|
|
|
|
#define DATA_HI or_l(0x00002000, &GPIO_OUT)
|
|
|
|
#define RS_LO and_l(~0x00008000, &GPIO_OUT)
|
|
|
|
#define RS_HI or_l(0x00008000, &GPIO_OUT)
|
|
|
|
|
2006-07-28 12:41:13 +00:00
|
|
|
/* cached settings values */
|
|
|
|
static bool cached_invert = false;
|
|
|
|
static bool cached_flip = false;
|
2006-09-26 20:46:17 +00:00
|
|
|
static int cached_contrast = DEFAULT_REMOTE_CONTRAST_SETTING;
|
2006-07-28 12:41:13 +00:00
|
|
|
|
|
|
|
bool remote_initialized = false;
|
2006-07-26 13:38:31 +00:00
|
|
|
|
2007-02-25 22:36:04 +00:00
|
|
|
|
2006-08-22 05:50:05 +00:00
|
|
|
/* Standard low-level byte writer. Requires CLK high on entry */
|
|
|
|
static inline void _write_byte(unsigned data)
|
2006-07-26 13:38:31 +00:00
|
|
|
{
|
2006-08-22 05:50:05 +00:00
|
|
|
asm volatile (
|
|
|
|
"move.l (%[gpo0]), %%d0 \n" /* Get current state of data line */
|
|
|
|
"and.l %[dbit], %%d0 \n"
|
|
|
|
"beq.s 1f \n" /* and set it as previous-state bit */
|
|
|
|
"bset #8, %[data] \n"
|
|
|
|
"1: \n"
|
|
|
|
"move.l %[data], %%d0 \n" /* Compute the 'bit derivative', i.e. a value */
|
|
|
|
"lsr.l #1, %%d0 \n" /* with 1's where the data changes from the */
|
|
|
|
"eor.l %%d0, %[data] \n" /* previous state, and 0's where it doesn't */
|
|
|
|
"swap %[data] \n" /* Shift data to upper byte */
|
|
|
|
"lsl.l #8, %[data] \n"
|
|
|
|
|
|
|
|
"move.l %[cbit], %%d1 \n" /* Prepare mask for flipping CLK */
|
|
|
|
"or.l %[dbit], %%d1 \n" /* and DATA at once */
|
2006-07-26 13:38:31 +00:00
|
|
|
|
2006-08-22 05:50:05 +00:00
|
|
|
"lsl.l #1,%[data] \n" /* Shift out MSB */
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %%d1, (%[gpo0]) \n" /* 1: Flip both CLK and DATA */
|
|
|
|
".word 0x51fa \n" /* (trapf.w - shadow next insn) */
|
|
|
|
"1: \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n" /* else flip CLK only */
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n" /* Flip CLK again */
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n" /* ..unrolled.. */
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %%d1, (%[gpo0]) \n"
|
|
|
|
".word 0x51fa \n"
|
|
|
|
"1: \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %%d1, (%[gpo0]) \n"
|
|
|
|
".word 0x51fa \n"
|
|
|
|
"1: \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %%d1, (%[gpo0]) \n"
|
|
|
|
".word 0x51fa \n"
|
|
|
|
"1: \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %%d1, (%[gpo0]) \n"
|
|
|
|
".word 0x51fa \n"
|
|
|
|
"1: \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %%d1, (%[gpo0]) \n"
|
|
|
|
".word 0x51fa \n"
|
|
|
|
"1: \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %%d1, (%[gpo0]) \n"
|
|
|
|
".word 0x51fa \n"
|
|
|
|
"1: \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %%d1, (%[gpo0]) \n"
|
|
|
|
".word 0x51fa \n"
|
|
|
|
"1: \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
"eor.l %[cbit], (%[gpo0]) \n"
|
|
|
|
: /* outputs */
|
|
|
|
[data]"+d"(data)
|
|
|
|
: /* inputs */
|
|
|
|
[gpo0]"a"(&GPIO_OUT),
|
|
|
|
[cbit]"d"(0x00004000),
|
|
|
|
[dbit]"d"(0x00002000)
|
|
|
|
: /* clobbers */
|
|
|
|
"d0", "d1"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fast low-level byte writer. Don't use with high CPU clock.
|
|
|
|
* Requires CLK high on entry */
|
|
|
|
static inline void _write_fast(unsigned data)
|
|
|
|
{
|
|
|
|
asm volatile (
|
|
|
|
"move.w %%sr,%%d3 \n" /* Get current interrupt level */
|
|
|
|
"move.w #0x2700,%%sr \n" /* Disable interrupts */
|
|
|
|
|
|
|
|
"move.l (%[gpo0]), %%d0 \n" /* Get current state of data port */
|
|
|
|
"move.l %%d0, %%d1 \n"
|
|
|
|
"and.l %[dbit], %%d1 \n" /* Check current state of data line */
|
|
|
|
"beq.s 1f \n" /* and set it as previous-state bit */
|
|
|
|
"bset #8, %[data] \n"
|
|
|
|
"1: \n"
|
|
|
|
"move.l %[data], %%d1 \n" /* Compute the 'bit derivative', i.e. a value */
|
|
|
|
"lsr.l #1, %%d1 \n" /* with 1's where the data changes from the */
|
|
|
|
"eor.l %%d1, %[data] \n" /* previous state, and 0's where it doesn't */
|
|
|
|
"swap %[data] \n" /* Shift data to upper byte */
|
|
|
|
"lsl.l #8, %[data] \n"
|
|
|
|
|
2007-07-19 21:24:47 +00:00
|
|
|
"move.l %%d0, %%d1 \n" /* precalculate opposite state of clock line */
|
|
|
|
"eor.l %[cbit], %%d1 \n"
|
|
|
|
|
2006-08-22 05:50:05 +00:00
|
|
|
"lsl.l #1,%[data] \n" /* Shift out MSB */
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %[dbit], %%d0 \n" /* 1: Flip data bit */
|
2007-07-19 21:24:47 +00:00
|
|
|
"eor.l %[dbit], %%d1 \n" /* for both clock states */
|
2006-08-22 05:50:05 +00:00
|
|
|
"1: \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"move.l %%d1, (%[gpo0]) \n" /* Output new state and set CLK */
|
|
|
|
"move.l %%d0, (%[gpo0]) \n" /* reset CLK */
|
2006-08-22 05:50:05 +00:00
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n" /* ..unrolled.. */
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %[dbit], %%d0 \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"eor.l %[dbit], %%d1 \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"1: \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"move.l %%d1, (%[gpo0]) \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"move.l %%d0, (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %[dbit], %%d0 \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"eor.l %[dbit], %%d1 \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"1: \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"move.l %%d1, (%[gpo0]) \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"move.l %%d0, (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %[dbit], %%d0 \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"eor.l %[dbit], %%d1 \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"1: \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"move.l %%d1, (%[gpo0]) \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"move.l %%d0, (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %[dbit], %%d0 \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"eor.l %[dbit], %%d1 \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"1: \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"move.l %%d1, (%[gpo0]) \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"move.l %%d0, (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %[dbit], %%d0 \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"eor.l %[dbit], %%d1 \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"1: \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"move.l %%d1, (%[gpo0]) \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"move.l %%d0, (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %[dbit], %%d0 \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"eor.l %[dbit], %%d1 \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"1: \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"move.l %%d1, (%[gpo0]) \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"move.l %%d0, (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"lsl.l #1,%[data] \n"
|
|
|
|
"bcc.s 1f \n"
|
|
|
|
"eor.l %[dbit], %%d0 \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"eor.l %[dbit], %%d1 \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"1: \n"
|
2007-07-19 21:24:47 +00:00
|
|
|
"move.l %%d1, (%[gpo0]) \n"
|
2006-08-22 05:50:05 +00:00
|
|
|
"move.l %%d0, (%[gpo0]) \n"
|
|
|
|
|
|
|
|
"move.w %%d3, %%sr \n" /* Restore interrupt level */
|
|
|
|
: /* outputs */
|
|
|
|
[data]"+d"(data)
|
|
|
|
: /* inputs */
|
|
|
|
[gpo0]"a"(&GPIO_OUT),
|
|
|
|
[cbit]"d"(0x00004000),
|
|
|
|
[dbit]"d"(0x00002000)
|
|
|
|
: /* clobbers */
|
|
|
|
"d0", "d1", "d2", "d3"
|
|
|
|
);
|
2006-07-26 13:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_remote_write_command(int cmd)
|
|
|
|
{
|
2006-08-22 05:50:05 +00:00
|
|
|
RS_LO;
|
|
|
|
CS_LO;
|
|
|
|
_write_byte(cmd);
|
|
|
|
CS_HI;
|
2006-07-26 13:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_remote_write_command_ex(int cmd, int data)
|
|
|
|
{
|
2006-08-22 05:50:05 +00:00
|
|
|
RS_LO;
|
|
|
|
CS_LO;
|
|
|
|
_write_byte(cmd);
|
|
|
|
_write_byte(data);
|
|
|
|
CS_HI;
|
2006-07-26 13:38:31 +00:00
|
|
|
}
|
|
|
|
|
2008-03-12 23:08:33 +00:00
|
|
|
void lcd_remote_write_data(const fb_remote_data *p_words, int count)
|
2006-07-26 13:38:31 +00:00
|
|
|
{
|
2008-03-12 23:08:33 +00:00
|
|
|
const unsigned char *p_bytes = (const unsigned char *)p_words;
|
|
|
|
const unsigned char *p_end = (const unsigned char *)(p_words + count);
|
2006-08-22 05:50:05 +00:00
|
|
|
|
|
|
|
RS_HI;
|
|
|
|
CS_LO;
|
|
|
|
if (cpu_frequency < 50000000)
|
|
|
|
{
|
|
|
|
while (p_bytes < p_end)
|
|
|
|
_write_fast(*p_bytes++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (p_bytes < p_end)
|
|
|
|
_write_byte(*p_bytes++);
|
|
|
|
}
|
|
|
|
CS_HI;
|
2006-07-26 13:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int lcd_remote_default_contrast(void)
|
|
|
|
{
|
2006-09-26 20:46:17 +00:00
|
|
|
return DEFAULT_REMOTE_CONTRAST_SETTING;
|
2006-07-26 13:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_remote_powersave(bool on)
|
|
|
|
{
|
2006-07-28 12:41:13 +00:00
|
|
|
if(remote_initialized) {
|
|
|
|
if (on)
|
|
|
|
lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
|
|
|
|
else
|
|
|
|
lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
|
|
|
|
}
|
2006-07-26 13:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_remote_set_contrast(int val)
|
|
|
|
{
|
2006-09-26 20:46:17 +00:00
|
|
|
if (val < 0)
|
|
|
|
val = 0;
|
|
|
|
else if (val > 63)
|
|
|
|
val = 63;
|
|
|
|
|
2006-07-26 13:38:31 +00:00
|
|
|
cached_contrast = val;
|
2006-07-28 12:41:13 +00:00
|
|
|
if(remote_initialized)
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_VOLUME, val);
|
2006-07-26 13:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool remote_detect(void)
|
|
|
|
{
|
2006-07-28 12:41:13 +00:00
|
|
|
return (GPIO_READ & 0x01000000)?false:true;
|
2006-07-26 13:38:31 +00:00
|
|
|
}
|
|
|
|
|
2006-07-28 12:41:13 +00:00
|
|
|
void lcd_remote_on(void)
|
|
|
|
{
|
2006-08-22 05:50:05 +00:00
|
|
|
CS_HI;
|
|
|
|
CLK_HI;
|
2006-07-26 13:38:31 +00:00
|
|
|
sleep(10);
|
2006-09-17 09:19:50 +00:00
|
|
|
|
2006-07-26 13:38:31 +00:00
|
|
|
lcd_remote_write_command(LCD_SET_DUTY_RATIO);
|
|
|
|
lcd_remote_write_command(0x70); /* 1/128 */
|
|
|
|
|
|
|
|
lcd_remote_write_command(LCD_OSC_ON);
|
|
|
|
|
|
|
|
lcd_remote_write_command(LCD_SELECT_DCDC | 2); /* DC/DC 5xboost */
|
|
|
|
|
|
|
|
lcd_remote_write_command(LCD_SELECT_RES | 7); /* Regulator resistor: 7.2 */
|
|
|
|
|
|
|
|
lcd_remote_write_command(LCD_SET_BIAS | 6); /* 1/11 */
|
|
|
|
|
|
|
|
lcd_remote_write_command(LCD_CONTROL_POWER | 7); /* All circuits ON */
|
2008-03-12 23:08:33 +00:00
|
|
|
|
2006-07-26 13:38:31 +00:00
|
|
|
sleep(30);
|
|
|
|
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_GRAY | 0, 0x00);
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_GRAY | 1, 0x00);
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_GRAY | 2, 0x0c);
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_GRAY | 3, 0x00);
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_GRAY | 4, 0xcc);
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_GRAY | 5, 0x00);
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_GRAY | 6, 0xcc);
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_GRAY | 7, 0x0c);
|
|
|
|
|
|
|
|
lcd_remote_write_command(LCD_SET_PWM_FRC | 6); /* 4FRC + 12PWM */
|
|
|
|
|
|
|
|
lcd_remote_write_command(LCD_DISPLAY_ON | 1); /* display on */
|
|
|
|
|
|
|
|
remote_initialized = true;
|
|
|
|
|
2006-07-28 12:41:13 +00:00
|
|
|
lcd_remote_set_flip(cached_flip);
|
2006-07-26 13:38:31 +00:00
|
|
|
lcd_remote_set_contrast(cached_contrast);
|
2006-07-28 12:41:13 +00:00
|
|
|
lcd_remote_set_invert_display(cached_invert);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_remote_off(void)
|
|
|
|
{
|
|
|
|
remote_initialized = false;
|
|
|
|
CS_HI;
|
|
|
|
RS_HI;
|
|
|
|
}
|
|
|
|
|
2006-09-17 09:19:50 +00:00
|
|
|
void lcd_remote_poweroff(void)
|
|
|
|
{
|
|
|
|
/* Set power save -> Power OFF (VDD - VSS) .. that's it */
|
|
|
|
if (remote_initialized && remote_detect())
|
|
|
|
lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
|
|
|
|
}
|
|
|
|
|
2008-03-12 23:08:33 +00:00
|
|
|
#ifndef BOOTLOADER
|
2007-02-25 22:36:04 +00:00
|
|
|
/* Monitor remote hotswap */
|
|
|
|
static void remote_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)
|
|
|
|
{
|
2007-07-28 08:12:05 +00:00
|
|
|
if (!(countdown % 48))
|
2007-02-25 22:36:04 +00:00
|
|
|
{
|
2007-07-28 08:12:05 +00:00
|
|
|
queue_broadcast(SYS_REMOTE_PLUGGED, 0);
|
2007-02-25 22:36:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (countdown == 0)
|
|
|
|
{
|
2007-07-28 08:12:05 +00:00
|
|
|
queue_broadcast(SYS_REMOTE_UNPLUGGED, 0);
|
2007-02-25 22:36:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-12 23:08:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void lcd_remote_init_device(void)
|
|
|
|
{
|
|
|
|
or_l(0x0000e000, &GPIO_OUT);
|
|
|
|
or_l(0x0000e000, &GPIO_ENABLE);
|
|
|
|
or_l(0x0000e000, &GPIO_FUNCTION);
|
|
|
|
|
|
|
|
or_l(0x00000020, &GPIO1_OUT);
|
|
|
|
or_l(0x00000020, &GPIO1_ENABLE);
|
|
|
|
or_l(0x00000020, &GPIO1_FUNCTION);
|
|
|
|
|
|
|
|
and_l(~0x01000000, &GPIO_OUT);
|
|
|
|
and_l(~0x01000000, &GPIO_ENABLE);
|
|
|
|
or_l(0x01000000, &GPIO_FUNCTION);
|
|
|
|
|
|
|
|
lcd_remote_clear_display();
|
|
|
|
#ifdef BOOTLOADER
|
|
|
|
lcd_remote_on();
|
|
|
|
#else
|
|
|
|
tick_add_task(remote_tick);
|
|
|
|
#endif
|
|
|
|
}
|
2007-02-25 22:36:04 +00:00
|
|
|
|
2006-07-28 12:41:13 +00:00
|
|
|
/* Update the display.
|
|
|
|
This must be called after all other LCD functions that change the display. */
|
|
|
|
void lcd_remote_update(void) ICODE_ATTR;
|
|
|
|
void lcd_remote_update(void)
|
|
|
|
{
|
|
|
|
int y;
|
|
|
|
if(remote_initialized) {
|
2007-02-20 19:31:34 +00:00
|
|
|
for(y = 0;y < LCD_REMOTE_FBHEIGHT;y++) {
|
2006-07-28 12:41:13 +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. */
|
|
|
|
lcd_remote_write_command(LCD_SET_PAGE | (y>5?y+2:y));
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_COLUMN | 0, 0);
|
2008-03-12 23:08:33 +00:00
|
|
|
lcd_remote_write_data(lcd_remote_framebuffer[y], LCD_REMOTE_WIDTH);
|
2006-07-28 12:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update a fraction of the display. */
|
|
|
|
void lcd_remote_update_rect(int, int, int, int) ICODE_ATTR;
|
|
|
|
void lcd_remote_update_rect(int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
if(remote_initialized) {
|
|
|
|
int ymax;
|
|
|
|
|
|
|
|
/* The Y coordinates have to work on even 8 pixel rows */
|
|
|
|
ymax = (y + height-1) >> 3;
|
|
|
|
y >>= 3;
|
|
|
|
|
|
|
|
if(x + width > LCD_REMOTE_WIDTH)
|
|
|
|
width = LCD_REMOTE_WIDTH - x;
|
|
|
|
if (width <= 0)
|
|
|
|
return; /* nothing left to do, 0 is harmful to lcd_write_data() */
|
2007-02-20 19:31:34 +00:00
|
|
|
if(ymax >= LCD_REMOTE_FBHEIGHT)
|
|
|
|
ymax = LCD_REMOTE_FBHEIGHT-1;
|
2006-07-28 12:41:13 +00:00
|
|
|
|
|
|
|
/* Copy specified rectangle bitmap to hardware
|
|
|
|
COM48-COM63 are not connected, so we need to skip those */
|
|
|
|
for (; y <= ymax; y++)
|
|
|
|
{
|
|
|
|
lcd_remote_write_command(LCD_SET_PAGE |
|
|
|
|
((y > 5?y + 2:y) & 0xf));
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_COLUMN | ((x >> 4) & 0xf),
|
|
|
|
x & 0xf);
|
|
|
|
|
2008-03-12 23:08:33 +00:00
|
|
|
lcd_remote_write_data(&lcd_remote_framebuffer[y][x], width);
|
|
|
|
}
|
2006-07-28 12:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_remote_set_invert_display(bool yesno)
|
|
|
|
{
|
|
|
|
cached_invert = yesno;
|
|
|
|
if(remote_initialized)
|
|
|
|
lcd_remote_write_command(LCD_REVERSE | yesno);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_remote_set_flip(bool yesno)
|
|
|
|
{
|
|
|
|
cached_flip = yesno;
|
|
|
|
if(remote_initialized) {
|
|
|
|
if(yesno) {
|
|
|
|
lcd_remote_write_command(LCD_SELECT_ADC | 0);
|
|
|
|
lcd_remote_write_command(LCD_SELECT_SHL | 0);
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_COM0, 16);
|
|
|
|
} else {
|
|
|
|
lcd_remote_write_command(LCD_SELECT_ADC | 1);
|
|
|
|
lcd_remote_write_command(LCD_SELECT_SHL | 8);
|
|
|
|
lcd_remote_write_command_ex(LCD_SET_COM0, 0);
|
|
|
|
}
|
|
|
|
}
|
2006-07-26 13:38:31 +00:00
|
|
|
}
|