YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
adc_esp8266.cpp
1// ---------------------------------------------
2// This file is part of
3// _ _ __ _ _ __ __
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
7//
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
11//
12// ---------------------------------------------
13//
14// ADC implementation for ESP8266.
15//
16#include "adc_esp8266.h"
17#include "assert.h"
18
19extern "C" {
20#include "user_interface.h"
21}
22adc_esp8266 adc_esp8266::inst;
23
24adc_esp8266::adc_esp8266() {}
25
26adc_esp8266::~adc_esp8266() {}
27
28void adc_esp8266::adcMode(uint8_t channel, uint16_t mode) {
29 assert(channel == 0 && (mode & ~ADC::FAST) == ADC::ADC_10_BIT);
30 _mode = mode;
31}
32
33adc_mode_t adc_esp8266::getMode(uint8_t channel) {
34 assert(channel == 0);
35 return ADC::ADC_10_BIT;
36}
37
38uint16_t
39adc_esp8266::adcReadRaw(uint8_t
40 channel) {
41 assert(channel == 0);
42 uint16_t res = 0;
43 if (
44 _mode & ADC::FAST
45 ) {
46 res = 0; //system_get_vdd33();
47 } else {
48 res = system_adc_read();
49 }
50 return
51 res;
52}
53
54float adc_esp8266::adcReadVoltage(uint8_t channel) {
55 assert(channel == 0);
56 return rawToVoltage(0, adcReadRaw(channel));
57}
58
59float adc_esp8266::rawToVoltage(uint8_t channel, uint16_t raw) {
60 assert(channel == 0);
61 return (float) raw / 960.0f;
62}