Add conditional logic / config for rpi mux uart selection -- default to all on
This commit is contained in:
parent
ee2a3230aa
commit
6b847b3bb0
|
@ -23,24 +23,39 @@ bool ledState = false;
|
||||||
void TC5_Handler(void);
|
void TC5_Handler(void);
|
||||||
void timerConfigure(int sampleRate);
|
void timerConfigure(int sampleRate);
|
||||||
|
|
||||||
|
// General UART configuration struct
|
||||||
|
struct {
|
||||||
|
// Whether or not the USB is used for serial communications (stand alone builds)
|
||||||
|
bool Serial = true;
|
||||||
|
// Whether or not the i2c is used for serial communication (_controller builds)
|
||||||
|
bool uartI2C = false;
|
||||||
|
|
||||||
|
// Use the generic uart setup with the rpi
|
||||||
|
bool Serial1 = true;
|
||||||
|
// Use uart0 on the rpi
|
||||||
|
bool rpiUART0 = true;
|
||||||
|
// Use uart5 on the rpi
|
||||||
|
bool rpiUART5 = true;
|
||||||
|
} uartConfig;
|
||||||
|
|
||||||
// Additional serial ports for communication <> RPI
|
// Additional serial ports for communication <> RPI
|
||||||
// https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports?view=all#creating-a-new-serial
|
// https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports?view=all#creating-a-new-serial
|
||||||
// D11 (RX) -- GPIO 8 (TX)
|
// D11 (RX) -- GPIO 8 (TX)
|
||||||
// D10 (TX) -- GPIO 10 (RX)
|
// D10 (TX) -- GPIO 10 (RX)
|
||||||
// MISO (RX) -- GPIO 32 (TX)
|
// MISO (RX) -- GPIO 32 (TX)
|
||||||
// MOSI (TX) -- GPIO 33 (RX)
|
// MOSI (TX) -- GPIO 33 (RX)
|
||||||
|
|
||||||
Uart rpiUART0 (&sercom1, 10, 11, SERCOM_RX_PAD_0, UART_TX_PAD_2);
|
Uart rpiUART0 (&sercom1, 10, 11, SERCOM_RX_PAD_0, UART_TX_PAD_2);
|
||||||
Uart rpiUART5 (&sercom4, PIN_SPI_MISO, PIN_SPI_MOSI, SERCOM_RX_PAD_0, UART_TX_PAD_2);
|
Uart rpiUART5 (&sercom4, PIN_SPI_MISO, PIN_SPI_MOSI, SERCOM_RX_PAD_0, UART_TX_PAD_2);
|
||||||
|
|
||||||
void SERCOM1_Handler() {
|
void SERCOM1_Handler() {
|
||||||
rpiUART0.IrqHandler();
|
rpiUART0.IrqHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SERCOM4_Handler() {
|
void SERCOM4_Handler() {
|
||||||
rpiUART5.IrqHandler();
|
rpiUART5.IrqHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Misc uart functions (defined after setup/loop)
|
||||||
|
void setupUARTs();
|
||||||
|
|
||||||
// Setup stuff needed for build
|
// Setup stuff needed for build
|
||||||
void setup() {
|
void setup() {
|
||||||
// Setup board LED
|
// Setup board LED
|
||||||
|
@ -50,11 +65,8 @@ void setup() {
|
||||||
timerConfigure(TIMER_MILLIS);
|
timerConfigure(TIMER_MILLIS);
|
||||||
timerStartCounter();
|
timerStartCounter();
|
||||||
|
|
||||||
// Setup serial ports
|
// Setup UARTS
|
||||||
Serial.begin(115200);
|
setupUARTs();
|
||||||
Serial1.begin(115200);
|
|
||||||
rpiUART0.begin(115200);
|
|
||||||
rpiUART5.begin(115200);
|
|
||||||
|
|
||||||
// Assign SERCOM functionality
|
// Assign SERCOM functionality
|
||||||
pinPeripheral(10, PIO_SERCOM);
|
pinPeripheral(10, PIO_SERCOM);
|
||||||
|
@ -64,23 +76,58 @@ void setup() {
|
||||||
// Main function
|
// Main function
|
||||||
int serialIncomingByte;
|
int serialIncomingByte;
|
||||||
void loop() {
|
void loop() {
|
||||||
while (Serial.available()) {
|
while (uartConfig.Serial && Serial.available()) {
|
||||||
uartBufferOutbound.push(Serial.read());
|
uartBufferOutbound.push(Serial.read());
|
||||||
Serial1.write(uartBufferOutbound.last());
|
if (uartConfig.Serial1) {
|
||||||
rpiUART0.write(uartBufferOutbound.last());
|
Serial1.write(uartBufferOutbound.last());
|
||||||
rpiUART5.write(uartBufferOutbound.last());
|
}
|
||||||
|
if (uartConfig.rpiUART0) {
|
||||||
|
rpiUART0.write(uartBufferOutbound.last());
|
||||||
|
}
|
||||||
|
if (uartConfig.rpiUART5) {
|
||||||
|
rpiUART5.write(uartBufferOutbound.last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (Serial1.available()) {
|
while (uartConfig.Serial1 && Serial1.available()) {
|
||||||
uartBufferInbound.push(Serial1.read());
|
uartBufferInbound.push(Serial1.read());
|
||||||
Serial.write(uartBufferInbound.last());
|
if (uartConfig.Serial) {
|
||||||
|
Serial.write(uartBufferInbound.last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (rpiUART0.available()) {
|
while (uartConfig.rpiUART0 && rpiUART0.available()) {
|
||||||
uartBufferInbound.push(rpiUART0.read());
|
uartBufferInbound.push(rpiUART0.read());
|
||||||
Serial.write(uartBufferInbound.last());
|
if (uartConfig.Serial) {
|
||||||
|
Serial.write(uartBufferInbound.last());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (rpiUART5.available()) {
|
while (uartConfig.rpiUART5 && rpiUART5.available()) {
|
||||||
uartBufferInbound.push(rpiUART5.read());
|
uartBufferInbound.push(rpiUART5.read());
|
||||||
Serial.write(uartBufferInbound.last());
|
if (uartConfig.Serial) {
|
||||||
|
Serial.write(uartBufferInbound.last());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method to setup / reset the uarts
|
||||||
|
void setupUARTs() {
|
||||||
|
// Close ALL serial ports and re-enable per config (config can change during runtime)
|
||||||
|
Serial.end();
|
||||||
|
Serial1.end();
|
||||||
|
rpiUART0.end();
|
||||||
|
rpiUART5.end();
|
||||||
|
|
||||||
|
// Setup serial ports
|
||||||
|
if (uartConfig.Serial) {
|
||||||
|
Serial.begin(115200);
|
||||||
|
}
|
||||||
|
if (uartConfig.Serial1) {
|
||||||
|
Serial1.begin(115200);
|
||||||
|
}
|
||||||
|
if (uartConfig.rpiUART0) {
|
||||||
|
rpiUART0.begin(115200);
|
||||||
|
}
|
||||||
|
if (uartConfig.rpiUART5) {
|
||||||
|
rpiUART5.begin(115200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue