Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
usb_pd_driver.h
1/*
2 * usb_pd_driver.h
3 *
4 * Created: 11/11/2017 23:55:25
5 * Author: jason
6 */
7
8#ifndef USB_PD_DRIVER_H_
9#define USB_PD_DRIVER_H_
10
11#include <stdint.h>
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17#include "../usb_pd.h"
18#include "../config.h"
19
20#define PD_POWER_SUPPLY_TURN_ON_DELAY 250 * MSEC_US /* us */
21#define PD_POWER_SUPPLY_TURN_OFF_DELAY 100 * MSEC_US /* us */
22
23/* Define typical operating power and max power */
24#define PD_OPERATING_POWER_MW (2250ull)
25
26#define PD_MIN_CURRENT_MA (100ull)
27#define PD_MIN_VOLTAGE_MV (5000ull)
28#define PD_MIN_POWER_MW (PD_MIN_VOLTAGE_MV * PD_MIN_CURRENT_MA / 1000)
29
30#define PD_MAX_CURRENT_MA (5000ull)
31#define PD_MAX_VOLTAGE_MV (20000ull)
32#define PD_MAX_POWER_MW (PD_MAX_VOLTAGE_MV * PD_MAX_CURRENT_MA / 1000)
33
34#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP | PDO_FIXED_COMM_CAP)
35
36#define usleep(us) (delay_us(us))
37#define msleep(ms) (delay_ms(ms))
38
40 {
41 uint16_t requestedVoltage_mV;
42 uint16_t requestedCurrent_mA;
43 };
44
46 {
47 uint32_t current_mA;
48 uint32_t voltage_mV;
49 uint32_t timestamp;
50 };
51
55 struct SourcePowerParameters get_OTG_requested_parameters();
56 struct SinkUsableParameters get_allowed_consuption();
57
58 void pd_startup();
59 void pd_turn_off();
60
61 void pd_loop();
62
64 void force_set_to_source(int force);
65
71 void set_allow_power_sourcing(const int allowPowerSourcing);
72
76 void set_battery_level(const uint8_t battLevelPercent);
77
81 void supsend_usb_pd(int shouldSuspend);
82
86 int is_activating_otg();
87
88 // should stop all vbus current loading
89 int should_stop_vbus_charge();
90
91 void pd_power_supply_reset();
92
93 extern uint8_t get_pd_source_cnt();
94 extern uint32_t get_pd_source(const uint8_t index);
95
96 extern uint32_t get_available_pd_current_mA();
97 extern uint32_t get_available_pd_voltage_mV();
98
99 // reset the cached values, call on power supply unplugged
100 extern void reset_cache();
101
102 // The associated cable is pd capable
103 int is_pd_conector();
104
105/* Standard macros / definitions */
106#ifndef MAX
107#define MAX(a, b) \
108 ({ \
109 __typeof__(a) temp_a = (a); \
110 __typeof__(b) temp_b = (b); \
111 \
112 temp_a > temp_b ? temp_a : temp_b; \
113 })
114#endif
115#ifndef MIN
116#define MIN(a, b) \
117 ({ \
118 __typeof__(a) temp_a = (a); \
119 __typeof__(b) temp_b = (b); \
120 \
121 temp_a < temp_b ? temp_a : temp_b; \
122 })
123#endif
124
125#ifdef __cplusplus
126}
127#endif
128
129#endif /* USB_PD_DRIVER_H_ */
Definition: usb_pd_driver.h:46
Definition: usb_pd_driver.h:40