forked from PAWPAW-Mirror/lib_xua
Use select for EP0 handling + split ep0 into init and loop
This commit is contained in:
@@ -53,6 +53,8 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
|
|||||||
[[distributable]]
|
[[distributable]]
|
||||||
void AudioHub(server i2s_frame_callback_if i2s, chanend c_aud, client i2c_master_if ?i2c, client output_gpio_if dac_reset);
|
void AudioHub(server i2s_frame_callback_if i2s, chanend c_aud, client i2c_master_if ?i2c, client output_gpio_if dac_reset);
|
||||||
void AudioHwConfigure(unsigned samFreq, client i2c_master_if i_i2c);
|
void AudioHwConfigure(unsigned samFreq, client i2c_master_if i_i2c);
|
||||||
|
void XUA_Endpoint0_select(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||||
|
chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, ?dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@@ -103,7 +105,8 @@ int main()
|
|||||||
|
|
||||||
// Endpoint 0 core from lib_xua
|
// Endpoint 0 core from lib_xua
|
||||||
// Note, since we are not using many features we pass in null for quite a few params..
|
// Note, since we are not using many features we pass in null for quite a few params..
|
||||||
XUA_Endpoint0(c_ep_out[0], c_ep_in[0], c_aud_ctl, null, null, null, null);
|
// XUA_Endpoint0(c_ep_out[0], c_ep_in[0], c_aud_ctl, null, null, null, null);
|
||||||
|
XUA_Endpoint0_select(c_ep_out[0], c_ep_in[0], c_aud_ctl, null, null, null, null);
|
||||||
|
|
||||||
// Buffering cores - handles audio data to/from EP's and gives/gets data to/from the audio I/O core
|
// Buffering cores - handles audio data to/from EP's and gives/gets data to/from the audio I/O core
|
||||||
XUA_Buffer_lite(c_ep_out[1], c_ep_in[1], c_ep_in[2], c_sof, c_aud_ctl, p_for_mclk_count, c_audio);
|
XUA_Buffer_lite(c_ep_out[1], c_ep_in[1], c_ep_in[2], c_sof, c_aud_ctl, p_for_mclk_count, c_audio);
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ void XUA_Buffer_lite(chanend c_aud_out, chanend c_feedback, chanend c_aud_in, ch
|
|||||||
// for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: samples_out[1];
|
// for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: samples_out[1];
|
||||||
int out_samps[NUM_USB_CHAN_OUT];
|
int out_samps[NUM_USB_CHAN_OUT];
|
||||||
fifo_ret_t ret = fifo_block_pop(host_to_device_fifo_ptr, out_samps, NUM_USB_CHAN_OUT);
|
fifo_ret_t ret = fifo_block_pop(host_to_device_fifo_ptr, out_samps, NUM_USB_CHAN_OUT);
|
||||||
if (ret != FIFO_SUCCESS) debug_printf("empty\n");
|
//if (ret != FIFO_SUCCESS) debug_printf("empty\n");
|
||||||
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: out_samps[i];
|
for (int i = 0; i < NUM_USB_CHAN_OUT; i++) c_audio_hub <: out_samps[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,13 +200,14 @@ const unsigned g_chanCount_In_HS[INPUT_FORMAT_COUNT] = {HS_STREAM_FORMAT_I
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Endpoint 0 function. Handles all requests to the device */
|
XUD_ep ep0_out;
|
||||||
void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
XUD_ep ep0_in;
|
||||||
|
|
||||||
|
void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||||
chanend c_mix_ctl, chanend c_clk_ctl, chanend c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_)
|
chanend c_mix_ctl, chanend c_clk_ctl, chanend c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_)
|
||||||
{
|
{
|
||||||
USB_SetupPacket_t sp;
|
ep0_out = XUD_InitEp(c_ep0_out);
|
||||||
XUD_ep ep0_out = XUD_InitEp(c_ep0_out);
|
ep0_in = XUD_InitEp(c_ep0_in);
|
||||||
XUD_ep ep0_in = XUD_InitEp(c_ep0_in);
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Dont need to init globals.. */
|
/* Dont need to init globals.. */
|
||||||
@@ -295,29 +296,11 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while(1)
|
}
|
||||||
{
|
|
||||||
#if XUA_LITE
|
|
||||||
unsigned char sbuffer[120];
|
|
||||||
unsigned length = 0;
|
|
||||||
XUD_Result_t result = XUD_RES_ERR;
|
|
||||||
|
|
||||||
//XUD_Result_t result = XUD_GetSetupBuffer(ep0_out, sbuffer, &length); //Flattened from xud_device
|
void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||||
result = XUD_GetSetupData(ep0_out, sbuffer, &length);//Flattened from XUD_EpFunctions.xc
|
chanend c_mix_ctl, chanend c_clk_ctl, chanend c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_)
|
||||||
|
{
|
||||||
// select{
|
|
||||||
// case XUD_GetSetupData_Select(c_ep0_out, ep0_out, &length, &result):
|
|
||||||
// break;
|
|
||||||
|
|
||||||
if (result == XUD_RES_OKAY)
|
|
||||||
{
|
|
||||||
/* Parse data buffer end populate SetupPacket struct */
|
|
||||||
USB_ParseSetupPacket(sbuffer, &sp);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
/* Returns XUD_RES_OKAY for success, XUD_RES_RST for bus reset */
|
|
||||||
XUD_Result_t result = USB_GetSetupPacket(ep0_out, ep0_in, &sp);
|
|
||||||
#endif
|
|
||||||
if (result == XUD_RES_OKAY)
|
if (result == XUD_RES_OKAY)
|
||||||
{
|
{
|
||||||
result = XUD_RES_ERR;
|
result = XUD_RES_ERR;
|
||||||
@@ -818,6 +801,39 @@ void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Endpoint 0 function. Handles all requests to the device */
|
||||||
|
void XUA_Endpoint0(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||||
|
chanend c_mix_ctl, chanend c_clk_ctl, chanend c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_)
|
||||||
|
{
|
||||||
|
USB_SetupPacket_t sp;
|
||||||
|
XUA_Endpoint0_init(c_ep0_out, c_ep0_in, c_audioControl, c_mix_ctl, c_clk_ctl, c_EANativeTransport_ctrl, dfuInterface);
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
#if XUA_LITE
|
||||||
|
unsigned char sbuffer[120];
|
||||||
|
unsigned length = 0;
|
||||||
|
XUD_Result_t result = XUD_RES_ERR;
|
||||||
|
|
||||||
|
//XUD_Result_t result = XUD_GetSetupBuffer(ep0_out, sbuffer, &length); //Flattened from xud_device
|
||||||
|
result = XUD_GetSetupData(ep0_out, sbuffer, &length);//Flattened from XUD_EpFunctions.xc
|
||||||
|
|
||||||
|
// select{
|
||||||
|
// case XUD_GetSetupData_Select(c_ep0_out, ep0_out, &length, &result):
|
||||||
|
// break;
|
||||||
|
|
||||||
|
if (result == XUD_RES_OKAY)
|
||||||
|
{
|
||||||
|
/* Parse data buffer end populate SetupPacket struct */
|
||||||
|
USB_ParseSetupPacket(sbuffer, &sp);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* Returns XUD_RES_OKAY for success, XUD_RES_RST for bus reset */
|
||||||
|
XUD_Result_t result = USB_GetSetupPacket(ep0_out, ep0_in, &sp);
|
||||||
|
#endif
|
||||||
|
XUA_Endpoint0_loop(result, sp, c_ep0_out, c_ep0_in, c_audioControl, c_mix_ctl, c_clk_ctl, c_EANativeTransport_ctrl, dfuInterface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* XUA_USB_EN*/
|
#endif /* XUA_USB_EN*/
|
||||||
|
|||||||
55
lib_xua/src/core/endpoint0/xua_ep0_wrapper.xc
Normal file
55
lib_xua/src/core/endpoint0/xua_ep0_wrapper.xc
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#include <xs1.h>
|
||||||
|
#include <safestring.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "xua.h"
|
||||||
|
|
||||||
|
#define DEBUG_UNIT EP0_WRAPPER
|
||||||
|
#define DEBUG_PRINT_ENABLE_EP0_WRAPPER 1
|
||||||
|
#include "debug_print.h"
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||||
|
chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, ?dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_);
|
||||||
|
void XUA_Endpoint0_loop(XUD_Result_t result, USB_SetupPacket_t sp, chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||||
|
chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, ?dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_);
|
||||||
|
#pragma select handler
|
||||||
|
void XUD_GetSetupData_Select(chanend c, XUD_ep e_out, unsigned &length, XUD_Result_t &result);
|
||||||
|
|
||||||
|
extern XUD_ep ep0_out;
|
||||||
|
extern XUD_ep ep0_in;
|
||||||
|
|
||||||
|
|
||||||
|
void XUA_Endpoint0_select(chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl,
|
||||||
|
chanend ?c_mix_ctl, chanend ?c_clk_ctl, chanend ?c_EANativeTransport_ctrl, CLIENT_INTERFACE(i_dfu, dfuInterface) VENDOR_REQUESTS_PARAMS_DEC_)
|
||||||
|
{
|
||||||
|
|
||||||
|
USB_SetupPacket_t sp;
|
||||||
|
XUA_Endpoint0_init(c_ep0_out, c_ep0_in, c_audioControl, c_mix_ctl, c_clk_ctl, c_EANativeTransport_ctrl, dfuInterface);
|
||||||
|
unsigned char sbuffer[120];
|
||||||
|
XUD_SetReady_Out(ep0_out, sbuffer);
|
||||||
|
while(1){
|
||||||
|
|
||||||
|
XUD_Result_t result = XUD_RES_ERR;
|
||||||
|
unsigned length = 0;
|
||||||
|
|
||||||
|
//XUD_Result_t result = XUD_GetSetupBuffer(ep0_out, sbuffer, &length); //Flattened from xud_device
|
||||||
|
// result = XUD_GetSetupData(ep0_out, sbuffer, length);//Flattened from XUD_EpFunctions.xc
|
||||||
|
|
||||||
|
select{
|
||||||
|
case XUD_GetSetupData_Select(c_ep0_out, ep0_out, length, result):
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == XUD_RES_OKAY)
|
||||||
|
{
|
||||||
|
/* Parse data buffer end populate SetupPacket struct */
|
||||||
|
USB_ParseSetupPacket(sbuffer, sp);
|
||||||
|
}
|
||||||
|
debug_printf("ep0, result: %d, length: %d\n", result, length); //-1 reset, 0 ok, 1 error
|
||||||
|
|
||||||
|
XUA_Endpoint0_loop(result, sp, c_ep0_out, c_ep0_in, c_audioControl, c_mix_ctl, c_clk_ctl, c_EANativeTransport_ctrl, dfuInterface);
|
||||||
|
XUD_SetReady_Out(ep0_out, sbuffer);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user