Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
current_sense_shunt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 The ChromiumOS Authors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_ADC_CURRENT_SENSE_SHUNT_H_
14#define ZEPHYR_INCLUDE_DRIVERS_ADC_CURRENT_SENSE_SHUNT_H_
15
16#include <zephyr/drivers/adc.h>
17
24
38
49#define CURRENT_SENSE_SHUNT_DT_SPEC_GET(node_id) \
50 { \
51 .port = ADC_DT_SPEC_GET(node_id), \
52 .shunt_micro_ohms = DT_PROP(node_id, shunt_resistor_micro_ohms), \
53 }
54
62static inline void current_sense_shunt_scale_dt(const struct current_sense_shunt_dt_spec *spec,
63 int32_t *v_to_i)
64{
65 /* store in a temporary 64 bit variable to prevent overflow during calculation */
66 int64_t tmp = *v_to_i;
67
68 /* multiplies by 1,000,000 before dividing by shunt resistance in micro-ohms. */
69 tmp = tmp * 1000000 / spec->shunt_micro_ohms;
70
71 *v_to_i = (int32_t)tmp;
72}
73
75
76#endif /* ZEPHYR_INCLUDE_DRIVERS_ADC_CURRENT_SENSE_SHUNT_H_ */
Main header file for ADC (Analog-to-Digital Converter) driver API.
static void current_sense_shunt_scale_dt(const struct current_sense_shunt_dt_spec *spec, int32_t *v_to_i)
Calculates the actual amperage from a measured voltage.
Definition current_sense_shunt.h:62
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__INT64_TYPE__ int64_t
Definition stdint.h:75
Container for ADC channel information specified in devicetree.
Definition adc.h:291
Current sense shunt DT struct.
Definition current_sense_shunt.h:32
const struct adc_dt_spec port
ADC channel info.
Definition current_sense_shunt.h:34
uint32_t shunt_micro_ohms
Shunt resistor value in micro-ohms.
Definition current_sense_shunt.h:36