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:
|
|
|
|
static void init() {
|
|
|
|
SPI.setHwCs(false);
|
|
|
|
pinMode(PIN_SD_CS, OUTPUT);
|
|
|
|
pinMode(PIN_VS1053_XCS, OUTPUT);
|
|
|
|
pinMode(PIN_VS1053_XDCS, OUTPUT);
|
2019-08-11 15:15:22 +00:00
|
|
|
pinMode(PIN_MCP, OUTPUT);
|
2019-08-04 11:42:07 +00:00
|
|
|
}
|
|
|
|
static void enable(uint8_t pin) {
|
|
|
|
digitalWrite(PIN_SD_CS, pin==PIN_SD_CS ? LOW : HIGH);
|
|
|
|
digitalWrite(PIN_VS1053_XCS, pin==PIN_VS1053_XCS ? LOW : HIGH);
|
|
|
|
digitalWrite(PIN_VS1053_XDCS, pin==PIN_VS1053_XDCS ? LOW : HIGH);
|
2019-08-11 15:15:22 +00:00
|
|
|
digitalWrite(PIN_MCP, pin==PIN_MCP ? LOW : HIGH);
|
|
|
|
|
2019-08-04 11:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printStatus() {
|
2019-08-11 15:15:22 +00:00
|
|
|
Serial.printf("CS state: SD:%d, VS1053_XCS:%d, VS1053_XDCS:%d, MCP:%d\n",
|
2019-08-06 18:50:11 +00:00
|
|
|
digitalRead(PIN_SD_CS),
|
|
|
|
digitalRead(PIN_VS1053_XCS),
|
2019-08-11 15:15:22 +00:00
|
|
|
digitalRead(PIN_VS1053_XDCS),
|
|
|
|
digitalRead(PIN_MCP));
|
2019-08-04 11:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void disable() {
|
|
|
|
enable(142);
|
|
|
|
}
|
|
|
|
};
|