| 12345678910111213141516171819202122 |
- #include "vbus_sensor.h"
- #include "bsp/bsp.h"
- #include "bsp/adc.h"
- static vbus_t _vbus;
- void vbus_sensor_init(void){
- _vbus.voltage_avg = 0;
- _vbus.avg_count = 5;
- vbus_sample_voltage();
- }
- void vbus_sample_voltage(void){
- u32 vadc = adc_sample_regular_channel(VBUS_V_CHAN, 16);
- _vbus.voltage_avg = ((float)vadc)/(65536.0f) * ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR;
- }
- float vbus_get_voltage(void){
- return _vbus.voltage_avg;
- }
|