Skip to content

Instantly share code, notes, and snippets.

@alexjaw
Created March 28, 2018 08:55
Show Gist options
  • Save alexjaw/694cc6ded4724afbdea04fca537bd709 to your computer and use it in GitHub Desktop.
Save alexjaw/694cc6ded4724afbdea04fca537bd709 to your computer and use it in GitHub Desktop.
xCORE-200 Multichannel Audio Platform simple gpio 1
/*
Simple gpio is based on xmos an00155 for xCORE-200 eXplorerKIT.
Here, I'm applying the code on MCA.
Observe that instead of using the led matrix on MCA, I'm using
a single bit port normally used for OPT_RX (which I monitor
with an oscilloscope).
I have built with unchanged Makefile Target, i.e. xCORE-200 Explorer Kit
Running: Press button 1 and observe the voltage level on OPT_RX.
*/
#include <xs1.h>
#include <platform.h>
#include <gpio.h>
// GPIO port declarations
on tile[1] : in port mca_btns = XS1_PORT_4B; //btn1 on P4B0...switch on P4B3
on tile[1] : out port mca_leds = XS1_PORT_1O; //OPT_RX NOT led
// GPIO handler routine
void gpio_mca_handler(client input_gpio_if button_1, client output_gpio_if led_1){
// LED state
unsigned int led_state = 0;
// Initial button event state, active low
button_1.event_when_pins_eq(0);
while (1) {
select {
// Triggered by events on button 1
case button_1.event():
if (button_1.input() == 0) {
led_state = ~led_state;
led_1.output(led_state);
// Set button event state to active high for debounce
button_1.event_when_pins_eq(1);
} else {
// Debounce button
delay_milliseconds(50);
button_1.event_when_pins_eq(0);
}
break;
}
}
}
// The main() function runs a single task which takes the gpio interfaces as parameters
int main() {
input_gpio_if i_mca_buttons[4];
output_gpio_if i_mca_leds[1]; //Actually OPT_RX, NOT the led matrix
par {
on tile[1] : input_gpio_with_events(i_mca_buttons, 4, mca_btns, null);
on tile[1] : output_gpio(i_mca_leds, 1, mca_leds, null);
on tile[0] : gpio_mca_handler(i_mca_buttons[0],
i_mca_leds[0]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment