36 lines
826 B
C++
36 lines
826 B
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
#include <SPI.h>
|
|
#include "config.h"
|
|
|
|
class SPIMaster {
|
|
public:
|
|
static void init() {
|
|
SPI.setHwCs(false);
|
|
pinMode(PIN_SD_CS, OUTPUT);
|
|
pinMode(PIN_VS1053_XCS, OUTPUT);
|
|
pinMode(PIN_VS1053_XDCS, OUTPUT);
|
|
pinMode(PIN_MCP, OUTPUT);
|
|
}
|
|
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);
|
|
digitalWrite(PIN_MCP, pin==PIN_MCP ? LOW : HIGH);
|
|
|
|
}
|
|
|
|
static void printStatus() {
|
|
Serial.printf("CS state: SD:%d, VS1053_XCS:%d, VS1053_XDCS:%d, MCP:%d\n",
|
|
digitalRead(PIN_SD_CS),
|
|
digitalRead(PIN_VS1053_XCS),
|
|
digitalRead(PIN_VS1053_XDCS),
|
|
digitalRead(PIN_MCP));
|
|
}
|
|
|
|
static void disable() {
|
|
enable(142);
|
|
}
|
|
};
|