Subversion Repositories svn.mios32

Rev

Rev 1919 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1284 tk 1
// $Id: app.c 1920 2014-01-08 19:29:35Z tk $
2
/*
3
 * MIOS32 Tutorial #028: OSC Client and Server
4
 * see README.txt for details
5
 *
6
 * ==========================================================================
7
 *
8
 *  Copyright (C) 2011 Thorsten Klose (tk@midibox.org)
9
 *  Licensed for personal non-commercial use only.
10
 *  All other rights reserved.
11
 *
12
 * ==========================================================================
13
 */
14
 
15
/////////////////////////////////////////////////////////////////////////////
16
// Include files
17
/////////////////////////////////////////////////////////////////////////////
18
 
19
#include <mios32.h>
20
#include "app.h"
21
 
22
#include <uip_task.h>
23
#include <osc_client.h>
24
 
25
#include "terminal.h"
26
#include "presets.h"
27
 
28
 
29
/////////////////////////////////////////////////////////////////////////////
30
// This hook is called after startup to initialize the application
31
/////////////////////////////////////////////////////////////////////////////
32
void APP_Init(void)
33
{
34
  // initialize all LEDs
35
  MIOS32_BOARD_LED_Init(0xffffffff);
36
 
37
  // install SysEx callback
38
  MIOS32_MIDI_SysExCallback_Init(APP_SYSEX_Parser);
39
 
40
  // read EEPROM content
41
  PRESETS_Init(0);
42
 
43
  // init terminal
44
  TERMINAL_Init(0);
45
 
46
  // initialize UIP Standard Task
47
  UIP_TASK_Init(0);
48
}
49
 
50
 
51
/////////////////////////////////////////////////////////////////////////////
52
// This task is running endless in background
53
/////////////////////////////////////////////////////////////////////////////
54
void APP_Background(void)
55
{
56
  // init LCD
57
  MIOS32_LCD_Clear();
58
  MIOS32_LCD_CursorSet(0, 0);
59
  MIOS32_LCD_PrintString("see README.txt   ");
60
  MIOS32_LCD_CursorSet(0, 1);
61
  MIOS32_LCD_PrintString("for details     ");
62
 
63
  // endless loop
64
  while( 1 ) {
1919 tk 65
    // do nothing
1284 tk 66
  }
67
}
68
 
69
 
70
/////////////////////////////////////////////////////////////////////////////
1919 tk 71
// This hook is called each mS from the main task which also handles DIN, ENC
72
// and AIN events. You could add more jobs here, but they shouldn't consume
73
// more than 300 uS to ensure the responsiveness of buttons, encoders, pots.
74
// Alternatively you could create a dedicated task for application specific
75
// jobs as explained in $MIOS32_PATH/apps/tutorials/006_rtos_tasks
76
/////////////////////////////////////////////////////////////////////////////
77
void APP_Tick(void)
78
{
1920 tk 79
  // PWM modulate the status LED (this is a sign of life)
80
  u32 timestamp = MIOS32_TIMESTAMP_Get();
81
  MIOS32_BOARD_LED_Set(1, (timestamp % 20) <= ((timestamp / 100) % 10));
1919 tk 82
}
83
 
84
 
85
/////////////////////////////////////////////////////////////////////////////
86
// This hook is called each mS from the MIDI task which checks for incoming
87
// MIDI events. You could add more MIDI related jobs here, but they shouldn't
88
// consume more than 300 uS to ensure the responsiveness of incoming MIDI.
89
/////////////////////////////////////////////////////////////////////////////
90
void APP_MIDI_Tick(void)
91
{
92
}
93
 
94
 
95
/////////////////////////////////////////////////////////////////////////////
1284 tk 96
// This hook is called when a MIDI package has been received
97
/////////////////////////////////////////////////////////////////////////////
98
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
99
{
100
  // SysEx would have to be handled by separate parser
101
  // see $MIOS32_PATH/apps/controllers/midio128 as example
102
  if( midi_package.type >= 4 && midi_package.type <= 7 )
103
    return;
104
 
105
  // forward USB/UART <-> OSC
106
  switch( port ) {
107
  case USB0:
108
    OSC_CLIENT_SendMIDIEvent(0, midi_package);
109
    break;
110
 
111
  case UART0:
112
    OSC_CLIENT_SendMIDIEvent(2, midi_package);
113
    break;
114
 
115
  case UART1:
116
    OSC_CLIENT_SendMIDIEvent(3, midi_package);
117
    break;
118
 
119
  case OSC0:
120
    MIOS32_MIDI_SendPackage(USB0, midi_package);
121
    break;
122
 
123
  case OSC2:
124
    MIOS32_MIDI_SendPackage(UART0, midi_package);
125
    break;
126
 
127
  case OSC3:
128
    MIOS32_MIDI_SendPackage(UART1, midi_package);
129
    break;
130
  }
131
}
132
 
133
 
134
/////////////////////////////////////////////////////////////////////////////
135
// This function parses an incoming sysex stream for MIOS32 commands
136
/////////////////////////////////////////////////////////////////////////////
137
s32 APP_SYSEX_Parser(mios32_midi_port_t port, u8 midi_in)
138
{
139
  // SysEx would have to be handled by separate parser
140
  // see $MIOS32_PATH/apps/controllers/midio128 as example
141
  return 0; // no error
142
}
143
 
144
 
145
/////////////////////////////////////////////////////////////////////////////
146
// This hook is called before the shift register chain is scanned
147
/////////////////////////////////////////////////////////////////////////////
148
void APP_SRIO_ServicePrepare(void)
149
{
150
}
151
 
152
 
153
/////////////////////////////////////////////////////////////////////////////
154
// This hook is called after the shift register chain has been scanned
155
/////////////////////////////////////////////////////////////////////////////
156
void APP_SRIO_ServiceFinish(void)
157
{
158
}
159
 
160
 
161
/////////////////////////////////////////////////////////////////////////////
162
// This hook is called when a button has been toggled
163
// pin_value is 1 when button released, and 0 when button pressed
164
/////////////////////////////////////////////////////////////////////////////
165
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
166
{
167
}
168
 
169
 
170
/////////////////////////////////////////////////////////////////////////////
171
// This hook is called when an encoder has been moved
172
// incrementer is positive when encoder has been turned clockwise, else
173
// it is negative
174
/////////////////////////////////////////////////////////////////////////////
175
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
176
{
177
}
178
 
179
 
180
/////////////////////////////////////////////////////////////////////////////
181
// This hook is called when a pot has been moved
182
/////////////////////////////////////////////////////////////////////////////
183
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
184
{
185
}