summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2021-06-20 10:06:32 +0200
committerTomasz Moń <desowin@gmail.com>2021-06-20 10:33:46 +0000
commit2ca5774cf9613b0f2c1d31d6054911b8cb36e131 (patch)
treeedf53ec38a68ee731250664d9565f01d65e48496
parent0faf978c3dec53f62c0b1624e883e9ee03b9c788 (diff)
downloadrockbox-2ca5774cf9613b0f2c1d31d6054911b8cb36e131.tar.gz
rockbox-2ca5774cf9613b0f2c1d31d6054911b8cb36e131.zip
Sansa Connect: Indicate charging status
Consider battery level down to 0 as safe as OF continues to operate normally even when at level 0. Change-Id: Ie3889e5662b9fa6588e20ad02d8953f29e28800c
-rw-r--r--firmware/export/config/sansaconnect.h2
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c53
-rw-r--r--firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c14
3 files changed, 41 insertions, 28 deletions
diff --git a/firmware/export/config/sansaconnect.h b/firmware/export/config/sansaconnect.h
index 016c8d108d..5909d3bf84 100644
--- a/firmware/export/config/sansaconnect.h
+++ b/firmware/export/config/sansaconnect.h
@@ -180,7 +180,7 @@
180#define FIRMWARE_OFFSET_FILE_DATA 8 180#define FIRMWARE_OFFSET_FILE_DATA 8
181 181
182/* Hardware controlled charging */ 182/* Hardware controlled charging */
183#define CONFIG_CHARGING CHARGING_SIMPLE 183#define CONFIG_CHARGING CHARGING_MONITOR
184 184
185#define CONFIG_USBOTG USBOTG_TNETV105 185#define CONFIG_USBOTG USBOTG_TNETV105
186 186
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
index 47c5489657..9d91093a02 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c
@@ -22,6 +22,7 @@
22#include <stdio.h> 22#include <stdio.h>
23#include "config.h" 23#include "config.h"
24#include "system.h" 24#include "system.h"
25#include "power.h"
25#include "kernel.h" 26#include "kernel.h"
26#include "logf.h" 27#include "logf.h"
27#include "avr-sansaconnect.h" 28#include "avr-sansaconnect.h"
@@ -80,7 +81,17 @@ static const char avr_thread_name[] = "avr";
80static struct semaphore avr_thread_trigger; 81static struct semaphore avr_thread_trigger;
81#endif 82#endif
82 83
83static int current_battery_level = 100; 84/* OF bootloader will refuse to start software if low power is set
85 * Bits 3, 4, 5, 6 and 7 are unknown.
86 */
87#define BATTERY_STATUS_LOW_POWER (1 << 2)
88#define BATTERY_STATUS_CHARGER_CONNECTED (1 << 1)
89#define BATTERY_STATUS_CHARGING (1 << 0)
90static uint8_t avr_battery_status;
91
92#define BATTERY_LEVEL_NOT_DETECTED (1 << 7)
93#define BATTERY_LEVEL_PERCENTAGE_MASK 0x7F
94static uint8_t avr_battery_level = 100;
84 95
85static inline unsigned short be2short(unsigned char* buf) 96static inline unsigned short be2short(unsigned char* buf)
86{ 97{
@@ -289,8 +300,26 @@ void avr_hid_init(void)
289 300
290int _battery_level(void) 301int _battery_level(void)
291{ 302{
292 /* Force shutoff when level read by AVR is 4 or lower */ 303 /* OF still plays music when level is at 0 */
293 return (current_battery_level > 4) ? current_battery_level : 0; 304 if (avr_battery_level & BATTERY_LEVEL_NOT_DETECTED)
305 {
306 return 0;
307 }
308 return avr_battery_level & BATTERY_LEVEL_PERCENTAGE_MASK;
309}
310
311unsigned int power_input_status(void)
312{
313 if (avr_battery_status & BATTERY_STATUS_CHARGER_CONNECTED)
314 {
315 return POWER_INPUT_USB_CHARGER;
316 }
317 return POWER_INPUT_NONE;
318}
319
320bool charging_state(void)
321{
322 return (avr_battery_status & BATTERY_STATUS_CHARGING) != 0;
294} 323}
295 324
296static void avr_hid_get_state(void) 325static void avr_hid_get_state(void)
@@ -300,18 +329,16 @@ static void avr_hid_get_state(void)
300 CMD_CLOSE}; 329 CMD_CLOSE};
301 330
302 static unsigned char buf[11]; 331 static unsigned char buf[11];
303 static unsigned char cmd_empty[1] = {0xCC};
304
305 spi_txrx(cmd, buf, sizeof(cmd));
306 332
307 /* 333 /* In very unlikely case the command has to be repeated */
308 * buf[8] contains some battery/charger related information (unknown) 334 do
309 * buf[9] contains battery level in percents (0-100) 335 {
310 */ 336 spi_txrx(cmd, buf, sizeof(cmd));
311 current_battery_level = (int)buf[9]; 337 }
312 338 while ((buf[1] != CMD_SYNC) || (buf[10] != CMD_CLOSE));
313 spi_txrx(cmd_empty, NULL, 1); /* request interrupt on button press */
314 339
340 avr_battery_status = buf[8];
341 avr_battery_level = buf[9];
315 parse_button_state(buf); 342 parse_button_state(buf);
316} 343}
317 344
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c
index ecdf3b1a75..b139572605 100644
--- a/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c
+++ b/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c
@@ -74,21 +74,7 @@ void power_off(void)
74 avr_hid_power_off(); 74 avr_hid_power_off();
75} 75}
76 76
77#if CONFIG_CHARGING
78unsigned int power_input_status(void)
79{
80 return POWER_INPUT_NONE;
81}
82
83/* Returns true if the unit is charging the batteries. */
84bool charging_state(void)
85{
86 return false;
87}
88#endif
89
90void ide_power_enable(bool on) 77void ide_power_enable(bool on)
91{ 78{
92 (void)on; 79 (void)on;
93} 80}
94