forked from letscontrolit/ESPEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hardware.ino
78 lines (71 loc) · 2.25 KB
/
Hardware.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/********************************************************************************************\
* Initialize specific hardware setings (only global ones, others are set through devices)
\*********************************************************************************************/
void hardwareInit()
{
// set GPIO pins state if not set to default
for (byte x=0; x < 17; x++)
if (Settings.PinBootStates[x] != 0)
switch(Settings.PinBootStates[x])
{
case 1:
pinMode(x,OUTPUT);
digitalWrite(x,LOW);
setPinState(1, x, PIN_MODE_OUTPUT, LOW);
break;
case 2:
pinMode(x,OUTPUT);
digitalWrite(x,HIGH);
setPinState(1, x, PIN_MODE_OUTPUT, HIGH);
break;
case 3:
pinMode(x,INPUT_PULLUP);
setPinState(1, x, PIN_MODE_INPUT, 0);
break;
}
// configure hardware pins according to eeprom settings.
if (Settings.Pin_i2c_sda != -1)
{
String log = F("INIT : I2C");
addLog(LOG_LEVEL_INFO, log);
Wire.begin(Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
if(Settings.WireClockStretchLimit)
{
String log = F("INIT : I2C custom clockstretchlimit:");
log += Settings.WireClockStretchLimit;
addLog(LOG_LEVEL_INFO, log);
Wire.setClockStretchLimit(Settings.WireClockStretchLimit);
}
}
// I2C Watchdog boot status check
if (Settings.WDI2CAddress != 0)
{
delay(500);
Wire.beginTransmission(Settings.WDI2CAddress);
Wire.write(0x83); // command to set pointer
Wire.write(17); // pointer value to status byte
Wire.endTransmission();
Wire.requestFrom(Settings.WDI2CAddress, (uint8_t)1);
if (Wire.available())
{
byte status = Wire.read();
if (status & 0x1)
{
String log = F("INIT : Reset by WD!");
addLog(LOG_LEVEL_ERROR, log);
lastBootCause = BOOT_CAUSE_EXT_WD;
}
}
}
// SPI Init
if (Settings.InitSPI)
{
SPI.setHwCs(false);
SPI.begin();
addLog(LOG_LEVEL_INFO, (char*)"INIT : SPI Init (without CS)");
}
else
{
addLog(LOG_LEVEL_INFO, (char*)"INIT : SPI not enabled");
}
}