Trying to impliment spi instead o i2c in AN00184_cdc_extended_explorer
Integrated bits from AN00160_using _SPI_master. (Tested fine on its own)
Interfaces created to facilitate comms between main.xc and app_virtual_com_extended.xc seems to be an issue.
Code: Select all
interface usb_cdc_interface cdc_data;
interface spi_master_if i_spi[1];
Code: Select all
// Copyright (c) 2016, XMOS Ltd, All rights reserved
#include <platform.h>
#include <xs1.h>
#include "usb.h"
//#include "i2c.h"
#include "xud_cdc.h"
#include "app_virtual_com_extended.h"
#include <spi.h>
// I2C interface ports
on tile[0]: port p_scl = XS1_PORT_1E;
on tile[0]: port p_sda = XS1_PORT_1F;
/* These ports are used for the SPI master */
out buffered port:32 p_sclk = on tile[0]: XS1_PORT_1A;
out port p_ss[1] = on tile[0]: {XS1_PORT_1D};
out buffered port:32 p_mosi = on tile[0]: XS1_PORT_1O;
in buffered port:32 p_miso = on tile[0]: XS1_PORT_1P;
/* USB Endpoint Defines */
#define XUD_EP_COUNT_OUT 2 //Includes EP0 (1 OUT EP0 + 1 BULK OUT EP)
#define XUD_EP_COUNT_IN 3 //Includes EP0 (1 IN EP0 + 1 INTERRUPT IN EP + 1 BULK IN EP)
int main() {
/* Channels to communicate with USB endpoints */
chan c_ep_out[XUD_EP_COUNT_OUT], c_ep_in[XUD_EP_COUNT_IN];
/* Interface to communicate with USB CDC (Virtual Serial) */
interface usb_cdc_interface cdc_data;
interface spi_master_if i_spi[1];
/* I2C interface */
//i2c_master_if i2c[1];
par
{
on USB_TILE: xud(c_ep_out, XUD_EP_COUNT_OUT, c_ep_in, XUD_EP_COUNT_IN, null, XUD_SPEED_HS, XUD_PWR_SELF);
on USB_TILE: Endpoint0(c_ep_out[0], c_ep_in[0]);
on USB_TILE: CdcEndpointsHandler(c_ep_in[1], c_ep_out[1], c_ep_in[2], cdc_data);
//on tile[0]: app_virtual_com_extended(cdc_data, i2c[0]);
//on tile[0]: i2c_master(i2c, 1, p_scl, p_sda, 10);
on tile[0]: spi_master(i_spi, 1, p_sclk, p_mosi, p_miso, p_ss, 1, null);
on tile[0]: app_virtual_com_extended(cdc_data, i_spi[0]);
}
return 0;
}
app_virtual_com_extended.xc
Code: Select all
// Copyright (c) 2016, XMOS Ltd, All rights reserved
#include <platform.h>
#include <xs1.h>
#include <stdio.h>
#include <string.h>
#include <timer.h>
#include "i2c.h"
#include "xud_cdc.h"
/* App specific defines */
#define MENU_MAX_CHARS 30
#define MENU_LIST 11
char app_menu[MENU_LIST][MENU_MAX_CHARS] = {
{"\n\r-------------------------\r\n"},
{"XMOS USB Virtual COM Demo\r\n"},
{"-------------------------\r\n"},
{"1. Switch to Echo mode\r\n"},
{"2. Toggle LED 1\r\n"},
{"3. Toggle LED 2\r\n"},
{"4. Toggle LED 3\r\n"},
{"5. Toggle LED 4\r\n"},
{"6. Read Accelerometer\r\n"},
{"7. Print timer ticks\r\n"},
{"-------------------------\r\n"},
};
char echo_mode_str[3][30] = {
{"Entered echo mode\r\n"},
{"Press Ctrl+Z to exit it\r\n"},
{"\r\nExit echo mode\r\n"},
};
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
/* Sends out the App menu over CDC virtual port*/
void show_menu(client interface usb_cdc_interface cdc)
{
unsigned length;
for(int i = 0; i < MENU_LIST; i++) {
length = strlen(app_menu[i]);
cdc.write(app_menu[i], length);
}
}
/* Application task */
//void app_virtual_com_extended(client interface usb_cdc_interface cdc, client interface i2c_master_if i2c)
void app_virtual_com_extended(client interface usb_cdc_interface cdc, client interface spi_master_if spi)
{
char value, tmp_string[50];
// app_init(spi);
show_menu(cdc);
while(1)
{
/* Check if user has input any character */
if(cdc.available_bytes())
{
value = cdc.get_char();
/* Do the chosen operation */
if(value == '1') {
show_menu(cdc);
}
}
} /* end of while(1) */
}
In: void app_virtual_com_extended(client interface usb_cdc_interface cdc, client interface spi_master_if spi)
Cannot ever get past during compiling:
The i2c implementation seems similar, both being typedef interface i2c_master_if { .. as well as typedef interface spi_master_if {../src/app_virtual_com_extended.xc:49:78: error: interface declared inside parameter list
void app_virtual_com_extended(client interface usb_cdc_interface cdc, client interface spi_master_if spi)
^~~~~~~~~~~~~~~~~~~~~~~
../src/app_virtual_com_extended.xc:49:71: error: parameter `spi' has incomplete type
void app_virtual_com_extended(client interface usb_cdc_interface cdc, client interface spi_master_if spi)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any input would be greatly appreciated.