Rev 1919 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
682 | tk | 1 | // $Id: app.c 1920 2014-01-08 19:29:35Z tk $ |
2 | /* |
||
3 | * MIOS32 Tutorial #005: Polling J5 Pins |
||
4 | * see README.txt for details |
||
5 | * |
||
6 | * ========================================================================== |
||
7 | * |
||
8 | * Copyright (C) 2009 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 | |||
23 | ///////////////////////////////////////////////////////////////////////////// |
||
24 | // This hook is called after startup to initialize the application |
||
25 | ///////////////////////////////////////////////////////////////////////////// |
||
26 | void APP_Init(void) |
||
27 | { |
||
28 | // initialize all LEDs |
||
29 | MIOS32_BOARD_LED_Init(0xffffffff); |
||
30 | |||
31 | // initialize all pins of J5A, J5B and J5C as inputs with internal Pull-Up |
||
32 | int pin; |
||
33 | for(pin=0; pin<12; ++pin) |
||
34 | MIOS32_BOARD_J5_PinInit(pin, MIOS32_BOARD_PIN_MODE_INPUT_PU); |
||
35 | } |
||
36 | |||
37 | |||
38 | ///////////////////////////////////////////////////////////////////////////// |
||
39 | // This task is running endless in background |
||
40 | ///////////////////////////////////////////////////////////////////////////// |
||
41 | void APP_Background(void) |
||
42 | { |
||
43 | u8 old_state[12]; // to store the state of 12 pins |
||
44 | |||
45 | // initialize pin state to inactive value |
||
46 | int pin; |
||
47 | for(pin=0; pin<12; ++pin) |
||
48 | old_state[pin] = 1; |
||
49 | |||
50 | while( 1 ) { // endless loop |
||
51 | // check each J5 pin for changes |
||
52 | for(pin=0; pin<12; ++pin) { |
||
53 | u8 new_state = MIOS32_BOARD_J5_PinGet(pin); |
||
54 | |||
55 | // pin changed? |
||
56 | if( new_state != old_state[pin] ) { |
||
57 | // store new state |
||
58 | old_state[pin] = new_state; |
||
59 | |||
60 | // send Note On/Off Event depending on new pin state |
||
61 | if( new_state == 0 ) // Jumper closed -> 0V |
||
62 | MIOS32_MIDI_SendNoteOn(DEFAULT, Chn1, 0x3c + pin, 127); |
||
63 | else // Jumper opened -> ca. 3.3V |
||
64 | MIOS32_MIDI_SendNoteOff(DEFAULT, Chn1, 0x3c + pin, 0); |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
70 | |||
71 | ///////////////////////////////////////////////////////////////////////////// |
||
1919 | tk | 72 | // This hook is called each mS from the main task which also handles DIN, ENC |
73 | // and AIN events. You could add more jobs here, but they shouldn't consume |
||
74 | // more than 300 uS to ensure the responsiveness of buttons, encoders, pots. |
||
75 | // Alternatively you could create a dedicated task for application specific |
||
76 | // jobs as explained in $MIOS32_PATH/apps/tutorials/006_rtos_tasks |
||
77 | ///////////////////////////////////////////////////////////////////////////// |
||
78 | void APP_Tick(void) |
||
79 | { |
||
1920 | tk | 80 | // PWM modulate the status LED (this is a sign of life) |
81 | u32 timestamp = MIOS32_TIMESTAMP_Get(); |
||
82 | MIOS32_BOARD_LED_Set(1, (timestamp % 20) <= ((timestamp / 100) % 10)); |
||
1919 | tk | 83 | } |
84 | |||
85 | |||
86 | ///////////////////////////////////////////////////////////////////////////// |
||
87 | // This hook is called each mS from the MIDI task which checks for incoming |
||
88 | // MIDI events. You could add more MIDI related jobs here, but they shouldn't |
||
89 | // consume more than 300 uS to ensure the responsiveness of incoming MIDI. |
||
90 | ///////////////////////////////////////////////////////////////////////////// |
||
91 | void APP_MIDI_Tick(void) |
||
92 | { |
||
93 | } |
||
94 | |||
95 | |||
96 | ///////////////////////////////////////////////////////////////////////////// |
||
682 | tk | 97 | // This hook is called when a MIDI package has been received |
98 | ///////////////////////////////////////////////////////////////////////////// |
||
99 | void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package) |
||
100 | { |
||
101 | } |
||
102 | |||
103 | |||
104 | ///////////////////////////////////////////////////////////////////////////// |
||
105 | // This hook is called before the shift register chain is scanned |
||
106 | ///////////////////////////////////////////////////////////////////////////// |
||
107 | void APP_SRIO_ServicePrepare(void) |
||
108 | { |
||
109 | } |
||
110 | |||
111 | |||
112 | ///////////////////////////////////////////////////////////////////////////// |
||
113 | // This hook is called after the shift register chain has been scanned |
||
114 | ///////////////////////////////////////////////////////////////////////////// |
||
115 | void APP_SRIO_ServiceFinish(void) |
||
116 | { |
||
117 | } |
||
118 | |||
119 | |||
120 | ///////////////////////////////////////////////////////////////////////////// |
||
121 | // This hook is called when a button has been toggled |
||
122 | // pin_value is 1 when button released, and 0 when button pressed |
||
123 | ///////////////////////////////////////////////////////////////////////////// |
||
124 | void APP_DIN_NotifyToggle(u32 pin, u32 pin_value) |
||
125 | { |
||
126 | } |
||
127 | |||
128 | |||
129 | ///////////////////////////////////////////////////////////////////////////// |
||
130 | // This hook is called when an encoder has been moved |
||
131 | // incrementer is positive when encoder has been turned clockwise, else |
||
132 | // it is negative |
||
133 | ///////////////////////////////////////////////////////////////////////////// |
||
134 | void APP_ENC_NotifyChange(u32 encoder, s32 incrementer) |
||
135 | { |
||
136 | } |
||
137 | |||
138 | |||
139 | ///////////////////////////////////////////////////////////////////////////// |
||
140 | // This hook is called when a pot has been moved |
||
141 | ///////////////////////////////////////////////////////////////////////////// |
||
142 | void APP_AIN_NotifyChange(u32 pin, u32 pin_value) |
||
143 | { |
||
144 | } |