Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
attiny44a_blink
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Strand
attiny44a_blink
Commits
cf382268
Commit
cf382268
authored
6 years ago
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Attempt to get songs to play
parent
7b56a163
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
midi_test.c
+121
-23
121 additions, 23 deletions
midi_test.c
with
121 additions
and
23 deletions
midi_test.c
+
121
−
23
View file @
cf382268
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define bit_delay_time 8.
5
// bit delay for 115200 with overhead
#define bit_delay_time 8.
4
// bit delay for 115200 with overhead
//#define bit_delay_time 31.82 // bit delay for 31250 with overhead
//#define bit_delay_time 31.82 // bit delay for 31250 with overhead
#define bit_delay() _delay_us(bit_delay_time) // RS232 bit delay
#define bit_delay() _delay_us(bit_delay_time) // RS232 bit delay
#define half_bit_delay() _delay_us(bit_delay_time/2) // RS232 half bit delay
#define half_bit_delay() _delay_us(bit_delay_time/2) // RS232 half bit delay
...
@@ -42,7 +42,11 @@
...
@@ -42,7 +42,11 @@
#define led_pin (1 << PB2)
#define led_pin (1 << PB2)
void
put_char
(
volatile
unsigned
char
*
port
,
unsigned
char
pin
,
char
txchar
)
{
#define note_on 144
#define note_off 128
void
put_char
(
volatile
unsigned
char
*
port
,
unsigned
char
pin
,
uint8_t
txchar
)
{
// send character in txchar on port pin
// send character in txchar on port pin
// assumes line driver (inverts bits)
// assumes line driver (inverts bits)
//
//
...
@@ -97,9 +101,15 @@ void put_char(volatile unsigned char *port, unsigned char pin, char txchar) {
...
@@ -97,9 +101,15 @@ void put_char(volatile unsigned char *port, unsigned char pin, char txchar) {
bit_delay
();
bit_delay
();
// char delay
// char delay
bit
_delay
();
char
_delay
();
}
}
struct
MidiEvent
{
uint16_t
tick
;
uint8_t
status
;
uint8_t
note
;
uint8_t
velocity
;
};
int
main
(
void
)
{
int
main
(
void
)
{
// Set the clock prescaler to 1.
// Set the clock prescaler to 1.
...
@@ -116,30 +126,118 @@ int main(void) {
...
@@ -116,30 +126,118 @@ int main(void) {
// Configure led_pin as an output.
// Configure led_pin as an output.
DDRB
|=
led_pin
;
DDRB
|=
led_pin
;
// Blink the LED with ~1.0s half-period.
uint16_t
current_tick
=
0
;
// 100 * 200 * 1024 / 20M ~ 2.5s
uint16_t
max_tick
=
960
;
int
count
=
0
;
uint8_t
event_index
=
0
;
// 120 ticks per quarter note
const
struct
MidiEvent
events
[]
=
{
// Stagefright
/*
{0, note_on, 40, 100},
{60, note_off, 40, 100},
{60, note_on, 40, 100},
{120, note_off, 40, 100},
{120, note_on, 40, 100},
{180, note_off, 40, 100},
{180, note_on, 42, 100},
{240, note_off, 42, 100},
{240, note_on, 43, 100},
{300, note_off, 43, 100},
{300, note_on, 43, 100},
{360, note_off, 43, 100},
{360, note_on, 44, 100},
{420, note_off, 44, 100},
{420, note_on, 44, 100},
{480, note_off, 44, 100},
//{480, note_on, 45, 100},
//{540, note_off, 45, 100},
{540, note_on, 45, 100},
{600, note_off, 45, 100},
{600, note_on, 45, 100},
{660, note_off, 45, 100},
{660, note_on, 47, 100},
{720, note_off, 47, 100},
{720, note_on, 48, 100},
{780, note_off, 48, 100},
{780, note_on, 48, 100},
{840, note_off, 48, 100},
{840, note_on, 51, 100},
{900, note_off, 51, 100},
{900, note_on, 51, 100},
{960, note_off, 51, 100},
*/
// Bb
{
0
,
note_on
,
58
,
100
},
{
30
,
note_on
,
62
,
100
},
{
60
,
note_on
,
65
,
100
},
{
90
,
note_on
,
69
,
100
},
{
180
,
note_off
,
69
,
100
},
{
180
,
note_off
,
65
,
100
},
{
180
,
note_off
,
62
,
100
},
{
180
,
note_off
,
58
,
100
},
{
240
+
0
,
note_on
,
58
,
100
},
{
240
+
30
,
note_on
,
61
,
100
},
{
240
+
60
,
note_on
,
64
,
100
},
{
240
+
90
,
note_on
,
67
,
100
},
{
240
+
180
,
note_off
,
67
,
100
},
{
240
+
180
,
note_off
,
64
,
100
},
{
240
+
180
,
note_off
,
61
,
100
},
{
240
+
180
,
note_off
,
58
,
100
},
{
480
+
0
,
note_on
,
60
,
100
},
{
480
+
30
,
note_on
,
64
,
100
},
{
480
+
60
,
note_on
,
65
,
100
},
{
480
+
90
,
note_on
,
69
,
100
},
{
480
+
180
,
note_off
,
69
,
100
},
{
480
+
180
,
note_off
,
65
,
100
},
{
480
+
180
,
note_off
,
64
,
100
},
{
480
+
180
,
note_off
,
60
,
100
},
{
720
+
0
,
note_on
,
60
,
100
},
{
720
+
30
,
note_on
,
63
,
100
},
{
720
+
60
,
note_on
,
65
,
100
},
{
720
+
90
,
note_on
,
69
,
100
},
{
720
+
180
,
note_off
,
69
,
100
},
{
720
+
180
,
note_off
,
65
,
100
},
{
720
+
180
,
note_off
,
63
,
100
},
{
720
+
180
,
note_off
,
60
,
100
},
// sentinel
{
65535
,
note_off
,
50
,
100
},
};
while
(
1
)
{
while
(
1
)
{
// If it's been 10ms, reset the timer and increment count.
if
(
TCNT0
>=
120
)
{
if
(
TCNT0
>=
200
)
{
TCNT0
=
0
;
TCNT0
=
0
;
++
count
;
++
current_tick
;
// When count reaches 100, turn the LED on and send a note on command.
while
(
events
[
event_index
].
tick
<=
current_tick
)
{
if
(
count
==
100
)
{
put_char
(
&
serial_port
,
serial_pin_out
,
events
[
event_index
].
status
);
PORTB
|=
led_pin
;
put_char
(
&
serial_port
,
serial_pin_out
,
events
[
event_index
].
note
);
put_char
(
&
serial_port
,
serial_pin_out
,
144
);
// note on
put_char
(
&
serial_port
,
serial_pin_out
,
events
[
event_index
].
velocity
);
put_char
(
&
serial_port
,
serial_pin_out
,
70
);
// note (A4)
++
event_index
;
put_char
(
&
serial_port
,
serial_pin_out
,
100
);
// velocity
}
}
// When count reaches 200, turn the LED off and send a note off command.
if
(
current_tick
==
max_tick
)
{
else
if
(
count
==
200
)
{
current_tick
=
0
;
PORTB
&=
~
led_pin
;
event_index
=
0
;
put_char
(
&
serial_port
,
serial_pin_out
,
128
);
// note off
PORTB
^=
led_pin
;
put_char
(
&
serial_port
,
serial_pin_out
,
70
);
// note (A4)
put_char
(
&
serial_port
,
serial_pin_out
,
100
);
// velocity
/*
count
=
0
;
while (events[event_index].tick <= current_tick) {
put_char(&serial_port, serial_pin_out, events[event_index].status);
put_char(&serial_port, serial_pin_out, events[event_index].note);
put_char(&serial_port, serial_pin_out, events[event_index].velocity);
++event_index;
}
*/
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment