summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2021-06-10 08:43:32 +0200
committerTomasz Moń <desowin@gmail.com>2021-06-10 08:43:32 +0200
commit551c74da55dc15238e76713d7477e7e4bfda60ef (patch)
tree90273d5fcda52138f8e47073ec106da2076eb2da /firmware/target/arm
parentf26499bd6717820607802ee99b9fa3d00a3d5dc4 (diff)
downloadrockbox-551c74da55dc15238e76713d7477e7e4bfda60ef.tar.gz
rockbox-551c74da55dc15238e76713d7477e7e4bfda60ef.zip
Sansa Connect: Remove fake battery voltage scale
Use battery percentage as reported by AVR. Change-Id: Id697d460b240798eb0b103f9e1f419906b87e9ca
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c11
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c65
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";
79static struct event_queue btn_queue; 79static struct event_queue btn_queue;
80#endif 80#endif
81 81
82static int current_battery_level = 100;
83
82static inline unsigned short be2short(unsigned char* buf) 84static 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 */ 289int _battery_level(void)
288void 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
290static void avr_hid_get_state(void) 295static 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
29static unsigned int current_battery_level = 100;
30
31/* This specifies the battery level that writes are still safe */
32const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
33{
34 5
35};
36
37/* Below this the player cannot be considered to operate reliably */
38const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
39{
40 4
41};
42
43/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
44const 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 */
50const 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] */
56int _battery_voltage(void)
57{
58 return current_battery_level;
59}
60
61void set_battery_level(unsigned int level)
62{
63 current_battery_level = level;
64}
65