diff --git a/src/dmdreader.cpp b/src/dmdreader.cpp index d65fe7f..eb2a190 100644 --- a/src/dmdreader.cpp +++ b/src/dmdreader.cpp @@ -222,20 +222,20 @@ void spi_abort() { } /** - * @brief Notify on pin SPI0_CS that data are ready on SPI + * @brief Notify on pin SPI_CS that data is ready * * The SPI master (the Pico is slave) should start a data transfer when this - * signal is received It toggles pin SPI0_CS to H + * signal is received It toggles pin SPI_CS to H * */ -void start_spi() { digitalWrite(SPI0_CS, HIGH); } +void start_spi() { digitalWrite(DMDREADER_SPI_CS, HIGH); } /** - * @brief Set pin SPI0_CS to L to signal that there is no active SPI data + * @brief Set pin _CS to L to signal that there is no active SPI data * transfer * */ -void finish_spi() { digitalWrite(SPI0_CS, LOW); } +void finish_spi() { digitalWrite(DMDREADER_SPI_CS, LOW); } /** * @brief Cleanly exit SPI by stopping the DMD pio and sending a blank dummy @@ -1555,8 +1555,8 @@ bool dmdreader_init(bool return_on_no_detection) { void dmdreader_spi_init() { // this is used to notify the Pi that data is available - pinMode(SPI0_CS, OUTPUT); - digitalWrite(SPI0_CS, LOW); + pinMode(DMDREADER_SPI_CS, OUTPUT); + digitalWrite(DMDREADER_SPI_CS, LOW); // Set up SPI header h.len = (((target_bytes + 3) / 4) * 4) + sizeof(h) + sizeof(ph); @@ -1567,9 +1567,9 @@ void dmdreader_spi_init() { // initialize SPI slave PIO dmdreader_error_blink(pio_claim_free_sm_and_add_program_for_gpio_range( - &clocked_output_program, &spi_pio, &spi_sm, &spi_offset, SPI_BASE, 4, - true)); - clocked_output_program_init(spi_pio, spi_sm, spi_offset, SPI_BASE); + &clocked_output_program, &spi_pio, &spi_sm, &spi_offset, + DMDREADER_SPI_BASE, 4, true)); + clocked_output_program_init(spi_pio, spi_sm, spi_offset, DMDREADER_SPI_BASE); // DMA for SPI spi_dma_channel = dma_claim_unused_channel(true); diff --git a/src/dmdreader_pins.h b/src/dmdreader_pins.h index e3daf16..a9c473d 100644 --- a/src/dmdreader_pins.h +++ b/src/dmdreader_pins.h @@ -27,11 +27,12 @@ #endif // SPI Defines -#define SPI0 spi0 -#define SPI_BASE 16 -#define SPI0_MISO SPI_BASE // 16 -#define SPI0_CS (SPI_BASE + 1) // 17 -#define SPI0_SCK (SPI_BASE + 2) // 18 -#define SPI0_MOSI (SPI_BASE + 3) // 19 +#ifndef DMDREADER_SPI_BASE +#define DMDREADER_SPI_BASE 16 // 16 is the default for backwards compatibility +#endif +#define DMDREADER_SPI_MISO SPI_BASE +#define DMDREADER_SPI_CS 17 // Is locked to 17 for all PPUC/DMD revisions +#define DMDREADER_SPI_SCK (DMDREADER_SPI_BASE + 2) +#define DMDREADER_SPI_MOSI (DMDREADER_SPI_BASE + 3) -#endif // DMD_READER_PINS_H +#endif // DMD_READER_PINS_H \ No newline at end of file