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 "../../../../src/system/bsp/pd/usb_pd.h"
18#include "../../../../src/system/bsp/pd/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
70 void set_source_role_wanted(const int wanted);
71
77 void set_allow_power_sourcing(const int allowPowerSourcing);
78
82 void set_battery_level(const uint8_t battLevelPercent);
83
87 void supsend_usb_pd(int shouldSuspend);
88
92 int is_activating_otg();
93
94 // should stop all vbus current loading
95 int should_stop_vbus_charge();
96
97 void pd_power_supply_reset();
98
99 extern uint8_t get_pd_source_cnt();
100 extern uint32_t get_pd_source(const uint8_t index);
101
102 extern uint32_t get_available_pd_current_mA();
103 extern uint32_t get_available_pd_voltage_mV();
104
105 // reset the cached values, call on power supply unplugged
106 extern void reset_cache();
107 // forget the received source capabilities (when the state machine restarts)
108 extern void reset_source_capabilities();
109
110 // The associated cable is pd capable
111 int is_pd_conector();
112
113/* Standard macros / definitions */
114#ifndef MAX
115#define MAX(a, b) \
116 ({ \
117 __typeof__(a) temp_a = (a); \
118 __typeof__(b) temp_b = (b); \
119 \
120 temp_a > temp_b ? temp_a : temp_b; \
121 })
122#endif
123#ifndef MIN
124#define MIN(a, b) \
125 ({ \
126 __typeof__(a) temp_a = (a); \
127 __typeof__(b) temp_b = (b); \
128 \
129 temp_a < temp_b ? temp_a : temp_b; \
130 })
131#endif
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* USB_PD_DRIVER_H_ */
Definition: usb_pd_driver.h:46
Definition: usb_pd_driver.h:40