summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/ypr0
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/ypr0')
-rw-r--r--firmware/target/hosted/ypr0/adc-target.h25
-rw-r--r--firmware/target/hosted/ypr0/ascodec-target.h92
-rw-r--r--firmware/target/hosted/ypr0/ascodec-ypr0.c206
-rw-r--r--firmware/target/hosted/ypr0/backlight-target.h29
-rw-r--r--firmware/target/hosted/ypr0/backlight-ypr0.c89
-rw-r--r--firmware/target/hosted/ypr0/button-target.h53
-rw-r--r--firmware/target/hosted/ypr0/button-ypr0.c103
-rw-r--r--firmware/target/hosted/ypr0/dir-target.h56
-rw-r--r--firmware/target/hosted/ypr0/fs-ypr0.c141
-rw-r--r--firmware/target/hosted/ypr0/i2c-target.h25
-rw-r--r--firmware/target/hosted/ypr0/kernel-ypr0.c163
-rw-r--r--firmware/target/hosted/ypr0/lc-ypr0.c40
-rw-r--r--firmware/target/hosted/ypr0/lcd-ypr0.c147
-rw-r--r--firmware/target/hosted/ypr0/powermgmt-ypr0.c133
-rw-r--r--firmware/target/hosted/ypr0/system-target.h37
-rw-r--r--firmware/target/hosted/ypr0/system-ypr0.c106
-rw-r--r--firmware/target/hosted/ypr0/usb-target.h25
-rw-r--r--firmware/target/hosted/ypr0/ypr0.make25
18 files changed, 1495 insertions, 0 deletions
diff --git a/firmware/target/hosted/ypr0/adc-target.h b/firmware/target/hosted/ypr0/adc-target.h
new file mode 100644
index 0000000000..bdbc4cfabd
--- /dev/null
+++ b/firmware/target/hosted/ypr0/adc-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: adc-target.h 29516 2011-03-05 15:31:52Z thomasjfox $
9 *
10 * Copyright (C) 2011 by Lorenzo Miori
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#ifndef __ADC_TARGET_H__
23#define __ADC_TARGET_H__
24
25#endif /* __ADC_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/ascodec-target.h b/firmware/target/hosted/ypr0/ascodec-target.h
new file mode 100644
index 0000000000..f4ecf20a1b
--- /dev/null
+++ b/firmware/target/hosted/ypr0/ascodec-target.h
@@ -0,0 +1,92 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $
9 *
10 * Module wrapper for AS3543 audio codec, using /dev/afe (afe.ko) of Samsung YP-R0
11 *
12 * Copyright (c) 2011 Lorenzo Miori
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#ifndef _ASCODEC_TARGET_H
25#define _ASCODEC_TARGET_H
26
27#include "as3514.h"
28#include "kernel.h"
29#include "adc.h"
30#include "ascodec.h"
31
32/* ioctl parameter struct */
33
34struct codec_req_struct {
35/* This works for every kind of afe.ko module requests */
36 unsigned char reg; /* Main register address */
37 unsigned char subreg; /* Set this only if you are reading/writing a PMU register*/
38 unsigned char value; /* To be read if reading a register; to be set if writing to a register */
39};
40
41int ascodec_init(void);
42void ascodec_close(void);
43int ascodec_write(unsigned int reg, unsigned int value);
44int ascodec_read(unsigned int reg);
45void ascodec_write_pmu(unsigned int index, unsigned int subreg, unsigned int value);
46int ascodec_read_pmu(unsigned int index, unsigned int subreg);
47void ascodec_set(unsigned int reg, unsigned int bits);
48void ascodec_clear(unsigned int reg, unsigned int bits);
49void ascodec_write_masked(unsigned int reg, unsigned int bits, unsigned int mask);
50int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data);
51unsigned short adc_read(int channel);
52void ascodec_lock(void);
53void ascodec_unlock(void);
54
55static inline bool ascodec_chg_status(void)
56{
57 return ascodec_read(AS3514_IRQ_ENRD0) & CHG_STATUS;
58}
59
60static inline bool ascodec_endofch(void)
61{
62 return ascodec_read(AS3514_IRQ_ENRD0) & CHG_ENDOFCH;
63}
64
65static inline void ascodec_monitor_endofch(void)
66{
67 ascodec_write(AS3514_IRQ_ENRD0, IRQ_ENDOFCH);
68}
69
70static inline void ascodec_wait_adc_finished(void)
71{
72 /*
73 * FIXME: not implemented
74 *
75 * If irqs are not available on the target platform,
76 * this should be most likely implemented by polling
77 * AS3514_IRQ_ENRD2 in the same way powermgmt-ascodec.c
78 * is polling IRQ_ENDOFCH.
79 */
80}
81
82static inline void ascodec_write_charger(int value)
83{
84 ascodec_write_pmu(AS3543_CHARGER, 1, value);
85}
86
87static inline int ascodec_read_charger(void)
88{
89 return ascodec_read_pmu(AS3543_CHARGER, 1);
90}
91
92#endif /* !_ASCODEC_TARGET_H */
diff --git a/firmware/target/hosted/ypr0/ascodec-ypr0.c b/firmware/target/hosted/ypr0/ascodec-ypr0.c
new file mode 100644
index 0000000000..a4e92e6f6b
--- /dev/null
+++ b/firmware/target/hosted/ypr0/ascodec-ypr0.c
@@ -0,0 +1,206 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: ascodec-target.h 26116 2010-05-17 20:53:25Z funman $
9 *
10 * Module wrapper for AS3543 audio codec, using /dev/afe (afe.ko) of Samsung YP-R0
11 *
12 * Copyright (c) 2011 Lorenzo Miori
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#include "fcntl.h"
25#include "unistd.h"
26#include "stdio.h"
27#include "string.h"
28#include "sys/ioctl.h"
29#include "stdlib.h"
30
31#include "ascodec-target.h"
32
33int afe_dev = -1;
34
35/* Write to a normal register */
36#define IOCTL_REG_WRITE 0x40034101
37/* Write to a PMU register */
38#define IOCTL_SUBREG_WRITE 0x40034103
39/* Read from a normal register */
40#define IOCTL_REG_READ 0x80034102
41/* Read from a PMU register */
42#define IOCTL_SUBREG_READ 0x80034103
43
44static struct mutex as_mtx;
45
46int ascodec_init(void) {
47
48 afe_dev = open("/dev/afe", O_RDWR);
49
50 mutex_init(&as_mtx);
51
52 return afe_dev;
53
54}
55
56void ascodec_close(void) {
57
58 if (afe_dev >= 0) {
59 close(afe_dev);
60 }
61
62}
63
64/* Read functions returns -1 if fail, otherwise the register's value if success */
65/* Write functions return >= 0 if success, otherwise -1 if fail */
66
67int ascodec_write(unsigned int reg, unsigned int value)
68{
69 struct codec_req_struct y;
70 struct codec_req_struct *p;
71 p = &y;
72 p->reg = reg;
73 p->value = value;
74 return ioctl(afe_dev, IOCTL_REG_WRITE, p);
75}
76
77int ascodec_read(unsigned int reg)
78{
79 int retval = -1;
80 struct codec_req_struct y;
81 struct codec_req_struct *p;
82 p = &y;
83 p->reg = reg;
84 retval = ioctl(afe_dev, IOCTL_REG_READ, p);
85 if (retval >= 0)
86 return p->value;
87 else
88 return retval;
89}
90
91void ascodec_write_pmu(unsigned int index, unsigned int subreg,
92 unsigned int value)
93{
94 struct codec_req_struct y;
95 struct codec_req_struct *p;
96 p = &y;
97 p->reg = index;
98 p->subreg = subreg;
99 p->value = value;
100 ioctl(afe_dev, IOCTL_SUBREG_WRITE, p);
101}
102
103int ascodec_read_pmu(unsigned int index, unsigned int subreg)
104{
105 int retval = -1;
106 struct codec_req_struct y;
107 struct codec_req_struct *p;
108 p = &y;
109 p->reg = index;
110 p->subreg = subreg;
111 retval = ioctl(afe_dev, IOCTL_SUBREG_READ, p);
112 if (retval >= 0)
113 return p->value;
114 else
115 return retval;
116}
117
118/* Helpers to set/clear bits */
119void ascodec_set(unsigned int reg, unsigned int bits)
120{
121 ascodec_write(reg, ascodec_read(reg) | bits);
122}
123
124void ascodec_clear(unsigned int reg, unsigned int bits)
125{
126 ascodec_write(reg, ascodec_read(reg) & ~bits);
127}
128
129void ascodec_write_masked(unsigned int reg, unsigned int bits,
130 unsigned int mask)
131{
132 ascodec_write(reg, (ascodec_read(reg) & ~mask) | (bits & mask));
133}
134
135/*FIXME: doesn't work */
136int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data)
137{
138 unsigned int i;
139
140 for (i=index; i<len; i++) {
141 data[i] = ascodec_read(i);
142 printf("Register %i: value=%i\n",index,data[i]);
143 }
144
145 printf("TOTAL: %i\n", i);
146
147 return i;
148}
149
150/*
151 * NOTE:
152 * After the conversion to interrupts, ascodec_(lock|unlock) are only used by
153 * adc-as3514.c to protect against other threads corrupting the result by using
154 * the ADC at the same time.
155 *
156 * Concurrent ascodec_(async_)?(read|write) calls are instead protected
157 * by the R0's Kernel I2C driver for ascodec (mutexed), so it's automatically safe
158 */
159
160void ascodec_lock(void)
161{
162 mutex_lock(&as_mtx);
163}
164
165void ascodec_unlock(void)
166{
167 mutex_unlock(&as_mtx);
168}
169
170/* Read 10-bit channel data */
171unsigned short adc_read(int channel)
172{
173 unsigned short data = 0;
174
175 if ((unsigned)channel >= NUM_ADC_CHANNELS)
176 return 0;
177
178 ascodec_lock();
179
180 /* Select channel */
181 ascodec_write(AS3514_ADC_0, (channel << 4));
182 unsigned char buf[2];
183
184 /*
185 * The AS3514 ADC will trigger an interrupt when the conversion
186 * is finished, if the corresponding enable bit in IRQ_ENRD2
187 * is set.
188 * Previously the code did not wait and this apparently did
189 * not pose any problems, but this should be more correct.
190 * Without the wait the data read back may be completely or
191 * partially (first one of the two bytes) stale.
192 */
193 /*FIXME: not implemented*/
194 ascodec_wait_adc_finished();
195
196 /* Read data */
197 ascodec_readbytes(AS3514_ADC_0, 2, buf);
198 data = (((buf[0] & 0x3) << 8) | buf[1]);
199
200 ascodec_unlock();
201 return data;
202}
203
204void adc_init(void)
205{
206}
diff --git a/firmware/target/hosted/ypr0/backlight-target.h b/firmware/target/hosted/ypr0/backlight-target.h
new file mode 100644
index 0000000000..561e159e8c
--- /dev/null
+++ b/firmware/target/hosted/ypr0/backlight-target.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: backlight-target.h 19322 2008-12-04 04:16:53Z jethead71 $
9 *
10 * Copyright (C) 2011 by Lorenzo Miori
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 BACKLIGHT_TARGET_H
22#define BACKLIGHT_TARGET_H
23
24bool _backlight_init(void);
25void _backlight_on(void);
26void _backlight_off(void);
27void _backlight_set_brightness(int brightness);
28
29#endif /* BACKLIGHT_TARGET_H */
diff --git a/firmware/target/hosted/ypr0/backlight-ypr0.c b/firmware/target/hosted/ypr0/backlight-ypr0.c
new file mode 100644
index 0000000000..930b56be2e
--- /dev/null
+++ b/firmware/target/hosted/ypr0/backlight-ypr0.c
@@ -0,0 +1,89 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: backlight-gigabeat-s.c 25800 2010-05-04 10:07:53Z jethead71 $
9 *
10 * Copyright (C) 2011 by Lorenzo Miori
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 "config.h"
22#include "system.h"
23#include "backlight.h"
24#include "backlight-target.h"
25#include "lcd.h"
26#include "as3514.h"
27#include "ascodec-target.h"
28#include <fcntl.h>
29#include "unistd.h"
30
31static bool backlight_on_status = true; /* Is on or off? */
32
33/*TODO: see if LCD sleep could be implemented in a better way -> ie using a rockbox feature */
34/* Turn off LCD power supply */
35static void _backlight_lcd_sleep(void)
36{
37 int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
38 write(fp, "1", 1);
39 close(fp);
40}
41/* Turn on LCD screen */
42static void _backlight_lcd_power(void)
43{
44 int fp = open("/sys/class/graphics/fb0/blank", O_RDWR);
45 write(fp, "0", 1);
46 close(fp);
47}
48
49bool _backlight_init(void)
50{
51 /* We have nothing to do */
52 return true;
53}
54
55void _backlight_on(void)
56{
57 if (!backlight_on_status)
58 {
59 /* Turn on lcd power before backlight */
60 _backlight_lcd_power();
61 /* Original app sets this to 0xb1 when backlight is on... */
62 ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0xb1);
63 }
64
65 backlight_on_status = true;
66
67}
68
69void _backlight_off(void)
70{
71 if (backlight_on_status) {
72 /* Disabling the DCDC15 completely, keeps brightness register value */
73 ascodec_write_pmu(AS3543_BACKLIGHT, 0x1, 0x00);
74 /* Turn off lcd power then */
75 _backlight_lcd_sleep();
76 }
77
78 backlight_on_status = false;
79}
80
81void _backlight_set_brightness(int brightness)
82{
83 /* Just another check... */
84 if (brightness > MAX_BRIGHTNESS_SETTING)
85 brightness = MAX_BRIGHTNESS_SETTING;
86 if (brightness < MIN_BRIGHTNESS_SETTING)
87 brightness = MIN_BRIGHTNESS_SETTING;
88 ascodec_write_pmu(AS3543_BACKLIGHT, 0x3, brightness << 3 & 0xf8);
89}
diff --git a/firmware/target/hosted/ypr0/button-target.h b/firmware/target/hosted/ypr0/button-target.h
new file mode 100644
index 0000000000..5d65d97607
--- /dev/null
+++ b/firmware/target/hosted/ypr0/button-target.h
@@ -0,0 +1,53 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: button-target.h 29248 2011-02-08 20:05:25Z thomasjfox $
9 *
10 * Copyright (C) 2011 by Lorenzo Miori
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#ifndef _BUTTON_TARGET_H_
23#define _BUTTON_TARGET_H_
24
25#include <stdbool.h>
26#include "config.h"
27
28void button_init_device(void);
29void button_close_device(void);
30int button_read_device(void);
31
32/* Logical buttons key codes */
33#define BUTTON_UP 0x00000001
34#define BUTTON_DOWN 0x00000002
35#define BUTTON_LEFT 0x00000004
36#define BUTTON_RIGHT 0x00000008
37#define BUTTON_USER 0x00000010
38#define BUTTON_MENU 0x00000020
39#define BUTTON_BACK 0x00000040
40#define BUTTON_POWER 0x00000080
41#define BUTTON_SELECT 0x00000100
42
43#define BUTTON_MAIN 0x1FF /* all buttons */
44
45/* No remote */
46#define BUTTON_REMOTE 0
47
48/* Software power-off */
49#define POWEROFF_BUTTON BUTTON_POWER
50/* About 3 seconds */
51#define POWEROFF_COUNT 10
52
53#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/hosted/ypr0/button-ypr0.c b/firmware/target/hosted/ypr0/button-ypr0.c
new file mode 100644
index 0000000000..4298410161
--- /dev/null
+++ b/firmware/target/hosted/ypr0/button-ypr0.c
@@ -0,0 +1,103 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: button-sdl.c 30482 2011-09-08 14:53:28Z kugel $
9 *
10 * Copyright (C) 2011 Lorenzo Miori
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 <stdio.h>
23#include <unistd.h>
24#include <fcntl.h>
25#include <stdlib.h> /* EXIT_SUCCESS */
26#include "config.h"
27#include "button.h"
28#include "kernel.h"
29#include "system.h"
30#include "button-target.h"
31
32/* R0 physical key codes */
33enum ypr0_buttons {
34 R0BTN_NONE = BUTTON_NONE,
35 R0BTN_POWER = 1,
36 R0BTN_UP,
37 R0BTN_DOWN,
38 R0BTN_RIGHT,
39 R0BTN_LEFT,
40 R0BTN_CENTRAL,
41 R0BTN_MENU,
42 R0BTN_BACK,
43 R0BTN_3DOTS = 11,
44};
45
46
47static int r0_btn_fd = 0;
48/* Samsung keypad driver doesn't allow multiple key combinations :( */
49static enum ypr0_buttons r0_read_key(void)
50{
51 unsigned char keys;
52
53 if (r0_btn_fd < 0)
54 return 0;
55
56 if (read(r0_btn_fd, &keys, 1))
57 return keys;
58
59 return 0;
60}
61
62/* Conversion from physical keypress code to logic key code */
63static int key_to_button(enum ypr0_buttons keyboard_button)
64{
65 switch (keyboard_button)
66 {
67 default: return BUTTON_NONE;
68 case R0BTN_POWER: return BUTTON_POWER;
69 case R0BTN_UP: return BUTTON_UP;
70 case R0BTN_DOWN: return BUTTON_DOWN;
71 case R0BTN_RIGHT: return BUTTON_RIGHT;
72 case R0BTN_LEFT: return BUTTON_LEFT;
73 case R0BTN_CENTRAL: return BUTTON_SELECT;
74 case R0BTN_MENU: return BUTTON_MENU;
75 case R0BTN_BACK: return BUTTON_BACK;
76 case R0BTN_3DOTS: return BUTTON_USER;
77 }
78}
79
80int button_read_device(void)
81{
82 return key_to_button(r0_read_key());
83}
84
85
86/* Open the keypad device: it is offered by r0Btn.ko module */
87void button_init_device(void)
88{
89 r0_btn_fd = open("/dev/r0Btn", O_RDONLY);
90 if (r0_btn_fd < 0)
91 printf("/dev/r0Btn open error!");
92}
93
94#ifdef BUTTON_DRIVER_CLOSE
95/* I'm not sure it's called at shutdown...give a check! */
96void button_close_device(void)
97{
98 if (r0_btn_fd >= 0) {
99 close(r0_btn_fd);
100 printf("/dev/r0Btn closed!");
101 }
102}
103#endif /* BUTTON_DRIVER_CLOSE */
diff --git a/firmware/target/hosted/ypr0/dir-target.h b/firmware/target/hosted/ypr0/dir-target.h
new file mode 100644
index 0000000000..48859526df
--- /dev/null
+++ b/firmware/target/hosted/ypr0/dir-target.h
@@ -0,0 +1,56 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
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#ifndef __DIR_TARGET_H__
23#define __DIR_TARGET_H__
24
25#include <dirent.h>
26/* including unistd.h is too noisy */
27extern int rmdir(const char* name);
28
29
30#define dirent_uncached dirent
31#define DIR_UNCACHED DIR
32#define opendir_uncached _opendir
33#define readdir_uncached _readdir
34#define closedir_uncached _closedir
35#define mkdir_uncached _mkdir
36#define rmdir_uncached rmdir
37
38#define dirent_ypr0 dirent
39#define DIR_ypr0 DIR
40#define opendir_ypr0 _opendir
41#define readdir_ypr0 _readdir
42#define closedir_ypr0 _closedir
43#define mkdir_ypr0 _mkdir
44#define rmdir_ypr0 rmdir
45
46extern DIR* _opendir(const char* name);
47extern int _mkdir(const char* name);
48extern int _closedir(DIR* dir);
49extern struct dirent *_readdir(DIR* dir);
50extern void fat_size(unsigned long *size, unsigned long *free);
51
52#define DIRFUNCTIONS_DEFINED
53#define DIRENT_DEFINED
54#define DIR_DEFINED
55
56#endif /* __DIR_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/fs-ypr0.c b/firmware/target/hosted/ypr0/fs-ypr0.c
new file mode 100644
index 0000000000..7f49a5f91a
--- /dev/null
+++ b/firmware/target/hosted/ypr0/fs-ypr0.c
@@ -0,0 +1,141 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
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 <stdlib.h>
23#include <sys/stat.h> /* stat() */
24#include <stdio.h> /* snprintf */
25#include <string.h> /* size_t */
26#include <dirent.h>
27#include <time.h> /* localtime() */
28#include "system-target.h"
29#include "dir-target.h"
30#include "file.h"
31#include "dir.h"
32#include "rbpaths.h"
33
34
35long filesize(int fd)
36{
37 struct stat buf;
38
39 if (!fstat(fd, &buf))
40 return buf.st_size;
41 else
42 return -1;
43}
44
45/* do we really need this in the app? */
46void fat_size(unsigned long* size, unsigned long* free)
47{
48 *size = *free = 0;
49}
50
51#undef opendir
52#undef closedir
53#undef mkdir
54#undef readdir
55
56/* need to wrap around DIR* because we need to save the parent's
57 * directory path in order to determine dirinfo */
58struct __dir {
59 DIR *dir;
60 char *path;
61};
62
63DIR* _opendir(const char *name)
64{
65 char *buf = malloc(sizeof(struct __dir) + strlen(name)+1);
66 if (!buf)
67 return NULL;
68
69 struct __dir *this = (struct __dir*)buf;
70
71 this->path = buf+sizeof(struct __dir);
72 /* definitely fits due to strlen() */
73 strcpy(this->path, name);
74
75 this->dir = opendir(name);
76
77 if (!this->dir)
78 {
79 free(buf);
80 return NULL;
81 }
82 return (DIR*)this;
83}
84
85int _mkdir(const char *name)
86{
87 return mkdir(name, 0777);
88}
89
90int _closedir(DIR *dir)
91{
92 struct __dir *this = (struct __dir*)dir;
93 int ret = closedir(this->dir);
94 free(this);
95 return ret;
96}
97
98struct dirent* _readdir(DIR* dir)
99{
100 struct __dir *d = (struct __dir*)dir;
101 return readdir(d->dir);
102}
103
104struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir)
105{
106 struct __dir *parent = (struct __dir*)_parent;
107 struct stat s;
108 struct tm *tm = NULL;
109 struct dirinfo ret;
110 char path[MAX_PATH];
111
112 snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
113 memset(&ret, 0, sizeof(ret));
114
115 if (!stat(path, &s))
116 {
117 if (S_ISDIR(s.st_mode))
118 {
119 ret.attribute = ATTR_DIRECTORY;
120 }
121 ret.size = s.st_size;
122 tm = localtime(&(s.st_mtime));
123 }
124
125 if (!lstat(path, &s) && S_ISLNK(s.st_mode))
126 {
127 ret.attribute |= ATTR_LINK;
128 }
129
130 if (tm)
131 {
132 ret.wrtdate = ((tm->tm_year - 80) << 9) |
133 ((tm->tm_mon + 1) << 5) |
134 tm->tm_mday;
135 ret.wrttime = (tm->tm_hour << 11) |
136 (tm->tm_min << 5) |
137 (tm->tm_sec >> 1);
138 }
139
140 return ret;
141}
diff --git a/firmware/target/hosted/ypr0/i2c-target.h b/firmware/target/hosted/ypr0/i2c-target.h
new file mode 100644
index 0000000000..3b046bba96
--- /dev/null
+++ b/firmware/target/hosted/ypr0/i2c-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: i2c-target.h 29516 2011-03-05 15:31:52Z thomasjfox $
9 *
10 * Copyright (C) 2010 by Thomas Martitz
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#ifndef __I2C_TARGET_H__
23#define __I2C_TARGET_H__
24
25#endif /* __I2C_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/kernel-ypr0.c b/firmware/target/hosted/ypr0/kernel-ypr0.c
new file mode 100644
index 0000000000..bcf2cee583
--- /dev/null
+++ b/firmware/target/hosted/ypr0/kernel-ypr0.c
@@ -0,0 +1,163 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
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
23#include <time.h>
24#include <signal.h>
25#include <errno.h>
26#include <unistd.h>
27#include <pthread.h>
28#include "config.h"
29#include "system.h"
30#include "button.h"
31#include "audio.h"
32#include "panic.h"
33#include "timer.h"
34
35
36static pthread_cond_t wfi_cond = PTHREAD_COND_INITIALIZER;
37static pthread_mutex_t wfi_mtx = PTHREAD_MUTEX_INITIALIZER;
38/*
39 * call tick tasks and wake the scheduler up */
40void timer_signal(union sigval arg)
41{
42 (void)arg;
43 call_tick_tasks();
44 interrupt();
45}
46
47/*
48 * wait on the sem which the signal handler posts to save cpu time (aka sleep)
49 *
50 * other mechanisms could use them as well */
51void wait_for_interrupt(void)
52{
53 pthread_cond_wait(&wfi_cond, &wfi_mtx);
54}
55
56/*
57 * Wakeup the kernel, if sleeping (shall not be called from a signal handler) */
58void interrupt(void)
59{
60 pthread_cond_signal(&wfi_cond);
61}
62
63
64/*
65 * setup a hrtimer to send a signal to our process every tick
66 */
67union sigval tick_arg = {
68 .sival_int = 0,
69};
70
71void tick_start(unsigned int interval_in_ms)
72{
73 int ret = 0;
74 timer_t timerid;
75 struct itimerspec ts;
76 sigevent_t sigev;
77
78 /* initializing in the declaration causes some weird warnings */
79 memset(&sigev, 0, sizeof(sigevent_t));
80 sigev.sigev_notify = SIGEV_THREAD,
81 sigev.sigev_notify_function = timer_signal;
82
83 ts.it_value.tv_sec = ts.it_interval.tv_sec = 0;
84 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = interval_in_ms*1000*1000;
85
86 /* add the timer */
87 ret |= timer_create(CLOCK_REALTIME, &sigev, &timerid);
88 ret |= timer_settime(timerid, 0, &ts, NULL);
89
90 /* Grab the mutex already now and leave it to this thread. We don't
91 * care about race conditions when signaling the condition (because
92 * they are not critical), but a mutex is necessary due to the API */
93 pthread_mutex_lock(&wfi_mtx);
94
95 if (ret != 0)
96 panicf("%s(): %s\n", __func__, strerror(errno));
97}
98
99#define cycles_to_microseconds(cycles) \
100 ((int)((1000000*cycles)/TIMER_FREQ))
101
102
103static timer_t timer_tid;
104static int timer_prio = -1;
105void (*global_unreg_callback)(void);
106void (*global_timer_callback)(void);
107
108static void timer_cb(union sigval arg)
109{
110 (void)arg;
111 if (global_timer_callback)
112 global_timer_callback();
113}
114
115bool timer_register(int reg_prio, void (*unregister_callback)(void),
116 long cycles, void (*timer_callback)(void))
117{
118 int ret = 0;
119 struct itimerspec ts;
120 sigevent_t sigev;
121 long in_us = cycles_to_microseconds(cycles);
122
123 if (reg_prio <= timer_prio || in_us <= 0)
124 return false;
125
126 if (timer_prio >= 0 && global_unreg_callback)
127 global_unreg_callback();
128
129 /* initializing in the declaration causes some weird warnings */
130 memset(&sigev, 0, sizeof(sigevent_t));
131 sigev.sigev_notify = SIGEV_THREAD,
132 sigev.sigev_notify_function = timer_cb;
133
134 ts.it_value.tv_sec = ts.it_interval.tv_sec = in_us / 1000000;
135 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = (in_us%1000000)*1000;
136
137 /* add the timer */
138 ret |= timer_create(CLOCK_REALTIME, &sigev, &timer_tid);
139 ret |= timer_settime(timer_tid, 0, &ts, NULL);
140
141 global_timer_callback = timer_callback;
142 global_unreg_callback = unregister_callback;
143 timer_prio = reg_prio;
144
145 return ret == 0;
146}
147
148bool timer_set_period(long cycles)
149{
150 struct itimerspec ts;
151 long in_us = cycles_to_microseconds(cycles);
152 ts.it_value.tv_sec = ts.it_interval.tv_sec = in_us / 1000000;
153 ts.it_value.tv_nsec = ts.it_interval.tv_nsec = (in_us%1000000)*1000;
154
155 return timer_settime(timer_tid, 0, &ts, NULL) == 0;
156}
157
158void timer_unregister(void)
159{
160 timer_delete(timer_tid);
161 timer_prio = -1;
162}
163
diff --git a/firmware/target/hosted/ypr0/lc-ypr0.c b/firmware/target/hosted/ypr0/lc-ypr0.c
new file mode 100644
index 0000000000..434e901a56
--- /dev/null
+++ b/firmware/target/hosted/ypr0/lc-ypr0.c
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
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 <string.h> /* size_t */
23#include "load_code.h"
24
25/* the load_code wrappers simply wrap, nothing to do */
26void *lc_open(const char *filename, unsigned char *buf, size_t buf_size)
27{
28 return _lc_open(filename, buf, buf_size);
29}
30
31void *lc_get_header(void *handle)
32{
33 return _lc_get_header(handle);
34}
35
36void lc_close(void *handle)
37{
38 _lc_close(handle);
39}
40
diff --git a/firmware/target/hosted/ypr0/lcd-ypr0.c b/firmware/target/hosted/ypr0/lcd-ypr0.c
new file mode 100644
index 0000000000..f0565ae2d4
--- /dev/null
+++ b/firmware/target/hosted/ypr0/lcd-ypr0.c
@@ -0,0 +1,147 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: lcd-bitmap.c 29248 2011-02-08 20:05:25Z thomasjfox $
9 *
10 * Copyright (C) 2011 Lorenzo Miori, Thomas Martitz
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 <stdlib.h>
23#include <unistd.h>
24#include <stdio.h>
25#include "string.h"
26#include <linux/fb.h>
27#include <sys/mman.h>
28#include <sys/ioctl.h>
29
30#include "file.h"
31#include "debug.h"
32#include "system.h"
33#include "screendump.h"
34#include "lcd.h"
35
36/* eqivalent to fb + y*width + x */
37#define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
38
39static int dev_fd = 0;
40static fb_data *dev_fb = 0;
41
42void lcd_update(void)
43{
44 /* update the entire display */
45 memcpy(dev_fb, lcd_framebuffer, sizeof(lcd_framebuffer));
46}
47
48/* Copy Rockbox frame buffer to the mmapped lcd device */
49void lcd_update_rect(int x, int y, int width, int height)
50{
51 /* nothing to draw? */
52 if ((width <= 0) || (height <= 0) || (x >= LCD_WIDTH) ||
53 (y >= LCD_HEIGHT) || (x + width <= 0) || (y + height <= 0))
54 return;
55
56 /* do the necessary clipping */
57 if (x < 0)
58 { /* clip left */
59 width += x;
60 x = 0;
61 }
62 if (y < 0)
63 { /* clip top */
64 height += y;
65 y = 0;
66 }
67 if (x + width > LCD_WIDTH)
68 width = LCD_WIDTH - x; /* clip right */
69 if (y + height > LCD_HEIGHT)
70 height = LCD_HEIGHT - y; /* clip bottom */
71
72 fb_data* src = LCDADDR(x, y);
73 fb_data* dst = dev_fb + y*LCD_WIDTH + x;
74
75 if (LCD_WIDTH == width)
76 { /* optimized full-width update */
77 memcpy(dst, src, width * height * sizeof(fb_data));
78 }
79 else
80 { /* row by row */
81 do
82 {
83 memcpy(dst, src, width * sizeof(fb_data));
84 src += LCD_WIDTH;
85 dst += LCD_WIDTH;
86 } while(--height > 0);
87 }
88}
89
90void lcd_shutdown(void)
91{
92 printf("FB closed.");
93 munmap(dev_fb, sizeof(lcd_framebuffer));
94 close(dev_fd);
95}
96
97void lcd_init_device(void)
98{
99 size_t screensize;
100 struct fb_var_screeninfo vinfo;
101 struct fb_fix_screeninfo finfo;
102
103 /* Open the framebuffer device */
104 dev_fd = open("/dev/fb0", O_RDWR);
105 if (dev_fd == -1) {
106 perror("Error: cannot open framebuffer device");
107 exit(1);
108 }
109 printf("The framebuffer device was opened successfully.\n");
110
111 /* Get the fixed properties */
112 if (ioctl(dev_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
113 perror("Error reading fixed information");
114 exit(2);
115 }
116
117 /* Now we get the settable settings, and we set 16 bit bpp */
118 if (ioctl(dev_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
119 perror("Error reading variable information");
120 exit(3);
121 }
122
123 vinfo.bits_per_pixel = 16;
124
125 if (ioctl(dev_fd, FBIOPUT_VSCREENINFO, &vinfo)) {
126 perror("fbset(ioctl)");
127 exit(4);
128 }
129
130 printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
131
132 /* Figure out the size of the screen in bytes */
133 screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
134 if (screensize != sizeof(lcd_framebuffer))
135 {
136 exit(4);
137 perror("Display and framebuffer mismatch!\n");
138 }
139
140 /* Map the device to memory */
141 dev_fb = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0);
142 if ((int)dev_fb == -1) {
143 perror("Error: failed to map framebuffer device to memory");
144 exit(4);
145 }
146 printf("The framebuffer device was mapped to memory successfully.\n");
147}
diff --git a/firmware/target/hosted/ypr0/powermgmt-ypr0.c b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
new file mode 100644
index 0000000000..5701e9f02f
--- /dev/null
+++ b/firmware/target/hosted/ypr0/powermgmt-ypr0.c
@@ -0,0 +1,133 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: powermgmt-sim.c 29543 2011-03-08 19:33:30Z thomasjfox $
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "system.h"
21#include <time.h>
22#include "kernel.h"
23#include "powermgmt.h"
24#include "ascodec-target.h"
25#include "stdio.h"
26
27#if 0 /*still unused*/
28/* The battery manufacturer's website shows discharge curves down to 3.0V,
29 so 'dangerous' and 'shutoff' levels of 3.4V and 3.3V should be safe.
30 */
31const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
32{
33 3550
34};
35
36const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
37{
38 3450
39};
40
41/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
42const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
43{
44 { 3300, 3692, 3740, 3772, 3798, 3828, 3876, 3943, 4013, 4094, 4194 }
45};
46
47#if CONFIG_CHARGING
48/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
49const unsigned short percent_to_volt_charge[11] =
50{
51 3417, 3802, 3856, 3888, 3905, 3931, 3973, 4025, 4084, 4161, 4219
52};
53#endif /* CONFIG_CHARGING */
54#endif
55
56#define BATT_MINMVOLT 3450 /* minimum millivolts of battery */
57#define BATT_MAXMVOLT 4150 /* maximum millivolts of battery */
58#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in
59 minutes */
60
61extern void send_battery_level_event(void);
62extern int last_sent_battery_level;
63extern int battery_percent;
64
65static unsigned int battery_millivolts = BATT_MAXMVOLT;
66/* estimated remaining time in minutes */
67static int powermgmt_est_runningtime_min = BATT_MAXRUNTIME;
68
69static void battery_status_update(void)
70{
71 static time_t last_change = 0;
72 time_t now;
73
74 time(&now);
75
76 if (last_change < now) {
77 last_change = now;
78
79 battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) /
80 (BATT_MAXMVOLT - BATT_MINMVOLT);
81
82 powermgmt_est_runningtime_min =
83 battery_percent * BATT_MAXRUNTIME / 100;
84 }
85
86 send_battery_level_event();
87}
88
89void battery_read_info(int *voltage, int *level)
90{
91 battery_status_update();
92
93 if (voltage)
94 *voltage = battery_millivolts;
95
96 if (level)
97 *level = battery_percent;
98}
99
100unsigned int battery_voltage(void)
101{
102 battery_status_update();
103 return battery_millivolts;
104}
105
106int battery_level(void)
107{
108 battery_status_update();
109 return battery_percent;
110}
111
112int battery_time(void)
113{
114 battery_status_update();
115 return powermgmt_est_runningtime_min;
116}
117
118bool battery_level_safe(void)
119{
120 return battery_level() >= 10;
121}
122
123void set_battery_capacity(int capacity)
124{
125 (void)capacity;
126}
127
128#if BATTERY_TYPES_COUNT > 1
129void set_battery_type(int type)
130{
131 (void)type;
132}
133#endif
diff --git a/firmware/target/hosted/ypr0/system-target.h b/firmware/target/hosted/ypr0/system-target.h
new file mode 100644
index 0000000000..07a3163ea9
--- /dev/null
+++ b/firmware/target/hosted/ypr0/system-target.h
@@ -0,0 +1,37 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
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 __SYSTEM_TARGET_H__
22#define __SYSTEM_TARGET_H__
23
24#define disable_irq()
25#define enable_irq()
26#define disable_irq_save() 0
27#define restore_irq(level) (void)level
28
29void wait_for_interrupt(void);
30void interrupt(void);
31
32static inline void commit_dcache(void) {}
33static inline void commit_discard_dcache(void) {}
34static inline void commit_discard_idcache(void) {}
35
36#define NEED_GENERIC_BYTESWAPS
37#endif /* __SYSTEM_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/system-ypr0.c b/firmware/target/hosted/ypr0/system-ypr0.c
new file mode 100644
index 0000000000..3a2b30339f
--- /dev/null
+++ b/firmware/target/hosted/ypr0/system-ypr0.c
@@ -0,0 +1,106 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: system-sdl.c 29925 2011-05-25 20:11:03Z thomasjfox $
9 *
10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
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 <stdlib.h>
23#include <string.h>
24#include <inttypes.h>
25#include "system.h"
26#include "panic.h"
27#include "debug.h"
28
29#if defined(HAVE_SDL_AUDIO) || defined(HAVE_SDL_THREADS) || defined(HAVE_SDL)
30#include <SDL.h>
31#endif
32
33#include "ascodec-target.h"
34
35void sim_do_exit(void)
36{
37 exit(EXIT_SUCCESS);
38}
39
40void shutdown_hw(void)
41{
42 /* Something that we need to do before exit on our platform YPR0 */
43 ascodec_close();
44 sim_do_exit();
45}
46
47uintptr_t *stackbegin;
48uintptr_t *stackend;
49void system_init(void)
50{
51 int *s;
52 /* fake stack, OS manages size (and growth) */
53 stackbegin = stackend = (uintptr_t*)&s;
54
55#if defined(HAVE_SDL_AUDIO) || defined(HAVE_SDL_THREADS) || defined(HAVE_SDL)
56 SDL_Init(0); /* need this if using any SDL subsystem */
57#endif
58 /* Here begins our platform specific initilization for various things */
59 ascodec_init();
60}
61
62
63void system_reboot(void)
64{
65 sim_do_exit();
66}
67
68void system_exception_wait(void)
69{
70 system_reboot();
71}
72
73#ifdef HAVE_ADJUSTABLE_CPU_FREQ
74#include <stdio.h>
75#include "file.h"
76/* This is the Linux Kernel CPU governor... */
77static void set_cpu_freq(int speed)
78{
79 char temp[10];
80 int cpu_dev;
81 cpu_dev = open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", O_WRONLY);
82 if (cpu_dev < 0)
83 return;
84 write(cpu_dev, temp, sprintf(temp, "%d", speed) + 1);
85 close(cpu_dev);
86}
87
88void set_cpu_frequency(long frequency)
89{
90 switch (frequency)
91 {
92 case CPUFREQ_MAX:
93 set_cpu_freq(532000);
94 cpu_frequency = CPUFREQ_MAX;
95 break;
96 case CPUFREQ_NORMAL:
97 set_cpu_freq(400000);
98 cpu_frequency = CPUFREQ_NORMAL;
99 break;
100 default:
101 set_cpu_freq(200000);
102 cpu_frequency = CPUFREQ_DEFAULT;
103 break;
104 }
105}
106#endif
diff --git a/firmware/target/hosted/ypr0/usb-target.h b/firmware/target/hosted/ypr0/usb-target.h
new file mode 100644
index 0000000000..237d179775
--- /dev/null
+++ b/firmware/target/hosted/ypr0/usb-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: usb-target.h 29516 2011-03-05 15:31:52Z thomasjfox $
9 *
10 * Copyright (C) 2010 by Thomas Martitz
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#ifndef __USB_TARGET_H__
23#define __USB_TARGET_H__
24
25#endif /* __USB_TARGET_H__ */
diff --git a/firmware/target/hosted/ypr0/ypr0.make b/firmware/target/hosted/ypr0/ypr0.make
new file mode 100644
index 0000000000..c2114878db
--- /dev/null
+++ b/firmware/target/hosted/ypr0/ypr0.make
@@ -0,0 +1,25 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10INCLUDES += -I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR)
11
12SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS)
13
14.SECONDEXPANSION: # $$(OBJ) is not populated until after this
15
16
17$(BUILDDIR)/rockbox.elf : $$(OBJ) $$(FIRMLIB) $$(VOICESPEEXLIB) $$(SKINLIB)
18 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -o $@ $(OBJ) \
19 -L$(BUILDDIR)/firmware -lfirmware \
20 -L$(BUILDDIR)/apps/codecs $(VOICESPEEXLIB:lib%.a=-l%) \
21 -L$(BUILDDIR)/lib -lskin_parser \
22 $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,-Map,$(BUILDDIR)/rockbox.map
23
24$(BUILDDIR)/rockbox : $(BUILDDIR)/rockbox.elf
25 $(call PRINTS,OC $(@F))$(OC) -S -x $< $@