Zephyr API 3.6.99
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
103 union {
104 struct {
108 };
109 struct {
111 };
112 };
113};
114
125typedef void (*bc12_callback_t)(const struct device *dev, struct bc12_partner_state *state,
126 void *user_data);
127
133__subsystem struct bc12_driver_api {
134 int (*set_role)(const struct device *dev, enum bc12_role role);
135 int (*set_result_cb)(const struct device *dev, bc12_callback_t cb, void *user_data);
136};
150__syscall int bc12_set_role(const struct device *dev, enum bc12_role role);
151
152static inline int z_impl_bc12_set_role(const struct device *dev, enum bc12_role role)
153{
154 const struct bc12_driver_api *api = (const struct bc12_driver_api *)dev->api;
155
156 return api->set_role(dev, role);
157}
158
169__syscall int bc12_set_result_cb(const struct device *dev, bc12_callback_t cb, void *user_data);
170
171static inline int z_impl_bc12_set_result_cb(const struct device *dev, bc12_callback_t cb,
172 void *user_data)
173{
174 const struct bc12_driver_api *api = (const struct bc12_driver_api *)dev->api;
175
176 return api->set_result_cb(dev, cb, user_data);
177}
178
179#ifdef __cplusplus
180}
181#endif
182
187#include <zephyr/syscalls/usb_bc12.h>
188
189#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:125
@ BC12_CHARGING_PORT
Definition usb_bc12.h:68
@ BC12_DISCONNECTED
Definition usb_bc12.h:66
@ BC12_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:101
int voltage_uv
Definition usb_bc12.h:107
int current_ua
Definition usb_bc12.h:106
bool pd_partner_connected
Definition usb_bc12.h:110
enum bc12_role bc12_role
Definition usb_bc12.h:102
enum bc12_type type
Definition usb_bc12.h:105
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409