/*
* adc.c
*
* Created on: 12/02/2015
* Author: PV`
*
*/
#include "ets_sys.h"
#include "osapi.h"
void ICACHE_FLASH_ATTR read_adcs(uint16 *ptr, uint16 len)
{
if(len != 0 && ptr != NULL) {
uint32 y;
uint16 z;
uint16 sar_x[8];
#if (0)
uint32 store_reg710 = READ_PERI_REG(0x60000710);
uint32 store_reg58e = READ_PERI_REG(0x600005e8);
uint32 store018 = READ_PERI_REG(0x3FF00018);
if((store_reg710 & 0xfe000000) != 0xfe000000) {
SET_PERI_REG_MASK(0x3FF00018,0x038f0000);
SET_PERI_REG_MASK(0x60000710,0xfe000000);
rom_i2c_writeReg_Mask(98,1,3,7,4,15);
rom_sar_init();
ets_delay_us(2);
SET_PERI_REG_MASK(0x600005e8,0x01800000);
ets_delay_us(2);
}
else pm_set_sleep_mode(4);
#endif
rom_i2c_writeReg_Mask(108,2,0,5,5,1);
SET_PERI_REG_MASK(0x60000D5C,0x00200000);
while(READ_PERI_REG(0x60000D50)&(0x7<<24));
while(len--) {
CLEAR_PERI_REG_MASK(0x60000D50,2);
SET_PERI_REG_MASK(0x60000D50,2);
while(READ_PERI_REG(0x60000D50)&(0x7<<24));
read_sar_dout(&sar_x[0]);
z = 0;
for(y = 0; y < 8; y++) z += sar_x[y];
z += 8;
z >>= 4;
*ptr++ = z;
};
rom_i2c_writeReg_Mask(108,2,0,5,5,0);
while(READ_PERI_REG(0x60000D50)&(0x7<<24));
CLEAR_PERI_REG_MASK(0x60000D5C,0x00200000);
CLEAR_PERI_REG_MASK(0x60000D60,1);
SET_PERI_REG_MASK(0x60000D60,1);
#if (0)
if((store_reg710 & 0xfe000000) != 0xfe000000) {
WRITE_PERI_REG(0x600005e8,((READ_PERI_REG(0x600005e8) & 0xfe7fffff) | 0x00800000));
rom_i2c_writeReg_Mask(98,1,3,7,4,0);
WRITE_PERI_REG(0x60000710, store_reg710);
WRITE_PERI_REG(0x3FF00018, store018);
}
else pm_wakeup_init(4,0);
#endif
}
}