Sign in to follow this  
Followers 0
ultra

decoding the blm_scalar driver

2 posts in this topic

i've been trying to figure out how the blm_scalar driver works (mios32\trunk\modules\blm_scalar.c) and adapt it to my own needs.

my pcb is a control surface with the two scalar circuits built in, and it just all connects via one ribbon cable to j8/j9. i've checked my schematic for problems several times, and have done continuity tests on the boards, and i'm 99% sure there aren't any problems with it (i did have to fix a couple).

i've figured a few things out, but so far, i'm having a couple problems.

the buttons:

only the buttons on the first scalar circuit give me any response from mios32. they work well, but there's no indication that the buttons on the second scalar circuit are working at all. i've added the following line to mios32_config.h:

#define BLM_SCALAR_NUM_MODULES 2

when i insert debugging code into the blm_scalar driver, i can see that 2 is what it's set at. but still, no buttons on the second scalar circuit respond.

the leds:

my led issue might not be as straightforward. i put the following line in mios32_config.h:

#define BLM_SCALAR_NUM_COLOURS 2

i have 2 color (red, green, orange) leds, so i assume that's the correct setting.

i took the code from the blm_scalar controller example (mios32\trunk\apps\controllers\blm_scalar\app.c) and modified it so that my keyboard's knobs change the mod and row values being sent in, and mask is defined by which key is played. it modifies the following line of code from the app:

blm_scalar_led[led_mod_ix][led_row_ix][0] &= ~led_mask;

of course, i also have the variations of it to turn on/off and set the color. i'm using the masks 1, 2, 4, 8, 16, 32, 64, and 128 for the keys. most of the leds do light up, and the color is changed with velocity. so most of the board is working fine.

a couple of problems though:

the leds that should light up with mask 1 don't do anything. i've double checked the circuit and everything seems fine. also, i have gotten them to turn on by using loops and BLM_SCALAR_DOUT_PinSet to turn on as many pins as i can. changing different led_mod_ix values doesn't do anything (for any of these, it's 0 for all) and changing row does indeed change row. but using the mask 1 doesn't light them up for some reason.

the second problem is with the second scalar circuit. i change mios32_config.h to have the following line:

#define BLM_SCALAR_NUM_MODULES 2

now the leds that were working properly are very dim and flickery. and also, i can't get the leds in the second circuit to light up (i'm not sure if i need different masks or mod_ix or row_ix). however, i did get some of them to light up when using the loops and BLM_SCALAR_DOUT_PinSet. and if i recall, all leds had the proper brightness.

otherwise, what does work, works great. any help with these problems would be greatly appreciated. sorry if this is a bit of a cross-post, but i've since figured a lot more out about the problems i'm having.

ultra

here is the code i'm trying to work with so far:

/*

 * ==========================================================================

 *

 *  Copyright (C) 2011 Drew Meyer (drew@sub-version.net)

 *  Licensed for personal non-commercial use only.

 *  All other rights reserved.

 * 

 * ==========================================================================

 */


/////////////////////////////////////////////////////////////////////////////

// Include files

/////////////////////////////////////////////////////////////////////////////


#include <mios32.h>

#include "app.h"

#include "mbltrigger.h"

#include "mblblm.h"

#include <blm_scalar.h>

#include <FreeRTOS.h>

#include <task.h>

#include <queue.h>


/////////////////////////////////////////////////////////////////////////////

// Local definitions

/////////////////////////////////////////////////////////////////////////////


#define PRIORITY_TASK_BLM_CHECK		( tskIDLE_PRIORITY + 2 )


/////////////////////////////////////////////////////////////////////////////

// Prototypes

/////////////////////////////////////////////////////////////////////////////

static void TASK_BLM_Check(void *pvParameters);



/////////////////////////////////////////////////////////////////////////////

// Local Variables

/////////////////////////////////////////////////////////////////////////////


u32 current_led = 33;

u8 current_color = 0;

u8 current_column = 0;

u8 current_row = 0;

u8 current_mask = 0;


/////////////////////////////////////////////////////////////////////////////

// This hook is called after startup to initialize the application

/////////////////////////////////////////////////////////////////////////////

void APP_Init(void)

{

	// initialize all LEDs

	MIOS32_BOARD_LED_Init(0xffffffff);

	// initialize BLM_SCALAR driver

	BLM_SCALAR_Init(0);

	// start BLM check task

	xTaskCreate(TASK_BLM_Check, (signed portCHAR *)"BLM_Check", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_BLM_CHECK, NULL);


}


/////////////////////////////////////////////////////////////////////////////

// This task is running endless in background

/////////////////////////////////////////////////////////////////////////////

void APP_Background(void)

{

}



/////////////////////////////////////////////////////////////////////////////

// This hook is called when a MIDI package has been received

/////////////////////////////////////////////////////////////////////////////

void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package)

{

  // control the Duo-LEDs via Note On/Off Events

  // The colour is controlled with velocity value:

  // 0x00:       both LEDs off

  // 0x01..0x3f: green LED on

  // 0x40..0x5f: red LED on

  // 0x60..0x7f: both LEDs on


  // MIDI event assignments: see README.txt

	MIOS32_BOARD_LED_Init(0xffffffff);

	if( midi_package.event == NoteOff || midi_package.event == NoteOn ) 

	{

		u8 chn = midi_package.chn;

		u8 note = midi_package.note;

		u8 velocity = midi_package.velocity;

		//DEBUG_MSG("note: %d", midi_package.note);

		if( midi_package.event == NoteOff || velocity == 0x00 ) 

		{

			// Note Off or velocity == 0x00: clear both LEDs

			blm_scalar_led[current_column][current_row][0] &= ~current_mask;

			blm_scalar_led[current_column][current_row][1] &= ~current_mask;

		} 

		else if( velocity < 0x40 ) 

		{

			// Velocity < 0x40: set green LED, clear red LED

			blm_scalar_led[current_column][current_row][0] |= current_mask;

			blm_scalar_led[current_column][current_row][1] &= ~current_mask;

			//DEBUG_MSG("green - column: %d row: %d mask: %d", current_column, current_row, current_mask);

		} 

		else if( velocity < 0x60 ) 

		{

			// Velocity < 0x60: clear green LED, set red LED

			blm_scalar_led[current_column][current_row][0] &= ~current_mask;

			blm_scalar_led[current_column][current_row][1] |= current_mask;

			// DEBUG_MSG("red - column: %d row: %d mask: %d", current_column, current_row, current_mask);

		} 

		else 

		{

			// Velocity >= 0x60: set both LEDs

			blm_scalar_led[current_column][current_row][0] |= current_mask;

			blm_scalar_led[current_column][current_row][1] |= current_mask;

			// DEBUG_MSG("both - column: %d row: %d mask: %d", current_column, current_row, current_mask);

		}

    }


	else if( midi_package.event == CC ) 

	{

		switch (midi_package.cc_number)

		{

			case 60:

			{

				current_column = midi_package.value;

				break;

			}

			case 61:

			{

				current_row = midi_package.value;

				break;

			}

			default:

			{

				break;

			}

		}

	}

	DEBUG_MSG("column: %d row: %d mask: %d", current_column, current_row, current_mask);

}



/////////////////////////////////////////////////////////////////////////////

// This hook is called before the shift register chain is scanned

/////////////////////////////////////////////////////////////////////////////

void APP_SRIO_ServicePrepare(void)

{

	// prepare DOUT registers to drive the column

	BLM_SCALAR_PrepareCol();

}



/////////////////////////////////////////////////////////////////////////////

// This hook is called after the shift register chain has been scanned

/////////////////////////////////////////////////////////////////////////////

void APP_SRIO_ServiceFinish(void)

{

	// call the BLM_GetRow function after scan is finished to capture the read DIN values

	BLM_SCALAR_GetRow();

}



/////////////////////////////////////////////////////////////////////////////

// This hook is called when a button has been toggled

// pin_value is 1 when button released, and 0 when button pressed

/////////////////////////////////////////////////////////////////////////////

void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)

{

	DEBUG_MSG("pin: %d pin_value: %d", pin, pin_value);

}



/////////////////////////////////////////////////////////////////////////////

// This hook is called when an encoder has been moved

// incrementer is positive when encoder has been turned clockwise, else

// it is negative

/////////////////////////////////////////////////////////////////////////////

void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)

{

}



/////////////////////////////////////////////////////////////////////////////

// This hook is called when a pot has been moved

/////////////////////////////////////////////////////////////////////////////

void APP_AIN_NotifyChange(u32 pin, u32 pin_value)

{

}



/////////////////////////////////////////////////////////////////////////////

// This task is called each mS to check the BLM button states

/////////////////////////////////////////////////////////////////////////////


// will be called on BLM pin changes (see TASK_BLM_Check)

void DIN_BLM_NotifyToggle(u32 pin, u32 pin_value)

{

	// determine row and column (depends on the way how the matrix has been connected)

	//DEBUG_MSG("pin: %d  value: %d", pin, pin_value);

	u8 blm_row = pin >> 3;

	u8 blm_column = pin & 7;

	u8 row = (blm_row >> 1);

	u8 column = blm_column | ((blm_row&1) << 3);

	u8 velocity = pin_value ? 0x00 : 0x7f;

	u8 button = MBLIVE_BLM_GetButton(row, column);

	//MBLIVE_BLM_SetLed(S0T3, RED);

	//DEBUG_MSG("button: %d", button);

}


static void TASK_BLM_Check(void *pvParameters)

{

	portTickType xLastExecutionTime;

	// Initialise the xLastExecutionTime variable on task entry

	xLastExecutionTime = xTaskGetTickCount();

	while( 1 ) 

	{

		vTaskDelayUntil(&xLastExecutionTime, 1 / portTICK_RATE_MS);

		// check for BLM pin changes, call DIN_BLM_NotifyToggle on each toggled pin

		BLM_SCALAR_ButtonHandler(DIN_BLM_NotifyToggle);

		// send layout informations each 5 seconds if BLM hasn't been updated

	}

}



Share this post


Link to post
Share on other sites

somehow i left out the code where it's assigning the mask. that's done by note numbers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0