Subversion Repositories svn.mios32

Rev

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

Rev Author Line No. Line
1373 tk 1
// $Id: app.c 2425 2016-11-03 00:44:22Z tk $
2
/*
3
 * MIOS32 Tutorial #012b: Scanning up to 64 analog pots from an AINSER module
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2011 Thorsten Klose (tk@midibox.org)
8
 *  Licensed for personal non-commercial use only.
9
 *  All other rights reserved.
10
 *
11
 * ==========================================================================
12
 */
13
 
14
/////////////////////////////////////////////////////////////////////////////
15
// Include files
16
/////////////////////////////////////////////////////////////////////////////
17
 
18
#include <mios32.h>
19
#include <ainser.h>
20
#include "app.h"
21
 
22
 
23
// include everything FreeRTOS related
24
#include <FreeRTOS.h>
25
#include <portmacro.h>
26
#include <task.h>
27
#include <queue.h>
28
#include <semphr.h>
29
 
30
 
31
// define priority level for AINSER_SCAN task:
32
// use same priority as MIOS32 specific tasks (3)
33
#define PRIORITY_TASK_AINSER_SCAN ( tskIDLE_PRIORITY + 3 )
34
 
35
// local prototype of the task function
36
static void TASK_AINSER_Scan(void *pvParameters);
37
 
38
 
39
/////////////////////////////////////////////////////////////////////////////
40
// This hook is called after startup to initialize the application
41
/////////////////////////////////////////////////////////////////////////////
42
void APP_Init(void)
43
{
44
  // initialize all LEDs
45
  MIOS32_BOARD_LED_Init(0xffffffff);
46
 
47
  // initialize the AINSER module(s)
48
  AINSER_Init(0);
49
 
50
  // start task
2425 tk 51
  xTaskCreate(TASK_AINSER_Scan, "AINSER_Scan", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_AINSER_SCAN, NULL);
1373 tk 52
}
53
 
54
 
55
/////////////////////////////////////////////////////////////////////////////
56
// This task is running endless in background
57
/////////////////////////////////////////////////////////////////////////////
58
void APP_Background(void)
59
{
60
}
61
 
62
 
63
/////////////////////////////////////////////////////////////////////////////
1919 tk 64
// This hook is called each mS from the main task which also handles DIN, ENC
65
// and AIN events. You could add more jobs here, but they shouldn't consume
66
// more than 300 uS to ensure the responsiveness of buttons, encoders, pots.
67
// Alternatively you could create a dedicated task for application specific
68
// jobs as explained in $MIOS32_PATH/apps/tutorials/006_rtos_tasks
69
/////////////////////////////////////////////////////////////////////////////
70
void APP_Tick(void)
71
{
72
}
73
 
74
 
75
/////////////////////////////////////////////////////////////////////////////
76
// This hook is called each mS from the MIDI task which checks for incoming
77
// MIDI events. You could add more MIDI related jobs here, but they shouldn't
78
// consume more than 300 uS to ensure the responsiveness of incoming MIDI.
79
/////////////////////////////////////////////////////////////////////////////
80
void APP_MIDI_Tick(void)
81
{
82
}
83
 
84
 
85
/////////////////////////////////////////////////////////////////////////////
1373 tk 86
// This hook is called when a MIDI package has been received
87
/////////////////////////////////////////////////////////////////////////////
88
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
89
{
90
}
91
 
92
 
93
/////////////////////////////////////////////////////////////////////////////
94
// This hook is called before the shift register chain is scanned
95
/////////////////////////////////////////////////////////////////////////////
96
void APP_SRIO_ServicePrepare(void)
97
{
98
}
99
 
100
 
101
/////////////////////////////////////////////////////////////////////////////
102
// This hook is called after the shift register chain has been scanned
103
/////////////////////////////////////////////////////////////////////////////
104
void APP_SRIO_ServiceFinish(void)
105
{
106
}
107
 
108
 
109
/////////////////////////////////////////////////////////////////////////////
110
// This hook is called when a button has been toggled
111
// pin_value is 1 when button released, and 0 when button pressed
112
/////////////////////////////////////////////////////////////////////////////
113
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
114
{
115
}
116
 
117
 
118
/////////////////////////////////////////////////////////////////////////////
119
// This hook is called when an encoder has been moved
120
// incrementer is positive when encoder has been turned clockwise, else
121
// it is negative
122
/////////////////////////////////////////////////////////////////////////////
123
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
124
{
125
}
126
 
127
 
128
/////////////////////////////////////////////////////////////////////////////
129
// This hook is called when a pot has been moved
130
/////////////////////////////////////////////////////////////////////////////
131
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
132
{
133
  // MIOS32_AIN not used here!!!
134
}
135
 
136
 
137
/////////////////////////////////////////////////////////////////////////////
138
// This hook is called when an AINSER pot has been moved
139
/////////////////////////////////////////////////////////////////////////////
140
static void APP_AINSER_NotifyChange(u32 module, u32 pin, u32 pin_value)
141
{
142
  // toggle Status LED on each AIN value change
1919 tk 143
  MIOS32_BOARD_LED_Set(0x0001, ~MIOS32_BOARD_LED_Get());
1373 tk 144
 
145
  // convert 12bit value to 7bit value
146
  u8 value_7bit = pin_value >> 5;
147
 
148
  // send MIDI event
149
  MIOS32_MIDI_SendCC(DEFAULT, Chn1, pin + 0x10, value_7bit);
150
}
151
 
152
 
153
/////////////////////////////////////////////////////////////////////////////
154
// This task scans AINSER pins and checks for updates
155
/////////////////////////////////////////////////////////////////////////////
156
static void TASK_AINSER_Scan(void *pvParameters)
157
{
158
  portTickType xLastExecutionTime;
159
 
160
  // Initialise the xLastExecutionTime variable on task entry
161
  xLastExecutionTime = xTaskGetTickCount();
162
 
163
  while( 1 ) {
164
    vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);
165
 
166
    // scan pins
167
    AINSER_Handler(APP_AINSER_NotifyChange);
168
  }
169
}
170