Subversion Repositories svn.mios32

Rev

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

Rev Author Line No. Line
981 JRFarmer 1
// $Id: app.c $
2
/*
3
 * MIOS32 Application Template
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) 2010 Jonathan Farmer (JRFarmer.com@gmail.com)
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>
1118 tk 19
#include <dpot.h>
981 JRFarmer 20
#include "app.h"
21
 
22
 
23
/////////////////////////////////////////////////////////////////////////////
24
// Global variables
25
/////////////////////////////////////////////////////////////////////////////
26
 
27
uint32_t auto_increment;
28
 
29
/////////////////////////////////////////////////////////////////////////////
30
// This hook is called after startup to initialize the application
31
/////////////////////////////////////////////////////////////////////////////
32
void APP_Init(void)
33
{
34
    int pot;
35
 
36
    // initialize all LEDs
37
    MIOS32_BOARD_LED_Init(0xFFFFFFFF);
38
 
39
    // initialize digital potentiometer interface
40
    DPOT_Init(0);
41
    MIOS32_MIDI_SendDebugMessage("DPOT module has been initialized!\n");
42
 
43
    // iniitialize digital pots to unique values
44
    for (pot = 0; pot < DPOT_NUM_POTS; pot++)
45
    {
46
        DPOT_Set_Value(pot, (uint16_t)(pot * 0x40));
47
        MIOS32_MIDI_SendDebugMessage("DPOT 0x%02X initialized to %04X\n",
48
                                     pot,
49
                                     DPOT_Get_Value(pot));
50
    }
51
 
52
    // setup each potentiometer for auto incrememting
53
    auto_increment = 0xFFFFFFFF;
54
}
55
 
56
 
57
/////////////////////////////////////////////////////////////////////////////
58
// This task is running endless in background
59
/////////////////////////////////////////////////////////////////////////////
60
void APP_Background(void)
61
{
1919 tk 62
}
63
 
64
 
65
/////////////////////////////////////////////////////////////////////////////
66
// This hook is called each mS from the main task which also handles DIN, ENC
67
// and AIN events. You could add more jobs here, but they shouldn't consume
68
// more than 300 uS to ensure the responsiveness of buttons, encoders, pots.
69
// Alternatively you could create a dedicated task for application specific
70
// jobs as explained in $MIOS32_PATH/apps/tutorials/006_rtos_tasks
71
/////////////////////////////////////////////////////////////////////////////
72
void APP_Tick(void)
73
{
981 JRFarmer 74
    int pot;
75
 
1920 tk 76
    // PWM modulate the status LED (this is a sign of life)
77
    u32 timestamp = MIOS32_TIMESTAMP_Get();
78
    MIOS32_BOARD_LED_Set(1, (timestamp % 20) <= ((timestamp / 100) % 10));
981 JRFarmer 79
 
1919 tk 80
    // Update potentiometer hardware
81
    DPOT_Update();
981 JRFarmer 82
 
1919 tk 83
    // increment all the digital pots
84
    for (pot = 0; pot < DPOT_NUM_POTS; pot++)
85
    {
86
      if (auto_increment & (0x00000001 << pot))
87
      {
88
    DPOT_Set_Value(pot, DPOT_Get_Value(pot) + 1);
89
      }
981 JRFarmer 90
    }
91
}
92
 
93
 
94
/////////////////////////////////////////////////////////////////////////////
1919 tk 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
/////////////////////////////////////////////////////////////////////////////
981 JRFarmer 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
    switch (midi_package.evnt0 >> 4)
110
    {
111
        case CC:
112
            if (midi_package.evnt1 > 6 && midi_package.evnt1 < 11)
113
            {
114
                DPOT_Set_Value((midi_package.evnt1 - 7), (midi_package.evnt2 << 1));
115
                auto_increment &= ~(0x00000001 << (midi_package.evnt1 - 7));
116
                MIOS32_MIDI_SendDebugMessage("Pot 0x%02X value set to 0x%02X\n",
117
                                             midi_package.evnt1 - 7,
118
                                             DPOT_Get_Value(midi_package.evnt1 - 7));
119
                MIOS32_MIDI_SendDebugMessage("auto_increment = 0x%08X\n", auto_increment);
120
            }
121
            break;
122
 
123
        default:
124
            if (midi_package.evnt0 != 0xFE)
125
            {
126
                // send received MIDI package to MIOS Terminal
127
                MIOS32_MIDI_SendDebugMessage("Port:%02X  Type:%X  Evnt0:%02X  Evnt1:%02X  Evnt2:%02X\n",
128
                                             port,
129
                                             midi_package.type,
130
                                             midi_package.evnt0, midi_package.evnt1, midi_package.evnt2);
131
            }
132
            break;
133
    }
134
}
135
 
136
 
137
/////////////////////////////////////////////////////////////////////////////
138
// This hook is called before the shift register chain is scanned
139
/////////////////////////////////////////////////////////////////////////////
140
void APP_SRIO_ServicePrepare(void)
141
{
142
}
143
 
144
 
145
/////////////////////////////////////////////////////////////////////////////
146
// This hook is called after the shift register chain has been scanned
147
/////////////////////////////////////////////////////////////////////////////
148
void APP_SRIO_ServiceFinish(void)
149
{
150
}
151
 
152
 
153
/////////////////////////////////////////////////////////////////////////////
154
// This hook is called when a button has been toggled
155
// pin_value is 1 when button released, and 0 when button pressed
156
/////////////////////////////////////////////////////////////////////////////
157
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
158
{
159
}
160
 
161
 
162
/////////////////////////////////////////////////////////////////////////////
163
// This hook is called when an encoder has been moved
164
// incrementer is positive when encoder has been turned clockwise, else
165
// it is negative
166
/////////////////////////////////////////////////////////////////////////////
167
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
168
{
169
}
170
 
171
 
172
/////////////////////////////////////////////////////////////////////////////
173
// This hook is called when a pot has been moved
174
/////////////////////////////////////////////////////////////////////////////
175
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
176
{
177
}