r4 functions

This commit is contained in:
Siwat Sirichai 2023-11-09 20:58:16 +07:00
parent 75967bf1b3
commit 3a335a9a08
2 changed files with 58 additions and 3 deletions

View File

@ -5,6 +5,7 @@ uint8_t inputBufferB;
PCF8574 inputBankA(INPUT_BANK_A_ADDRESS);
PCF8574 inputBankB(INPUT_BANK_B_ADDRESS);
PCF8574 utilBank(UTIL_BANK_ADDRESS);
Adafruit_PWMServoDriver pwmBank = Adafruit_PWMServoDriver(PWM_BANK_ADDRESS);
FRAM ESPMega_FRAM;
@ -22,6 +23,7 @@ void ESPMega_begin()
Wire.begin(14, 33);
inputBankA.begin();
inputBankB.begin();
utilBank.begin();
pwmBank.begin();
ESPMega_FRAM.begin(FRAM_ADDRESS);
// ESPMegaPRO v3 use the PWMBank to drive Half Bridge
@ -168,7 +170,6 @@ bool ESPMega_updateTimeFromNTP()
{
ESPMega_setTime(timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec,
timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year + 1900);
}
return true;
}
@ -176,3 +177,43 @@ bool ESPMega_updateTimeFromNTP()
}
#endif
void ESPMega_mapIO(int pin, int channel)
{
if (channel < 4 && channel >= 0)
{
if (pin == 4 || pin == 32)
{
utilBank.write(5, (channel - channel % 2) / 2);
utilBank.write(4, channel % 2);
}
if (pin == 12 || pin == 17)
{
utilBank.write(7, (channel - channel % 2) / 2);
utilBank.write(6, channel % 2);
}
}
}
void ESPMega_RS485_begin()
{
Serial1.begin(115200);
ESPMega_RS485_recieveEnable();
}
void ESPMega_RS485_transmitEnable()
{
utilBank.write(0, 1);
utilBank.write(1, 0);
}
void ESPMega_RS485_recieveEnable()
{
utilBank.write(0, 0);
utilBank.write(1, 1);
}
void ESPMega_RS485_disable() {
utilBank.write(0, 0);
utilBank.write(1, 0);
}

View File

@ -16,6 +16,7 @@
#define INPUT_BANK_A_ADDRESS 0x21
#define INPUT_BANK_B_ADDRESS 0x22
#define UTIL_BANK_ADDRESS 0x24
#define PWM_BANK_ADDRESS 0x5F
#define RTC_ADDRESS 0x68
#define ANALOG_INPUT_BANK_A_ADDRESS 0x48
@ -128,3 +129,16 @@ void ESPMega_dacWrite(int id, int value);
#endif
#endif
/**
* Map a pair of GPIO pin to a Multiplexer Channel
* through the ESPMega's Muxer
* @param pin The number of a multiplexing-capable pin in a pair to map [12,17], [4,32]
* @param channel Muxer channel to map to (0-3)
*/
void ESPMega_mapIO(int pin, int channel);
void ESPMega_RS485_begin();
void ESPMega_RS485_transmitEnable();
void ESPMega_RS485_recieveEnable();
void ESPMega_RS485_disable();