added song skipping

This commit is contained in:
Jay Robson 2024-09-29 18:07:58 +10:00
parent 42e6f7c79f
commit 376a2ef6de
9 changed files with 45 additions and 12 deletions

View File

@ -8,7 +8,9 @@
#include "indicator.hpp"
const int PIN_NEXT = 8;
bool state_next = 1;
static bool state_next = 1;
static uint32_t addr_next = 0;
void buttons::init() {
pinMode(PIN_NEXT, INPUT_PULLUP);
@ -19,6 +21,7 @@ static void on_next() {
case scheduler::State::play:
scheduler::state = scheduler::State::skip;
indicator::reset();
data::jump(addr_next);
tones::clear_all();
dac::reset();
break;
@ -29,12 +32,10 @@ static void on_next() {
}
void buttons::update() {
if(!digitalRead(PIN_NEXT) && state_next) {
delay(1);
state_next = 0;
}
else if(digitalRead(PIN_NEXT) && !state_next) {
delay(1);
on_next();
@ -42,3 +43,7 @@ void buttons::update() {
}
}
void buttons::set_addr_next(uint32_t addr) {
addr_next = addr;
}

View File

@ -4,5 +4,6 @@
namespace buttons {
void init();
void update();
void set_addr_next(uint32_t addr);
};

View File

@ -62,7 +62,7 @@ void data::update() {
scheduler::reset();
break;
}
} else if(mode != Mode::local) {
} else {
mode = Mode::local;
eeprom::jump(0);
scheduler::state = scheduler::State::pause;
@ -87,3 +87,23 @@ unsigned data::read(char* data, unsigned len) {
return count;
}
bool data::jump(uint32_t addr) {
switch(mode) {
case Mode::local:
eeprom::jump(addr);
break;
default:
return false;
}
return true;
}
uint32_t data::get_addr() {
switch(mode) {
case Mode::local:
return eeprom::get_addr();
default:
return 0;
}
}

View File

@ -12,5 +12,7 @@ namespace data {
void update();
unsigned read(char* data, unsigned len);
bool jump(uint32_t addr);
uint32_t get_addr();
};

View File

@ -22,11 +22,7 @@ static void wait_for_responsive(uint8_t i2c_addr) {
}
static uint8_t get_i2c_addr(uint32_t at) {
uint8_t i2c_addr = ADDR;
if(at > 0xffff) {
i2c_addr |= 1;
}
return i2c_addr;
return ADDR ^ (at >> 16);
}
static void set_address(uint8_t i2c_addr, uint16_t at) {
@ -78,3 +74,7 @@ void eeprom::page_write(uint32_t at, const char* data) {
delay(WRITE_MS);
}
uint32_t eeprom::get_addr() {
return at;
}

View File

@ -8,7 +8,7 @@ namespace eeprom {
constexpr uint8_t PAGE_SIZE = 128;
constexpr uint32_t BLOCK_SIZE = 0x10000;
constexpr uint32_t LENGTH = 0x20000;
constexpr uint32_t LENGTH = 0x80000;
inline SoftTWI mem(A4, A5);
@ -16,5 +16,6 @@ namespace eeprom {
void jump(uint32_t addr);
void read(char* data, uint16_t len);
void page_write(uint32_t at, const char* data);
uint32_t get_addr();
};

View File

@ -43,6 +43,7 @@ namespace entry {
struct Config {
uint32_t us_per_tick;
uint8_t amplitude;
uint32_t jump_addr;
};
struct Generic {
@ -68,7 +69,7 @@ namespace entry {
case Type::clear_ts:
return 4;
case Type::config:
return 5;
return 8;
case Type::stop:
default:
return 1;

View File

@ -6,6 +6,7 @@
#include "entry.hpp"
#include "tones.hpp"
#include "util.hpp"
#include "buttons.hpp"
using namespace scheduler;
@ -52,6 +53,8 @@ static void do_next() {
switch(type) {
case entry::Type::config: {
buttons::set_addr_next((v & bm(24)) + data::get_addr());
v >>= 24;
config.amplitude = v & bm(8);
v >>= 8;
config.us_per_tick = v & bm(29);

View File

@ -13,6 +13,6 @@ inline void swap(T& a, T& b) {
a = t;
}
#define bm(V) (((uint64_t)1 << V) - 1);
#define bm(V) (((uint64_t)1 << V) - 1)
#define size(V) (sizeof(V) / sizeof(V[0]))