summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/rk27xx/debug-target.h2
-rw-r--r--firmware/target/arm/rk27xx/hm801/button-hm801.c68
-rw-r--r--firmware/target/arm/rk27xx/hm801/button-target.h47
-rw-r--r--firmware/target/arm/rk27xx/hm801/power-hm801.c49
-rw-r--r--firmware/target/arm/rk27xx/hm801/powermgmt-hm801.c60
-rw-r--r--firmware/target/arm/rk27xx/lcd-hifiman.c (renamed from firmware/target/arm/rk27xx/hm60x/lcd-hm60x.c)0
-rw-r--r--firmware/target/arm/rk27xx/lcdif-rk27xx.c2
-rw-r--r--firmware/target/arm/rk27xx/sd-rk27xx.c8
8 files changed, 233 insertions, 3 deletions
diff --git a/firmware/target/arm/rk27xx/debug-target.h b/firmware/target/arm/rk27xx/debug-target.h
index c083b9282a..fb4abaeed7 100644
--- a/firmware/target/arm/rk27xx/debug-target.h
+++ b/firmware/target/arm/rk27xx/debug-target.h
@@ -26,7 +26,7 @@
26 26
27#ifdef RK27_GENERIC 27#ifdef RK27_GENERIC
28#define DEBUG_CANCEL BUTTON_VOL 28#define DEBUG_CANCEL BUTTON_VOL
29#elif defined(HM60X) 29#elif defined(HM60X) || defined(HM801)
30#define DEBUG_CANCEL BUTTON_LEFT 30#define DEBUG_CANCEL BUTTON_LEFT
31#endif 31#endif
32 32
diff --git a/firmware/target/arm/rk27xx/hm801/button-hm801.c b/firmware/target/arm/rk27xx/hm801/button-hm801.c
new file mode 100644
index 0000000000..8e3d46bf0d
--- /dev/null
+++ b/firmware/target/arm/rk27xx/hm801/button-hm801.c
@@ -0,0 +1,68 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 Andrew Ryabinin
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "system.h"
24#include "button.h"
25#include "adc.h"
26
27void button_init_device(void) {
28 /* setup button gpio as input */
29 GPIO_PCCON &= ~(POWEROFF_BUTTON);
30}
31
32int button_read_device(void) {
33 int adc_val = adc_read(ADC_BUTTONS);
34 int button = 0;
35
36 if (adc_val < 480) { /* middle */
37 if (adc_val < 200) { /* 200 - 0 */
38 if (adc_val < 30) {
39 button = BUTTON_UP;
40 } else {
41 button = BUTTON_RIGHT; /* 30 - 200 */
42 }
43 } else { /* 200 - 480 */
44 if (adc_val < 370) {
45 button = BUTTON_SELECT;
46 } else {
47 button = BUTTON_DOWN;
48 }
49 }
50 } else { /* > 480 */
51 if (adc_val < 690) { /* 480 - 690 */
52 if (adc_val < 580) {
53 button = BUTTON_LEFT;
54 } else {
55 button = BUTTON_NEXT;
56 }
57 } else { /* > 680 */
58 if (adc_val < 840) {
59 button = BUTTON_PREV;
60 } else {
61 if (adc_val < 920) {
62 button = BUTTON_PLAY;
63 }
64 }
65 }
66 }
67 return button | (GPIO_PCDR & POWEROFF_BUTTON);
68}
diff --git a/firmware/target/arm/rk27xx/hm801/button-target.h b/firmware/target/arm/rk27xx/hm801/button-target.h
new file mode 100644
index 0000000000..4af054b07c
--- /dev/null
+++ b/firmware/target/arm/rk27xx/hm801/button-target.h
@@ -0,0 +1,47 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 Andrew Ryabinin
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _BUTTON_TARGET_H_
22#define _BUTTON_TARGET_H_
23
24#include <stdbool.h>
25#include "config.h"
26
27void button_init_device(void);
28int button_read_device(void);
29
30
31#define BUTTON_UP 0x00000001
32#define BUTTON_DOWN 0x00000004
33#define BUTTON_LEFT 0x00000008
34#define BUTTON_RIGHT 0x00000010
35#define BUTTON_SELECT 0x00000020
36#define BUTTON_NEXT 0x00000040
37#define BUTTON_PREV 0x00000080
38#define BUTTON_PLAY 0x00000100
39
40
41#define BUTTON_REMOTE 0
42
43
44#define POWEROFF_BUTTON 0x02
45#define POWEROFF_COUNT 30
46
47#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/rk27xx/hm801/power-hm801.c b/firmware/target/arm/rk27xx/hm801/power-hm801.c
new file mode 100644
index 0000000000..18a0566a78
--- /dev/null
+++ b/firmware/target/arm/rk27xx/hm801/power-hm801.c
@@ -0,0 +1,49 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright © 2009 Bertrik Sikken
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdbool.h>
22#include "config.h"
23#include "inttypes.h"
24#include "power.h"
25#include "panic.h"
26#include "system.h"
27#include "usb_core.h" /* for usb_charging_maxcurrent_change */
28
29void power_off(void)
30{
31 GPIO_PCDR &= ~(1<<0);
32 while(1);
33}
34
35void power_init(void)
36{
37 GPIO_PCDR |= (1<<0);
38 GPIO_PCCON |= (1<<0);
39}
40
41unsigned int power_input_status(void)
42{
43 return (usb_detect() == USB_INSERTED) ? POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
44}
45
46bool charging_state(void)
47{
48 return true;
49}
diff --git a/firmware/target/arm/rk27xx/hm801/powermgmt-hm801.c b/firmware/target/arm/rk27xx/hm801/powermgmt-hm801.c
new file mode 100644
index 0000000000..a815d893b2
--- /dev/null
+++ b/firmware/target/arm/rk27xx/hm801/powermgmt-hm801.c
@@ -0,0 +1,60 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright © 2011 Andrew Ryabinin
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "adc.h"
24#include "adc-target.h"
25#include "powermgmt.h"
26
27/* Battery voltage calculation and discharge/charge curves for the HiFiMAN HM-801.
28
29 I don't know how to calculate battery voltage, so all values represented here is just
30 values from adc battery channel, not millivolts.
31 Discharge and charge curves have not been calibrated yet.
32*/
33
34const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
35{
36 /* OF power off device when this value reached */
37 430
38};
39
40const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
41{
42 425
43};
44
45/* adc values of 0%, 10%, ... 100% when charging disabled */
46const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
47{
48 /* TODO: simple uncalibrated curve */
49 { 425, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520 }
50};
51
52/* adc values of 0%, 10%, ... 100% when charging enabled */
53const unsigned short percent_to_volt_charge[11] =
54 /* TODO: simple uncalibrated curve */
55 { 425, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520 };
56
57unsigned int battery_adc_voltage(void)
58{
59 return adc_read(ADC_BATTERY);
60}
diff --git a/firmware/target/arm/rk27xx/hm60x/lcd-hm60x.c b/firmware/target/arm/rk27xx/lcd-hifiman.c
index 932154da8d..932154da8d 100644
--- a/firmware/target/arm/rk27xx/hm60x/lcd-hm60x.c
+++ b/firmware/target/arm/rk27xx/lcd-hifiman.c
diff --git a/firmware/target/arm/rk27xx/lcdif-rk27xx.c b/firmware/target/arm/rk27xx/lcdif-rk27xx.c
index aeee63ee7e..a5e18b0800 100644
--- a/firmware/target/arm/rk27xx/lcdif-rk27xx.c
+++ b/firmware/target/arm/rk27xx/lcdif-rk27xx.c
@@ -37,7 +37,7 @@ unsigned int lcd_data_transform(unsigned int data)
37 /* g = ((data & 0x00000300) >> 2) | ((data & 0x000000e0) >> 3); */ 37 /* g = ((data & 0x00000300) >> 2) | ((data & 0x000000e0) >> 3); */
38 g = ((data & 0x00000300) << 6) | ((data & 0x000000e0) << 5); 38 g = ((data & 0x00000300) << 6) | ((data & 0x000000e0) << 5);
39 b = (data & 0x00000001f) << 3; 39 b = (data & 0x00000001f) << 3;
40#elif defined(HM60X) 40#elif defined(HM60X) || defined(HM801)
41 /* 16 bit interface */ 41 /* 16 bit interface */
42 r = (data & 0x0000f800) << 8; 42 r = (data & 0x0000f800) << 8;
43 g = (data & 0x000007e0) << 5; 43 g = (data & 0x000007e0) << 5;
diff --git a/firmware/target/arm/rk27xx/sd-rk27xx.c b/firmware/target/arm/rk27xx/sd-rk27xx.c
index 1742852c16..f3081d2d7d 100644
--- a/firmware/target/arm/rk27xx/sd-rk27xx.c
+++ b/firmware/target/arm/rk27xx/sd-rk27xx.c
@@ -126,10 +126,16 @@ static void mmu_buff_reset(void)
126 MMU_CTRL |= MMU_BUFII_RESET | MMU_BUFI_RESET; 126 MMU_CTRL |= MMU_BUFII_RESET | MMU_BUFI_RESET;
127} 127}
128 128
129/* My generic device uses PC7 pin, active low */
130static inline bool card_detect_target(void) 129static inline bool card_detect_target(void)
131{ 130{
131#if defined(RK27_GENERIC)
132/* My generic device uses PC7 pin, active low */
132 return !(GPIO_PCDR & 0x80); 133 return !(GPIO_PCDR & 0x80);
134#elif defined(HM60X) || defined(HM801)
135 return !(GPIO_PFDR & (1<<2));
136#else
137#error "Unknown target"
138#endif
133} 139}
134 140
135/* Send command to the SD card. Command finish is signaled in ISR */ 141/* Send command to the SD card. Command finish is signaled in ISR */