Commit 445acda4 authored by Snorre Nilssen Vestli's avatar Snorre Nilssen Vestli

Initial add, Tesla IO mostly done

parents

Microsoft Visual Studio Solution File, Format Version 11.00
# Atmel Studio Solution File, Format Version 11.00
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "TeslaMidi", "TeslaMidi\TeslaMidi.cproj", "{E2ECC8A3-D5C6-44F6-BEE0-23A8D5846B0A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AVR = Debug|AVR
Release|AVR = Release|AVR
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E2ECC8A3-D5C6-44F6-BEE0-23A8D5846B0A}.Debug|AVR.ActiveCfg = Debug|AVR
{E2ECC8A3-D5C6-44F6-BEE0-23A8D5846B0A}.Debug|AVR.Build.0 = Debug|AVR
{E2ECC8A3-D5C6-44F6-BEE0-23A8D5846B0A}.Release|AVR.ActiveCfg = Release|AVR
{E2ECC8A3-D5C6-44F6-BEE0-23A8D5846B0A}.Release|AVR.Build.0 = Release|AVR
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
/*
* MIDI.c
*
* Created: 19.08.2014 23:32:07
* Author: Snorre
*/
void midi_init();
\ No newline at end of file
/*
* MIDI.h
*
* Created: 19.08.2014 23:34:37
* Author: Snorre
*/
#ifndef MIDI_H_
#define MIDI_H_
void midi_init();
#endif /* MIDI_H_ */
\ No newline at end of file
/*
* TeslaMidi.c
*
* Created: 18.08.2014 21:05:01
* Author: SNV
*/
#include <avr/io.h>
#include "MIDI.h"
#include "tesla_io.h"
#include "panel_io.h"
#include "watchdog.h"
int main(void)
{
uint8_t error;
//TESLA IO SAFE
tesla_init();
//PANEL IO INIT
panel_init();
//WATCHDOG INIT
error = watchdog_init();
if (error){
//watchdog tripped, set IO appropriately and hold.
}
//MIDI INIT
midi_init();
//WAIT FOR READY
panel_wait_run();
//WATCHDOG_START
watchdog_start();
//CARRIER_START
for (uint8_t i = 0; i < 2 ; i++){
tesla_channel_enable(i);
}
tesla_carrier_enable();
while(1)
{
//POLL MIDI USART
//PARSE MIDI
//HANDLE MIDI OUT
//READ PANEL IO
//PANEL STATE
//HANDLE WAVE IO
//PET DOG
}
}
\ No newline at end of file
/*
* miditable.h
*
* Created: 24.08.2014 15:35:37
* Author: Snorre
*/
#ifndef MIDITABLE_H_
#define MIDITABLE_H_
const uint16_t midi_per[128] = {
61156,
57724,
54484,
51426,
48540,
45815,
43244,
40817,
38526,
36364,
34323,
32396,
30578,
28862,
27242,
25713,
24270,
22908,
21622,
20408,
19263,
18182,
17161,
16198,
15289,
14431,
13621,
12856,
12135,
11454,
10811,
10204,
9631,
9091,
8581,
8099,
7645,
7215,
6810,
6428,
6067,
5727,
5405,
5102,
4816,
4545,
4290,
4050,
3822,
3608,
3405,
3214,
3034,
2863,
2703,
2551,
2408,
2273,
2145,
2025,
1911,
1804,
1703,
1607,
1517,
1432,
1351,
1276,
1204,
1136,
1073,
1012,
956,
902,
851,
804,
758,
716,
676,
638,
602,
568,
536,
506,
478,
451,
426,
402,
379,
358,
338,
319,
301,
284,
268,
253,
239,
225,
213,
201,
190,
179,
169,
159,
150,
142,
134,
127,
119,
113,
106,
100,
95,
89,
84,
80,
75,
71,
67,
63,
60,
56,
53,
50,
47,
45,
42,
40
};
/* Table giving max CC values for note channels given (T_on < 700us) and (T_on < per/2),
* and given 500khz timer clock
*
*/
const uint16_t midi_note_max[128]= {
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
350,
338,
319,
301,
284,
268,
253,
239,
226,
213,
201,
190,
179,
169,
160,
151,
142,
134,
127,
120,
113,
107,
101,
95,
90,
85,
80,
75,
71,
67,
64,
60,
57,
53,
50,
48,
45,
42,
40,
38,
36,
34,
32,
30,
28,
27,
25,
24,
23,
21,
20
};
// should be in flash
// isn't.
#endif /* MIDITABLE_H_ */
\ No newline at end of file
/*
* panel_io.c
*
* Created: 19.08.2014 23:33:20
* Author: Snorre
*/
/*
* panel_io.h
*
* Created: 19.08.2014 23:34:47
* Author: Snorre
*/
#ifndef PANEL_IO_H_
#define PANEL_IO_H_
void panel_init();
void panel_wait_run();
void panel_update();
uint8_t panel_get_level();
void panel_set_led_on(uint8_t ledmask);
void panel_set_led_off(uint8_t ledmask);
#define PANEL_ERROR (1 << 0)
#endif /* PANEL_IO_H_ */
\ No newline at end of file
/*
* tesla_io.c
*
* Created: 19.08.2014 23:33:38
* Author: Snorre
*/
#include <avr/io.h>
#include "tesladefs.h"
#include "tesla_io.h"
#include "teslaarrays.h"
#include "miditable.h"
#include "panel_io.h"
void tesla_init(){
// SET ALL IO SAFE
TESLA_C_PORT.DIR |= TESLA_C_PIN_bm;
TESLA_C_PORT.OUTCLR |= TESLA_C_PIN_bm;
TESLA_O0_PORT.DIR |= TESLA_O0_PIN_bm;
TESLA_O0_PORT.OUTCLR |= TESLA_O0_PIN_bm;
TESLA_O1_PORT.DIR |= TESLA_O0_PIN_bm;
TESLA_O1_PORT.OUTCLR |= TESLA_O0_PIN_bm;
TESLA_O2_PORT.DIR |= TESLA_O0_PIN_bm;
TESLA_O2_PORT.OUTCLR |= TESLA_O0_PIN_bm;
TESLA_O3_PORT.DIR |= TESLA_O0_PIN_bm;
TESLA_O3_PORT.OUTCLR |= TESLA_O0_PIN_bm;
for (uint8_t i = 0; i < TESLA_MAX_CHANNELS;i++){
tesla_channel_enable(i);
}
tesla_carrier_disable();
//RTFD
}
void tesla_channel_enable(uint8_t channel){
//RTFD
tesla_channel_stop(channel);
teslatimers[channel]->CTRLB |= teslacc_bm[channel]|TC_WGMODE_SINGLESLOPE_gc;
}
void tesla_carrier_enable(){
TESLA_C_TIMER.PER = TESLA_CARRIER_PER_FULL;
*TESLA_C_OCR = TESLA_CARRIER_PER_ON;
TESLA_C_TIMER.CNT = 0;
TESLA_C_TIMER.CTRLB = TESLA_C_CC_bm | TC_WGMODE_SINGLESLOPE_gc;
TESLA_C_TIMER.CTRLA = TC_CLKSEL_DIV1_gc;
// RTFD
}
void tesla_carrier_disable(){
TESLA_C_TIMER.CTRLA = TC_CLKSEL_OFF_gc;
TESLA_C_TIMER.CNT = 0;
TESLA_C_PORT.OUTCLR = TESLA_C_PIN_bm;
// RTFD
}
void tesla_channel_play(uint8_t channel, uint8_t note, uint8_t strenght){
if (channel >= TESLA_MAX_CHANNELS){
tesla_panic();
}
// stop channel to ensure known state when configuring
tesla_channel_stop(channel);
*teslacc[channel] = (((uint32_t) panel_get_level()) * ((uint32_t)midi_note_max[note])) >> 8;
//Should max scale with level?
//lookup & set PER
teslatimers[channel]->PER = midi_per[channel]; //bend?
//lookup (if necessary) and set prescaler
teslatimers[channel]->CTRLA = TC_CLKSEL_DIV64_gc;
//RTFD
}
void tesla_channel_stop(uint8_t channel){
if (channel >= TESLA_MAX_CHANNELS){
tesla_panic();
}
// STOP TIMER
teslatimers[channel]->CTRLA = TC_CLKSEL_OFF_gc;
// CLEAR TIMER
teslatimers[channel]->CNT = 0;
// CLEAR IO
teslaport[channel]->OUTCLR = teslaportpinbm[channel];
// CLEAR OCR
*teslacc[channel] = 0;
//RTFD
}
void tesla_panic(){
// turn off everything
tesla_carrier_disable();
for (uint8_t i = 0; i < TESLA_MAX_CHANNELS; i++){
tesla_channel_stop(i);
}
panel_set_led_on(PANEL_ERROR);
// wait forever
while(1);
}
\ No newline at end of file
/*
* tesla_io.h
*
* Created: 19.08.2014 23:34:55
* Author: Snorre
*/
#ifndef TESLA_IO_H_
#define TESLA_IO_H_
void tesla_init();
void tesla_channel_enable(uint8_t channel);
void tesla_carrier_enable();
void tesla_carrier_disable();
void tesla_channel_stop(uint8_t channel);
void tesla_channel_play(uint8_t channel, uint8_t note, uint8_t strenght);
void tesla_panic();
#endif /* TESLA_IO_H_ */
\ No newline at end of file
/*
* teslatimers.h
*
* Created: 24.08.2014 13:46:04
* Author: Snorre
*/
#ifndef TESLATIMERS_H_
#define TESLATIMERS_H_
#include <avr/io.h>
#include "tesladefs.h"
// ASSUMES TC0_struct Binary compatible with TC1_struct given no illegal register access.
// Verify this repeatedly when reviewing
TC0_t* teslatimers[4] = {
&TESLA_O0_TIMER,
&TESLA_O1_TIMER,
&TESLA_O2_TIMER,
&TESLA_O3_TIMER
};
volatile uint16_t* teslacc[4] = {
TESLA_O0_OCR,
TESLA_O1_OCR,
TESLA_O2_OCR,
TESLA_O3_OCR
};
PORT_t* teslaport[4] = {
&TESLA_O0_PORT,
&TESLA_O1_PORT,
&TESLA_O2_PORT,
&TESLA_O3_PORT
};
uint8_t teslaportpinbm[4] = {
TESLA_O0_PIN_bm,
TESLA_O1_PIN_bm,
TESLA_O2_PIN_bm,
TESLA_O3_PIN_bm
};
uint8_t teslacc_bm[4] = {
TESLA_O0_CC_bm,
TESLA_O1_CC_bm,
TESLA_O2_CC_bm,
TESLA_O3_CC_bm
};
#endif /* TESLATIMERS_H_ */
\ No newline at end of file
/*
* tesladefs.h
*
* Created: 19.08.2014 23:59:46
* Author: Snorre
*/
#ifndef TESLADEFS_H_
#define TESLADEFS_H_
#include <avr/io.h>
#define TESLA_MAX_ON 700 us
#define TESLA_CARRIER_PER_FULL 16
#define TESLA_CARRIER_PER_ON 2 // ?
#define TESLA_MAX_CHANNELS 2
#define TESLA_O0_PORT PORTC
#define TESLA_O0_PIN 0
#define TESLA_O0_PIN_bm (1 << TESLA_O0_PIN)
#define TESLA_O0_TIMER TCC0
#define TESLA_O0_OCR (&((&TESLA_O0_TIMER)->CCA))
#define TESLA_O0_CC_bm TC0_CCAEN_bm
#define TESLA_O1_PORT PORTC
#define TESLA_O1_PIN 0
#define TESLA_O1_PIN_bm (1 << TESLA_O1_PIN)
#define TESLA_O1_TIMER TCC0
#define TESLA_O1_OCR (&((&TESLA_O0_TIMER)->CCA))
#define TESLA_O1_CC_bm TC0_CCAEN_bm
#define TESLA_O2_PORT PORTC
#define TESLA_O2_PIN 0
#define TESLA_O2_PIN_bm (1 << TESLA_O2_PIN)
#define TESLA_O2_TIMER TCC0
#define TESLA_O2_OCR (&((&TESLA_O0_TIMER)->CCA))
#define TESLA_O2_CC_bm TC0_CCAEN_bm
#define TESLA_O3_PORT PORTC
#define TESLA_O3_PIN 0
#define TESLA_O3_PIN_bm (1 << TESLA_O3_PIN)
#define TESLA_O3_TIMER TCC0
#define TESLA_O3_OCR (&((&TESLA_O0_TIMER)->CCA))
#define TESLA_O3_CC_bm TC0_CCAEN_bm
#define TESLA_C_PORT PORTC
#define TESLA_C_PIN 0
#define TESLA_C_PIN_bm (1 << TESLA_C_PIN)
#define TESLA_C_TIMER TCC1
#define TESLA_C_OCR (&((&TESLA_O0_TIMER)->CCA))
#define TESLA_C_CC_bm TC0_CCAEN_bm
#endif /* TESLADEFS_H_ */
\ No newline at end of file
/*
* watchdog.c
*
* Created: 19.08.2014 23:32:46
* Author: Snorre
*/
/*
* watchdog.h
*
* Created: 19.08.2014 23:35:05
* Author: Snorre
*/
#ifndef WATCHDOG_H_
#define WATCHDOG_H_
uint8_t watchdog_init();
void watchdog_start();
void watchdog_pet();
#endif /* WATCHDOG_H_ */
\ No newline at end of file
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