summaryrefslogtreecommitdiff
path: root/zephyr/include/emul/emul_charger.h
blob: 87303181e866a24f7aef0de7ba3cb9784a27c55e (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
/* Copyright 2021 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/**
 * @file
 *
 * @brief Backend API for USB-C charger emulator
 */

#ifndef __EMUL_CHARGER_H
#define __EMUL_CHARGER_H

#include <emul.h>
#include "emul/emul_tcpci.h"

/**
 * @brief USB-C charger emulator backend API
 * @defgroup charger_emul USB-C charger emulator
 * @{
 *
 * USB-C charger emulator can be attached to TCPCI emulator. It is able to
 * respond to some TCPM messages. It always attach as source and present
 * hardcoded set of source capabilities.
 */

/** Structure describing charger emulator */
struct charger_emul_data {
	/** Operations used by TCPCI emulator */
	struct tcpci_emul_partner_ops ops;
	/** Work used to send message with delay */
	struct k_work_delayable delayed_send;
	/** Pointer to connected TCPCI emulator */
	const struct emul *tcpci_emul;
	/** Queue for delayed messages */
	struct k_fifo to_send;
	/** Next SOP message id */
	int msg_id;
};

/**
 * @brief Initialise USB-C charger emulator. Need to be called before any other
 *        function.
 *
 * @param data Pointer to USB-C charger emulator
 */
void charger_emul_init(struct charger_emul_data *data);

/**
 * @brief Connect emulated device to TCPCI
 *
 * @param data Pointer to USB-C charger emulator
 * @param tcpci_emul Poinetr to TCPCI emulator to connect
 *
 * @return 0 on success
 * @return negative on TCPCI connect error or send source capabilities error
 */
int charger_emul_connect_to_tcpci(struct charger_emul_data *data,
				  const struct emul *tcpci_emul);

/**
 * @}
 */

#endif /* __EMUL_CHARGER */