Subversion Repositories svn.mios32

Rev

Rev 1993 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1993 Rev 2425
1
// $Id: app.c 1993 2014-05-05 22:16:29Z tk $
1
// $Id: app.c 2425 2016-11-03 00:44:22Z tk $
2
/*
2
/*
3
 * MIOS32 Tutorial #027: Standard Control Surface
3
 * MIOS32 Tutorial #027: Standard Control Surface
4
 * see README.txt for details
4
 * see README.txt for details
5
 *
5
 *
6
 * MODIFICATION: buttons and encoders are connected to DIN shift register
6
 * MODIFICATION: buttons and encoders are connected to DIN shift register
7
 * instead of J10
7
 * instead of J10
8
 * Soft button mode disabled, using a cursor instead (see mios32_config.h)
8
 * Soft button mode disabled, using a cursor instead (see mios32_config.h)
9
 *
9
 *
10
 * ==========================================================================
10
 * ==========================================================================
11
 *
11
 *
12
 *  Copyright (C) 2011 Thorsten Klose (tk@midibox.org)
12
 *  Copyright (C) 2011 Thorsten Klose (tk@midibox.org)
13
 *  Licensed for personal non-commercial use only.
13
 *  Licensed for personal non-commercial use only.
14
 *  All other rights reserved.
14
 *  All other rights reserved.
15
 *
15
 *
16
 * ==========================================================================
16
 * ==========================================================================
17
 */
17
 */
18
18
19
/////////////////////////////////////////////////////////////////////////////
19
/////////////////////////////////////////////////////////////////////////////
20
// Include files
20
// Include files
21
/////////////////////////////////////////////////////////////////////////////
21
/////////////////////////////////////////////////////////////////////////////
22
22
23
#include <mios32.h>
23
#include <mios32.h>
24
#include "app.h"
24
#include "app.h"
25
25
26
// include source of the SCS
26
// include source of the SCS
27
#include <scs.h>
27
#include <scs.h>
28
#include "scs_config.h"
28
#include "scs_config.h"
29
29
30
#include "cc_labels.h"
30
#include "cc_labels.h"
31
31
32
// include everything FreeRTOS related we don't understand yet ;)
32
// include everything FreeRTOS related we don't understand yet ;)
33
#include <FreeRTOS.h>
33
#include <FreeRTOS.h>
34
#include <portmacro.h>
34
#include <portmacro.h>
35
#include <task.h>
35
#include <task.h>
36
#include <queue.h>
36
#include <queue.h>
37
#include <semphr.h>
37
#include <semphr.h>
38
38
39
39
40
// define priority level for control surface handler
40
// define priority level for control surface handler
41
// use lower priority as MIOS32 specific tasks (2), so that slow LCDs don't affect overall performance
41
// use lower priority as MIOS32 specific tasks (2), so that slow LCDs don't affect overall performance
42
#define PRIORITY_TASK_PERIOD_1mS_LP ( tskIDLE_PRIORITY + 2 )
42
#define PRIORITY_TASK_PERIOD_1mS_LP ( tskIDLE_PRIORITY + 2 )
43
43
44
// local prototype of the task function
44
// local prototype of the task function
45
static void TASK_Period_1mS_LP(void *pvParameters);
45
static void TASK_Period_1mS_LP(void *pvParameters);
46
46
47
47
48
/////////////////////////////////////////////////////////////////////////////
48
/////////////////////////////////////////////////////////////////////////////
49
// This hook is called after startup to initialize the application
49
// This hook is called after startup to initialize the application
50
/////////////////////////////////////////////////////////////////////////////
50
/////////////////////////////////////////////////////////////////////////////
51
void APP_Init(void)
51
void APP_Init(void)
52
{
52
{
53
  // initialize all LEDs
53
  // initialize all LEDs
54
  MIOS32_BOARD_LED_Init(0xffffffff);
54
  MIOS32_BOARD_LED_Init(0xffffffff);
55
55
56
  // initialize CC label module
56
  // initialize CC label module
57
  CC_LABELS_Init(0);
57
  CC_LABELS_Init(0);
58
58
59
  // initialize all J10 pins as inputs with internal Pull-Up
59
  // initialize all J10 pins as inputs with internal Pull-Up
60
  int pin;
60
  int pin;
61
  for(pin=0; pin<8; ++pin)
61
  for(pin=0; pin<8; ++pin)
62
    MIOS32_BOARD_J10_PinInit(pin, MIOS32_BOARD_PIN_MODE_INPUT_PU);
62
    MIOS32_BOARD_J10_PinInit(pin, MIOS32_BOARD_PIN_MODE_INPUT_PU);
63
63
64
  // initialize Standard Control Surface
64
  // initialize Standard Control Surface
65
  SCS_Init(0);
65
  SCS_Init(0);
66
66
67
  // configure rotary encoder connected to DIN SR
67
  // configure rotary encoder connected to DIN SR
68
  // use 1 instead of 0, since encoder 0 is used at J10
68
  // use 1 instead of 0, since encoder 0 is used at J10
69
  mios32_enc_config_t enc_config = MIOS32_ENC_ConfigGet(0);
69
  mios32_enc_config_t enc_config = MIOS32_ENC_ConfigGet(0);
70
  enc_config.cfg.type = DETENTED2; // see mios32_enc.h for available types
70
  enc_config.cfg.type = DETENTED2; // see mios32_enc.h for available types
71
  enc_config.cfg.sr = APP_SCS_ENC_SR; // defined in mios32_defines.h
71
  enc_config.cfg.sr = APP_SCS_ENC_SR; // defined in mios32_defines.h
72
  enc_config.cfg.pos = APP_SCS_ENC_FIRST_PIN; // defined in mios32_defines.h
72
  enc_config.cfg.pos = APP_SCS_ENC_FIRST_PIN; // defined in mios32_defines.h
73
  enc_config.cfg.speed = NORMAL;
73
  enc_config.cfg.speed = NORMAL;
74
  enc_config.cfg.speed_par = 0;
74
  enc_config.cfg.speed_par = 0;
75
  MIOS32_ENC_ConfigSet(1, enc_config);
75
  MIOS32_ENC_ConfigSet(1, enc_config);
76
76
77
  // initialize local SCS configuration
77
  // initialize local SCS configuration
78
  SCS_CONFIG_Init(0);
78
  SCS_CONFIG_Init(0);
79
79
80
  // start task
80
  // start task
81
  xTaskCreate(TASK_Period_1mS_LP, (signed portCHAR *)"1mS_LP", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS_LP, NULL);
81
  xTaskCreate(TASK_Period_1mS_LP, "1mS_LP", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS_LP, NULL);
82
}
82
}
83
83
84
84
85
/////////////////////////////////////////////////////////////////////////////
85
/////////////////////////////////////////////////////////////////////////////
86
// This task is running endless in background
86
// This task is running endless in background
87
/////////////////////////////////////////////////////////////////////////////
87
/////////////////////////////////////////////////////////////////////////////
88
void APP_Background(void)
88
void APP_Background(void)
89
{
89
{
90
}
90
}
91
91
92
92
93
/////////////////////////////////////////////////////////////////////////////
93
/////////////////////////////////////////////////////////////////////////////
94
// This hook is called each mS from the main task which also handles DIN, ENC
94
// This hook is called each mS from the main task which also handles DIN, ENC
95
// and AIN events. You could add more jobs here, but they shouldn't consume
95
// and AIN events. You could add more jobs here, but they shouldn't consume
96
// more than 300 uS to ensure the responsiveness of buttons, encoders, pots.
96
// more than 300 uS to ensure the responsiveness of buttons, encoders, pots.
97
// Alternatively you could create a dedicated task for application specific
97
// Alternatively you could create a dedicated task for application specific
98
// jobs as explained in $MIOS32_PATH/apps/tutorials/006_rtos_tasks
98
// jobs as explained in $MIOS32_PATH/apps/tutorials/006_rtos_tasks
99
/////////////////////////////////////////////////////////////////////////////
99
/////////////////////////////////////////////////////////////////////////////
100
void APP_Tick(void)
100
void APP_Tick(void)
101
{
101
{
102
  // PWM modulate the status LED (this is a sign of life)
102
  // PWM modulate the status LED (this is a sign of life)
103
  u32 timestamp = MIOS32_TIMESTAMP_Get();
103
  u32 timestamp = MIOS32_TIMESTAMP_Get();
104
  MIOS32_BOARD_LED_Set(1, (timestamp % 20) <= ((timestamp / 100) % 10));
104
  MIOS32_BOARD_LED_Set(1, (timestamp % 20) <= ((timestamp / 100) % 10));
105
}
105
}
106
106
107
107
108
/////////////////////////////////////////////////////////////////////////////
108
/////////////////////////////////////////////////////////////////////////////
109
// This hook is called each mS from the MIDI task which checks for incoming
109
// This hook is called each mS from the MIDI task which checks for incoming
110
// MIDI events. You could add more MIDI related jobs here, but they shouldn't
110
// MIDI events. You could add more MIDI related jobs here, but they shouldn't
111
// consume more than 300 uS to ensure the responsiveness of incoming MIDI.
111
// consume more than 300 uS to ensure the responsiveness of incoming MIDI.
112
/////////////////////////////////////////////////////////////////////////////
112
/////////////////////////////////////////////////////////////////////////////
113
void APP_MIDI_Tick(void)
113
void APP_MIDI_Tick(void)
114
{
114
{
115
}
115
}
116
116
117
117
118
/////////////////////////////////////////////////////////////////////////////
118
/////////////////////////////////////////////////////////////////////////////
119
// This hook is called when a MIDI package has been received
119
// This hook is called when a MIDI package has been received
120
/////////////////////////////////////////////////////////////////////////////
120
/////////////////////////////////////////////////////////////////////////////
121
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
121
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
122
{
122
{
123
}
123
}
124
124
125
125
126
/////////////////////////////////////////////////////////////////////////////
126
/////////////////////////////////////////////////////////////////////////////
127
// This hook is called before the shift register chain is scanned
127
// This hook is called before the shift register chain is scanned
128
/////////////////////////////////////////////////////////////////////////////
128
/////////////////////////////////////////////////////////////////////////////
129
void APP_SRIO_ServicePrepare(void)
129
void APP_SRIO_ServicePrepare(void)
130
{
130
{
131
  // pass current pin state of the DINs (not J10)
131
  // pass current pin state of the DINs (not J10)
132
  // not available for STM32F1xx, which uses the SRIO instead
132
  // not available for STM32F1xx, which uses the SRIO instead
133
  SCS_AllPinsSet(0xff00 | MIOS32_BOARD_J10_Get());
133
  SCS_AllPinsSet(0xff00 | MIOS32_BOARD_J10_Get());
134
134
135
  // update encoders/buttons of SCS
135
  // update encoders/buttons of SCS
136
  SCS_EncButtonUpdate_Tick();
136
  SCS_EncButtonUpdate_Tick();
137
}
137
}
138
138
139
139
140
/////////////////////////////////////////////////////////////////////////////
140
/////////////////////////////////////////////////////////////////////////////
141
// This hook is called after the shift register chain has been scanned
141
// This hook is called after the shift register chain has been scanned
142
/////////////////////////////////////////////////////////////////////////////
142
/////////////////////////////////////////////////////////////////////////////
143
void APP_SRIO_ServiceFinish(void)
143
void APP_SRIO_ServiceFinish(void)
144
{
144
{
145
}
145
}
146
146
147
147
148
/////////////////////////////////////////////////////////////////////////////
148
/////////////////////////////////////////////////////////////////////////////
149
// This hook is called when a button has been toggled
149
// This hook is called when a button has been toggled
150
// pin_value is 1 when button released, and 0 when button pressed
150
// pin_value is 1 when button released, and 0 when button pressed
151
/////////////////////////////////////////////////////////////////////////////
151
/////////////////////////////////////////////////////////////////////////////
152
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
152
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
153
{
153
{
154
  // for STM32 (no J10 available, accordingly encoder/buttons connected to DIN):
154
  // for STM32 (no J10 available, accordingly encoder/buttons connected to DIN):
155
  // if DIN pin number between 0..7: pass to SCS
155
  // if DIN pin number between 0..7: pass to SCS
156
  if( pin < 8 )
156
  if( pin < 8 )
157
    SCS_DIN_NotifyToggle(pin, pin_value);
157
    SCS_DIN_NotifyToggle(pin, pin_value);
158
}
158
}
159
159
160
160
161
/////////////////////////////////////////////////////////////////////////////
161
/////////////////////////////////////////////////////////////////////////////
162
// This hook is called when an encoder has been moved
162
// This hook is called when an encoder has been moved
163
// incrementer is positive when encoder has been turned clockwise, else
163
// incrementer is positive when encoder has been turned clockwise, else
164
// it is negative
164
// it is negative
165
/////////////////////////////////////////////////////////////////////////////
165
/////////////////////////////////////////////////////////////////////////////
166
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
166
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
167
{
167
{
168
  // pass encoder event to SCS handler
168
  // pass encoder event to SCS handler
169
  if( encoder == SCS_ENC_MENU_ID || encoder == 1 ) // encoder at J10 and our encoder connected to DIN SR
169
  if( encoder == SCS_ENC_MENU_ID || encoder == 1 ) // encoder at J10 and our encoder connected to DIN SR
170
    SCS_ENC_MENU_NotifyChange(incrementer);
170
    SCS_ENC_MENU_NotifyChange(incrementer);
171
  else {
171
  else {
172
    MIOS32_MIDI_SendDebugMessage("Encoder #%d not mapped (inc=%d)\n", encoder, incrementer);
172
    MIOS32_MIDI_SendDebugMessage("Encoder #%d not mapped (inc=%d)\n", encoder, incrementer);
173
  }
173
  }
174
}
174
}
175
175
176
176
177
/////////////////////////////////////////////////////////////////////////////
177
/////////////////////////////////////////////////////////////////////////////
178
// This hook is called when a pot has been moved
178
// This hook is called when a pot has been moved
179
/////////////////////////////////////////////////////////////////////////////
179
/////////////////////////////////////////////////////////////////////////////
180
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
180
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
181
{
181
{
182
}
182
}
183
183
184
184
185
/////////////////////////////////////////////////////////////////////////////
185
/////////////////////////////////////////////////////////////////////////////
186
// This task handles the control surface
186
// This task handles the control surface
187
/////////////////////////////////////////////////////////////////////////////
187
/////////////////////////////////////////////////////////////////////////////
188
static void TASK_Period_1mS_LP(void *pvParameters)
188
static void TASK_Period_1mS_LP(void *pvParameters)
189
{
189
{
190
  MIOS32_LCD_Clear();
190
  MIOS32_LCD_Clear();
191
191
192
  while( 1 ) {
192
  while( 1 ) {
193
    vTaskDelay(1 / portTICK_RATE_MS);
193
    vTaskDelay(1 / portTICK_RATE_MS);
194
194
195
    // call SCS handler
195
    // call SCS handler
196
    SCS_Tick();
196
    SCS_Tick();
197
  }
197
  }
198
}
198
}
199
199
200
 
200