mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-10 14:42:08 +03:00
better analogRead
This commit is contained in:
@ -21,34 +21,13 @@
|
|||||||
#include "wiring_private.h"
|
#include "wiring_private.h"
|
||||||
#include "pins_arduino.h"
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
|
extern uint16_t readvdd33(void);
|
||||||
|
|
||||||
void analogReference(uint8_t mode) {}
|
void analogReference(uint8_t mode) {}
|
||||||
|
|
||||||
extern int __analogRead(uint8_t pin) {
|
extern int __analogRead(uint8_t pin) {
|
||||||
if(pin == 17){
|
if(pin == 17){
|
||||||
//return system_adc_read();
|
return readvdd33() >> 2; // readvdd33 is 12 bit
|
||||||
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 digitalRead(pin) * 1023;
|
return digitalRead(pin) * 1023;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user