diff options
author | Tomasz Moń <desowin@gmail.com> | 2021-06-10 08:43:32 +0200 |
---|---|---|
committer | Tomasz Moń <desowin@gmail.com> | 2021-06-10 08:43:32 +0200 |
commit | 551c74da55dc15238e76713d7477e7e4bfda60ef (patch) | |
tree | 90273d5fcda52138f8e47073ec106da2076eb2da /firmware/target | |
parent | f26499bd6717820607802ee99b9fa3d00a3d5dc4 (diff) |
Sansa Connect: Remove fake battery voltage scale
Use battery percentage as reported by AVR.
Change-Id: Id697d460b240798eb0b103f9e1f419906b87e9ca
Diffstat (limited to 'firmware/target')
-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"; static struct event_queue btn_queue; #endif +static int current_battery_level = 100; + static inline unsigned short be2short(unsigned char* buf) { return (unsigned short)((buf[0] << 8) | buf[1]); @@ -284,8 +286,11 @@ void avr_hid_init(void) mutex_init(&avr_mtx); } -/* defined in powermgmt-sansaconnect.c */ -void set_battery_level(unsigned int level); +int _battery_level(void) +{ + /* Force shutoff when level read by AVR is 4 or lower */ + return (current_battery_level > 4) ? current_battery_level : 0; +} static void avr_hid_get_state(void) { @@ -302,7 +307,7 @@ static void avr_hid_get_state(void) * buf[8] contains some battery/charger related information (unknown) * buf[9] contains battery level in percents (0-100) */ - set_battery_level((unsigned int)buf[9]); + current_battery_level = (int)buf[9]; spi_txrx(cmd_empty, NULL, 1); /* request interrupt on button press */ 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 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id: $ - * - * Copyright (C) 2011 by Tomasz Moń - * - * 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 "powermgmt.h" -#include "kernel.h" - -/* Use fake linear scale as AVR does the voltage to percentage conversion */ - -static unsigned int current_battery_level = 100; - -/* This specifies the battery level that writes are still safe */ -const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = -{ - 5 -}; - -/* Below this the player cannot be considered to operate reliably */ -const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = -{ - 4 -}; - -/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ -const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = -{ - { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }, -}; - -/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ -const unsigned short percent_to_volt_charge[11] = -{ - 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, -}; - -/* Returns battery voltage from ADC [millivolts] */ -int _battery_voltage(void) -{ - return current_battery_level; -} - -void set_battery_level(unsigned int level) -{ - current_battery_level = level; -} - |