diff options
Diffstat (limited to 'firmware/target/arm/tms320dm320/sansa-connect')
-rw-r--r-- | firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c | 11 | ||||
-rw-r--r-- | firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c | 65 |
2 files changed, 8 insertions, 68 deletions
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c index 6a649038b7..ec35af9f62 100644 --- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c +++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c | |||
@@ -79,6 +79,8 @@ static const char btn_thread_name[] = "buttons"; | |||
79 | static struct event_queue btn_queue; | 79 | static struct event_queue btn_queue; |
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | static int current_battery_level = 100; | ||
83 | |||
82 | static inline unsigned short be2short(unsigned char* buf) | 84 | static inline unsigned short be2short(unsigned char* buf) |
83 | { | 85 | { |
84 | return (unsigned short)((buf[0] << 8) | buf[1]); | 86 | return (unsigned short)((buf[0] << 8) | buf[1]); |
@@ -284,8 +286,11 @@ void avr_hid_init(void) | |||
284 | mutex_init(&avr_mtx); | 286 | mutex_init(&avr_mtx); |
285 | } | 287 | } |
286 | 288 | ||
287 | /* defined in powermgmt-sansaconnect.c */ | 289 | int _battery_level(void) |
288 | void set_battery_level(unsigned int level); | 290 | { |
291 | /* Force shutoff when level read by AVR is 4 or lower */ | ||
292 | return (current_battery_level > 4) ? current_battery_level : 0; | ||
293 | } | ||
289 | 294 | ||
290 | static void avr_hid_get_state(void) | 295 | static void avr_hid_get_state(void) |
291 | { | 296 | { |
@@ -302,7 +307,7 @@ static void avr_hid_get_state(void) | |||
302 | * buf[8] contains some battery/charger related information (unknown) | 307 | * buf[8] contains some battery/charger related information (unknown) |
303 | * buf[9] contains battery level in percents (0-100) | 308 | * buf[9] contains battery level in percents (0-100) |
304 | */ | 309 | */ |
305 | set_battery_level((unsigned int)buf[9]); | 310 | current_battery_level = (int)buf[9]; |
306 | 311 | ||
307 | spi_txrx(cmd_empty, NULL, 1); /* request interrupt on button press */ | 312 | spi_txrx(cmd_empty, NULL, 1); /* request interrupt on button press */ |
308 | 313 | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c deleted file mode 100644 index 8b3f05107c..0000000000 --- a/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
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 "powermgmt.h" | ||
25 | #include "kernel.h" | ||
26 | |||
27 | /* Use fake linear scale as AVR does the voltage to percentage conversion */ | ||
28 | |||
29 | static unsigned int current_battery_level = 100; | ||
30 | |||
31 | /* This specifies the battery level that writes are still safe */ | ||
32 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
33 | { | ||
34 | 5 | ||
35 | }; | ||
36 | |||
37 | /* Below this the player cannot be considered to operate reliably */ | ||
38 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
39 | { | ||
40 | 4 | ||
41 | }; | ||
42 | |||
43 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
44 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | ||
45 | { | ||
46 | { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }, | ||
47 | }; | ||
48 | |||
49 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | ||
50 | const unsigned short percent_to_volt_charge[11] = | ||
51 | { | ||
52 | 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, | ||
53 | }; | ||
54 | |||
55 | /* Returns battery voltage from ADC [millivolts] */ | ||
56 | int _battery_voltage(void) | ||
57 | { | ||
58 | return current_battery_level; | ||
59 | } | ||
60 | |||
61 | void set_battery_level(unsigned int level) | ||
62 | { | ||
63 | current_battery_level = level; | ||
64 | } | ||
65 | |||