From ef47c771efc58ff573027bd257b3cff9ccd0b3c4 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Sun, 17 Nov 2019 14:24:01 +0100 Subject: [PATCH] You can now get and set the state of all CS pins at once. --- include/spi_master.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/include/spi_master.h b/include/spi_master.h index 83b62c0..47c57df 100644 --- a/include/spi_master.h +++ b/include/spi_master.h @@ -6,6 +6,8 @@ class SPIMaster { public: + static uint8_t state; + static void init() { PIN_SD_CS_SETUP(); PIN_VS1053_XCS_SETUP(); @@ -16,28 +18,57 @@ public: static void select_sd(bool enabled=true) { PIN_SD_CS(enabled ? LOW : HIGH); + if (enabled) { + state |= 1; + } else { + state &= ~1; + } delayMicroseconds(MCP_SPI_SETTING_DELAY); } static void select_vs1053_xcs(bool enabled=true) { PIN_VS1053_XCS(enabled ? LOW : HIGH); + if (enabled) { + state |= 2; + } else { + state &= ~2; + } delayMicroseconds(MCP_SPI_SETTING_DELAY); } static void select_vs1053_xdcs(bool enabled=true) { PIN_VS1053_XDCS(enabled ? LOW : HIGH); + if (enabled) { + state |= 4; + } else { + state &= ~4; + } delayMicroseconds(MCP_SPI_SETTING_DELAY); } static void select_rc522(bool enabled=true) { PIN_RC522_CS(enabled ? LOW : HIGH); + if (enabled) { + state |= 8; + } else { + state &= ~8; + } delayMicroseconds(MCP_SPI_SETTING_DELAY); } + static void set_state(uint8_t s) { + disable(); + if (s & 1) select_sd(); + if (s & 2) select_vs1053_xcs(); + if (s & 4) select_vs1053_xdcs(); + if (s & 8) select_rc522(); + } + static void disable() { PIN_SD_CS(HIGH); PIN_VS1053_XCS(HIGH); PIN_VS1053_XDCS(HIGH); PIN_RC522_CS(HIGH); + state = 0; } -}; +}; \ No newline at end of file