From d4942cc74c82c465ea395637c77ed06565b8b497 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Fri, 29 Jun 2018 16:09:28 -0400 Subject: Add Xuelin iHIFI 770/770C/800 support Taken from the xvortex fork (Roman Stolyarov) Ported, rebased, and cleaned up by myself. Change-Id: I7b2bca2d29502f2e4544e42f3d122786dd4b7978 --- firmware/target/arm/rk27xx/ihifi2/audio-ihifi770.c | 88 +++++++ firmware/target/arm/rk27xx/ihifi2/audio-ihifi800.c | 67 +++++ firmware/target/arm/rk27xx/ihifi2/button-ihifi.c | 99 +++++++ firmware/target/arm/rk27xx/ihifi2/button-target.h | 50 ++++ firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770.c | 285 +++++++++++++++++++++ firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770c.c | 248 ++++++++++++++++++ firmware/target/arm/rk27xx/ihifi2/lcd-ihifi800.c | 228 +++++++++++++++++ firmware/target/arm/rk27xx/ihifi2/lcd-target.h | 26 ++ firmware/target/arm/rk27xx/ihifi2/power-ihifi.c | 53 ++++ .../target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c | 64 +++++ .../target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c | 64 +++++ .../target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c | 64 +++++ 12 files changed, 1336 insertions(+) create mode 100644 firmware/target/arm/rk27xx/ihifi2/audio-ihifi770.c create mode 100644 firmware/target/arm/rk27xx/ihifi2/audio-ihifi800.c create mode 100644 firmware/target/arm/rk27xx/ihifi2/button-ihifi.c create mode 100644 firmware/target/arm/rk27xx/ihifi2/button-target.h create mode 100644 firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770.c create mode 100644 firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770c.c create mode 100644 firmware/target/arm/rk27xx/ihifi2/lcd-ihifi800.c create mode 100644 firmware/target/arm/rk27xx/ihifi2/lcd-target.h create mode 100644 firmware/target/arm/rk27xx/ihifi2/power-ihifi.c create mode 100644 firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c create mode 100644 firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c create mode 100644 firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c (limited to 'firmware/target/arm/rk27xx/ihifi2') diff --git a/firmware/target/arm/rk27xx/ihifi2/audio-ihifi770.c b/firmware/target/arm/rk27xx/ihifi2/audio-ihifi770.c new file mode 100644 index 0000000000..a21ea9cfef --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/audio-ihifi770.c @@ -0,0 +1,88 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "system.h" +#include "kernel.h" +#include "audiohw.h" + +void wm8740_hw_init(void) +{ + GPIO_PADR &= ~(1<<0); /* MD */ + GPIO_PACON |= (1<<0); + + GPIO_PADR &= ~(1<<1); /* MC */ + GPIO_PACON |= (1<<1); + + SCU_IOMUXB_CON &= ~(1<<2); + GPIO_PCDR |= (1<<4); /* ML */ + GPIO_PCCON |= (1<<4); +} + +void wm8740_set_md(const int val) +{ + if (val) + GPIO_PADR |= (1<<0); + else + GPIO_PADR &= ~(1<<0); +} + +void wm8740_set_mc(const int val) +{ + if (val) + GPIO_PADR |= (1<<1); + else + GPIO_PADR &= ~(1<<1); +} + +void wm8740_set_ml(const int val) +{ + if (val) + GPIO_PCDR |= (1<<4); + else + GPIO_PCDR &= ~(1<<4); +} + +static void pop_ctrl(const int val) +{ + if (val) + GPIO_PADR |= (1<<7); + else + GPIO_PADR &= ~(1<<7); +} + +void audiohw_postinit(void) +{ + pop_ctrl(0); + sleep(HZ/4); + wm8740_hw_init(); + audiohw_init(); + sleep(HZ/2); + pop_ctrl(1); + sleep(HZ/4); + audiohw_unmute(); +} + +void audiohw_close(void) +{ + audiohw_mute(); + pop_ctrl(0); + sleep(HZ/4); +} diff --git a/firmware/target/arm/rk27xx/ihifi2/audio-ihifi800.c b/firmware/target/arm/rk27xx/ihifi2/audio-ihifi800.c new file mode 100644 index 0000000000..14b126c72a --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/audio-ihifi800.c @@ -0,0 +1,67 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "system.h" +#include "kernel.h" +#include "audiohw.h" +#include "i2c-rk27xx.h" + +#define ES9018_I2C_ADDR 0x90 + +static unsigned char buf; + +void es9018_write_reg(uint8_t reg, uint8_t val) +{ + buf = val; + i2c_write(ES9018_I2C_ADDR, reg, sizeof(buf), (void*)&buf); +} + +uint8_t es9018_read_reg(uint8_t reg) +{ + i2c_read(ES9018_I2C_ADDR, reg, sizeof(buf), (void*)&buf); + return buf; +} + +static void pop_ctrl(const int val) +{ + if (val) + GPIO_PADR |= (1<<7); + else + GPIO_PADR &= ~(1<<7); +} + +void audiohw_postinit(void) +{ + pop_ctrl(0); + sleep(HZ/4); + audiohw_init(); + sleep(HZ/2); + pop_ctrl(1); + sleep(HZ/4); + audiohw_unmute(); +} + +void audiohw_close(void) +{ + audiohw_mute(); + pop_ctrl(0); + sleep(HZ/4); +} diff --git a/firmware/target/arm/rk27xx/ihifi2/button-ihifi.c b/firmware/target/arm/rk27xx/ihifi2/button-ihifi.c new file mode 100644 index 0000000000..172853a83a --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/button-ihifi.c @@ -0,0 +1,99 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * 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 "kernel.h" +#include "button.h" +#include "adc.h" +#include "backlight.h" + +static bool soft_hold = false; +#ifndef BOOTLOADER +static unsigned hold_counter = 0; +#ifndef IHIFI800 +#define HOLDBUTTON gpio_btn +#define HOLDCNTMAX HZ +#else +#define HOLDBUTTON (gpio_btn) && (adc_val > 325) && (adc_val < 480) +#define HOLDCNTMAX (HZ/10) +#endif +#endif + +void button_init_device(void) { + GPIO_PCCON &= ~(1<<1); /* PWR BTN */ + GPIO_PCCON &= ~(1<<7); /* CD */ +} + +bool button_hold(void) +{ + return soft_hold; +} + +int button_read_device(void) { + int adc_val = adc_read(ADC_BUTTONS); + int gpio_btn = GPIO_PCDR & (1<<1); + + int button = BUTTON_NONE; + + if (gpio_btn) + button |= BUTTON_POWER; + +#ifndef BOOTLOADER + if (HOLDBUTTON) { + if (++hold_counter == HOLDCNTMAX) { + soft_hold = !soft_hold; + backlight_hold_changed(soft_hold); + } + } else { + hold_counter = 0; + } + if (soft_hold) { + return (hold_counter <= HOLDCNTMAX) ? BUTTON_NONE : button; + } +#endif + + if (adc_val < 792) { + if (adc_val < 480) { + if (adc_val < 170) { + if (adc_val < 46) { + button |= BUTTON_HOME; // 0-45 + } else { + button |= BUTTON_PLAY; // 46-169 + } + } else { + if (adc_val < 325) { + button |= BUTTON_NEXT; // 170-324 + } else { + button |= BUTTON_VOL_UP;// 325-479 + } + } + } else { + if (adc_val < 636) { + button |= BUTTON_VOL_DOWN;// 480-635 + } else { + button |= BUTTON_PREV; // 636-791 + } + } + } + + return button; +} diff --git a/firmware/target/arm/rk27xx/ihifi2/button-target.h b/firmware/target/arm/rk27xx/ihifi2/button-target.h new file mode 100644 index 0000000000..211e20e1d6 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/button-target.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _BUTTON_TARGET_H_ +#define _BUTTON_TARGET_H_ + +#define HAS_BUTTON_HOLD + +/* Main unit's buttons */ +#define BUTTON_POWER 0x00000001 +#define BUTTON_HOME 0x00000002 +#define BUTTON_PREV 0x00000004 +#define BUTTON_NEXT 0x00000008 +#define BUTTON_PLAY 0x00000010 +#define BUTTON_VOL_UP 0x00000020 +#define BUTTON_VOL_DOWN 0x00000040 + +#define BUTTON_LEFT 0 +#define BUTTON_RIGHT 0 + +#define BUTTON_MAIN (BUTTON_POWER | BUTTON_HOME | BUTTON_PREV | BUTTON_NEXT | \ + BUTTON_PLAY | BUTTON_VOL_UP | BUTTON_VOL_DOWN) + +/* Software power-off */ +#ifndef IHIFI800 +#define POWEROFF_BUTTON BUTTON_POWER +#else +#define POWEROFF_BUTTON BUTTON_HOME +#endif + +#define POWEROFF_COUNT 30 + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770.c b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770.c new file mode 100644 index 0000000000..23505d9fa0 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770.c @@ -0,0 +1,285 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "kernel.h" +#include "lcd.h" +#include "system.h" +#include "cpu.h" +#include "lcdif-rk27xx.h" + +static bool display_on = false; + +void lcd_display_init(void) +{ + unsigned int i, x, y; + + lcd_cmd(0x11); + + lcd_cmd(0x13); + + mdelay(120); + + lcd_cmd(0x29); + + lcd_cmd(0xB0); + lcd_data(0x05); + lcd_data(0x00); + lcd_data(0xF0); + lcd_data(0x0A); + lcd_data(0x41); + lcd_data(0x02); + lcd_data(0x0A); + lcd_data(0x30); + lcd_data(0x31); + lcd_data(0x36); + lcd_data(0x37); + lcd_data(0x40); + lcd_data(0x02); + lcd_data(0x3F); + lcd_data(0x40); + lcd_data(0x02); + lcd_data(0x81); + lcd_data(0x04); + lcd_data(0x05); + lcd_data(0x64); + + lcd_cmd(0xFC); + lcd_data(0x88); + lcd_data(0x00); + lcd_data(0x10); + lcd_data(0x01); + lcd_data(0x01); + lcd_data(0x10); + lcd_data(0x42); + lcd_data(0x42); + lcd_data(0x22); + lcd_data(0x11); + lcd_data(0x11); + lcd_data(0x22); + lcd_data(0x99); + lcd_data(0xAA); + lcd_data(0xAA); + lcd_data(0xAA); + lcd_data(0xBB); + lcd_data(0xBB); + lcd_data(0xAA); + lcd_data(0x33); + lcd_data(0x33); + lcd_data(0x11); + lcd_data(0x01); + lcd_data(0x01); + lcd_data(0x01); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0xC0); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + + lcd_cmd(0xFD); + lcd_data(0x88); + lcd_data(0x00); + lcd_data(0x10); + lcd_data(0x01); + lcd_data(0x01); + lcd_data(0x10); + lcd_data(0x42); + lcd_data(0x42); + lcd_data(0x22); + lcd_data(0x11); + lcd_data(0x11); + lcd_data(0x22); + lcd_data(0x99); + lcd_data(0xAA); + lcd_data(0xAA); + lcd_data(0xAA); + lcd_data(0xBB); + lcd_data(0xBB); + lcd_data(0xAA); + lcd_data(0x33); + lcd_data(0x33); + lcd_data(0x11); + lcd_data(0x01); + lcd_data(0x01); + lcd_data(0x01); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x03); + + lcd_cmd(0xBE); + lcd_data(0x00); + lcd_data(0x15); + lcd_data(0x16); + lcd_data(0x08); + lcd_data(0x09); + lcd_data(0x15); + lcd_data(0x10); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + + lcd_cmd(0xC0); + lcd_data(0x0E); + lcd_data(0x01); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + + lcd_cmd(0xC1); + lcd_data(0x2F); + lcd_data(0x23); + lcd_data(0xB4); + lcd_data(0xFF); + lcd_data(0x24); + lcd_data(0x03); + lcd_data(0x20); + lcd_data(0x02); + lcd_data(0x02); + lcd_data(0x02); + lcd_data(0x20); + lcd_data(0x20); + lcd_data(0x00); + + lcd_cmd(0xC2); + lcd_data(0x03); + + lcd_cmd(0x26); + lcd_data(0x08); + + lcd_cmd(0x35); + + lcd_cmd(0x36); + lcd_data(0x04); + + lcd_cmd(0x3A); + lcd_data(0x05); + + lcd_cmd(0x2A); + lcd_data(0x013F); + + lcd_cmd(0x2B); + lcd_data(0xEF); + + lcd_cmd(0x2C); + + lcd_cmd(0x2D); + for (i = 0; i < 0x20; i++) { + lcd_data(i << 1); + } + for (i = 0; i < 0x40; i++) { + lcd_data(i); + } + for (i = 0; i < 0x20; i++) { + lcd_data(i << 1); + } + + lcd_cmd(0x2A); + lcd_data(0x00); + + lcd_cmd(0x2B); + lcd_data(0x00); + + lcd_cmd(0x11); + + mdelay(120); + + lcd_cmd(0x29); + + lcd_cmd(0x2C); + + for (x = 0; x < LCD_WIDTH; x++) + for(y=0; y < LCD_HEIGHT; y++) + lcd_data(0x00); + + display_on = true; +} + +void lcd_enable (bool on) +{ + if (on == display_on) + return; + + lcdctrl_bypass(1); + LCDC_CTRL |= RGB24B; + + if (on) { + lcd_cmd(0x11); + mdelay(120); + lcd_cmd(0x29); + lcd_cmd(0x2C); + } else { + lcd_cmd(0x28); + mdelay(120); + lcd_cmd(0x10); + } + + display_on = on; + LCDC_CTRL &= ~RGB24B; +} + +void lcd_set_gram_area(int x_start, int y_start, + int x_end, int y_end) +{ + lcdctrl_bypass(1); + LCDC_CTRL |= RGB24B; + + lcd_cmd(0x2A); + lcd_data((x_start&0xff00)>>8); + lcd_data(x_start&0x00ff); + lcd_data((x_end&0xff00)>>8); + lcd_data(x_end&0x00ff); + + lcd_cmd(0x2B); + lcd_data((y_start&0xff00)>>8); + lcd_data(y_start&0x00ff); + lcd_data((y_end&0xff00)>>8); + lcd_data(y_end&0x00ff); + + lcd_cmd(0x2C); + + LCDC_CTRL &= ~RGB24B; +} + +bool lcd_active() +{ + return display_on; +} + +/* Blit a YUV bitmap directly to the LCD */ +void lcd_blit_yuv(unsigned char * const src[3], + int src_x, int src_y, int stride, + int x, int y, int width, int height) +{ + (void)src; + (void)src_x; + (void)src_y; + (void)stride; + (void)x; + (void)y; + (void)width; + (void)height; +} diff --git a/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770c.c b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770c.c new file mode 100644 index 0000000000..311b8057cb --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi770c.c @@ -0,0 +1,248 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "kernel.h" +#include "lcd.h" +#include "system.h" +#include "cpu.h" +#include "lcdif-rk27xx.h" + +static bool display_on = false; + +void lcd_display_init(void) +{ + unsigned int x, y; + + lcd_cmd(0x13); + + mdelay(120); + + lcd_cmd(0x35); + lcd_data(0x00); + + lcd_cmd(0x36); + lcd_data(0x48); + + lcd_cmd(0xD0); + lcd_data(0x00); + lcd_data(0x05); + + lcd_cmd(0xEF); + lcd_data(0x07); + + lcd_cmd(0xF2); + lcd_data(0x1B); + lcd_data(0x16); + lcd_data(0x0F); + lcd_data(0x08); + lcd_data(0x08); + lcd_data(0x08); + lcd_data(0x08); + lcd_data(0x10); + lcd_data(0x00); + lcd_data(0x1C); + lcd_data(0x16); + + lcd_cmd(0xF3); + lcd_data(0x01); + lcd_data(0x41); + lcd_data(0x15); + lcd_data(0x0D); + lcd_data(0x33); + lcd_data(0x63); + lcd_data(0x46); + lcd_data(0x10); + + lcd_cmd(0xF4); + lcd_data(0x5B); + lcd_data(0x5B); + lcd_data(0x55); + lcd_data(0x55); + lcd_data(0x44); + + lcd_cmd(0xF5); + lcd_data(0x12); + lcd_data(0x11); + lcd_data(0x06); + lcd_data(0xF0); + lcd_data(0x00); + lcd_data(0x1F); + + lcd_cmd(0xF6); + lcd_data(0x80); + lcd_data(0x10); + lcd_data(0x00); + + lcd_cmd(0xFD); + lcd_data(0x11); + lcd_data(0x1D); + lcd_data(0x00); + + lcd_cmd(0xF8); + lcd_data(0x00); + lcd_data(0x15); + lcd_data(0x01); + lcd_data(0x08); + lcd_data(0x15); + lcd_data(0x22); + lcd_data(0x25); + lcd_data(0x28); + lcd_data(0x14); + lcd_data(0x13); + lcd_data(0x10); + lcd_data(0x11); + lcd_data(0x09); + lcd_data(0x24); + lcd_data(0x28); + + lcd_cmd(0xF9); + lcd_data(0x00); + lcd_data(0x15); + lcd_data(0x01); + lcd_data(0x08); + lcd_data(0x15); + lcd_data(0x22); + lcd_data(0x25); + lcd_data(0x28); + lcd_data(0x14); + lcd_data(0x13); + lcd_data(0x10); + lcd_data(0x11); + lcd_data(0x09); + lcd_data(0x24); + lcd_data(0x28); + + lcd_cmd(0xFC); + lcd_data(0x00); + lcd_data(0x15); + lcd_data(0x01); + lcd_data(0x08); + lcd_data(0x15); + lcd_data(0x22); + lcd_data(0x25); + lcd_data(0x28); + lcd_data(0x14); + lcd_data(0x13); + lcd_data(0x10); + lcd_data(0x11); + lcd_data(0x09); + lcd_data(0x24); + lcd_data(0x28); + + lcd_cmd(0x36); + lcd_data(0x48); + + lcd_cmd(0x3A); + lcd_data(0x55); + + lcd_cmd(0x2A); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x01); + lcd_data(0x3F); + + lcd_cmd(0x2B); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0xEF); + + lcd_cmd(0x11); + + mdelay(120); + + lcd_cmd(0x29); + + lcd_cmd(0x2C); + + for (x = 0; x < LCD_WIDTH; x++) + for(y=0; y < LCD_HEIGHT; y++) + lcd_data(0x00); + + display_on = true; +} + +void lcd_enable (bool on) +{ + if (on == display_on) + return; + + lcdctrl_bypass(1); + LCDC_CTRL |= RGB24B; + + if (on) { + lcd_cmd(0x11); + mdelay(120); + lcd_cmd(0x29); + lcd_cmd(0x2C); + } else { + lcd_cmd(0x28); + mdelay(120); + lcd_cmd(0x10); + } + + display_on = on; + LCDC_CTRL &= ~RGB24B; +} + +void lcd_set_gram_area(int x_start, int y_start, + int x_end, int y_end) +{ + lcdctrl_bypass(1); + LCDC_CTRL |= RGB24B; + + lcd_cmd(0x2A); + lcd_data((x_start&0xff00)>>8); + lcd_data(x_start&0x00ff); + lcd_data((x_end&0xff00)>>8); + lcd_data(x_end&0x00ff); + + lcd_cmd(0x2B); + lcd_data((y_start&0xff00)>>8); + lcd_data(y_start&0x00ff); + lcd_data((y_end&0xff00)>>8); + lcd_data(y_end&0x00ff); + + lcd_cmd(0x2C); + + LCDC_CTRL &= ~RGB24B; +} + +bool lcd_active() +{ + return display_on; +} + +/* Blit a YUV bitmap directly to the LCD */ +void lcd_blit_yuv(unsigned char * const src[3], + int src_x, int src_y, int stride, + int x, int y, int width, int height) +{ + (void)src; + (void)src_x; + (void)src_y; + (void)stride; + (void)x; + (void)y; + (void)width; + (void)height; +} diff --git a/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi800.c b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi800.c new file mode 100644 index 0000000000..821b52dcb6 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/lcd-ihifi800.c @@ -0,0 +1,228 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "kernel.h" +#include "lcd.h" +#include "system.h" +#include "cpu.h" +#include "lcdif-rk27xx.h" + +static bool display_on = false; + +void lcd_display_init(void) +{ + unsigned int x, y; + + lcd_cmd(0xEF); + lcd_data(0x03); + lcd_data(0x80); + lcd_data(0x02); + + lcd_cmd(0xCF); + lcd_data(0x00); + lcd_data(0xC1); + lcd_data(0x30); + + lcd_cmd(0xED); + lcd_data(0x67); + lcd_data(0x03); + lcd_data(0x12); + lcd_data(0x81); + + lcd_cmd(0xE8); + lcd_data(0x85); + lcd_data(0x11); + lcd_data(0x79); + + lcd_cmd(0xCB); + lcd_data(0x39); + lcd_data(0x2C); + lcd_data(0x00); + lcd_data(0x34); + lcd_data(0x06); + + lcd_cmd(0xF7); + lcd_data(0x20); + + lcd_cmd(0xEA); + lcd_data(0x00); + lcd_data(0x00); + + lcd_cmd(0xC0); + lcd_data(0x1D); + + lcd_cmd(0xC1); + lcd_data(0x12); + + lcd_cmd(0xC5); + lcd_data(0x44); + lcd_data(0x3C); + + lcd_cmd(0xC7); + lcd_data(0x88); + + lcd_cmd(0x3A); + lcd_data(0x55); + + lcd_cmd(0x36); + lcd_data(0x0C); + + lcd_cmd(0xB1); + lcd_data(0x00); + lcd_data(0x17); + + lcd_cmd(0xB6); + lcd_data(0x0A); + lcd_data(0xA2); + + lcd_cmd(0xF2); + lcd_data(0x00); + + lcd_cmd(0x26); + lcd_data(0x01); + + lcd_cmd(0xE0); + lcd_data(0x0F); + lcd_data(0x22); + lcd_data(0x1C); + lcd_data(0x1B); + lcd_data(0x08); + lcd_data(0x0F); + lcd_data(0x48); + lcd_data(0xB8); + lcd_data(0x34); + lcd_data(0x05); + lcd_data(0x0C); + lcd_data(0x09); + lcd_data(0x0F); + lcd_data(0x07); + lcd_data(0x00); + + lcd_cmd(0xE1); + lcd_data(0x00); + lcd_data(0x23); + lcd_data(0x24); + lcd_data(0x07); + lcd_data(0x10); + lcd_data(0x07); + lcd_data(0x38); + lcd_data(0x47); + lcd_data(0x4B); + lcd_data(0x0A); + lcd_data(0x13); + lcd_data(0x06); + lcd_data(0x30); + lcd_data(0x38); + lcd_data(0x0F); + + lcd_cmd(0x2A); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0xEF); + + lcd_cmd(0x2B); + lcd_data(0x00); + lcd_data(0x00); + lcd_data(0x01); + lcd_data(0x3F); + + lcd_cmd(0x11); + + mdelay(120); + + lcd_cmd(0x29); + + lcd_cmd(0x2C); + + for (x = 0; x < LCD_WIDTH; x++) + for(y=0; y < LCD_HEIGHT; y++) + lcd_data(0x00); + + display_on = true; +} + +void lcd_enable (bool on) +{ + if (on == display_on) + return; + + lcdctrl_bypass(1); + LCDC_CTRL |= RGB24B; + + if (on) { + lcd_cmd(0x11); + mdelay(120); + lcd_cmd(0x29); + lcd_cmd(0x2C); + } else { + lcd_cmd(0x28); + mdelay(120); + lcd_cmd(0x10); + } + + display_on = on; + LCDC_CTRL &= ~RGB24B; +} + +void lcd_set_gram_area(int x_start, int y_start, + int x_end, int y_end) +{ + lcdctrl_bypass(1); + LCDC_CTRL |= RGB24B; + + lcd_cmd(0x2A); + lcd_data((x_start&0xff00)>>8); + lcd_data(x_start&0x00ff); + lcd_data((x_end&0xff00)>>8); + lcd_data(x_end&0x00ff); + + lcd_cmd(0x2B); + lcd_data((y_start&0xff00)>>8); + lcd_data(y_start&0x00ff); + lcd_data((y_end&0xff00)>>8); + lcd_data(y_end&0x00ff); + + lcd_cmd(0x2C); + + LCDC_CTRL &= ~RGB24B; +} + +bool lcd_active() +{ + return display_on; +} + +/* Blit a YUV bitmap directly to the LCD */ +void lcd_blit_yuv(unsigned char * const src[3], + int src_x, int src_y, int stride, + int x, int y, int width, int height) +{ + (void)src; + (void)src_x; + (void)src_y; + (void)stride; + (void)x; + (void)y; + (void)width; + (void)height; +} diff --git a/firmware/target/arm/rk27xx/ihifi2/lcd-target.h b/firmware/target/arm/rk27xx/ihifi2/lcd-target.h new file mode 100644 index 0000000000..6b2aa5d8a5 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/lcd-target.h @@ -0,0 +1,26 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef LCD_TARGET_H +#define LCD_TARGET_H + +#define LCD_DATABUS_WIDTH LCDIF_16BIT +#endif diff --git a/firmware/target/arm/rk27xx/ihifi2/power-ihifi.c b/firmware/target/arm/rk27xx/ihifi2/power-ihifi.c new file mode 100644 index 0000000000..cc489eacfe --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/power-ihifi.c @@ -0,0 +1,53 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include +#include "config.h" +#include "inttypes.h" +#include "power.h" +#include "panic.h" +#include "system.h" +#include "usb_core.h" /* for usb_charging_maxcurrent_change */ +#include "adc.h" + +void power_off(void) +{ + GPIO_PCCON &= ~(1<<0); + while(1); +} + +void power_init(void) +{ + GPIO_PCDR |= (1<<0); + GPIO_PCCON |= (1<<0); + + GPIO_PADR &= ~(1<<7); /* MUTE */ + GPIO_PACON |= (1<<7); +} + +unsigned int power_input_status(void) +{ + return (usb_detect() == USB_INSERTED) ? POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; +} + +bool charging_state(void) +{ + return (adc_read(ADC_EXTRA) < 512); +} diff --git a/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c new file mode 100644 index 0000000000..b0ff4f5a7b --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770.c @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "adc.h" +#include "adc-target.h" +#include "powermgmt.h" + +/* Battery voltage calculation and discharge/charge curves for the iHiFi 770 + + Battery voltage is calculated under the assumption that the adc full-scale + readout represents 3.00V and that the battery ADC channel is fed with + exactly half of the battery voltage (through a resistive divider). + Charge curve have not been calibrated yet. +*/ + +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + /* 5% */ + 3500, +}; + +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + /* 0% */ + 3300, +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + { 3300, 3570, 3660, 3696, 3712, 3742, 3798, 3865, 3935, 4020, 4130 } +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = + { 3300, 3570, 3660, 3696, 3712, 3742, 3798, 3865, 3935, 4020, 4130 }; + +/* full-scale ADC readout (2^10) in millivolt */ +#define BATTERY_SCALE_FACTOR 6296 + +/* Returns battery voltage from ADC [millivolts] */ +int _battery_voltage(void) +{ + return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10; +} diff --git a/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c new file mode 100644 index 0000000000..613553010b --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi770c.c @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "adc.h" +#include "adc-target.h" +#include "powermgmt.h" + +/* Battery voltage calculation and discharge/charge curves for the iHiFi 770C + + Battery voltage is calculated under the assumption that the adc full-scale + readout represents 3.00V and that the battery ADC channel is fed with + exactly half of the battery voltage (through a resistive divider). + Charge curve have not been calibrated yet. +*/ + +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + /* 5% */ + 3500, +}; + +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + /* 0% */ + 3300, +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + { 3300, 3570, 3660, 3696, 3712, 3742, 3798, 3865, 3935, 4020, 4130 } +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = + { 3300, 3570, 3660, 3696, 3712, 3742, 3798, 3865, 3935, 4020, 4130 }; + +/* full-scale ADC readout (2^10) in millivolt */ +#define BATTERY_SCALE_FACTOR 6296 + +/* Returns battery voltage from ADC [millivolts] */ +int _battery_voltage(void) +{ + return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10; +} diff --git a/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c new file mode 100644 index 0000000000..26f4e47b93 --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/powermgmt-ihifi800.c @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2016 by Roman Stolyarov + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "adc.h" +#include "adc-target.h" +#include "powermgmt.h" + +/* Battery voltage calculation and discharge/charge curves for the iHiFi 800 + + Battery voltage is calculated under the assumption that the adc full-scale + readout represents 3.00V and that the battery ADC channel is fed with + exactly half of the battery voltage (through a resistive divider). + Charge curve have not been calibrated yet. +*/ + +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + /* 5% */ + 3628, +}; + +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + /* 0% */ + 3300, +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + { 3300, 3649, 3701, 3726, 3745, 3778, 3831, 3904, 3965, 4056, 4160 } +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = + { 3300, 3649, 3701, 3726, 3745, 3778, 3831, 3904, 3965, 4056, 4160 }; + +/* full-scale ADC readout (2^10) in millivolt */ +#define BATTERY_SCALE_FACTOR 6296 + +/* Returns battery voltage from ADC [millivolts] */ +int _battery_voltage(void) +{ + return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 10; +} -- cgit v1.2.3