HI,
I have little experience in programming, I'm trying to understand the code, but I can't figure out how the ports are determined.
In Opencart.h there is such a definition for the BiBoard v1 board
#define VOICE_RX 26
#define VOICE_TX 25
#define UART_RX2 9
#define UART_TX2 10
There is a code like this in ModuleManager.h
#ifdef BiBoard_V1_0
Serial2.begin(115200, SERIAL_8N1, 9, 10);
And at the same time in the camera.h library
#ifdef BiBoard_V1_0
#define USE_WIRE1
#ifdef USE_WIRE1
#define CAMERA_WIRE Wire1
#define CAMERA_WIRE Wire
……
#ifdef USE_WIRE1
CAMERA_WIRE.begin(UART_TX2, UART_RX2, 400000);
I can't figure out pins 9 and 10 are simultaneously involved for both IC2 and UART at the same time. How is this possible?
Hi, good catch!
Pin 9 and 10 can be used either as I2C or UART. But at the same time, in a function set, their role is fixed.
The modules are not activated simultaneously. More specifically, Serial2 is typically used by a master device, such as the Raspberry Pi. If a camera is needed, it's usually attached to the Pi rather than connected to the I2C port of the BiBoard.
In the module manager, there's a logic check for the case when both modules are competing for the same port. The previous logic was to make all the modules exclusive. i.e., only one module can be active, and it will turn off the other modules. In a later revision, we excluded the voice and the backtouch sensor from the rule. However, the camera will still force Serial2 to turn off.
void reconfigureTheActiveModule(char *moduleCode) {
if (moduleCode[0] == '?') {
showModuleStatus();
return;
}
bool statusChangedQ = false;
// PTHL("mode", moduleCode); // negative number will deactivate all the modules
for (byte i = 0; i < sizeof(moduleList) / sizeof(char); i++) { // disable unneeded modules
if (moduleActivatedQ[i] && moduleList[i] != moduleCode[0]) { // if the modules is active and different from the new module
if ((moduleList[i] == EXTENSION_VOICE || moduleList[i] == EXTENSION_BACKTOUCH) && moduleCode[0] != '~') // it won't disable the voice and backtouch
continue;
PTHL("- disable", moduleNames[i]);
stopModule(moduleList[i]);
moduleActivatedQ[i] = false;
statusChangedQ = true;
#ifdef I2C_EEPROM_ADDRESS
i2c_eeprom_write_byte(EEPROM_MODULE_ENABLED_LIST + i, false);
#endif
}
}
#ifndef I2C_EEPROM_ADDRESS
config.putBytes("moduleState", moduleActivatedQ, sizeof(moduleList) / sizeof(char));
#endif
for (byte i = 0; i < sizeof(moduleList) / sizeof(char); i++) {
if (moduleList[i] == moduleCode[0] && !moduleActivatedQ[i]) {
PTHL("+ enable", moduleNames[i]);
initModule(moduleList[i]);
statusChangedQ = true;
}
}
if (statusChangedQ) // if the status of the modules has changed, show the new status
showModuleStatus();
}