# MUX - Raspberry Pi Edition

This folder contains the necessary sources and information to build a MUX for Raspberry Pis. This mux can be used independently or with the controller.

Note : The mux needs to be configured via sources if not used with the controller.

## Important Considerations

- The Raspberry Pi 4 has 5 available UARTS and we only document how to wire for UART0/1 and UART5
- The Raspberry Pi's prior to the 4 had only UART0 exposed. Please use ONLY the UART0 configuration and setup for these devices.

## Hardware / BoM

| Item | Quantity | Unit Cost |
| ---- | -------- | --------- |
| [Feather M0 Basic Proto](https://www.adafruit.com/product/2772) | 1 | $19.95 |
| [FeatherWing Proto](https://www.adafruit.com/product/2884) | 1 | $4.95 |
| [2x20 pin IDC Box Header](https://www.adafruit.com/product/1993) | 1 | $0.75 |
| [GPIO Ribbon Cable for Raspberry Pi](https://www.adafruit.com/product/1988) | 1 | $2.95 |
| [Header Kit for Feather](https://www.adafruit.com/product/2886) | 1 | $0.96 |
| [I2C Non-Volatile FRAM Breakout](https://www.adafruit.com/product/1895) | 2 | $9.95 |

## Schematic

This build is ```i2c``` focused for additional parts. Please hookup using standard ```i2c``` methods.

| Raspberry Pi Header Pin | Arduino Pin |
| ----------------------- | ----------- |
| 6 | Gnd |
| 8 | A1 |
| 10 | A2 |
| 32 | 10 |
| 33 | 11 |
| 1 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
| 2 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
| 3 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
| 4 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
| 13 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
| 14 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
| 15 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |
| 16 | NOT CONNECTED TO ANYTHING / CUT PIN ON HEADER |

## Libraries Used

### Local

These libraries are used by the project and contained in the ```src/``` folder local to the project.

### External

These libraries are used by the project and can be installed via the Arduino IDE library manager.

- [CircularBuffer](https://github.com/rlogiacco/CircularBuffer)

## Implementation (Incomplete)

- FRAM break out for configuration persistence
- Fall back to saved config *and* goes into stand alone via usb port *if* it's not seeing the main board
- Receive configuration over i2c
- Save configuration to FRAM
- FRAM config reading
- Ability to have USB *and* i2c for the UART output
  - Use ring buffer @ 16k for i2c
  - Send direct to USB and then add to ring buffer (always send over usb even if not used)

## Implementation (Complete)

## Building / Uploading

The ```make.ps1```, ```build.ps1``` and ```upload.ps1``` scripts can be used to build/upload this project. These scripts call the ```arduino-cli``` commands programatically.
