2019-08-04 11:42:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-06 18:50:11 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <SPI.h>
|
|
|
|
#include "config.h"
|
|
|
|
|
2019-08-04 11:42:07 +00:00
|
|
|
class SPIMaster {
|
|
|
|
public:
|
2019-11-14 19:42:02 +00:00
|
|
|
static void init() {
|
2019-11-10 13:45:33 +00:00
|
|
|
PIN_SD_CS_SETUP();
|
|
|
|
PIN_VS1053_XCS_SETUP();
|
|
|
|
PIN_VS1053_XDCS_SETUP();
|
|
|
|
PIN_RC522_CS_SETUP();
|
|
|
|
disable();
|
2019-08-04 11:42:07 +00:00
|
|
|
}
|
2019-08-11 15:15:22 +00:00
|
|
|
|
2019-11-14 19:42:02 +00:00
|
|
|
static void select_sd(bool enabled=true) {
|
2019-11-10 13:45:33 +00:00
|
|
|
PIN_SD_CS(enabled ? LOW : HIGH);
|
|
|
|
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
2019-08-04 11:42:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-14 19:42:02 +00:00
|
|
|
static void select_vs1053_xcs(bool enabled=true) {
|
2019-11-10 13:45:33 +00:00
|
|
|
PIN_VS1053_XCS(enabled ? LOW : HIGH);
|
|
|
|
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
2019-08-04 11:42:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-14 19:42:02 +00:00
|
|
|
static void select_vs1053_xdcs(bool enabled=true) {
|
2019-11-10 13:45:33 +00:00
|
|
|
PIN_VS1053_XDCS(enabled ? LOW : HIGH);
|
|
|
|
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
|
|
|
}
|
|
|
|
|
2019-11-14 19:42:02 +00:00
|
|
|
static void select_rc522(bool enabled=true) {
|
2019-11-10 13:45:33 +00:00
|
|
|
PIN_RC522_CS(enabled ? LOW : HIGH);
|
|
|
|
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
|
|
|
}
|
|
|
|
|
2019-11-14 19:42:02 +00:00
|
|
|
static void disable() {
|
2019-11-10 13:45:33 +00:00
|
|
|
PIN_SD_CS(HIGH);
|
|
|
|
PIN_VS1053_XCS(HIGH);
|
|
|
|
PIN_VS1053_XDCS(HIGH);
|
|
|
|
PIN_RC522_CS(HIGH);
|
2019-08-04 11:42:07 +00:00
|
|
|
}
|
|
|
|
};
|