Skip to content

Commit 27812c8

Browse files
author
Emilie Gillet
committed
Stages: final firmware
1 parent d1e0571 commit 27812c8

13 files changed

+284
-386
lines changed

stages/chain_state.cc

+33-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const uint32_t kRightKey = stmlib::FourCC<'o', 'v', 'e', 'r'>::value;
4343
// How long before unpatching an input actually breaks the chain.
4444
const uint32_t kUnpatchedInputDelay = 2000;
4545
const int32_t kLongPressDuration = 800;
46+
const int32_t kVeryLongPressDuration = 3000;
4647

4748
void ChainState::Init(SerialLink* left, SerialLink* right) {
4849
index_ = 0;
@@ -298,6 +299,14 @@ void ChainState::Configure(SegmentGenerator* segment_generator) {
298299
!channel_state_[channel].input_patched();
299300
}
300301
if (dirty || num_segments != segment_generator[i].num_segments()) {
302+
// The alt mode is only available for single segments.
303+
if (num_segments != 1) {
304+
for (int j = 0; j < num_segments; ++j) {
305+
if (configuration[j].type == segment::TYPE_ALT) {
306+
configuration[j].type = segment::TYPE_RAMP;
307+
}
308+
}
309+
}
301310
segment_generator[i].Configure(true, configuration, num_segments);
302311
}
303312
set_loop_status(i, 0, last_loop);
@@ -471,16 +480,26 @@ void ChainState::PollSwitches() {
471480
request_ = MakeLoopChangeRequest(first_pressed, switch_index);
472481
switch_press_time_[first_pressed] = -1;
473482
switch_press_time_[switch_index] = -1;
474-
} else if (switch_press_time_[switch_index] > kLongPressDuration) {
475-
// Long press on a single button.
483+
} else if (switch_press_time_[switch_index] == kLongPressDuration) {
484+
// Long press on a single button: send the loop change message
485+
// only once.
476486
request_ = MakeLoopChangeRequest(switch_index, switch_index);
487+
} else if (switch_press_time_[switch_index] > kVeryLongPressDuration) {
488+
request_ = MakeLoopChangeRequest(switch_index, switch_index);
489+
const bool valid_loop = request_.request != REQUEST_NONE;
490+
const bool single_segment = \
491+
request_.argument[0] == request_.argument[3] || \
492+
request_.argument[0] == (request_.argument[3] - 1);
493+
if (valid_loop && single_segment) {
494+
request_.request = REQUEST_SET_ALT_SEGMENT_TYPE;
495+
}
477496
switch_press_time_[switch_index] = -1;
478497
} else {
479498
first_pressed = switch_index;
480499
}
481500
}
482501
} else {
483-
if (switch_press_time_[switch_index] > 5) {
502+
if (switch_press_time_[switch_index] > 5 && switch_press_time_[switch_index] < kLongPressDuration) {
484503
// A button has been released after having been held for a
485504
// sufficiently long time (5ms), but not for long enough to be
486505
// detected as a long press.
@@ -509,15 +528,22 @@ void ChainState::HandleRequest(Settings* settings) {
509528
uint8_t type_bits = s->segment_configuration[i] & 0x3;
510529
uint8_t loop_bit = s->segment_configuration[i] & 0x4;
511530

512-
if (request_.request == REQUEST_SET_SEGMENT_TYPE) {
531+
if (request_.request == REQUEST_SET_ALT_SEGMENT_TYPE) {
532+
if (channel == request_.argument[0]) {
533+
type_bits = 0x3;
534+
loop_bit = 0x4;
535+
dirty = true;
536+
}
537+
} else if (request_.request == REQUEST_SET_SEGMENT_TYPE) {
513538
if (channel == request_.argument[0]) {
514-
s->segment_configuration[i] = ((type_bits + 1) % 3) | loop_bit;
539+
type_bits = ((type_bits + 1) % 3);
515540
dirty |= true;
516541
}
517542
} else if (request_.request == REQUEST_SET_LOOP) {
518543
uint8_t new_loop_bit = loop_bit;
519544
if ((channel >= request_.argument[0] && channel < request_.argument[3])) {
520545
new_loop_bit = 0x0;
546+
type_bits = type_bits % 3;
521547
}
522548
if (channel == request_.argument[1] || channel == request_.argument[2]) {
523549
if (request_.argument[1] == request_.argument[2]) {
@@ -526,9 +552,10 @@ void ChainState::HandleRequest(Settings* settings) {
526552
new_loop_bit = 0x4;
527553
}
528554
}
529-
s->segment_configuration[i] = type_bits | new_loop_bit;
530555
dirty |= new_loop_bit != loop_bit;
556+
loop_bit = new_loop_bit;
531557
}
558+
s->segment_configuration[i] = type_bits | loop_bit;
532559
}
533560

534561
if (dirty) {

stages/chain_state.h

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class ChainState {
166166

167167
enum Request {
168168
REQUEST_NONE,
169+
REQUEST_SET_ALT_SEGMENT_TYPE = 0xfd,
169170
REQUEST_SET_SEGMENT_TYPE = 0xfe,
170171
REQUEST_SET_LOOP = 0xff
171172
};

stages/drivers/leds.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void Leds::Write() {
120120
for (uint16_t i = 0; i < 16; ++i) {
121121
// GPIO_WriteBit(GPIOB, kPinClk, Bit_RESET);
122122
GPIOB->BRR = kPinClk;
123-
123+
__asm__("nop");
124124
if (leds_data & 0x8000) {
125125
// GPIO_WriteBit(GPIOB, kPinData, Bit_SET);
126126
GPIOB->BSRR = kPinData;
@@ -132,6 +132,7 @@ void Leds::Write() {
132132

133133
// GPIO_WriteBit(GPIOB, kPinClk, Bit_SET);
134134
GPIOB->BSRR = kPinClk;
135+
__asm__("nop");
135136
}
136137
// GPIO_WriteBit(GPIOB, kPinEnable, Bit_SET);
137138
GPIOB->BSRR = kPinEnable;

stages/makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ UPLOAD_COMMAND = upload_combo_jtag_erase_first
3939
TARGET = stages
4040
PACKAGES = stages \
4141
stages/drivers \
42-
stages/ramp \
42+
tides2/ramp \
4343
stmlib/dsp \
4444
stmlib/utils \
4545
stmlib/system

stages/ramp_extractor.cc

-207
This file was deleted.

0 commit comments

Comments
 (0)