Habe jetzt alles fertig angeschlossen gehabt und musste folgendes feststellen:
Es ist eine 2x 16x16 Button Matrix gebaut worden, mit der Kathode der Diode gerichtet nach DOUT (16DOUT-Z-Diode-32DIN).
Bei der Midi In Message in Mios32 bekomme ich immer nur eine Taste pro Kanal und Matrix angezeigt, egal welche ich pro Kanal drücke.
Taste 1-15 zeigen das selbe bei betätigen an, als Taste 16 bei Kanal 1-16, in Matrix 1 und das selbe Spiel bei der 2ten Matrix.
D.h.:
BM1_Chn1_Btn1-16 , BM1_Chn2_Btn1-16 , BM1_Chn3_Btn1-16 , BM1_Chn4_Btn1-16 , … , BM1_Chn16_Btn1-16
Chn1_0x3C_00 , Chn2_0x3C_00 , Chn3_0x3C_00 , Chn4_0x3C_00 , … , Chn16_0x3C_00
Chn1_0x3C_3f , Chn2_0x3C_3f , Chn3_0x3C_3f , Chn4_0x3C_3f , … , Chn16_0x3C_3f
BM2_Chn1_Btn1-16 , BM2_Chn2_Btn1-16 , BM2_Chn3_Btn1-16 , BM2_Chn4_Btn1-16 , … , BM2_Chn16_Btn1-16
Chn1_0x4C_00 , Chn2_0x4C_00 , Chn3_0x4C_00 , Chn4_0x4C_00 , … , Chn16_0x4C_00
Chn1_0x4C_3f , Chn2_0x4C_3f , Chn3_0x4C_3f , Chn4_0x4C_3f , … , Chn16_0x4C_3f
egal welche der 16 Tasten pro Kanal ich in der Matrix betätige.
Es kommt die selbe Message in Midi IN an, als würde er die einzelen “Rows” pro “Columns” nicht verwerten.
Programmauszug aus app.c:
/////////////////////////////////////////////////////////////////////////////
// Local definitions
/////////////////////////////////////////////////////////////////////////////
#define NUM_MATRICES 2
// define priority level for MATRIX_SCAN task:
// use same priority as MIOS32 specific tasks (3)
#define PRIORITY_TASK_MATRIX_SCAN ( tskIDLE_PRIORITY + 3 )
// local prototype of the task function
static void TASK_MATRIX_Scan(void *pvParameters);
/////////////////////////////////////////////////////////////////////////////
// Local variables
/////////////////////////////////////////////////////////////////////////////
static u8 enc_virtual_pos[NUM_ENCODERS];
static u16 matrix16x16_button_row_values[NUM_MATRICES][16];
static u16 matrix16x16_button_row_changed[NUM_MATRICES][16];
static u8 matrix16x16_ctr;
/////////////////////////////////////////////////////////////////////////////
// This hook is called after startup to initialize the application
/////////////////////////////////////////////////////////////////////////////
void APP_Init(void)
{
// initialize all LEDs
MIOS32_BOARD_LED_Init(0xffffffff);matrix16x16_ctr = 0;
u8 mod;
for(mod=0; mod<NUM_MATRICES; ++mod) {
u8 row;
for(row=0; row<16; ++row) {
matrix16x16_button_row_values[mod][row] = 0xffff;
matrix16x16_button_row_changed[mod][row] = 0x0000;
}
}
/////////////////////////////////////////////////////////////////////////////
// This hook is called before the shift register chain is scanned
/////////////////////////////////////////////////////////////////////////////
void APP_SRIO_ServicePrepare(void)
{
// 2 * 16x16 Matrix DOUTs
if( ++matrix16x16_ctr >= 16 )
matrix16x16_ctr = 0;
u16 matrix_select = ~(1 << matrix16x16_ctr); // if cathodes are connected to DOUTs
#if DOUT_16x16_L
MIOS32_DOUT_SRSet(DOUT_16x16_L-1, (matrix_select >> 0) & 0xff);
#endif
#if DOUT_16x16_R
MIOS32_DOUT_SRSet(DOUT_16x16_R-1, (matrix_select >> 8) & 0xff);
#endif
/////////////////////////////////////////////////////////////////////////////
// This hook is called after the shift register chain has been scanned
/////////////////////////////////////////////////////////////////////////////
void APP_SRIO_ServiceFinish(void)
{
const u8 din_map[2*2] = {
DIN_16x16_L0,
DIN_16x16_R0,
DIN_16x16_L1,
DIN_16x16_R1
};
// check for DIN changes
// Note: matrix16x16_ctr was incremented before in APP_SRIO_ServicePrepare()
int selected_row = (matrix16x16_ctr-1) & 0xf;
// check DINs
int mod;
for(mod=0; mod<NUM_MATRICES; ++mod) {
int sr0 = din_map[2*mod+0];
int sr1 = din_map[2*mod+1];
u16 sr_value = 0;
if( sr0 ) {
MIOS32_DIN_SRChangedGetAndClear(sr0-1, 0xff); // ensure that change won’t be propagated to normal DIN handler
sr_value |= (MIOS32_DIN_SRGet(sr0-1) << 0);
}
if( sr1 ) {
MIOS32_DIN_SRChangedGetAndClear(sr1-1, 0xff); // ensure that change won’t be propagated to normal DIN handler
sr_value |= (MIOS32_DIN_SRGet(sr1-1) << 8);
}
// determine pin changes
u16 changed = sr_value ^ matrix16x16_button_row_values[mod][selected_row];
if( changed ) {
// add them to existing notifications
matrix16x16_button_row_changed[mod][selected_row] |= changed;
// store new value
matrix16x16_button_row_values[mod][selected_row] = sr_value;
}
}
}
/////////////////////////////////////////////////////////////////////////////
// This task scans MATRIX pins periodically
/////////////////////////////////////////////////////////////////////////////
static void TASK_MATRIX_Scan(void *pvParameters)
{
u8 old_state[12]; // to store the state of 12 pins
u8 debounce_ctr[12]; // to store debounce delay counters
portTickType xLastExecutionTime;
// initialize pin state and debounce counters to inactive value
int pin;
for(pin=0; pin<12; ++pin) {
old_state[pin] = 1;
debounce_ctr[pin] = 0;
}
// Initialise the xLastExecutionTime variable on task entry
xLastExecutionTime = xTaskGetTickCount();
while( 1 ) {
vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);
// check all shift registers for DIN pin changes
int mod;
for(mod=0; mod<NUM_MATRICES; ++mod) {
int row;
for(row=0; row<16; ++row) {
// check if there are pin changes - must be atomic!
MIOS32_IRQ_Disable();
u8 changed = matrix16x16_button_row_changed[mod][row];
matrix16x16_button_row_changed[mod][row] = 0;
MIOS32_IRQ_Enable();
// any pin change at this SR?
if( !changed )
continue;
// check all 16 pins of the SR
int sr_pin;
for(sr_pin=0; sr_pin<16; ++sr_pin)
if( changed & (1 << sr_pin) ) {
u32 pin = 16*row + sr_pin;
u8 value = (matrix16x16_button_row_values[mod][row] & (1 << sr_pin)) ? 1 : 0;
// decoding: 2*256 pins mapped to channel 1..16
u8 chn = pin / 16;
// each channel has 16 buttons
u8 note = mod*16 + 0x3c; // 0x3c is C-3
// velocity: 0x7f if button pressed, 0x00 if button depressed
u8 velocity = value ? 0x00 : 0x7f;
// send MIDI event
MIOS32_MIDI_SendNoteOn(DEFAULT, chn, note, velocity);
}
}
}
}
}
Ansonsten macht es spass und funktioniert auch alles.
Einige Problem tauchen noch auf beim lernen, der vielen Variablen und Befehle für die C-Programmierung. :hairy:
Was nicht ist, kann noch werden!!!
Vielleicht weiss “der ein oder andere”
was es mit dem fehler auf sich hat.
Greets