Compare commits
No commits in common. "6b847b3bb0f7d51bdf6d4fd768ad1bb585ac4bff" and "af189005c99a88108488391547ace4ccaf4fdb61" have entirely different histories.
6b847b3bb0
...
af189005c9
2
hardware/mux_rpi/.gitignore
vendored
2
hardware/mux_rpi/.gitignore
vendored
|
@ -1 +1 @@
|
||||||
build/
|
./build/
|
|
@ -23,39 +23,24 @@ 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
|
||||||
|
@ -65,8 +50,11 @@ void setup() {
|
||||||
timerConfigure(TIMER_MILLIS);
|
timerConfigure(TIMER_MILLIS);
|
||||||
timerStartCounter();
|
timerStartCounter();
|
||||||
|
|
||||||
// Setup UARTS
|
// Setup serial ports
|
||||||
setupUARTs();
|
Serial.begin(115200);
|
||||||
|
Serial1.begin(115200);
|
||||||
|
rpiUART0.begin(115200);
|
||||||
|
rpiUART5.begin(115200);
|
||||||
|
|
||||||
// Assign SERCOM functionality
|
// Assign SERCOM functionality
|
||||||
pinPeripheral(10, PIO_SERCOM);
|
pinPeripheral(10, PIO_SERCOM);
|
||||||
|
@ -76,60 +64,25 @@ void setup() {
|
||||||
// Main function
|
// Main function
|
||||||
int serialIncomingByte;
|
int serialIncomingByte;
|
||||||
void loop() {
|
void loop() {
|
||||||
while (uartConfig.Serial && Serial.available()) {
|
while (Serial.available()) {
|
||||||
uartBufferOutbound.push(Serial.read());
|
uartBufferOutbound.push(Serial.read());
|
||||||
if (uartConfig.Serial1) {
|
|
||||||
Serial1.write(uartBufferOutbound.last());
|
Serial1.write(uartBufferOutbound.last());
|
||||||
}
|
|
||||||
if (uartConfig.rpiUART0) {
|
|
||||||
rpiUART0.write(uartBufferOutbound.last());
|
rpiUART0.write(uartBufferOutbound.last());
|
||||||
}
|
|
||||||
if (uartConfig.rpiUART5) {
|
|
||||||
rpiUART5.write(uartBufferOutbound.last());
|
rpiUART5.write(uartBufferOutbound.last());
|
||||||
}
|
}
|
||||||
}
|
while (Serial1.available()) {
|
||||||
while (uartConfig.Serial1 && Serial1.available()) {
|
|
||||||
uartBufferInbound.push(Serial1.read());
|
uartBufferInbound.push(Serial1.read());
|
||||||
if (uartConfig.Serial) {
|
|
||||||
Serial.write(uartBufferInbound.last());
|
Serial.write(uartBufferInbound.last());
|
||||||
}
|
}
|
||||||
}
|
while (rpiUART0.available()) {
|
||||||
while (uartConfig.rpiUART0 && rpiUART0.available()) {
|
|
||||||
uartBufferInbound.push(rpiUART0.read());
|
uartBufferInbound.push(rpiUART0.read());
|
||||||
if (uartConfig.Serial) {
|
|
||||||
Serial.write(uartBufferInbound.last());
|
Serial.write(uartBufferInbound.last());
|
||||||
}
|
}
|
||||||
}
|
while (rpiUART5.available()) {
|
||||||
while (uartConfig.rpiUART5 && rpiUART5.available()) {
|
|
||||||
uartBufferInbound.push(rpiUART5.read());
|
uartBufferInbound.push(rpiUART5.read());
|
||||||
if (uartConfig.Serial) {
|
|
||||||
Serial.write(uartBufferInbound.last());
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Timer handler
|
// Timer handler
|
||||||
void TC5_Handler (void) {
|
void TC5_Handler (void) {
|
||||||
|
|
Reference in a new issue