blob: 5c2e0b49a18cc88c2768eea31c8741174fd95d0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* power_button.h - Power button function.
* Hides chip-specific implementation behind this interface.
*/
#ifndef __CHIP_INTERFACE_BATTERY_H
#define __CHIP_INTERFACE_BATTERY_H
/*********** Battery SMBus *********************************************/
/* Initialize the SMBus */
EcError EcBatteryInit(void);
/* Send a command to battery. Blocking */
EcError EcBatterySendCommand(...);
/* non-blocking read so that it can support both polling mode
* and interrupt callback.
*/
EcError EcBatteryRecvCommand(...);
/* Register a callback when a packet comes from SMBus */
EcError EcRegisterBatteryInterrupt(void (*isr)(...));
#if 0 /* example code */
void BatteryPacketArrive(...) {
EcBatteryRecvCommand(); // read the packet.
}
... somewhere in code ...
EcRegisterBatteryInterrupt(BatteryPacketArrive);
#endif
/*********** Battery Present *********************************************/
/*
* Initialize the battery present as GPIO input pin and enable interrupt for
* callback.
*/
EcError EcBatteryPresentInit(void);
/* Calls GPIOPinRead() to read the GPIO state. */
/* TODO: has the state been debounced? */
EcError EcBatteryPrensentState(void);
/* Register a calback function. It is called while AC is plugged in or
* unplugged.
*/
EcError EcBatteryPresentRegister(void (*callback)(void));
/* Below is the example code to register this function. */
#if 0
/* This callback function is implemented in Chrome OS features layer. */
void BatteryStateChanged(void) {
int battery_present = EcBatteryPresentState();
if (battery_present) {
// start to authenticate battery;
// once authenticated, charge the battery;
} else {
// stop charge battery;
}
}
... somewhere in init code ...
EcBatteryPresentRegister(BatteryStateChanged);
#endif /* #if 0 */
#endif /* __CHIP_INTERFACE_BATTERY_H */
|