LEDMATRIX 4x20 - Software Modifications

The changes are explicitely marked, so that the same modifications can be applied to other MIOS applications. All modifications are based on midibox64e_v2_1. I just used this one as basis because it best fitted my other controller needs. Eached modified program text is shown in a box. Changes are marked red. Some text around each modified program text is given to illustrate where in the file the change belongs. Don't be afraid of the many changes, in the end they're less than it looks, and include the default settings and MIDI mappings you need to make anyway.

File app_defines.h

Add memory location for LEDMATRIX multiplex counter:

...
MB64E_TS_STATUS     EQU 0x0b8
MB64E_FADER_LAST_TURNED_00 EQU  0x0b9
MB64E_FADER_LAST_TURNED_7F EQU  0x0ba
MB64E_FADER_NEW_VALUE    EQU    0x0bb
MB64E_FADER_LAST_VALUE   EQU    0x0bc

MB64E_LEDMATRIX_CTR EQU 0x0bd ; counts through LED columns

MB64E_DATA_BUFFER  EQU  0x0c0  ; used for page writes/reads
MB64E_DATA_BUFFER_END  EQU  0x0ff  ; could also be overlayed with restorable registers (like MB64E_ENC_EVNT*)
...


File main.asm

Change variables:

...
#define DEFAULT_NUMBER_ENCS         8 ; encoders 8 .. 27 used for LEDMATRIX colors
#define DEFAULT_ENCODER_GROUP_WIDTH 8
...


Disable LEDRINGS:

...
#define LEDRINGS_SR_ENC1_16_CATHODES_1  0
#define LEDRINGS_SR_ENC1_16_CATHODES_2  0
#define LEDRINGS_SR_ENC1_16_ANODES_1    0
#define LEDRINGS_SR_ENC1_16_ANODES_2    0
...


Add definitions of the DOUT shift registers used for LEDMATRIX:

...
#define DEFAULT_ENC_SPEED_FAST_DIV  2  ; (2: divider = 2^(7-2) = 32)

; 4x20 LED matrix definitions
; SR A contains the cathodes (3..0) and the first 4 diode outputs (7..4)
; SR B and C contain the other 16 diode outputs
#define LEDMATRIX_SR_A 0 
#define LEDMATRIX_SR_B 1 
#define LEDMATRIX_SR_C 2 


; This DIN map allows you to customize the MB64E application to different hardwares
; The MB64E dump structure allows the use of up to 64 buttons, they are grouped to 8 buttons per shift register
; Define the used shift registers for the buttons here
; the shift registers are counted from one - means: 1 for the first, 2 for the second, etc...
; mark unused button groups with 0
    ;; NOTE: by default, the first two DIN shift registers are used for the encoders
#define DEFAULT_DIN_SR_PIN_01_08  2
...


Change service prepare function so that LEDMATRIX handler is called instead of LEDRINGS handler:

...
USER_SR_Service_Prepare
    ;; call LEDrings handler
    ;; call MB64E_LEDRINGS_Handler
    ;; call LED matrix handler
    call MB64E_LEDMATRIX_Handler
    ;; branch to the Rx/Tx LED handler
    goto MIDI_RXTX_Handler
...


Add include of LEDMATRIX include file:

...
;; ---[ MB64E kernel ]---
#include "mb64e_bank.inc"
...
#include "mb64e_ledrings.inc"
#include "mb64e_ledmatrix.inc"
#include "mb64e_lcd.inc"
...
...


File mb64e_presets.inc

Define the midi notes/controllers used to set the LEDMATRIX colors (the lower 4 bit of the 7 bit controller value select the RGB resp. RG/RG color as described in the circuit diagram). An entry of 0xbN 0x0M ... means controller M channel N+1. 0xb1 0x07 for example is controller 7 (volume) on channel 2.

...
;; ---[ Controller Enc Bank ]------------------------------------------------
MB64E_Presets
MB64E_Presets_FLASH_Lower
MB64E_Presets_OffsetEncs
MB64E_Presets_OffsetEncsRge0    ; preset: volume (Bn 07)
  ENCODER_ENTRY 0xb0, 0x07, 0x00, 0x7f ; first 8 encoders
  ENCODER_ENTRY 0xb1, 0x07, 0x00, 0x7f
  ENCODER_ENTRY 0xb2, 0x07, 0x00, 0x7f
  ENCODER_ENTRY 0xb3, 0x07, 0x00, 0x7f
  ENCODER_ENTRY 0xb4, 0x07, 0x00, 0x7f
  ENCODER_ENTRY 0xb5, 0x07, 0x00, 0x7f
  ENCODER_ENTRY 0xb6, 0x07, 0x00, 0x7f
  ENCODER_ENTRY 0xb7, 0x07, 0x00, 0x7f
  ENCODER_ENTRY 0xb8, 0x07, 0x00, 0x7f ; row 1 column 1 
  ENCODER_ENTRY 0xb9, 0x07, 0x00, 0x7f ;       column 2
  ENCODER_ENTRY 0xba, 0x07, 0x00, 0x7f ;       column 3
  ENCODER_ENTRY 0xbb, 0x07, 0x00, 0x7f ;       column 4
  ENCODER_ENTRY 0xbc, 0x07, 0x00, 0x7f ; row 2 (center)
  ENCODER_ENTRY 0xbd, 0x07, 0x00, 0x7f
  ENCODER_ENTRY 0xbe, 0x07, 0x00, 0x7f
  ENCODER_ENTRY 0xbf, 0x07, 0x00, 0x7f

MB64E_Presets_OffsetEncsRge1    ; preset: panorama (Bn 0A)
  ENCODER_ENTRY 0xb0, 0x0a, 0x00, 0x7f ; row 3
  ENCODER_ENTRY 0xb1, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xb2, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xb3, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xb4, 0x0a, 0x00, 0x7f ; row 4
  ENCODER_ENTRY 0xb5, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xb6, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xb7, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xb8, 0x0a, 0x00, 0x7f ; row 2 (left/right)
  ENCODER_ENTRY 0xb9, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xba, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xbb, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xbc, 0x0a, 0x00, 0x7f ; other encoders follow
  ENCODER_ENTRY 0xbd, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xbe, 0x0a, 0x00, 0x7f
  ENCODER_ENTRY 0xbf, 0x0a, 0x00, 0x7f
...


Change the following table to define default color values of the LEDs in the matrix (after turning controller on):

...
MB64E_Presets_OffsetEncValues
    ;; page 0
    ;; first 8 positions used by real encoders
    db  0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
    ;; LEDMATRIX row 1
    db  0x0c, 0x0c, 0x0c, 0x0c
    ;; LEDMATRIX row 2 (center)
    db  0x00, 0x00, 0x00, 0x00
       
    ;; page 1
    ;; LEDMATRIX row 3
    db  0x01, 0x01, 0x01, 0x01
    ;; LEDMATRIX row 4
    db  0x03, 0x03, 0x03, 0x03
    ;; LEDMATRIX row 2 (left/right)
    db  0x09, 0x09, 0x09, 0x09
    ;; more encoders follow
    db  0x40, 0x40, 0x40, 0x40
  
    ;; page 2
    db  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
    ;; page 3
...


File mb64e_ledmatrix.inc

This is a new file. You may download it by saving this file to your disk.

And here is an annotated version of the file, with lots of explanations
(sorry, for the long comments, I had no time yet to write shorter ones).

;
; MIDIbox64E
; LED matrix handler
;
; ==========================================================================
;
; Copyright (C) 2005  Ralf Suckow (R.Suckow@t-online.de)
; 
; ==========================================================================
; 
; This file is part of MIDIbox64E
;
; MIDIbox64E is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; MIDIbox64E is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with MIDIbox64E; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
;
; ==========================================================================

;; --------------------------------------------------------------------------
;;  called by USER_SR_Service_Prepare
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
;; --------------------------------------------------------------------------
MB64E_LEDMATRIX_Handler
    ;; increment LED rings counter
    SET_BSR MB64E_LEDMATRIX_CTR
    incf    MB64E_LEDMATRIX_CTR, W, BANKED
    andlw   0x03
    movwf   MB64E_LEDMATRIX_CTR, BANKED

    ; counter is in WREG
    rcall   MB64E_LEDMATRIX_CathodesGet
    movwf   IRQ_TMP1

    movlw   0x00
    rcall   MB64E_LEDMATRIX_AnodesGet    
    swapf   WREG, W
    iorwf   IRQ_TMP1, W

    ; pattern in WREG containing cathodes and first four anodes 
    movwf   MIOS_PARAMETER1
    movlw   LEDMATRIX_SR_A
    call    MIOS_DOUT_SRSet

    movlw   0x04
    rcall   MB64E_LEDMATRIX_AnodesGet    
    movwf   IRQ_TMP1
    movlw   0x08
    rcall   MB64E_LEDMATRIX_AnodesGet    
    swapf   WREG, W
    iorwf   IRQ_TMP1, W

    ; pattern in WREG containing anodes 4...11 
    movwf   MIOS_PARAMETER1
    movlw   LEDMATRIX_SR_B
    call    MIOS_DOUT_SRSet

    movlw   0x0c
    rcall   MB64E_LEDMATRIX_AnodesGet    
    movwf   IRQ_TMP1
    movlw   0x10
    rcall   MB64E_LEDMATRIX_AnodesGet    
    swapf   WREG, W
    iorwf   IRQ_TMP1, W

    ; pattern in WREG containing anodes 12 ... 19
    movwf   MIOS_PARAMETER1
    movlw   LEDMATRIX_SR_C
    call    MIOS_DOUT_SRSet

    return


    ;; input: counter 0 ... 3 in WREG 
    ;; due to the use of drivers, the cathode needs a value of 1
    ;; to connnect the driver output to ground (isn't that what a cathode is about)
MB64E_LEDMATRIX_CathodesGet
    JUMPTABLE_2BYTES_UNSECURE
    retlw   b'00000001'
    retlw   b'00000010'
    retlw   b'00000100'
    retlw   b'00001000'

    ;; input: number of first controller in row (0, 4, 8, 12, 16) in WREG
MB64E_LEDMATRIX_AnodesGet
    SET_BSR MB64E_LEDMATRIX_CTR
    addwf   MB64E_LEDMATRIX_CTR, W, BANKED ; controller is group + column counter

    lfsr    FSR2, MB64E_ENC_VALUES_00 + 8
    movf    PLUSW2, W                   ; get entry value (7 bit)
    andlw   0x0f                        ; four bits per controller
    return