Moto Mods Firmware: Battery Protocol

Overview

The Battery protocol allows the Moto Z to inquire about the battery on the Moto Mod.  The data includes battery voltage, temperature and capacity. 
  
To provide and receive power from the Moto Z, the Moto Mod is required to support the Power Transfer Protocol.


Hardware Manifest

Hardware Manifest files reside in apps/greybus-utils/manifests, one should be created for your unique project.

0x08 is the identifier for the Battery protocol.

Two entries are necessary for Battery, one for the Interface and one for the Bundle.

To support Charge Only mode, the Battery protocol must be in the Bundle with the Power Transfer protocol. If any other protocols are included in the bundle with Power Transfer and Battery, the Moto Mod will not be supported in Charge Only mode.

; Battery interface on CPort XX
[cport-descriptor XX]
bundle = YY
protocol = 0x08

; Battery related Bundle YY
[bundle-descriptor YY]
class = 0x08

XX shall be a unique integer (within your hardware manifest) defining which CPort is used for Battery.

YY shall be a unique integer (within your hardware manifest) which Bundle the Battery CPort is a member of.


Implementation

The Low level Battery device driver is specific to the hardware and reports current battery state upon requests.

Files

nuttx/include/nuttx/device_battery.h

This file defines the device_battery_type_ops structure and provides the glue to the Greybus Battery channel.

nuttx/configs/ara/bridge/src/battery_dummy.c

This file provides the starting point for your development. It should be copied into nuttx/configs/PROJECT/src for your specific Project and modified.

Methods

A battery device driver must implement methods defined in the device_battery_type_ops structure.

Reporting battery technology type: get_technology

The get_technology function reports the technology type of the Moto Mod battery from a set of defined types.

int (*get_technology)(struct device *dev, uint32_t *tech)
Parameters
dev Pointer to structure of device data
tech The output value is battery technology, based off a set of defined values:
GB_BATTERY_TECH_UNKNOWN
GB_BATTERY_TECH_NiMH
GB_BATTERY_TECH_LION
GB_BATTERY_TECH_LIPO
GB_BATTERY_TECH_LiFe
GB_BATTERY_TECH_NiCd
GB_BATTERY_TECH_LiMn
0x0000
0x0001
0x0002
0x0003
0x0004
0x0005
0x0006
Return
int 0 on success, negative errno on error

Reporting battery charging status: get_status

The get_status function reports the current charging status of the Moto Mod battery.

int (*get_status)(struct device *dev, uint16_t *status)
Parameters
dev Pointer to structure of device data
status The output value is battery status
Return
int 0 on success, negative errno on error

Reporting battery voltage: get_voltage

The get_voltage function reports an accurate reading of the Moto Mod battery voltage.

int (*get_voltage)(struct device *dev, uint32_t *voltage)
Parameters
dev Pointer to structure of device data
voltage The output value is battery voltage in microvolts
Return
int 0 on success, negative errno on error

Reporting battery current: get_current

The get_current function reports an accurate reading of the current being currently supplied or drawn from the Moto Mod battery.

int (*get_current)(struct device *dev, int *current)
Parameters
dev Pointer to structure of device data
current The output value is battery current in microamps
Return
int 0 on success, negative errno on error

Reporting battery capacity in percentage: get_percent_capacity

The get_percent_capacity function reports Moto Mod battery percent capacity.

int (*get_percent_capacity)(struct device *dev, uint32_t *percent_cap)
Parameters
dev Pointer to structure of device data
percent_cap The output value is battery level in percent
Return
int 0 on success, negative errno on error

Reporting battery total capacity: get_total_capacity

The get_total_capacity function reports total Moto Mod battery capacity.

int (*get_total_capacity)(struct device *dev, uint32_t *total_cap)
Parameters
dev Pointer to structure of device data
total_cap The output value is battery total design capacity in mAh
Return
int 0 on success, negative errno on error

Reporting battery temperature: get_temperature

The get_temperature function reports current temperature of the Moto Mod battery.

int (*get_temperature)(struct device *dev, int *temperature)
Parameters
dev Pointer to structure of device data
temperature The output value is battery temperature in 0.1 Celsius
Return
int 0 on success, negative errno on error