Subversion Repositories svn.mios32

Rev

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

Rev Author Line No. Line
1302 tk 1
// $Id: app.c 2425 2016-11-03 00:44:22Z tk $
2
/*
3
 * MIOS32 Application Template
4
 *
5
 * ==========================================================================
6
 *
7
 *  Copyright (C) <year> <your name> (<your email address>)
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 <blm_cheapo.h>
20
 
21
#include "app.h"
22
 
23
// include everything FreeRTOS related we don't understand yet ;)
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 button handler (same as MIOS tasks)
32
#define PRIORITY_TASK_PERIOD_1mS ( tskIDLE_PRIORITY + 3 )
33
 
34
// local prototype of the task function
35
static void TASK_Period_1mS(void *pvParameters);
36
 
37
 
38
/////////////////////////////////////////////////////////////////////////////
39
// This hook is called after startup to initialize the application
40
/////////////////////////////////////////////////////////////////////////////
41
void APP_Init(void)
42
{
43
  // initialize all LEDs
44
  MIOS32_BOARD_LED_Init(0xffffffff);
45
 
46
  // initialize cheapo BLM
47
  BLM_CHEAPO_Init(0);
48
 
49
  // start task
2425 tk 50
  xTaskCreate(TASK_Period_1mS, "1mS", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS, NULL);
1302 tk 51
 
52
}
53
 
54
 
55
/////////////////////////////////////////////////////////////////////////////
56
// This task is running endless in background
57
/////////////////////////////////////////////////////////////////////////////
58
void APP_Background(void)
59
{
60
  // endless loop
61
  while( 1 ) {
62
    // toggle the state of all LEDs (allows to measure the execution speed with a scope)
63
    MIOS32_BOARD_LED_Set(0xffffffff, ~MIOS32_BOARD_LED_Get());
64
 
65
  }
66
}
67
 
68
 
69
/////////////////////////////////////////////////////////////////////////////
70
// This hook is called when a MIDI package has been received
71
/////////////////////////////////////////////////////////////////////////////
72
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
73
{
74
}
75
 
76
 
77
/////////////////////////////////////////////////////////////////////////////
78
// This hook is called before the shift register chain is scanned
79
/////////////////////////////////////////////////////////////////////////////
80
void APP_SRIO_ServicePrepare(void)
81
{
82
  // -> BLM_CHEAPO driver
83
  BLM_CHEAPO_PrepareCol();
84
}
85
 
86
 
87
/////////////////////////////////////////////////////////////////////////////
88
// This hook is called after the shift register chain has been scanned
89
/////////////////////////////////////////////////////////////////////////////
90
void APP_SRIO_ServiceFinish(void)
91
{
92
  // -> BLM_CHEAPO driver
93
  BLM_CHEAPO_GetRow();
94
}
95
 
96
 
97
/////////////////////////////////////////////////////////////////////////////
98
// This hook is called when a button has been toggled
99
// pin_value is 1 when button released, and 0 when button pressed
100
/////////////////////////////////////////////////////////////////////////////
101
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
102
{
103
}
104
 
105
 
106
/////////////////////////////////////////////////////////////////////////////
107
// This hook is called when an encoder has been moved
108
// incrementer is positive when encoder has been turned clockwise, else
109
// it is negative
110
/////////////////////////////////////////////////////////////////////////////
111
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
112
{
113
}
114
 
115
 
116
/////////////////////////////////////////////////////////////////////////////
117
// This hook is called when a pot has been moved
118
/////////////////////////////////////////////////////////////////////////////
119
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
120
{
121
}
122
 
123
 
124
/////////////////////////////////////////////////////////////////////////////
125
// This task handles the buttons
126
/////////////////////////////////////////////////////////////////////////////
127
void APP_BLM_CHEAPO_NotifyToggle(u32 pin, u32 pin_value)
128
{
129
  MIOS32_MIDI_SendDebugMessage("Pin:%d  Value:%d\n", pin, pin_value);
130
 
131
  // forward to LED
132
  // note that button value is inverted (1 if depressed)
133
  BLM_CHEAPO_DOUT_PinSet(pin, pin_value ? 0 : 1);
134
}
135
 
136
static void TASK_Period_1mS(void *pvParameters)
137
{
138
  while( 1 ) {
139
    vTaskDelay(1 / portTICK_RATE_MS);
140
 
141
    // -> BLM_CHEAPO driver
142
    BLM_CHEAPO_ButtonHandler(APP_BLM_CHEAPO_NotifyToggle);
143
  }
144
}