summaryrefslogtreecommitdiff
path: root/firmware/export/axp173.h
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-02-27 22:08:58 +0000
committerAidan MacDonald <amachronic@protonmail.com>2021-03-28 00:01:37 +0000
commit3ec66893e377b088c1284d2d23adb2aeea6d7965 (patch)
treeb647717f83ad56b15dc42cfdef5d04d68cd9bd6b /firmware/export/axp173.h
parent83fcbedc65f4b9ae7e491ecf6f07c0af4b245f74 (diff)
downloadrockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.tar.gz
rockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.zip
New port: FiiO M3K on bare metal
Change-Id: I7517e7d5459e129dcfc9465c6fbd708619888fbe
Diffstat (limited to 'firmware/export/axp173.h')
-rw-r--r--firmware/export/axp173.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/firmware/export/axp173.h b/firmware/export/axp173.h
new file mode 100644
index 0000000000..60519138e1
--- /dev/null
+++ b/firmware/export/axp173.h
@@ -0,0 +1,94 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
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 __AXP173_H__
23#define __AXP173_H__
24
25#include <stdbool.h>
26#include <stdint.h>
27
28#define ADC_ACIN_VOLTAGE 0
29#define ADC_ACIN_CURRENT 1
30#define ADC_VBUS_VOLTAGE 2
31#define ADC_VBUS_CURRENT 3
32#define ADC_INTERNAL_TEMP 4
33#define ADC_TS_INPUT 5
34#define ADC_BATTERY_VOLTAGE 6
35#define ADC_CHARGE_CURRENT 7
36#define ADC_DISCHARGE_CURRENT 8
37#define ADC_APS_VOLTAGE 9
38#define ADC_BATTERY_POWER 10
39#define NUM_ADC_CHANNELS 11
40
41/* ADC sampling rates */
42#define AXP173_ADC_RATE_25HZ 0
43#define AXP173_ADC_RATE_50HZ 1
44#define AXP173_ADC_RATE_100HZ 2
45#define AXP173_ADC_RATE_200HZ 3
46
47/* Return values of axp173_battery_status() */
48#define AXP173_BATT_DISCHARGING 0
49#define AXP173_BATT_CHARGING 1
50#define AXP173_BATT_FULL 2
51
52/* Bits returned by axp173_input_status() */
53#define AXP173_INPUT_AC (1 << 0)
54#define AXP173_INPUT_USB (1 << 1)
55#define AXP173_INPUT_BATTERY (1 << 2)
56#define AXP173_INPUT_EXTERNAL (AXP173_INPUT_AC|AXP173_INPUT_USB)
57
58/* Must be called from power_init() to initialize the driver state */
59extern void axp173_init(void);
60
61/* Basic battery and power supply status */
62extern int axp173_battery_status(void);
63extern int axp173_input_status(void);
64
65/* ADC access -- ADCs which are not enabled will return INT_MIN if read.
66 * The output of axp173_adc_read() is normalized to appropriate units:
67 *
68 * - for voltages, the scale is millivolts
69 * - for currents, the scale is milliamps
70 * - for temperatures, the scale is tenths of a degree Celsius
71 * - for power, the scale is microwatts
72 *
73 * See the comment in axp173_adc_conv_raw() for raw value precision/scale.
74 */
75extern int axp173_adc_read(int adc);
76extern int axp173_adc_read_raw(int adc);
77extern int axp173_adc_conv_raw(int adc, int value);
78extern int axp173_adc_get_enabled(void);
79extern void axp173_adc_set_enabled(int adc_bits);
80extern int axp173_adc_get_rate(void);
81extern void axp173_adc_set_rate(int rate);
82
83/* - axp173_cc_read() reads the coulomb counters
84 * - axp173_cc_clear() resets both counters to zero
85 * - axp173_cc_enable() will stop/start the counters running
86 */
87extern void axp173_cc_read(uint32_t* charge, uint32_t* discharge);
88extern void axp173_cc_clear(void);
89extern void axp173_cc_enable(bool en);
90
91/* Debug menu */
92extern bool axp173_debug_menu(void);
93
94#endif /* __AXP173_H__ */