Intermediary commit. Nothing's working, everything is broken. Let's start over now...

This commit is contained in:
2019-08-04 13:42:07 +02:00
parent 128d76cebc
commit 2a7dd5d8a1
9 changed files with 232 additions and 6 deletions

View File

@ -1,9 +1,32 @@
#pragma once
#include <Arduino.h>
#define PIN_SD_CS D1
#define PIN_VS1053_CS D2
#define PIN_RC522_CS D3
// Pins according to https://www.instructables.com/id/NodeMCU-ESP8266-Details-and-Pinout/
// D0 = 16
// D1 = 5
// D2 = 4
// D3 = 0
// D4 = 2
// D5 = 14
// D6 = 12
// D7 = 13
// D8 = 15
// A0 = 17
// Other usable pins:
// 6, 7, 8, 11 not readable
// 1, 3, 6, 7, 8, 11 nor writable -> 1 (TX) and 3 (RX) can be used read-only
// 9 -> S2
// 10 -> S3
#define RX 3
#define TX 1
#define PIN_SD_CS D4
#define PIN_VS1053_XCS D8
#define PIN_VS1053_XRESET D3
#define PIN_VS1053_XDCS D1
#define PIN_VS1053_DREQ D2
#define PIN_RC522_CS D0
#define PIN_BTN_VOL_UP D4
#define PIN_BTN_VOL_DOWN D5

View File

@ -1,13 +1,15 @@
#pragma once
#include "player.h"
#include "sd_card.h"
class Controller {
private:
Player* _player;
SDCard* _sd_card;
public:
Controller(Player* p) : _player(p) {}
Controller(Player* p, SDCard* c) : _player(p), _sd_card(c) {}
void vol_up();
void vol_down();
void track_next();

View File

@ -1,7 +1,27 @@
#pragma once
#include "sd_card.h"
#include "config.h"
#define SCI_MODE 0x00
#define SCI_STATUS 0x01
#define SCI_CLOCKF 0x03
#define CMD_WRITE 0x02
#define CMD_READ 0x03
#define XRESET PIN_VS1053_XRESET
#define DREQ PIN_VS1053_DREQ
class Player {
private:
SDCard* _sd_card;
void _reset();
void _init();
void _wait();
uint16_t _read_register(uint8_t address, uint32_t spi_speed, uint16_t t);//=SPI_CLOCK_DIV4);
void _write_register(uint8_t address, uint16_t value, uint32_t spi_speed);//=SPI_CLOCK_DIV2);
public:
Player(SDCard* c);
void vol_up();
void vol_down();
void track_next();

8
include/sd_card.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <SD.h>
#include "config.h"
class SDCard {
public:
SDCard();
};

27
include/spi_master.h Normal file
View File

@ -0,0 +1,27 @@
#pragma once
class SPIMaster {
public:
static void init() {
SPI.setHwCs(false);
pinMode(PIN_SD_CS, OUTPUT);
pinMode(PIN_VS1053_XCS, OUTPUT);
pinMode(PIN_VS1053_XDCS, 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);
}
static void printStatus() {
Serial.printf("CS state: SD:%d, VS1053_XCS:%d, VS1053_XDCS:%d\n",
digitalRead(PIN_SD_CS),
digitalRead(PIN_VS1053_XCS),
digitalRead(PIN_VS1053_XDCS));
}
static void disable() {
enable(142);
}
};