My guess is that I need to call READ_PERI_REG(PIN_NAME) beforehand and store the bitvalues but after reviewing the definition I'm not quite sure. It would be appreciated if anyone had some guidance.
I am using the code below to autodetect which pin the DHT22 is on.
Code: Select all
void AutoDetect()
{
//This code may need to get the values before setting the Pin_Func_Select to restore after
//I think the code for Pin_Func_Selct macro is in Eagle_soc.h
/*
#define PIN_FUNC_SELECT(PIN_NAME, FUNC) do { \
WRITE_PERI_REG(PIN_NAME, \
(READ_PERI_REG(PIN_NAME) \
& (~(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S))) \
| ( (((FUNC&BIT2)<<2)|(FUNC&0x3))<<PERIPHS_IO_MUX_FUNC_S) ); \
} while (0)
*/
ThermostatConfig.programmed = 1;
ThermostatConfig.ThermostatType = MySensor_DHT22;
ThermostatConfig.PowerMethod = 0;
int i;
for(i = 15; i >= 0; i--)
{
os_printf("Detecting Therm on GPIO %d", i);
PIN_FUNC_SELECT(g_pin_muxes[i], g_pin_funcs[i]);
PIN_PULLUP_EN(g_pin_muxes[i]);
ThermostatConfig.GPIO = i;
if (pollDHTData())
{
os_printf("Therm Detected on GPIO %d", i);
return;
}
if (i == 12)
{
i = 6; //Skip over bad Pins
}
if (i == 3)
{
i = 1; //Pin 2 and 3 crashes the esp when using this method
}
}
ThermostatConfig.programmed = 0;
ThermostatConfig.ThermostatType = 0;
ThermostatConfig.PowerMethod = 0;
}