Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
C
crowbx
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacob Vosmaer
crowbx
Commits
bf40d446
Commit
bf40d446
authored
May 01, 2020
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Invert midi_read return value
parent
d77229c0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
22 deletions
+15
-22
crowbx.c
crowbx.c
+4
-4
midi-test.h
midi-test.h
+4
-4
midi.c
midi.c
+5
-9
midi.h
midi.h
+2
-5
No files found.
crowbx.c
View file @
bf40d446
...
...
@@ -32,7 +32,7 @@ void uart_buffer_push(uint8_t x) {
uint8_t
uart_buffer_pop
(
uint8_t
*
x
)
{
ATOMIC_BLOCK
(
ATOMIC_RESTORESTATE
)
{
if
(
uart_buffer
.
head
==
uart_buffer
.
tail
)
{
return
1
;
// error: uart_buffer is empty
return
false
;
// error: uart_buffer is empty
}
*
x
=
uart_buffer
.
data
[
uart_buffer
.
head
];
...
...
@@ -40,7 +40,7 @@ uint8_t uart_buffer_pop(uint8_t *x) {
(
uart_buffer
.
head
+
1
)
%
ARRAY_SIZE
(
uart_buffer
.
data
);
}
return
0
;
return
true
;
}
ISR
(
USART_RX_vect
)
{
...
...
@@ -171,13 +171,13 @@ int main(void) {
do_clock_update
();
uint8_t
status
,
data1
,
data2
;
if
(
midi_read
(
&
status
,
&
data1
,
&
data2
)
!=
MIDI_READ_OK
)
{
if
(
!
midi_read
(
&
status
,
&
data1
,
&
data2
)
)
{
continue
;
}
switch
(
status
)
{
case
MIDI_NOTE_ON
:
if
(
data2
>
0
)
{
if
(
data2
)
{
programs
[
current_program
].
note_on
(
data1
);
}
else
{
programs
[
current_program
].
note_off
(
data1
);
...
...
midi-test.h
View file @
bf40d446
...
...
@@ -13,8 +13,8 @@ uint8_t midi_load(uint8_t *status, uint8_t *data1, uint8_t *data2);
{ \
uint8_t _status, _avail, _data1, _data2; \
_avail = midi_load(&_status, &_data1, &_data2); \
assert(
(_avail != MIDI_READ_OK) == !avail);
\
if (_avail
== MIDI_READ_OK) {
\
assert(
!_avail == !avail);
\
if (_avail
) {
\
assert(((_data1 << 8) | _data2) == data); \
assert(_status == status); \
} \
...
...
@@ -24,8 +24,8 @@ uint8_t midi_load(uint8_t *status, uint8_t *data1, uint8_t *data2);
{ \
uint8_t _status, _avail, _data1, _data2; \
_avail = midi_load(&_status, &_data1, &_data2); \
assert(
(_avail != MIDI_READ_OK) == !avail);
\
if (_avail
== MIDI_READ_OK) {
\
assert(
!_avail == !avail);
\
if (_avail
) {
\
assert((_data1 << 8) == data1); \
assert(_status == status); \
} \
...
...
midi.c
View file @
bf40d446
...
...
@@ -18,7 +18,7 @@ const uint8_t statuses[] = {
[
MIDI_PITCH_BEND
]
=
0
b1110
,
};
uint8_t
midi_data_available
(
void
)
{
bool
midi_data_available
(
void
)
{
if
(
midi
.
status
==
MIDI_PROGRAM_CHANGE
)
{
return
midi
.
data_received
==
1
;
}
...
...
@@ -69,22 +69,18 @@ void midi_parse(uint8_t b) {
void
midi_init
()
{
midi_status_init
();
}
uint8_t
midi_load
(
uint8_t
*
status
,
uint8_t
*
data1
,
uint8_t
*
data2
)
{
if
(
!
midi_data_available
())
{
return
MIDI_READ_NO_DATA
;
}
*
status
=
midi
.
status
;
*
data1
=
midi
.
data
[
0
];
*
data2
=
midi
.
data
[
1
];
return
MIDI_READ_OK
;
return
midi_data_available
()
;
}
uint8_t
midi_read
(
uint8_t
*
status
,
uint8_t
*
data1
,
uint8_t
*
data2
)
{
bool
midi_read
(
uint8_t
*
status
,
uint8_t
*
data1
,
uint8_t
*
data2
)
{
uint8_t
uart_data
;
if
(
uart_read
(
&
uart_data
))
{
return
MIDI_READ_NO_DATA
;
if
(
!
uart_read
(
&
uart_data
))
{
return
false
;
}
midi_parse
(
uart_data
);
...
...
midi.h
View file @
bf40d446
#ifndef MIDI_H
#define MIDI_H
#include <stdbool.h>
#include <stdint.h>
enum
_statuses
{
...
...
@@ -24,10 +25,6 @@ enum _cc {
void
midi_init
(
void
);
void
midi_set_channel
(
uint8_t
channel
);
enum
{
MIDI_READ_OK
,
MIDI_READ_NO_DATA
,
};
uint8_t
midi_read
(
uint8_t
*
status
,
uint8_t
*
data1
,
uint8_t
*
data2
);
bool
midi_read
(
uint8_t
*
status
,
uint8_t
*
data1
,
uint8_t
*
data2
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment