1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +03:00

better analogRead

This commit is contained in:
ficeto 2015-05-19 15:30:46 +03:00
parent 6f0d3ff2ab
commit c06b727fad

View File

@ -21,34 +21,13 @@
#include "wiring_private.h"
#include "pins_arduino.h"
extern uint16_t readvdd33(void);
void analogReference(uint8_t mode) {}
extern int __analogRead(uint8_t pin) {
if(pin == 17){
//return system_adc_read();
uint8_t i;
uint16_t data[8];
rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1);
ESP8266_REG(0xD5C) |= (1 << 21);
while ((ESP8266_REG(0xD50) & (7 << 24)) > 0);
ESP8266_REG(0xD50) &= ~(1 << 1);
ESP8266_REG(0xD50) |= (1 << 1);
delayMicroseconds(2);
while ((ESP8266_REG(0xD50) & (7 << 24)) > 0);
read_sar_dout(data);
rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1);
while ((ESP8266_REG(0xD50) & (7 << 24)) > 0);
ESP8266_REG(0xD5C) &= ~(1 << 21);
ESP8266_REG(0xD60) |= (1 << 0);
ESP8266_REG(0xD60) &= ~(1 << 0);
uint16_t tout = 0;
for (i = 0; i < 8; i++) tout += data[i];
return tout >> 4;//tout is 10 bits fraction
return readvdd33() >> 2; // readvdd33 is 12 bit
}
return digitalRead(pin) * 1023;
}