Line data Source code
1 1 : /* 2 : * Copyright (c) 2022 Google LLC 3 : * 4 : * SPDX-License-Identifier: Apache-2.0 5 : */ 6 : 7 : /** 8 : * @file 9 : * @brief Backend APIs for the BC1.2 emulators. 10 : */ 11 : 12 : #ifndef ZEPHYR_INCLUDE_DRIVERS_USB_EMUL_BC12_H_ 13 : #define ZEPHYR_INCLUDE_DRIVERS_USB_EMUL_BC12_H_ 14 : 15 : #include <zephyr/drivers/emul.h> 16 : #include <zephyr/drivers/usb/usb_bc12.h> 17 : 18 : #ifdef __cplusplus 19 : extern "C" { 20 : #endif 21 : 22 : /** 23 : * @brief BC1.2 backend emulator APIs 24 : * @defgroup b12_emulator_backend BC1.2 backed emulator APIs 25 : * @ingroup io_interfaces 26 : * @{ 27 : */ 28 : 29 : /** 30 : * @cond INTERNAL_HIDDEN 31 : * 32 : * These are for internal use only, so skip these in public documentation. 33 : */ 34 : __subsystem struct bc12_emul_driver_api { 35 : int (*set_charging_partner)(const struct emul *emul, enum bc12_type partner_type); 36 : int (*set_pd_partner)(const struct emul *emul, bool connected); 37 : }; 38 : /** 39 : * @endcond 40 : */ 41 : 42 : /** 43 : * @brief Set the charging partner type connected to the BC1.2 device. 44 : * 45 : * The corresponding BC1.2 emulator updates the vendor specific registers 46 : * to simulate connection of the specified charging partner type. The emulator 47 : * also generates an interrupt for processing by the real driver, if supported. 48 : * 49 : * @param target Pointer to the emulator structure for the BC1.2 emulator instance. 50 : * @param partner_type The simulated partner type. Set to BC12_TYPE_NONE to 51 : * disconnect the charging partner. 52 : * 53 : * @retval 0 If successful. 54 : * @retval -EINVAL if the partner type is not supported. 55 : */ 56 1 : static inline int bc12_emul_set_charging_partner(const struct emul *target, 57 : enum bc12_type partner_type) 58 : { 59 : const struct bc12_emul_driver_api *backend_api = 60 : (const struct bc12_emul_driver_api *)target->backend_api; 61 : 62 : return backend_api->set_charging_partner(target, partner_type); 63 : } 64 : 65 : /** 66 : * @brief Set the portable device partner state. 67 : * 68 : * The corresponding BC1.2 emulator updates the vendor specific registers 69 : * to simulate connection or disconnection of a portable device partner. 70 : * The emulator also generates an interrupt for processing by the real driver, 71 : * if supported. 72 : * 73 : * @param target Pointer to the emulator structure for the BC1.2 emulator instance. 74 : * @param connected If true, emulate a connection of a portable device partner. If 75 : * false, emulate a disconnect event. 76 : * 77 : * @retval 0 If successful. 78 : * @retval -EINVAL if the connection/disconnection of PD partner is not supported. 79 : */ 80 1 : static inline int bc12_emul_set_pd_partner(const struct emul *target, bool connected) 81 : { 82 : const struct bc12_emul_driver_api *backend_api = 83 : (const struct bc12_emul_driver_api *)target->backend_api; 84 : 85 : return backend_api->set_pd_partner(target, connected); 86 : } 87 : 88 : #ifdef __cplusplus 89 : } 90 : #endif 91 : 92 : /** 93 : * @} 94 : */ 95 : 96 : #endif /* ZEPHYR_INCLUDE_DRIVERS_USB_EMUL_BC12_H_ */