Changed from MCP23S17 to MCP23017. Lots of changes.
Doesn't really work because of timing stuff.
This commit is contained in:
@ -20,6 +20,24 @@
|
||||
#define RX 3
|
||||
#define TX 1
|
||||
|
||||
// Pins for MCP23017
|
||||
#define GPA0 0
|
||||
#define GPA1 1
|
||||
#define GPA2 2
|
||||
#define GPA3 3
|
||||
#define GPA4 4
|
||||
#define GPA5 5
|
||||
#define GPA6 6
|
||||
#define GPA7 7
|
||||
#define GPB0 8
|
||||
#define GPB1 9
|
||||
#define GPB2 10
|
||||
#define GPB3 11
|
||||
#define GPB4 12
|
||||
#define GPB5 13
|
||||
#define GPB6 14
|
||||
#define GPB7 15
|
||||
|
||||
#define SHOW_DEBUG
|
||||
//#define SHOW_TRACE
|
||||
#define FTP_DEBUG
|
||||
@ -30,21 +48,44 @@
|
||||
#define VS1053_SLEEP_DELAY 5000
|
||||
#define MQTT_REPORT_INTERVAL 10000
|
||||
|
||||
#define PIN_SD_CS(x) (_mcp->digitalWrite(GPB3, x))
|
||||
#define PIN_SD_CS_SETUP() (_mcp->pinMode(GPB3, OUTPUT))
|
||||
|
||||
#define PIN_SD_CS D4
|
||||
#define PIN_VS1053_XCS D8
|
||||
#define PIN_VS1053_XRESET 16
|
||||
#define PIN_MCP D3
|
||||
#define PIN_VS1053_XDCS D1
|
||||
#define PIN_VS1053_DREQ D2
|
||||
#define PIN_RC522_CS D0
|
||||
#define SPEAKER_L 15
|
||||
#define SPEAKER_R 14
|
||||
#define PIN_VS1053_XCS(x) (digitalWrite(D8, x))
|
||||
#define PIN_VS1053_XCS_SETUP() (pinMode(D8, OUTPUT))
|
||||
|
||||
#define PIN_BTN_VOL_UP D4
|
||||
#define PIN_BTN_VOL_DOWN D5
|
||||
#define PIN_BTN_TRACK_NEXT D6
|
||||
#define PIN_BTN_TRACK_PREV D7
|
||||
#define PIN_VS1053_XRESET(x) (_mcp->digitalWrite(GPB7, x))
|
||||
#define PIN_VS1053_XRESET_SETUP() (_mcp->pinMode(GPB7, OUTPUT))
|
||||
|
||||
#define PIN_VS1053_XDCS(x) (digitalWrite(D3, x))
|
||||
#define PIN_VS1053_XDCS_SETUP() (pinMode(D3, OUTPUT))
|
||||
|
||||
#define PIN_VS1053_DREQ() (_mcp->digitalRead(GPB2))
|
||||
#define PIN_VS1053_DREQ_SETUP() (_mcp->pinMode(GPB2, INPUT))
|
||||
|
||||
#define PIN_RC522_CS(x) (digitalWrite(D0, x))
|
||||
#define PIN_RC522_CS_SETUP() (pinMode(D0, OUTPUT))
|
||||
|
||||
#define PIN_SPEAKER_L(x) (_mcp->digitalWrite(GPB5, x))
|
||||
#define PIN_SPEAKER_L_SETUP() (_mcp->pinMode(GPB5, OUTPUT))
|
||||
|
||||
#define PIN_SPEAKER_R(x) (_mcp->digitalWrite(GPB6, x))
|
||||
#define PIN_SPEAKER_R_SETUP() (_mcp->pinMode(GPB6, OUTPUT))
|
||||
|
||||
#define BTN_PREV() ( ! _mcp->digitalRead(GPA0))
|
||||
#define BTN_PREV_SETUP() {_mcp->pinMode(GPA0, INPUT); _mcp->pullUp(GPA0, HIGH);}
|
||||
|
||||
#define BTN_VOL_UP() ( ! _mcp->digitalRead(GPA1))
|
||||
#define BTN_VOL_UP_SETUP() {_mcp->pinMode(GPA1, INPUT); _mcp->pullUp(GPA1, HIGH);}
|
||||
|
||||
#define BTN_VOL_DOWN() ( ! _mcp->digitalRead(GPA2))
|
||||
#define BTN_VOL_DOWN_SETUP() {_mcp->pinMode(GPA2, INPUT); _mcp->pullUp(GPA2, HIGH);}
|
||||
|
||||
#define BTN_NEXT() ( ! _mcp->digitalRead(GPA3))
|
||||
#define BTN_NEXT_SETUP() {_mcp->pinMode(GPA3, INPUT); _mcp->pullUp(GPA3, HIGH);}
|
||||
|
||||
|
||||
#define MCP_I2C_ADDR 7
|
||||
|
||||
#define NUM_BUTTONS 4
|
||||
|
||||
@ -54,6 +95,8 @@
|
||||
#define VOLUME_MAX 255
|
||||
#define VOLUME_STEP 0x08
|
||||
|
||||
#define MCP_SPI_SETTING_DELAY 1
|
||||
|
||||
#define RFID_SCAN_INTERVAL 100
|
||||
|
||||
|
||||
|
@ -5,17 +5,19 @@
|
||||
#include "player.h"
|
||||
#include "mqtt_client.h"
|
||||
#include <MFRC522.h>
|
||||
#include <MCP23S17/MCP23S17.h>
|
||||
#include <Adafruit_MCP23017.h>
|
||||
|
||||
class Controller {
|
||||
private:
|
||||
MFRC522* _rfid;
|
||||
MCP* _mcp;
|
||||
Adafruit_MCP23017* _mcp;
|
||||
SPIMaster* _spi;
|
||||
MQTTClient* _mqtt_client;
|
||||
bool _rfid_enabled = true;
|
||||
void _check_rfid();
|
||||
void _check_serial();
|
||||
void _check_buttons();
|
||||
bool _debounce_button(uint8_t index);
|
||||
uint32_t _get_rfid_card_uid();
|
||||
uint32_t _last_rfid_card_uid = 0;
|
||||
uint8_t _no_rfid_card_count = 0;
|
||||
@ -30,7 +32,7 @@ private:
|
||||
unsigned long _last_mqtt_report_at = 0;
|
||||
void _send_mqtt_report();
|
||||
public:
|
||||
Controller(Player* p, MCP* m);
|
||||
Controller(Player* p, Adafruit_MCP23017* m, SPIMaster* s);
|
||||
void set_mqtt_client(MQTTClient* m);
|
||||
String get_status_json();
|
||||
void loop();
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include <ESP8266WebServer.h>
|
||||
#include "spi_master.h"
|
||||
#include "player.h"
|
||||
#include "controller.h"
|
||||
#include <SD.h>
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <SD.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <MCP23S17/MCP23S17.h>
|
||||
#include <Adafruit_MCP23017.h>
|
||||
#include "spi_master.h"
|
||||
|
||||
#define SCI_MODE 0x00
|
||||
#define SCI_STATUS 0x01
|
||||
@ -23,11 +24,6 @@
|
||||
#define SM_CANCEL 0x0008
|
||||
#define SS_DO_NOT_JUMP 0x8000
|
||||
|
||||
#define XRESET PIN_VS1053_XRESET
|
||||
#define DREQ PIN_VS1053_DREQ
|
||||
#define XCS PIN_VS1053_XCS
|
||||
#define XDCS PIN_VS1053_XDCS
|
||||
|
||||
class Player {
|
||||
private:
|
||||
enum state { uninitialized, idle, playing, stopping,
|
||||
@ -81,10 +77,11 @@ private:
|
||||
uint8_t _volume;
|
||||
uint16_t _stop_delay;
|
||||
uint32_t _skip_to;
|
||||
MCP* _mcp;
|
||||
Adafruit_MCP23017* _mcp;
|
||||
SPIMaster* _spi;
|
||||
unsigned long _stopped_at;
|
||||
public:
|
||||
Player(MCP* m);
|
||||
Player(Adafruit_MCP23017* m, SPIMaster* s);
|
||||
void vol_up();
|
||||
void vol_down();
|
||||
void track_next();
|
||||
|
@ -5,31 +5,42 @@
|
||||
#include "config.h"
|
||||
|
||||
class SPIMaster {
|
||||
private:
|
||||
Adafruit_MCP23017* _mcp;
|
||||
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);
|
||||
|
||||
SPIMaster(Adafruit_MCP23017* m) {
|
||||
_mcp = m;
|
||||
PIN_SD_CS_SETUP();
|
||||
PIN_VS1053_XCS_SETUP();
|
||||
PIN_VS1053_XDCS_SETUP();
|
||||
PIN_RC522_CS_SETUP();
|
||||
disable();
|
||||
}
|
||||
|
||||
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));
|
||||
void select_sd(bool enabled=true) {
|
||||
PIN_SD_CS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
static void disable() {
|
||||
enable(142);
|
||||
void select_vs1053_xcs(bool enabled=true) {
|
||||
PIN_VS1053_XCS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void select_vs1053_xdcs(bool enabled=true) {
|
||||
PIN_VS1053_XDCS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void select_rc522(bool enabled=true) {
|
||||
PIN_RC522_CS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void disable() {
|
||||
PIN_SD_CS(HIGH);
|
||||
PIN_VS1053_XCS(HIGH);
|
||||
PIN_VS1053_XDCS(HIGH);
|
||||
PIN_RC522_CS(HIGH);
|
||||
}
|
||||
};
|
||||
|
8
include/tools.h
Normal file
8
include/tools.h
Normal file
@ -0,0 +1,8 @@
|
||||
#include <Adafruit_MCP23017.h>
|
||||
#include "config.h"
|
||||
|
||||
void print_mcp_status(Adafruit_MCP23017* mcp) {
|
||||
DEBUG(" AAAAAAAA BBBBBBBB\n");
|
||||
DEBUG(" 76543210 76543210\n");
|
||||
DEBUG("State of MCP pins: %08s %08s\n", String(mcp->readGPIO(0), 2).c_str(), String(mcp->readGPIO(1), 2).c_str());
|
||||
}
|
Reference in New Issue
Block a user