summaryrefslogtreecommitdiff
path: root/chip_interface/battery.h
blob: e5c3337a9c0a7151657ffd12214d183b0fc008e6 (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
/* power_button.h - Power button function.
 *                  Hides chip-specific implementation behind this interface.
 *
 * (Chromium license) */

#ifndef __CHIP_INTERFACE_BATTERY_H
#define __CHIP_INTERFACE_BATTERY_H


/***********  Battery SMBus  *********************************************/
/* Initialize the SMBus */
EcError CrBatteryInit(void);

/* Send a command to battery. Blocking */
EcError CrBatterySendCommand(...);

/* non-blocking read so that it can support both polling mode
 * and interrupt callback.
 */
EcError CrBatteryRecvCommand(...);

/* Register a callback when a packet comes from SMBus */
EcError CrRegisterBatteryInterrupt(void (*isr)(...));

#if 0  /* example code */
void BatteryPacketArrive(...) {
  CrBatteryRecvCommand();  // read the packet.
}

  ... somewhere in code ...
  CrRegisterBatteryInterrupt(BatteryPacketArrive);

#endif


/***********  Battery Present  *********************************************/
/*
 * Initialize the battery present as GPIO input pin and enable interrupt for
 * callback.
 */
EcError CrBatteryPresentInit(void);

/* Calls GPIOPinRead() to read the GPIO state. */
/* TODO: has the state been debounced? */
EcError CrBatteryPrensentState(void);

/* Register a calback function. It is called while AC is plugged in or
 * unplugged.
 */
EcError CrBatteryPresentRegister(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 = CrBatteryPresentState();
  if (battery_present) {
    // start to authenticate battery;
    // once authenticated, charge the battery;
  } else {
    // stop charge battery;
  }
}
  ... somewhere in init code ...
  CrBatteryPresentRegister(BatteryStateChanged);

#endif /* #if 0 */

#endif  /* __CHIP_INTERFACE_BATTERY_H */