Subversion Repositories svn.mios32

Rev

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

Rev Author Line No. Line
454 this 1
/*
2
 * Checks the handling of a button/LED matrix driven by the blm_x module
3
 *
4
 * ==========================================================================
5
 *
6
 *  Copyright (C) 2009 Matthias M├Ąchler (maechler@mm-computing.ch / thismaechler@gmx.ch)
7
 *  Licensed for personal non-commercial use only.
8
 *  All other rights reserved.
9
 *
10
 * ==========================================================================
11
 */
12
 
13
/////////////////////////////////////////////////////////////////////////////
14
// Include files
15
/////////////////////////////////////////////////////////////////////////////
16
 
17
#include <mios32.h>
18
#include "app.h"
19
 
20
#include <blm_x.h>
21
 
22
#include <FreeRTOS.h>
23
#include <task.h>
24
#include <queue.h>
25
 
26
 
27
/////////////////////////////////////////////////////////////////////////////
28
// Local definitions
29
/////////////////////////////////////////////////////////////////////////////
30
 
538 this 31
#define PRIORITY_TASK_BLM_CHECK    ( tskIDLE_PRIORITY + 2 )
454 this 32
 
33
 
34
/////////////////////////////////////////////////////////////////////////////
35
// Prototypes
36
/////////////////////////////////////////////////////////////////////////////
37
static void TASK_BLM_Check(void *pvParameters);
38
 
39
 
40
/////////////////////////////////////////////////////////////////////////////
41
// Global Variables
42
/////////////////////////////////////////////////////////////////////////////
43
 
44
u8 last_btn = 0;
45
u8 last_btn_value = 1;
458 this 46
 
454 this 47
u32 last_led_color = 0;
458 this 48
 
454 this 49
u32 btn_change_count = 0;
458 this 50
u32 last_btn_change_count = 1;
454 this 51
 
52
/////////////////////////////////////////////////////////////////////////////
53
// This hook is called after startup to initialize the application
54
/////////////////////////////////////////////////////////////////////////////
55
void APP_Init(void){
538 this 56
  s32 i;
57
  blm_x_config_t blm_x_conf;
58
  // initialize all LEDs
59
  MIOS32_BOARD_LED_Init(0xffffffff);
60
  // initialize BLM driver
61
  BLM_X_Init();
62
  blm_x_conf = BLM_X_ConfigGet();
63
  blm_x_conf.debounce_delay = 10;
64
  BLM_X_ConfigSet(blm_x_conf);
65
  // start BLM check task
2425 tk 66
  xTaskCreate(TASK_BLM_Check, "BLM_Check", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_BLM_CHECK, NULL);
538 this 67
  //send init message
68
  MIOS32_MIDI_SendDebugMessage("BLM_X Test-Application Started");
69
  //display all possible LED color combinations (if matrix is big enough!)
70
  for(i=0;i < BLM_X_NUM_ROWS*BLM_X_LED_NUM_COLS; i++){
71
    if((++last_led_color) >> BLM_X_LED_NUM_COLORS)
72
      last_led_color = 1;
73
    BLM_X_LEDColorSet(i,last_led_color);
74
    }
75
  last_led_color = 0;
76
  }
454 this 77
 
78
 
79
/////////////////////////////////////////////////////////////////////////////
80
// This task is running endless in background
81
/////////////////////////////////////////////////////////////////////////////
82
void APP_Background(void){
538 this 83
  // init LCD
84
  MIOS32_LCD_Clear();
85
  // endless loop: print status information on LCD
86
  while( 1 ) {
87
    MIOS32_LCD_CursorSet(0, 0);
88
    // print text on LCD screen, send debug message
89
    if(btn_change_count != last_btn_change_count){
90
      MIOS32_LCD_CursorSet(0, 0);
91
      MIOS32_LCD_PrintFormattedString("Button #%3d %c", last_btn, last_btn_value ? 'o' : '*');
92
      MIOS32_MIDI_SendDebugMessage("Button #%3d %c - Changes: %5d", last_btn, last_btn_value ? 'o' : '*',btn_change_count);
93
      MIOS32_LCD_CursorSet(0, 1);
94
      MIOS32_LCD_PrintFormattedString("Color:0x%X Count:%d", BLM_X_LEDColorGet(last_btn), btn_change_count);
95
      last_btn_change_count = btn_change_count;
96
      }
97
    }
98
  }
454 this 99
 
100
 
101
/////////////////////////////////////////////////////////////////////////////
674 tk 102
// This hook is called when a MIDI package has been received
454 this 103
/////////////////////////////////////////////////////////////////////////////
674 tk 104
void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)
538 this 105
{
106
}
454 this 107
 
108
 
109
/////////////////////////////////////////////////////////////////////////////
110
// This hook is called before the shift register chain is scanned
111
/////////////////////////////////////////////////////////////////////////////
112
void APP_SRIO_ServicePrepare(void){
538 this 113
  //sets board led's to 0 (enables to measure the time consumed by the srio-service & blm stuff
114
  MIOS32_BOARD_LED_Set(0xffffffff, 0);
115
  //prepare DOUT registers to drive the row
116
  BLM_X_PrepareRow();
117
  }
454 this 118
 
119
 
120
/////////////////////////////////////////////////////////////////////////////
121
// This hook is called after the shift register chain has been scanned
122
/////////////////////////////////////////////////////////////////////////////
123
void APP_SRIO_ServiceFinish(void){
538 this 124
  // call the BLM_GetRow function after scan is finished to capture the read DIN values
125
  BLM_X_GetRow();
126
  //sets board led's back to 1 (enables to measure the time consumed by the srio-service & blm stuff
127
  MIOS32_BOARD_LED_Set(0xffffffff, 1);
128
  }
454 this 129
 
130
 
131
/////////////////////////////////////////////////////////////////////////////
132
// This hook is called when a button has been toggled
133
// pin_value is 1 when button released, and 0 when button pressed
134
/////////////////////////////////////////////////////////////////////////////
135
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)
136
{
137
}
138
 
139
 
140
/////////////////////////////////////////////////////////////////////////////
141
// This hook is called when an encoder has been moved
142
// incrementer is positive when encoder has been turned clockwise, else
143
// it is negative
144
/////////////////////////////////////////////////////////////////////////////
145
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)
146
{
147
}
148
 
149
 
150
/////////////////////////////////////////////////////////////////////////////
151
// This hook is called when a pot has been moved
152
/////////////////////////////////////////////////////////////////////////////
153
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)
154
{
155
}
156
 
157
 
158
/////////////////////////////////////////////////////////////////////////////
159
// This task is called each mS to check the BLM button states
160
/////////////////////////////////////////////////////////////////////////////
161
 
162
// will be called on BLM pin changes (see TASK_BLM_Check)
163
void BLM_Button_NotifyToggle(u32 btn, u32 value){
538 this 164
  if(!value){
165
    // increment LED color, swap to 0 when all available color bits are set
166
    last_led_color++;
167
    if(btn != last_btn || (last_led_color >> BLM_X_LED_NUM_COLORS) )
168
      last_led_color = 0;
169
    // output LED color
170
    BLM_X_LEDColorSet(btn,last_led_color);
171
    MIOS32_MIDI_SendDebugMessage("LED #%3d color set to 0x%08x", btn, last_led_color);
172
    }
173
  // store btn & value, increment button change counter
174
  last_btn = btn;
175
  last_btn_value = value;
176
  btn_change_count++;
177
  }
454 this 178
 
179
static void TASK_BLM_Check(void *pvParameters){
538 this 180
  portTickType xLastExecutionTime;
181
    // Initialize the xLastExecutionTime variable on task entry
182
    xLastExecutionTime = xTaskGetTickCount();
183
    while( 1 ) {
184
     vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);
185
      // check for BLM pin changes, call BLM_Button_NotifyToggle on each toggled pin
186
      BLM_X_BtnHandler(BLM_Button_NotifyToggle);
187
      }
188
  }