Commit 70a997ec authored by Jacob Vosmaer's avatar Jacob Vosmaer

More inlining

parent 4531b71a
......@@ -8,7 +8,6 @@
#include "list.h"
#include "midi.h"
#include "pitch_env.h"
#include "uart.h"
#include "vibrato_rate.h"
#include "voice.h"
......@@ -41,55 +40,6 @@ void pitch_env_set_decay(uint8_t decay);
void pitch_env_set_amount(uint8_t amount);
void pitch_env_trigger(uint8_t voice);
static struct {
uint8_t data[16];
uint8_t head;
uint8_t tail;
} uart_buffer;
void uart_buffer_push(uint8_t x) {
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
uart_buffer.data[uart_buffer.tail] = x;
uart_buffer.tail =
(uart_buffer.tail + 1) % ARRAY_SIZE(uart_buffer.data);
}
}
uint8_t uart_buffer_pop(uint8_t *x) {
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
if (uart_buffer.head == uart_buffer.tail) {
return false; // error: uart_buffer is empty
}
*x = uart_buffer.data[uart_buffer.head];
uart_buffer.head =
(uart_buffer.head + 1) % ARRAY_SIZE(uart_buffer.data);
}
return true;
}
ISR(USART_RX_vect) {
uint8_t uart_status = UCSR0A;
if (!(uart_status & _BV(RXC0))) {
// No UART data available
return;
}
// Read data to clear all status bits
uint8_t uart_data = UDR0;
if (uart_status & (_BV(FE0) | _BV(DOR0) | _BV(UPE0))) {
// There was a UART error
return;
}
uart_buffer_push(uart_data);
}
uint8_t uart_read(uint8_t *data) { return uart_buffer_pop(data); }
void poly_init(void);
void poly_note_on(uint8_t note);
void poly_note_off(uint8_t note);
......@@ -372,15 +322,7 @@ void poly2_note_off(uint8_t note) {
poly2_assign_available_voices();
}
static uint8_t _gate_retrig[NUM_VOICES];
enum {
// RETRIG_DELAY should be as low as possible to reduce MIDI latency, but
// high enough to allow the hardware envelope generators in the CrowBX
// to
// reset. I know 0x3f to be too low.
RETRIG_DELAY = 0x5f,
};
static uint8_t gate_counters[NUM_VOICES];
void gate_init(void) {
for_each_voice (v) { gate_off(v); }
......@@ -401,7 +343,7 @@ void gate_off(uint8_t v) {
return;
}
_gate_retrig[v] = 0;
gate_counters[v] = 0;
*(g->port) &= ~(g->mask);
}
......@@ -411,21 +353,27 @@ void gate_on(uint8_t v) {
}
gate_off(v);
_gate_retrig[v] = RETRIG_DELAY;
// RETRIG_DELAY should be as low as possible to reduce MIDI latency, but
// high enough to allow the hardware envelope generators in the CrowBX
// to reset. I know 0x3f to be too low.
enum { RETRIG_DELAY = 0x5f };
gate_counters[v] = RETRIG_DELAY;
}
void gate_update(uint8_t delta) {
for_each_voice (v) {
if (_gate_retrig[v] == 0) {
if (gate_counters[v] == 0) {
continue;
}
if (delta < _gate_retrig[v]) {
_gate_retrig[v] -= delta;
if (delta < gate_counters[v]) {
gate_counters[v] -= delta;
continue;
}
_gate_retrig[v] = 0;
gate_counters[v] = 0;
gate_on_legato(v);
pitch_env_trigger(v);
}
......@@ -685,3 +633,51 @@ uint16_t clamp_add(uint16_t x, int16_t delta) {
}
return x + add;
}
static struct {
uint8_t data[16];
uint8_t head;
uint8_t tail;
} uart_buffer;
void uart_buffer_push(uint8_t x) {
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
uart_buffer.data[uart_buffer.tail] = x;
uart_buffer.tail =
(uart_buffer.tail + 1) % ARRAY_SIZE(uart_buffer.data);
}
}
uint8_t uart_buffer_pop(uint8_t *x) {
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
if (uart_buffer.head == uart_buffer.tail) {
return false; // error: uart_buffer is empty
}
*x = uart_buffer.data[uart_buffer.head];
uart_buffer.head =
(uart_buffer.head + 1) % ARRAY_SIZE(uart_buffer.data);
}
return true;
}
ISR(USART_RX_vect) {
uint8_t uart_status = UCSR0A;
if (!(uart_status & _BV(RXC0))) {
// No UART data available
return;
}
// Read data to clear all status bits
uint8_t uart_data = UDR0;
if (uart_status & (_BV(FE0) | _BV(DOR0) | _BV(UPE0))) {
// There was a UART error
return;
}
uart_buffer_push(uart_data);
}
uint8_t uart_read(uint8_t *data) { return uart_buffer_pop(data); }
#include "midi.h"
#include "array_size.h"
#include "uart.h"
#include <string.h>
static struct {
......
......@@ -24,7 +24,7 @@ enum _cc {
void midi_init(void);
void midi_set_channel(uint8_t channel);
bool midi_read(uint8_t *status, uint8_t *data1, uint8_t *data2);
uint8_t uart_read(uint8_t *data);
#endif
#ifndef UART_H
#define UART_H
#include <stdint.h>
uint8_t uart_read(uint8_t *data);
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment