Compare commits

..

No commits in common. "6b847b3bb0f7d51bdf6d4fd768ad1bb585ac4bff" and "af189005c99a88108488391547ace4ccaf4fdb61" have entirely different histories.

2 changed files with 19 additions and 66 deletions

View file

@ -1 +1 @@
build/
./build/

View file

@ -23,39 +23,24 @@ bool ledState = false;
void TC5_Handler(void);
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
// 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)
// D10 (TX) -- GPIO 10 (RX)
// MISO (RX) -- GPIO 32 (TX)
// MOSI (TX) -- GPIO 33 (RX)
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);
void SERCOM1_Handler() {
rpiUART0.IrqHandler();
}
void SERCOM4_Handler() {
rpiUART5.IrqHandler();
}
// Misc uart functions (defined after setup/loop)
void setupUARTs();
// Setup stuff needed for build
void setup() {
// Setup board LED
@ -65,8 +50,11 @@ void setup() {
timerConfigure(TIMER_MILLIS);
timerStartCounter();
// Setup UARTS
setupUARTs();
// Setup serial ports
Serial.begin(115200);
Serial1.begin(115200);
rpiUART0.begin(115200);
rpiUART5.begin(115200);
// Assign SERCOM functionality
pinPeripheral(10, PIO_SERCOM);
@ -76,58 +64,23 @@ void setup() {
// Main function
int serialIncomingByte;
void loop() {
while (uartConfig.Serial && Serial.available()) {
while (Serial.available()) {
uartBufferOutbound.push(Serial.read());
if (uartConfig.Serial1) {
Serial1.write(uartBufferOutbound.last());
}
if (uartConfig.rpiUART0) {
rpiUART0.write(uartBufferOutbound.last());
}
if (uartConfig.rpiUART5) {
rpiUART5.write(uartBufferOutbound.last());
}
Serial1.write(uartBufferOutbound.last());
rpiUART0.write(uartBufferOutbound.last());
rpiUART5.write(uartBufferOutbound.last());
}
while (uartConfig.Serial1 && Serial1.available()) {
while (Serial1.available()) {
uartBufferInbound.push(Serial1.read());
if (uartConfig.Serial) {
Serial.write(uartBufferInbound.last());
}
Serial.write(uartBufferInbound.last());
}
while (uartConfig.rpiUART0 && rpiUART0.available()) {
while (rpiUART0.available()) {
uartBufferInbound.push(rpiUART0.read());
if (uartConfig.Serial) {
Serial.write(uartBufferInbound.last());
}
Serial.write(uartBufferInbound.last());
}
while (uartConfig.rpiUART5 && rpiUART5.available()) {
while (rpiUART5.available()) {
uartBufferInbound.push(rpiUART5.read());
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);
Serial.write(uartBufferInbound.last());
}
}