Subversion Repositories svn.mios32

Compare Revisions

Ignore whitespace Rev 2499 → Rev 2500

/trunk/modules/blm_x/blm_x.c
12,7 → 12,7
* Copyright (C) 2009 Matthias Mächler (maechler@mm-computing.ch, thismaechler@gmx.ch)
* Licensed for personal non-commercial use only.
* All other rights reserved.
*
*
* ==========================================================================
*/
 
74,10 → 74,10
debounce_ctr[r][i] = 0;
#endif
#endif
#if (BLM_X_LED_FIRST_DOUT_SR > 0)
#if (BLM_X_LED_FIRST_DOUT_SR > 0)
// initialize LED-rows
for(i=0; i<BLM_X_NUM_LED_SR; ++i)
BLM_X_LED_rows[r][i] = 0x00;
BLM_X_LED_rows[r][i] = 0x00;
#endif
}
// clear debounce counter for debounce-mode 1
90,7 → 90,7
blm_x_config.btn_first_din_sr = BLM_X_BTN_FIRST_DIN_SR;
blm_x_config.rowsel_inv_mask = BLM_X_ROWSEL_INV_MASK;
blm_x_config.color_mode = BLM_X_COLOR_MODE;
blm_x_config.debounce_delay = 0;
blm_x_config.debounce_delay = BLM_X_DEBOUNCE_DELAY;
// init current row
current_row = 0;
return 0;
119,7 → 119,7
dout_value ^= blm_x_config.rowsel_inv_mask;
// output on CATHODES register
MIOS32_DOUT_SRSet(blm_x_config.rowsel_dout_sr - 1, dout_value);
#if (BLM_X_LED_FIRST_DOUT_SR > 0)
#if (BLM_X_LED_FIRST_DOUT_SR > 0)
// output value of LED rows depending on current row
for(i = 0;i < BLM_X_NUM_LED_SR;i++)
MIOS32_DOUT_SRSet(blm_x_config.led_first_dout_sr - 1 + i, BLM_X_LED_rows[current_row][i]);
143,7 → 143,7
scanned_row = current_row ? (current_row -1) : (BLM_X_NUM_ROWS - 1);
// ensure that change won't be propagated to normal DIN handler
for(sr = 0; sr < BLM_X_NUM_BTN_SR; sr++)
MIOS32_DIN_SRChangedGetAndClear(blm_x_config.btn_first_din_sr - 1 + sr, 0xff);
MIOS32_DIN_SRChangedGetAndClear(blm_x_config.btn_first_din_sr - 1 + sr, 0xff);
#if (BLM_X_DEBOUNCE_MODE < 2)
#if (BLM_X_DEBOUNCE_MODE == 1)
// cheap debounce handling. ignore any changes if debounce_ctr > 0
164,7 → 164,7
btn_rows[scanned_row][sr] = sr_value;
MIOS32_IRQ_Enable();
//*** end atomic block ***
}
}
#if (BLM_X_DEBOUNCE_MODE == 1)
}
else
186,8 → 186,7
MIOS32_IRQ_Disable();
// set change-notification-bit. if a second change happens before the last change was notified (clear
// changed flags), the change flag will be unset (two changes -> original value)
if( ( btn_rows_changed[scanned_row][sr] ^=
(sr_value & pin_mask) ^ (btn_rows[scanned_row][sr] & pin_mask) ) & pin_mask )
if( ( btn_rows_changed[scanned_row][sr] ^= (sr_value & pin_mask) ^ (btn_rows[scanned_row][sr] & pin_mask) ) & pin_mask )
debounce_ctr[scanned_row][sr*8 + pin] = blm_x_config.debounce_delay;//restart debounce delay
//set the new value bit
if(sr_value & pin_mask)
198,7 → 197,7
//*** end atomic block ***
}
}
}
}
#endif
return 0;
#else
209,7 → 208,7
 
/////////////////////////////////////////////////////////////////////////////
// This function should be called from a task to check for button changes
// periodically. Events (change from 0->1 or from 1->0) will be notified
// periodically. Events (change from 0->1 or from 1->0) will be notified
// via the given callback function <notify_hook> with following parameters:
// <notifcation-hook>(u32 btn, u32 value)
// IN: -
271,8 → 270,8
return -1;//buttons disabled
#endif
}
 
 
/////////////////////////////////////////////////////////////////////////////
// returns the buttons serial-register value for a row / SR
// IN: button row in <row>, row-SR in <sr>
295,7 → 294,7
// OUT: returns < 0 if LED/color not available
/////////////////////////////////////////////////////////////////////////////
s32 BLM_X_LEDSet(u32 led, u32 color, u32 value){
#if (BLM_X_LED_FIRST_DOUT_SR > 0)
#if (BLM_X_LED_FIRST_DOUT_SR > 0)
u32 row,sr,pin;
// check if LED/color available
if( led >= BLM_X_NUM_ROWS * BLM_X_LED_NUM_COLS || color > BLM_X_LED_NUM_COLORS )
317,7 → 316,7
return -1;//LED's disabled
#endif
}
 
/////////////////////////////////////////////////////////////////////////////
// sets all colors of a LED
// IN: LED number in <led>, color in <color_mask> (each bit represents a color, LSB = color 0)
347,7 → 346,7
return 0;
#else
return -1;//LED's disabled
#endif
#endif
}
 
/////////////////////////////////////////////////////////////////////////////
381,7 → 380,7
return color;
#else
return 0;//LED's disabled
#endif
#endif
}
 
/////////////////////////////////////////////////////////////////////////////
408,7 → 407,7
return -1;//LED's disabled
#endif
}
 
/////////////////////////////////////////////////////////////////////////////
// returns the LED serial-register value for a row / SR
// IN: LED row in <row>, row-SR in <sr>
431,7 → 430,7
// OUT: < 0 on error (SR not available), 0 on success
/////////////////////////////////////////////////////////////////////////////
s32 BLM_X_LEDSRSet(u8 row, u8 sr, u8 sr_value){
#if (BLM_X_LED_FIRST_DOUT_SR > 0)
#if (BLM_X_LED_FIRST_DOUT_SR > 0)
if (row > BLM_X_NUM_ROWS -1 || sr > BLM_X_NUM_LED_SR - 1)
return -1;
BLM_X_LED_rows[row][sr] = sr_value;
440,7 → 439,7
return -1;//LED's disabled
#endif
}
 
/////////////////////////////////////////////////////////////////////////////
// sets the blm_x soft configurations
// IN: config, struct with members:
451,7 → 450,7
// .color_mode
// .debounce_delay
// OUT: returns < 0 on error, 0 on success
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
s32 BLM_X_ConfigSet(blm_x_config_t config){
blm_x_config = config;
return 0;
467,7 → 466,7
// .rowsel_inv_mask
// .color_mode
// .debounce_delay
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
blm_x_config_t BLM_X_ConfigGet(void){
return blm_x_config;
}
/trunk/modules/blm_x/blm_x.h
6,7 → 6,7
* Copyright (C) 2009 Matthias Mächler (maechler@mm-computing.ch, thismaechler@gmx.ch)
* Licensed for personal non-commercial use only.
* All other rights reserved.
*
*
* ==========================================================================
*/
 
59,7 → 59,7
 
 
// DOUT shift register to which the cathodes of the LEDs are connected (row selectors).
// if less than 5 rows are defined, the higher nibble of the SR outputs will be always
// if less than 5 rows are defined, the higher nibble of the SR outputs will be always
// identical to the lower nibble.
//
// This option can be re-configured by software ( BLM_X_ConfigSet(..) )
109,6 → 109,11
#define BLM_X_DEBOUNCE_MODE 0
#endif
 
// debounce delay (num scan cycles; [scan cycle duration] = [num rows] * [interval betw. BLM_X_GetRow calls] )
#ifndef BLM_X_DEBOUNCE_DELAY
#define BLM_X_DEBOUNCE_DELAY 1
#endif
 
// 0: colors will be mapped to serial registers grouped by color (see section "Serial registers")
// 1: colors will be mapped to serial registers grouped by LED-columns (see section "Serial registers")
//
/trunk/modules/blm_x/README.txt
25,9 → 25,9
You will need one DOUT serial-register for the select-lines. If there are less than
5 rows, the first nibble will be mirrored to the second one (pin 0-3 == pin 4-7).
 
For the buttons you will need [ceil(BLM_X_BTN_NUM_COLS / 8)] DIN SR's.
For the buttons you will need [ceil(BLM_X_BTN_NUM_COLS / 8)] DIN SR's.
 
For the LED's you will need [ceil(BLM_X_LED_NUM_COLS * BLM_X_LED_NUM_COLORS / 8)] DOUT SR's.
For the LED's you will need [ceil(BLM_X_LED_NUM_COLS * BLM_X_LED_NUM_COLORS / 8)] DOUT SR's.
 
In color-mode 0 ,the colors will be mapped to the registers grouped by colors (standard mode):
[LED-col 0, color 0][LED-col 1, color 0][LED-col 2, color 0]....[LED-col 0, color1][LED-col 1, color1]...
35,8 → 35,8
[LED-col 0, color 0][LED-col 0, color 1][LED-col 0, color 2]....[LED-col 1, color0][LED-col 1, color1]...
Choose the mode that fits your plans to wire the LED-matrix on the hardware side.
 
If you want to work directly on the virtual SR's (bypass LED-set / -get functions), you may prefer to
choose BLM_X_LED_NUM_COLS values like 4,8,12,16 etc. and color-mode 0. If you set LED states only by
If you want to work directly on the virtual SR's (bypass LED-set / -get functions), you may prefer to
choose BLM_X_LED_NUM_COLS values like 4,8,12,16 etc. and color-mode 0. If you set LED states only by
module functions, you don't have to care about this on the software side.
 
Note that serial register assignment / color mode can be re-configured by software ( BLM_X_ConfigSet(..) ).
46,9 → 46,9
----------
Debounce-modes 1 and 2 are available: mode 1 uses a single counter, which decrements each scan-cycle
(BLM_X_NUM_ROWS rows scanned), and will be set to debounce_delay again each time a button-state was
changed. Until the counter is 0, all button changes will be ignored.
Debounce-mode 2 uses individual counters for each button, which consumes a bit more memory and
performance.
changed. Until the counter is 0, all button changes will be ignored.
Debounce-mode 2 uses individual counters for each button, which consumes a bit more memory and
performance.
You can disable debouncing completly by setting BLM_X_DEBOUNCE_MODE = 0
 
Debounce-delay can be configured by software ( BLM_X_ConfigSet(..) ), and will be set to 0 by default.
73,7 → 73,7
#define BLM_X_LED_NUM_COLORS 3
 
// DOUT shift register to which the cathodes of the LEDs are connected (row selectors).
// If less than 5 rows are defined, the higher nibble of the SR outputs will be always
// If less than 5 rows are defined, the higher nibble of the SR outputs will be always
// identical to the lower nibble. Note that SR's are counted from 1.
//
// This option can be re-configured by software ( BLM_X_ConfigSet(..) )
98,7 → 98,7
#define BLM_X_BTN_FIRST_DIN_SR 1
 
// Set an inversion mask for the row selection shift registers if sink drivers (transistors)
// have been added to the cathode lines.
// have been added to the cathode lines.
// Note: with no sink drivers connected, the LED's brightnes may be affected by the number
// of active LED's in the same row.
// Settings: 0x00 - no sink drivers
115,11 → 115,15
// 2: individual debouncing of all buttons
#define BLM_X_DEBOUNCE_MODE 0
 
// debounce delay (num scan cycles; [scan cycle duration] = [num rows] * [interval betw. BLM_X_GetRow calls] )
#define BLM_X_DEBOUNCE_DELAY 1
 
 
// 0: colors will be mapped to serial registers grouped by color (see section "Serial registers")
// 1: colors will be mapped to serial registers grouped by LED-columns (see section "Serial registers")
//
// This option can be re-configured by software ( BLM_X_ConfigSet(..) )
BLM_X_COLOR_MODE 0
#define BLM_X_COLOR_MODE 0
 
 
Module Functions
131,19 → 135,19
 
s32 BLM_X_PrepareRow(void);
Prepares the next row in the matrix (sets row-selector DOUT - values and LED DOUT values
for the row).
for the row).
This hook should be called in APP_SRIO_ServicePrepare() in your application.
 
 
s32 BLM_X_GetRow(void);
Reads the the values of the buttons DIN registers for the currently selected row, and
writes it to the internal button-state registers.
writes it to the internal button-state registers.
This hook should be called in APP_SRIO_ServiceFinish() in your application.
 
 
s32 BLM_X_BtnHandler(void *notify_hook)
This hook checks the internal button-state registers for changes and calls
notify_hook(u32 btn, u32 value) for each changed button.
This hook checks the internal button-state registers for changes and calls
notify_hook(u32 btn, u32 value) for each changed button.
This hook should be called regulary by your application, e.g. in a separate task.
 
 
200,7 → 204,7
 
Performance
-----------
The whole SRIO service takes ca.
The whole SRIO service takes ca.
- ca. 280uS without the BLM-X module hooks
- ca.290uS with 4 rows, 4 cols, 3 colors, debounce mode 2 (LEDs & buttons)
- ca. 320uS with 8 rows, 16 cols, 3 colors, debounce mode 2 (LEDs & buttons)
208,4 → 212,3
Most of this additional time is consumed by heavy debouncing (mode 2). Without any
debouncing (not required in most applications, 4 rows == 4mS scan cycle), this
additional time will be dramatically lower.