Skip to content

Instantly share code, notes, and snippets.

@zzsnzmn
Created February 1, 2018 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzsnzmn/45f614052f9c4f2e82ddf419a6f8617d to your computer and use it in GitHub Desktop.
Save zzsnzmn/45f614052f9c4f2e82ddf419a6f8617d to your computer and use it in GitHub Desktop.
/* issues
- preset save blip with internal timer vs ext trig
*/
#include <stdio.h>
// asf
#include "delay.h"
#include "compiler.h"
#include "flashc.h"
#include "preprocessor.h"
#include "print_funcs.h"
#include "intc.h"
#include "pm.h"
#include "gpio.h"
#include "spi.h"
#include "sysclk.h"
// skeleton
#include "types.h"
#include "events.h"
#include "i2c.h"
#include "init_trilogy.h"
#include "init_common.h"
#include "monome.h"
#include "timers.h"
#include "adc.h"
#include "util.h"
#include "ftdi.h"
// this
#include "conf_board.h"
#include "ii.h"
#define FIRSTRUN_KEY 0x22
typedef const struct {
u8 fresh;
u8 preset_select;
} nvram_data_t;
u8 preset_mode, preset_select, front_timer;
u8 edit_prob, live_in, scale_select;
u8 pattern, next_pattern, pattern_jump;
u8 series_pos, series_next, series_jump, series_playing, scroll_pos;
u8 key_alt, key_meta, center;
u8 held_keys[32], key_count, key_times[256];
s8 keycount_pos;
u16 cv0, cv1;
u8 param_accept, *param_dest8;
u16 *param_dest;
u8 quantize_in;
u8 clock_phase;
u16 clock_time, clock_temp;
u8 series_step;
u16 adc[4];
u8 SIZE, LENGTH, VARI;
typedef void(*re_t)(void);
re_t re;
// NVRAM data structure located in the flash array.
__attribute__((__section__(".flash_nvram")))
static nvram_data_t flashy;
////////////////////////////////////////////////////////////////////////////////
// prototypes
static void refresh_vari(void);
static void refresh_mono(void);
static void refresh_preset(void);
static void clock(u8 phase);
// start/stop monome polling/refresh timers
extern void timers_set_monome(void);
extern void timers_unset_monome(void);
// check the event queue
static void check_events(void);
// handler protos
static void handler_None(s32 data) { ;; }
static void handler_KeyTimer(s32 data);
static void handler_Front(s32 data);
static void handler_ClockNormal(s32 data);
static void handler_ClockExt(s32 data);
static void ww_process_ii(uint8_t *data, uint8_t l);
u8 flash_is_fresh(void);
void flash_unfresh(void);
void flash_write(void);
void flash_read(void);
#define printint print_dbg_ulong
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#define SEQUENCE_COUNT 14
/* static const u16 FOURTHS_GRID_MAP[128] = { */
/* 238, 408, 578, 749, 919, 1090, 1260, 1431, 1601, 1772, 1942, 2113, 2283, 2453, 2624, 2794, */
/* 204, 374, 544, 715, 885, 1056, 1226, 1397, 1567, 1738, 1908, 2079, 2249, 2419, 2590, 2760, */
/* 170, 340, 510, 681, 851, 1022, 1192, 1363, 1533, 1704, 1874, 2045, 2215, 2385, 2556, 2726, */
/* 136, 306, 476, 647, 817, 988, 1158, 1329, 1499, 1670, 1840, 2011, 2181, 2351, 2522, 2692, */
/* 102, 272, 442, 613, 783, 954, 1124, 1295, 1465, 1636, 1806, 1977, 2147, 2317, 2488, 2658, */
/* 68, 238, 408, 579, 749, 920, 1090, 1261, 1431, 1602, 1772, 1943, 2113, 2283, 2454, 2624, */
/* 34, 204, 374, 545, 715, 886, 1056, 1227, 1397, 1568, 1738, 1909, 2079, 2249, 2420, 2590, */
/* 0, 170, 340, 511, 681, 852, 1022, 1193, 1363, 1534, 1704, 1875, 2045, 2215, 2386, 2556, */
/* }; */
/* static const u16 FOURTHS_GRID_MAP[128] = { */
/* 238, 408, 578, 749, 919, 1090, 1260, 1431, 1601, 1772, 1942, 2113, 2283, 2453, 2624, 2794, */
/* 204, 374, 544, 715, 885, 1056, 1226, 1397, 1567, 1738, 1908, 2079, 2249, 2419, 2590, 2760, */
/* 170, 340, 510, 681, 851, 1022, 1192, 1363, 1533, 1704, 1874, 2045, 2215, 2385, 2556, 2726, */
/* 136, 306, 476, 647, 817, 988, 1158, 1329, 1499, 1670, 1840, 2011, 2181, 2351, 2522, 2692, */
/* 102, 272, 442, 613, 783, 954, 1124, 1295, 1465, 1636, 1806, 1977, 2147, 2317, 2488, 2658, */
/* 68, 238, 408, 579, 749, 920, 1090, 1261, 1431, 1602, 1772, 1943, 2113, 2283, 2454, 2624, */
/* 34, 204, 374, 545, 715, 886, 1056, 1227, 1397, 1568, 1738, 1909, 2079, 2249, 2420, 2590, */
/* 0, 170, 340, 511, 681, 852, 1022, 1193, 1363, 1534, 1704, 1875, 2045, 2215, 2386, 2556, */
/* }; */
// guitar tuning
static const u16 FOURTHS_GRID_MAP[128] = {
816, 850, 884, 918, 952, 986, 1020, 1054, 1088, 1122, 1156, 1190, 1224, 1258, 1292, 1326,
816, 850, 884, 918, 952, 986, 1020, 1054, 1088, 1122, 1156, 1190, 1224, 1258, 1292, 1326,
816, 850, 884, 918, 952, 986, 1020, 1054, 1088, 1122, 1156, 1190, 1224, 1258, 1292, 1326,
646, 680, 714, 748, 782, 816, 850, 884, 918, 952, 986, 1020, 1054, 1088, 1122, 1156,
510, 544, 578, 612, 646, 680, 714, 748, 782, 816, 850, 884, 918, 952, 986, 1020,
340, 374, 408, 442, 476, 510, 544, 578, 612, 646, 680, 714, 748, 782, 816, 850,
170, 204, 238, 272, 306, 340, 374, 408, 442, 476, 510, 544, 578, 612, 646, 680,
0, 34, 68, 102, 136, 170, 204, 238, 272, 306, 340, 374, 408, 442, 476, 510,
};
typedef struct node node;
struct node {
node *prev;
node *next;
u8 val;
u8 ticks;
};
typedef struct sequence sequence;
struct sequence {
node *current;
node *head;
node *tail;
node buttons[128];
};
static sequence sequences[SEQUENCE_COUNT];
static u8 activeSequenceIdx = 0;
static u8 sequenceA = 0;
static u8 sequenceB = 7;
static void clear_sequence(u8 sequence_idx);
static void init_buttons(void);
static void route_key_event(u8 x, u8 y, u8 z);
static void button_press(u8 idx);
static void button_release(u8 idx);
static void app_clock(void);
void update_display(void);
void pop_node(node *node);
void append_node(node *node);
static u8 latchA;
static u8 latchB;
static u8 lastHeldIdx;
static u8 buttonCountA;
static u8 gateCountB;
void init_buttons() {
static u8 i;
for(activeSequenceIdx = 0; activeSequenceIdx < SEQUENCE_COUNT; activeSequenceIdx++) {
sequences[activeSequenceIdx].current = NULL;
sequences[activeSequenceIdx].head = NULL;
sequences[activeSequenceIdx].tail = NULL;
for(i = 0; i < 128; i++) {
sequences[activeSequenceIdx].buttons[i].val = i;
sequences[activeSequenceIdx].buttons[i].ticks = 1;
}
}
buttonCountA = 0;
activeSequenceIdx = 0;
}
void clear_sequence(u8 sequence_idx) {
static u8 i;
for(i = 0; i < 128; i++) {
sequences[sequence_idx].buttons[i].next = NULL;
sequences[sequence_idx].buttons[i].prev = NULL;
}
sequences[sequence_idx].head = NULL;
sequences[sequence_idx].tail = NULL;
sequences[sequence_idx].current = NULL;
}
void set_active_sequence(u8 x, u8 y, u8 idx);
void set_active_sequence(u8 x, u8 y, u8 idx) {
// if we've pressed latch when it's already active
if (idx == 7) {
latchA ^= 1;
if (latchA == 0 && activeSequenceIdx < 7) {
clear_sequence(sequenceA);
}
return;
}
if (idx < 7) {
// XXXX
activeSequenceIdx = idx;
sequenceA = activeSequenceIdx;
return;
}
if (idx == 23) {
latchB ^= 1;
if(latchB == 0 && activeSequenceIdx >= 7 && activeSequenceIdx < 14) {
clear_sequence(sequenceB);
}
return;
}
if (idx > 15 && idx < 16 + 7) {
print_dbg("second loop\r\n");
activeSequenceIdx = idx - 9;
sequenceB = activeSequenceIdx;
return;
}
}
void gate_on(void);
void gate_on(void) {
/*if(sequences[sequenceA].current != NULL) {*/
gpio_set_gpio_pin(B00);
gpio_set_gpio_pin(B01);
/*}*/
/*if(sequences[sequenceB].current != NULL) {*/
gpio_set_gpio_pin(B02);
gpio_set_gpio_pin(B03);
/*}*/
}
void gate_off(void);
void gate_off(void) {
/*if (gateCountA == 0) {*/
gpio_clr_gpio_pin(B00);
gpio_clr_gpio_pin(B01);
/*}*/
/*if (gateCountB == 0) {*/
gpio_clr_gpio_pin(B02);
gpio_clr_gpio_pin(B03);
/*}*/
}
void set_cv(void);
void set_cv(void) {
// write to DAC
spi_selectChip(DAC_SPI,DAC_SPI_NPCS);
// update A
spi_write(DAC_SPI,0x31);
spi_write(DAC_SPI,cv0>>4);
spi_write(DAC_SPI,cv0<<4);
spi_unselectChip(DAC_SPI,DAC_SPI_NPCS);
spi_selectChip(DAC_SPI,DAC_SPI_NPCS);
// update B
spi_write(DAC_SPI,0x38);
spi_write(DAC_SPI,cv1>>4);
spi_write(DAC_SPI,cv1<<4);
spi_unselectChip(SPI,DAC_SPI_NPCS);
}
void set_tick_length(node *node, u8 len);
void set_tick_length(node *node, u8 len) {
node->ticks = len;
}
void route_key_event(u8 x, u8 y, u8 z) {
u8 index;
// only compute when calling node add/remove
index = y*16 + x;
if (z) {
button_press(index);
} else {
button_release(index);
}
}
void button_press(u8 idx) {
print_dbg("press: ");
printint(idx);
print_dbg("\r\n");
if (idx > 127)
return;
monomeLedBuffer[idx] = 15;
cv0 = FOURTHS_GRID_MAP[idx];
cv1 = FOURTHS_GRID_MAP[idx];
set_cv();
buttonCountA++;
lastHeldIdx = idx;
gate_on();
update_display();
}
void append_node(node *node) {
}
void button_release(u8 idx) {
if (idx > 127)
return;
if(idx == lastHeldIdx) {
lastHeldIdx = -1;
}
buttonCountA--;
monomeLedBuffer[idx] = 0;
monomeFrameDirty++;
if (buttonCountA < 1) {
gate_off();
}
update_display();
}
void pop_node(node *node) {
}
void update_display() {
static u8 i;
/*for(i = 0; i < 128; i++) {*/
/*monomeLedBuffer[i] = 0;*/
/*}*/
/*monomeLedBuffer[7] = latchA * 15;*/
/*monomeLedBuffer[23] = latchB * 15;*/
// sequenceA indicator
/*monomeLedBuffer[sequenceA] = 15;*/
// sequenceB indicator
/*monomeLedBuffer[sequenceB+8] = 15;*/
/*if (sequences[activeSequenceIdx].current)*/
/*monomeLedBuffer[sequences[activeSequenceIdx].current->val] = 15;*/
}
void step_forward(u8 idx, u8 *gateCount);
void step_forward(u8 idx, u8 *gateCount) {
// takes a sequence idx by number and steps it forward
/* static u8 countA, countB; */
if (sequences[idx].current == NULL && sequences[idx].head) {
/* print_dbg("1st \r\n"); */
sequences[idx].current = sequences[idx].head;
} else if (sequences[idx].current && sequences[idx].current->next && *gateCount == 0) {
/* print_dbg("2nd \r\n"); */
sequences[idx].current = sequences[idx].current->next;
} else if (*gateCount == 0 && sequences[idx].head) {
/* print_dbg("3rd \r\n"); */
sequences[idx].current = sequences[idx].head;
}
if (*gateCount == 0 && sequences[idx].current) {
/* print_dbg("gate branch \r\n"); */
*gateCount = sequences[idx].current->ticks;
}
}
void app_clock() {
/*step_forward(sequenceA, &gateCountA);*/
/* step_forward(sequenceB, &gateCountB); */
/*if (sequences[sequenceA].current) {*/
/*cv0 = FOURTHS_GRID_MAP[sequences[sequenceA].current->val];*/
/*print_dbg("set cvA: ");*/
/*printint(sequences[sequenceA].current->val);*/
/* print_dbg("gate_count: "); */
/* printint(sequences[sequenceA].current->ticks); */
/* print_dbg("gateCountA: "); */
/* printint(gateCountA); */
/*gateCountA = gateCountA - 1;*/
/*}*/
/*if (sequences[sequenceB].current) {*/
/*cv1 = FOURTHS_GRID_MAP[sequences[sequenceB].current->val];*/
/*print_dbg("set cvB: ");*/
/*printint(sequences[sequenceB].current->val);*/
/*gateCountB = gateCountB - 1;*/
/*}*/
/*update_display();*/
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// application clock code
void clock(u8 phase) {
if(phase) {
// set front pin
gpio_set_gpio_pin(B10);
// call out of band clock function
app_clock();
// XXX maybe break this into another thingy, can't handle two sequences
// ON
/*if(sequences[sequenceA].current != NULL) {*/
/*gpio_set_gpio_pin(B00);*/
/*gpio_set_gpio_pin(B01);*/
/*}*/
/*if(sequences[sequenceB].current != NULL) {*/
/*gpio_set_gpio_pin(B02);*/
/*gpio_set_gpio_pin(B03);*/
/*}*/
monomeFrameDirty++;
// write to DAC
spi_selectChip(DAC_SPI,DAC_SPI_NPCS);
// update A
spi_write(DAC_SPI,0x31);
spi_write(DAC_SPI,cv0>>4);
spi_write(DAC_SPI,cv0<<4);
spi_unselectChip(DAC_SPI,DAC_SPI_NPCS);
spi_selectChip(DAC_SPI,DAC_SPI_NPCS);
// update B
spi_write(DAC_SPI,0x38);
spi_write(DAC_SPI,cv1>>4);
spi_write(DAC_SPI,cv1<<4);
spi_unselectChip(SPI,DAC_SPI_NPCS);
}
else {
// clear front pins
gpio_clr_gpio_pin(B10);
// clear all triggers
/*if (gateCountA == 0) {*/
/*gpio_clr_gpio_pin(B00);*/
/*gpio_clr_gpio_pin(B01);*/
/*}*/
/*if (gateCountB == 0) {*/
/*gpio_clr_gpio_pin(B02);*/
/*gpio_clr_gpio_pin(B03);*/
/*}*/
}
}
////////////////////////////////////////////////////////////////////////////////
// timers
static softTimer_t clockTimer = { .next = NULL, .prev = NULL };
static softTimer_t keyTimer = { .next = NULL, .prev = NULL };
static softTimer_t adcTimer = { .next = NULL, .prev = NULL };
static softTimer_t monomePollTimer = { .next = NULL, .prev = NULL };
static softTimer_t monomeRefreshTimer = { .next = NULL, .prev = NULL };
static void clockTimer_callback(void* o) {
if(clock_external == 0) {
// print_dbg("\r\ntimer.");
clock_phase++;
if(clock_phase>1) clock_phase=0;
(*clock_pulse)(clock_phase);
}
}
static void keyTimer_callback(void* o) {
static event_t e;
e.type = kEventKeyTimer;
e.data = 0;
event_post(&e);
}
static void adcTimer_callback(void* o) {
static event_t e;
e.type = kEventPollADC;
e.data = 0;
event_post(&e);
}
// monome polling callback
static void monome_poll_timer_callback(void* obj) {
// asynchronous, non-blocking read
// UHC callback spawns appropriate events
ftdi_read();
}
// monome refresh callback
static void monome_refresh_timer_callback(void* obj) {
// XXX: here we call the refresh callback
// when monome fame is dirty
if(monomeFrameDirty > 0) {
static event_t e;
e.type = kEventMonomeRefresh;
event_post(&e);
}
}
// monome: start polling
void timers_set_monome(void) {
timer_add(&monomePollTimer, 20, &monome_poll_timer_callback, NULL );
timer_add(&monomeRefreshTimer, 30, &monome_refresh_timer_callback, NULL );
}
// monome stop polling
void timers_unset_monome(void) {
// print_dbg("\r\n unsetting monome timers");
timer_remove( &monomePollTimer );
timer_remove( &monomeRefreshTimer );
}
////////////////////////////////////////////////////////////////////////////////
// event handlers
static void handler_FtdiConnect(s32 data) { ftdi_setup(); }
static void handler_FtdiDisconnect(s32 data) {
timers_unset_monome();
}
static void handler_MonomeConnect(s32 data) {
print_dbg("\r\n// monome connect /////////////////");
keycount_pos = 0;
key_count = 0;
SIZE = monome_size_x();
LENGTH = SIZE - 1;
print_dbg("\r monome size: ");
print_dbg_ulong(SIZE);
VARI = monome_is_vari();
print_dbg("\r monome vari: ");
print_dbg_ulong(VARI);
if(VARI) re = &refresh_vari;
else re = &refresh_mono;
timers_set_monome();
}
static void handler_MonomePoll(s32 data) { monome_read_serial(); }
static void handler_MonomeRefresh(s32 data) {
if(monomeFrameDirty) {
if(preset_mode == 0) (*re)(); //refresh_mono();
else refresh_preset();
(*monome_refresh)();
}
}
static void handler_Front(s32 data) {
print_dbg("\r\n FRONT HOLD");
if(data == 0) {
front_timer = 15;
if(preset_mode) preset_mode = 0;
else preset_mode = 1;
}
else {
front_timer = 0;
}
monomeFrameDirty++;
}
static void handler_PollADC(s32 data) {
u16 i;
adc_convert(&adc);
// CLOCK POT INPUT
i = adc[0];
i = i>>2;
if(i != clock_temp) {
// 1000ms - 24ms
clock_time = 25000 / (i + 25);
timer_set(&clockTimer, clock_time);
}
clock_temp = i;
// PARAM POT INPUT
if(param_accept && edit_prob) {
*param_dest8 = adc[1] >> 4; // scale to 0-255;
}
else if(param_accept) {
if(quantize_in)
*param_dest = (adc[1] / 34) * 34;
else
*param_dest = adc[1];
monomeFrameDirty++;
}
else if(key_meta) {
i = adc[1]>>6;
if(i > 58)
i = 58;
if(i != scroll_pos) {
scroll_pos = i;
monomeFrameDirty++;
}
}
}
static void handler_SaveFlash(s32 data) {
flash_write();
}
static void handler_KeyTimer(s32 data) {
if(front_timer) {
if(front_timer == 1) {
static event_t e;
e.type = kEventSaveFlash;
event_post(&e);
preset_mode = 0;
front_timer--;
}
else front_timer--;
}
}
static void handler_ClockNormal(s32 data) {
clock_external = !gpio_get_pin_value(B09);
}
static void handler_ClockExt(s32 data) {
clock(data);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// application grid code
static void handler_MonomeGridKey(s32 data) {
u8 x, y, z;
monome_grid_key_parse_event_data(data, &x, &y, &z);
route_key_event(x, y, z);
monomeFrameDirty++;
}
////////////////////////////////////////////////////////////////////////////////
// application grid redraw
static void refresh_vari() {
monome_set_quadrant_flag(0);
monome_set_quadrant_flag(1);
}
// application grid redraw without varibright
static void refresh_mono() {
monome_set_quadrant_flag(0);
monome_set_quadrant_flag(1);
}
static void refresh_preset() {
monome_set_quadrant_flag(0);
monome_set_quadrant_flag(1);
}
static void ww_process_ii(uint8_t *data, uint8_t l) {
}
// assign event handlers
static inline void assign_main_event_handlers(void) {
app_event_handlers[ kEventFront ] = &handler_Front;
// app_event_handlers[ kEventTimer ] = &handler_Timer;
app_event_handlers[ kEventPollADC ] = &handler_PollADC;
app_event_handlers[ kEventKeyTimer ] = &handler_KeyTimer;
app_event_handlers[ kEventSaveFlash ] = &handler_SaveFlash;
app_event_handlers[ kEventClockNormal ] = &handler_ClockNormal;
app_event_handlers[ kEventClockExt ] = &handler_ClockExt;
app_event_handlers[ kEventFtdiConnect ] = &handler_FtdiConnect ;
app_event_handlers[ kEventFtdiDisconnect ] = &handler_FtdiDisconnect ;
app_event_handlers[ kEventMonomeConnect ] = &handler_MonomeConnect ;
app_event_handlers[ kEventMonomeDisconnect ] = &handler_None ;
app_event_handlers[ kEventMonomePoll ] = &handler_MonomePoll ;
app_event_handlers[ kEventMonomeRefresh ] = &handler_MonomeRefresh ;
app_event_handlers[ kEventMonomeGridKey ] = &handler_MonomeGridKey ;
}
// app event loop
void check_events(void) {
static event_t e;
if( event_next(&e) ) {
(app_event_handlers)[e.type](e.data);
}
}
// flash commands
u8 flash_is_fresh(void) {
return (flashy.fresh != FIRSTRUN_KEY);
}
// write fresh status
void flash_unfresh(void) {
flashc_memset8((void*)&(flashy.fresh), FIRSTRUN_KEY, 4, true);
}
void flash_write(void) {
}
void flash_read(void) {
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// main
int main(void)
{
sysclk_init();
init_dbg_rs232(FMCK_HZ);
init_gpio();
assign_main_event_handlers();
init_events();
init_tc();
init_spi();
init_adc();
irq_initialize_vectors();
register_interrupts();
cpu_irq_enable();
init_usb_host();
init_monome();
init_i2c_slave(0x10);
print_dbg("\r\n\n// white whale //////////////////////////////// ");
print_dbg_ulong(sizeof(flashy));
if(flash_is_fresh()) {
print_dbg("\r\nfirst run.");
flash_unfresh();
}
else {
}
init_buttons();
LENGTH = 15;
SIZE = 16;
re = &refresh_vari;
process_ii = &ww_process_ii;
clock_pulse = &clock;
clock_external = !gpio_get_pin_value(B09);
timer_add(&clockTimer,120,&clockTimer_callback, NULL);
timer_add(&keyTimer,50,&keyTimer_callback, NULL);
timer_add(&adcTimer,100,&adcTimer_callback, NULL);
// out of ADC range to force tempo
clock_temp = 10000;
while (true) {
check_events();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment