Subversion Repositories svn.mios32

Rev

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

Rev Author Line No. Line
1244 tk 1
// $Id: app.c 2425 2016-11-03 00:44:22Z tk $
2
/*
3
 * MIOS32 Tutorial #027: Standard Control Surface
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 source of the SCS
23
#include <scs.h>
24
#include "scs_config.h"
25
 
26
#include "cc_labels.h"
27
 
28
// include everything FreeRTOS related we don't understand yet ;)
29
#include <FreeRTOS.h>
30
#include <portmacro.h>
31
#include <task.h>
32
#include <queue.h>
33
#include <semphr.h>
34
 
35
 
36
// define priority level for control surface handler
37
// use lower priority as MIOS32 specific tasks (2), so that slow LCDs don't affect overall performance
38
#define PRIORITY_TASK_PERIOD_1mS_LP ( tskIDLE_PRIORITY + 2 )
39
 
40
// local prototype of the task function
41
static void TASK_Period_1mS_LP(void *pvParameters);
42
 
43
 
44
/////////////////////////////////////////////////////////////////////////////
45
// This hook is called after startup to initialize the application
46
/////////////////////////////////////////////////////////////////////////////
47
void APP_Init(void)
48
{
49
  // initialize all LEDs
50
  MIOS32_BOARD_LED_Init(0xffffffff);
51
 
52
  // initialize CC label module
53
  CC_LABELS_Init(0);
54
 
55
  // initialize all J10 pins as inputs with internal Pull-Up
56
  int pin;
57
  for(pin=0; pin<8; ++pin)
58
    MIOS32_BOARD_J10_PinInit(pin, MIOS32_BOARD_PIN_MODE_INPUT_PU);
59
 
60
  // initialize Standard Control Surface
61
  SCS_Init(0);
62
 
63
  // initialize local SCS configuration
64
  SCS_CONFIG_Init(0);
65
 
66
  // start task
2425 tk 67
  xTaskCreate(TASK_Period_1mS_LP, "1mS_LP", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS_LP, NULL);
1244 tk 68
}
69
 
70
 
71
/////////////////////////////////////////////////////////////////////////////
72
// This task is running endless in background
73
/////////////////////////////////////////////////////////////////////////////
74
void APP_Background(void)
75
{
76
}
77
 
78
 
79
/////////////////////////////////////////////////////////////////////////////
1919 tk 80
// This hook is called each mS from the main task which also handles DIN, ENC
81
// and AIN events. You could add more jobs here, but they shouldn't consume
82
// more than 300 uS to ensure the responsiveness of buttons, encoders, pots.
83
// Alternatively you could create a dedicated task for application specific
84
// jobs as explained in $MIOS32_PATH/apps/tutorials/006_rtos_tasks
85
/////////////////////////////////////////////////////////////////////////////
86
void APP_Tick(void)
87
{
1920 tk 88
  // PWM modulate the status LED (this is a sign of life)
89
  u32 timestamp = MIOS32_TIMESTAMP_Get();
90
  MIOS32_BOARD_LED_Set(1, (timestamp % 20) <= ((timestamp / 100) % 10));
1919 tk 91
}
92
 
93
 
94
/////////////////////////////////////////////////////////////////////////////
95
// This hook is called each mS from the MIDI task which checks for incoming
96
// MIDI events. You could add more MIDI related jobs here, but they shouldn't
97
// consume more than 300 uS to ensure the responsiveness of incoming MIDI.
98
/////////////////////////////////////////////////////////////////////////////
99
void APP_MIDI_Tick(void)
100
{
101
}
102
 
103
 
104
/////////////////////////////////////////////////////////////////////////////
1244 tk 105
// This hook is called when a MIDI package has been received
106
/////////////////////////////////////////////////////////////////////////////
107
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
108
{
109
}
110
 
111
 
112
/////////////////////////////////////////////////////////////////////////////
113
// This hook is called before the shift register chain is scanned
114
/////////////////////////////////////////////////////////////////////////////
115
void APP_SRIO_ServicePrepare(void)
116
{
117
  // pass current pin state of J10
1962 tk 118
  // not available for STM32F1xx, which uses the SRIO instead
1249 tk 119
  SCS_AllPinsSet(0xff00 | MIOS32_BOARD_J10_Get());
1244 tk 120
 
121
  // update encoders/buttons of SCS
122
  SCS_EncButtonUpdate_Tick();
123
}
124
 
125
 
126
/////////////////////////////////////////////////////////////////////////////
127
// This hook is called after the shift register chain has been scanned
128
/////////////////////////////////////////////////////////////////////////////
129
void APP_SRIO_ServiceFinish(void)
130
{
131
}
132
 
133
 
134
/////////////////////////////////////////////////////////////////////////////
135
// This hook is called when a button has been toggled
136
// pin_value is 1 when button released, and 0 when button pressed
137
/////////////////////////////////////////////////////////////////////////////
138
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
139
{
140
  // for STM32 (no J10 available, accordingly encoder/buttons connected to DIN):
141
  // if DIN pin number between 0..7: pass to SCS
142
  if( pin < 8 )
143
    SCS_DIN_NotifyToggle(pin, pin_value);
144
}
145
 
146
 
147
/////////////////////////////////////////////////////////////////////////////
148
// This hook is called when an encoder has been moved
149
// incrementer is positive when encoder has been turned clockwise, else
150
// it is negative
151
/////////////////////////////////////////////////////////////////////////////
152
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
153
{
154
  // pass encoder event to SCS handler
155
  if( encoder == SCS_ENC_MENU_ID )
156
    SCS_ENC_MENU_NotifyChange(incrementer);
157
}
158
 
159
 
160
/////////////////////////////////////////////////////////////////////////////
161
// This hook is called when a pot has been moved
162
/////////////////////////////////////////////////////////////////////////////
163
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
164
{
165
}
166
 
167
 
168
/////////////////////////////////////////////////////////////////////////////
1247 tk 169
// This task handles the control surface
1244 tk 170
/////////////////////////////////////////////////////////////////////////////
171
static void TASK_Period_1mS_LP(void *pvParameters)
172
{
173
  MIOS32_LCD_Clear();
174
 
175
  while( 1 ) {
176
    vTaskDelay(1 / portTICK_RATE_MS);
177
 
178
    // call SCS handler
179
    SCS_Tick();
180
  }
181
}
182