Lines Matching +full:vbus +full:- +full:discharge

4  * SPDX-License-Identifier: Apache-2.0
24 * @brief Reads and returns VBUS measured in mV
27 * @retval -EIO on failure
31 const struct usbc_vbus_config *const config = dev->config; in adc_vbus_measure()
32 struct usbc_vbus_data *data = dev->data; in adc_vbus_measure()
36 __ASSERT(meas != NULL, "ADC VBUS meas must not be NULL"); in adc_vbus_measure()
38 ret = adc_read(config->adc_channel.dev, &data->sequence); in adc_vbus_measure()
44 value = data->sample; in adc_vbus_measure()
45 ret = adc_raw_to_millivolts_dt(&config->adc_channel, &value); in adc_vbus_measure()
51 if (config->full_ohm > 0) { in adc_vbus_measure()
52 /* VBUS is scaled down though a voltage divider */ in adc_vbus_measure()
53 value = (value * 1000) / ((config->output_ohm * 1000) / config->full_ohm); in adc_vbus_measure()
61 * @brief Checks if VBUS is at a particular level
63 * @retval true if VBUS is at the level voltage, else false
89 * @brief Sets pin to discharge VBUS
92 * @retval -EIO on failure
93 * @retval -ENOENT if enable pin isn't defined
98 const struct usbc_vbus_config *const config = dev->config; in adc_vbus_discharge()
99 const struct gpio_dt_spec *gcd = &config->discharge_gpios; in adc_vbus_discharge()
100 int ret = -ENOENT; in adc_vbus_discharge()
102 if (gcd->port) { in adc_vbus_discharge()
109 * @brief Sets pin to enable VBUS measurments
112 * @retval -EIO on failure
113 * @retval -ENOENT if enable pin isn't defined
118 const struct usbc_vbus_config *const config = dev->config; in adc_vbus_enable()
119 const struct gpio_dt_spec *gcp = &config->power_gpios; in adc_vbus_enable()
120 int ret = -ENOENT; in adc_vbus_enable()
122 if (gcp->port) { in adc_vbus_enable()
129 * @brief Initializes the ADC VBUS Driver
132 * @retval -EIO on failure
136 const struct usbc_vbus_config *const config = dev->config; in adc_vbus_init()
137 struct usbc_vbus_data *data = dev->data; in adc_vbus_init()
138 const struct gpio_dt_spec *gcp = &config->power_gpios; in adc_vbus_init()
139 const struct gpio_dt_spec *gcd = &config->discharge_gpios; in adc_vbus_init()
142 if (!adc_is_ready_dt(&config->adc_channel)) { in adc_vbus_init()
144 return -ENODEV; in adc_vbus_init()
147 /* Configure VBUS Measurement enable pin if defined */ in adc_vbus_init()
148 if (gcp->port) { in adc_vbus_init()
149 if (!device_is_ready(gcp->port)) { in adc_vbus_init()
150 LOG_ERR("%s: device not ready", gcp->port->name); in adc_vbus_init()
151 return -EIO; in adc_vbus_init()
156 gcp->port->name, gcp->pin, ret); in adc_vbus_init()
161 /* Configure VBUS Discharge pin if defined */ in adc_vbus_init()
162 if (gcd->port) { in adc_vbus_init()
163 if (!device_is_ready(gcd->port)) { in adc_vbus_init()
164 LOG_ERR("%s: device not ready", gcd->port->name); in adc_vbus_init()
165 return -EIO; in adc_vbus_init()
170 gcd->port->name, gcd->pin, ret); in adc_vbus_init()
176 data->sequence.buffer = &data->sample; in adc_vbus_init()
177 data->sequence.buffer_size = sizeof(data->sample); in adc_vbus_init()
179 ret = adc_channel_setup_dt(&config->adc_channel); in adc_vbus_init()
185 ret = adc_sequence_init_dt(&config->adc_channel, &data->sequence); in adc_vbus_init()
197 .discharge = adc_vbus_discharge,
202 "No compatible USB-C VBUS Measurement instance found");