Skip to content

Commit

Permalink
better analogRead
Browse files Browse the repository at this point in the history
  • Loading branch information
ficeto authored and ficeto committed May 19, 2015
1 parent fbd86a2 commit 09bb758
Showing 1 changed file with 3 additions and 24 deletions.
Expand Up @@ -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;
}
Expand Down

0 comments on commit 09bb758

Please sign in to comment.