Zephyr Project API 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
usb_bc12.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Google LLC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_USB_USB_BC12_H_
13#define ZEPHYR_INCLUDE_DRIVERS_USB_USB_BC12_H_
14
15#include <zephyr/device.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
28/* FIXME - make these Kconfig options */
29
36#define BC12_CHARGER_VOLTAGE_UV 5000 * 1000
48#define BC12_CHARGER_MIN_CURR_UA 2500
50#define BC12_CHARGER_MAX_CURR_UA 1500 * 1000
51
61#define BC12_CURR_UA(val) CLAMP(val, BC12_CHARGER_MIN_CURR_UA, BC12_CHARGER_MAX_CURR_UA)
70
88
95 union {
96 struct {
112 };
113 struct {
119 };
120 };
121};
122
133typedef void (*bc12_callback_t)(const struct device *dev, struct bc12_partner_state *state,
134 void *user_data);
135
141__subsystem struct bc12_driver_api {
142 int (*set_role)(const struct device *dev, enum bc12_role role);
143 int (*set_result_cb)(const struct device *dev, bc12_callback_t cb, void *user_data);
144};
158__syscall int bc12_set_role(const struct device *dev, enum bc12_role role);
159
160static inline int z_impl_bc12_set_role(const struct device *dev, enum bc12_role role)
161{
162 const struct bc12_driver_api *api = (const struct bc12_driver_api *)dev->api;
163
164 return api->set_role(dev, role);
165}
166
177__syscall int bc12_set_result_cb(const struct device *dev, bc12_callback_t cb, void *user_data);
178
179static inline int z_impl_bc12_set_result_cb(const struct device *dev, bc12_callback_t cb,
180 void *user_data)
181{
182 const struct bc12_driver_api *api = (const struct bc12_driver_api *)dev->api;
183
184 return api->set_result_cb(dev, cb, user_data);
185}
186
187#ifdef __cplusplus
188}
189#endif
190
195#include <zephyr/syscalls/usb_bc12.h>
196
197#endif /* ZEPHYR_INCLUDE_DRIVERS_USB_USB_BC12_H_ */
bc12_role
BC1.2 device role.
Definition usb_bc12.h:65
int bc12_set_result_cb(const struct device *dev, bc12_callback_t cb, void *user_data)
Register a callback for BC1.2 results.
int bc12_set_role(const struct device *dev, enum bc12_role role)
Set the BC1.2 role.
bc12_type
BC1.2 charging partner type.
Definition usb_bc12.h:72
void(* bc12_callback_t)(const struct device *dev, struct bc12_partner_state *state, void *user_data)
BC1.2 callback for charger configuration.
Definition usb_bc12.h:133
@ BC12_CHARGING_PORT
BC1.2 device is a charging port.
Definition usb_bc12.h:68
@ BC12_DISCONNECTED
No BC1.2 device connected.
Definition usb_bc12.h:66
@ BC12_PORTABLE_DEVICE
BC1.2 device is a portable device.
Definition usb_bc12.h:67
@ BC12_TYPE_PROPRIETARY
Proprietary charging port.
Definition usb_bc12.h:82
@ BC12_TYPE_UNKNOWN
Unknown charging port, BC1.2 detection failed.
Definition usb_bc12.h:84
@ BC12_TYPE_CDP
Charging Downstream Port.
Definition usb_bc12.h:80
@ BC12_TYPE_SDP
Standard Downstream Port.
Definition usb_bc12.h:76
@ BC12_TYPE_NONE
No partner connected.
Definition usb_bc12.h:74
@ BC12_TYPE_COUNT
Count of valid BC12 types.
Definition usb_bc12.h:86
@ BC12_TYPE_DCP
Dedicated Charging Port.
Definition usb_bc12.h:78
state
Definition parser_state.h:29
BC1.2 detected partner state.
Definition usb_bc12.h:92
int voltage_uv
Voltage, in uV, that the charging partner provides.
Definition usb_bc12.h:111
int current_ua
Current, in uA, that the charging partner provides.
Definition usb_bc12.h:106
bool pd_partner_connected
True if a PD partner is currently connected.
Definition usb_bc12.h:118
enum bc12_role bc12_role
Current role of the BC1.2 device.
Definition usb_bc12.h:94
enum bc12_type type
Charging partner type.
Definition usb_bc12.h:101
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516