Addressing MC board LED's/GPIO Pins

New to XMOS and XCore? Get started here.
Post Reply
ztrail
Junior Member
Posts: 7
Joined: Mon Dec 11, 2017 4:53 am

Addressing MC board LED's/GPIO Pins

Post by ztrail »

Hi,

trying to address the LED's on my XK-AUDIO-216-MC.

#####################

Found this in gpio_access.h in the sw_usb_audio project, but no clue as how to use it.

Bitwise operations?

/*LED array defines*/
#define LED_ALL_ON 0xf00f
#define LED_SQUARE_BIG 0x9009
#define LED_SQUARE_SML 0x6006
#define LED_ROW_1 0xf001 // ignores that there are 4 rows!
#define LED_ROW_2 0xf003
#define LED_ROW_3 0xf007
#define ALL_OFF 0x0000

// LED array masks
#define LED_MASK_COL_OFF 0x7fff
#define LED_MASK_DISABLE 0xffff


Could someone provide an example of usage?

###################

Also in the hardware manual, a different approach:

UI signal: LED_ROW_0
xCORE GPIO: X1D14
Port: P4C0
Description: Row 0 LED driver control (active low), and so on....


This info is similar to code in the flashing_leds project written for the Start board:
port p = XS1_PORT_4A; // p is acessing 4-bit port A on Start board.

There does not seem to be a XS1_PORT_XX define scheme for MC builds. What's the format?
All WAG's result in "error: initializer element is not constant port q = X1D15_P4C1" yada yada

p <: 0; // on?
p <: 1 // off?


Could someone provide an example of usage?

####################

Thanks!


User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Hello.

1) Download the xCORE-200 Multichannel Audio Platform Hardware Manual for this kit:

https://www.xmos.com/support/boards?product=18334

https://www.xmos.com/support/boards?pro ... nent=18687

2) Start with reviewing page 13 - figure 22 of this guide which offers the LED matrix to XMOS port pin mappings.

Image

Observe that the XMOS port pins being used have the prefix of X1 (ie. X1D14, etc.). This means that the ports are linked to Tile[1] of the CPU. This is important else you will be shooting blanks if attempting to code up for use with X0D14 which is linked to Tile[0]. Review the source code defines / header files from XMOS for this kit which should have the valid assignments already.

From the same table, we know that Tile[1] is mapped to this LED matrix and specifically, port P4C0..P4C3 = ROWs & P4D0..P4D3 = COLUMNs. Again, all on Tile[1] for both.

3) See page 25, figure 35 for the detailed schematics on how the LED matrix is wired. Note the use of mosfets for each column and for each row.

Image

4) To turn ON a column, that PORT BIT on the XMOS port must be 0 (zero; Active Low to enable the local mosfet). If HIGH, column is OFF.

5) To turn ON a row, that PORT BIT on the XMOS port must be 0 (zero; Active Low to enable the local mosfet). If HIGH, row is OFF.

6) To turn ON a LED, the column for that specific LED must be ON along with the ROW for that specific LED must be ON.

Examples:

a) to turn ON LED D22, make column zero (P4D0=0) and row three (P4C3=0) both low. Again, keep in mind, all through Tile[1] access for these port pins.

b) to turn ON LED D18, make column zero (P4D0=0) and row two (P4C2=0) both low.

In searching through the downloadable audio source code package, found the following important routines for the LED matrix access:


Image

Code: Select all

/* Buttons/switch port */
in port p_sw = on tile[1] : XS1_PORT_4B;

/* LED grid port */
out port p_leds_row = on tile[1] : XS1_PORT_4C;
out port p_leds_col = on tile[1] : XS1_PORT_4D;

void OutputLedVal(unsigned char x)
{
    p_leds_row <: (unsigned) (x & 0xf);
    p_leds_col <: (unsigned) (x >> 4);
}
Note the use of the Tile[1] for the respective port pin access.

Try the following examples and post your results:

Code: Select all

void my_led_matrix(void)
{

// turn ON all of the 9 LEDs in the matrix (column & row = 0 = LOW to turn ON the mosfets)
p_leds_row <: 0;
p_leds_col <: 0;

delay_milliseconds(2500);

// turn ON D22 only
p_leds_row <: 0x07; // Bit 3 for Row 3 = 0 only
p_leds_col <: 0x0E; // Bit 0 for Column 0 = 0 only

delay_milliseconds(2500);

// turn ON D18 only
p_leds_row <: 0x0B; // Bit 2 for Row 2 = 0 only
p_leds_col <: 0x0E; // Bit 0 for Column 0 = 0 only

delay_milliseconds(2500);

}
Disclaimer: Do not own this kit and the above details are from reviewing the documentation and related schematics and source code.
ztrail
Junior Member
Posts: 7
Joined: Mon Dec 11, 2017 4:53 am

Post by ztrail »

I was able to successfully build a minimalistic project for playing with lights on the xk-audio-216-mc.

Code: Select all


#include <platform.h>
#include <gpio.h>

/* Buttons/switch port */
in port p_sw = on tile[1] : XS1_PORT_4B;

/* LED grid port */
out port p_leds_row = on tile[1] : XS1_PORT_4C;
out port p_leds_col = on tile[1] : XS1_PORT_4D;

void my_led_matrix(void) {

    while (1) {

        p_leds_row <: 0x7
        ; // 0111 row 1
        delay_milliseconds(500)
        ;

        p_leds_row <: 0xB
        ; // 1011 row 2
        delay_milliseconds(500)
        ;

        p_leds_row <: 0xD
        ; // 1101 row 3
        delay_milliseconds(500)
        ;

        p_leds_row <: 0xE
        ; // 1110 row 4
        delay_milliseconds(500)
        ;

        p_leds_row <: 0x0
        ; // 0000 row all on
        delay_milliseconds(500)
        ;



        p_leds_col <: 0x1
        ; // 0001 column 4
        delay_milliseconds(500)
        ;

        p_leds_col <: 0x2
        ; // 0010 column 3
        delay_milliseconds(500)
        ;

        p_leds_col <: 0x4
        ; // 0100 column 2
        delay_milliseconds(500)
        ;

        p_leds_col <: 0x8
        ; // 1000 column 1
        delay_milliseconds(500)
        ;
}
}

int main(void)
{
	par 
	{
		on tile[1] : my_led_matrix();
	}

	return 0;
}

I have some other related questions better stated in new threads.

Thanks for your help!
afaf
Member++
Posts: 16
Joined: Mon Apr 09, 2018 10:46 am

Post by afaf »

Hi ~~
may I have about app_flash_led zip , for me to import archive file.
I just want to verify xCORE-200 MC AUDIO about LED.
User avatar
mon2
XCore Legend
Posts: 1913
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Post by mon2 »

Hi. Try the attached. Post your results. The compiled .xe file is also enclosed.

PS: Do not own this kit but code should work as written.
Attachments
led_blinker_xc216.zip
(36.85 KiB) Downloaded 314 times
led_blinker_xc216.zip
(36.85 KiB) Downloaded 314 times
afaf
Member++
Posts: 16
Joined: Mon Apr 09, 2018 10:46 am

Post by afaf »

It's works, it's great, it really helps my beginners, thanks a lot~~

Step1: File\Import\
Step2: Select
General\Existing Projects into Workspace\Next\
Step3: Select archive file: ..\path\... \led_blinker_xc216.zip
Step4: Build
Step5: Run AS \ Run Configurations \

Step6: It's work.
afaf
Member++
Posts: 16
Joined: Mon Apr 09, 2018 10:46 am

Post by afaf »

It is real "hello world" at XK-AUDIO-216-MC
Post Reply