136 lines
2.4 KiB
C
136 lines
2.4 KiB
C
#include <hwo/utils.h>
|
|
#include <hwo/threads.h>
|
|
#include <usb/usb.h>
|
|
|
|
#include <avr/io.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
#include <io/pipe.h>
|
|
|
|
/*
|
|
struct usb_io_stream_info
|
|
{
|
|
uint8_t configuration;
|
|
uint8_t rx,
|
|
tx;
|
|
uint8_t options;
|
|
};
|
|
|
|
int usb_endpoint_put(char ch,FILE *stream)
|
|
{
|
|
int result;
|
|
struct usb_io_stream_info *si = fdev_get_udata(stream);
|
|
if (!si)
|
|
return _FDEV_ERR;
|
|
|
|
if (si->configuration != usb_device.current_configuration) {
|
|
return _FDEV_ERR;
|
|
};
|
|
|
|
if (si->tx == -1)
|
|
return _FDEV_ERR;
|
|
|
|
{
|
|
ATOMIC
|
|
|
|
result = pipe_put( ch, usb_device.endpoints[ si->tx ].pipe );
|
|
if (result != -1)
|
|
{
|
|
avr_usb_endpoint_select( si->tx );
|
|
usb_device_enable_irq( USB_IRQ_TXIN );
|
|
};
|
|
};
|
|
return result;
|
|
};
|
|
|
|
int usb_endpoint_get(FILE *stream)
|
|
{
|
|
int ch;
|
|
struct usb_io_stream_info *si = fdev_get_udata(stream);
|
|
|
|
if (!si)
|
|
return _FDEV_ERR;
|
|
|
|
if (si->configuration != usb_device.current_configuration) {
|
|
return _FDEV_ERR;
|
|
};
|
|
|
|
if (si->rx == -1)
|
|
return _FDEV_ERR;
|
|
|
|
{
|
|
ATOMIC
|
|
|
|
ch = pipe_get(usb_device.endpoints[si->rx].pipe);
|
|
if (ch >= 0)
|
|
{
|
|
avr_usb_endpoint_select( si->rx );
|
|
usb_device_enable_irq( USB_IRQ_RXOUT );
|
|
};
|
|
|
|
};
|
|
return ch;
|
|
};
|
|
|
|
FILE* usb_endpoint_stream(uint8_t rx,uint8_t tx)
|
|
{
|
|
return usb_endpoint_stream_ex(rx,tx,1,0);
|
|
};
|
|
|
|
FILE* usb_endpoint_stream_ex(uint8_t rx,uint8_t tx,uint8_t configuration,uint8_t options)
|
|
{
|
|
struct usb_io_stream_info *stream_info = malloc( sizeof( struct usb_io_stream_info ) );
|
|
FILE* stream;
|
|
|
|
if (stream_info)
|
|
{
|
|
stream_info->configuration = configuration;
|
|
stream_info->rx = rx;
|
|
stream_info->tx = tx;
|
|
stream_info->options = 0;
|
|
|
|
stream = fdevopen(usb_endpoint_put,usb_endpoint_get);
|
|
if (stream)
|
|
{
|
|
fdev_set_udata( stream, stream_info );
|
|
usb_endpoint_stream_options( stream, options );
|
|
return stream;
|
|
};
|
|
free( stream_info );
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
int usb_endpoint_stream_options(FILE* stream,uint8_t options)
|
|
{
|
|
struct usb_io_stream_info *sinfo = (struct usb_io_stream_info*)fdev_get_udata(stream);
|
|
|
|
#if 1
|
|
|
|
if (sinfo->rx != -1)
|
|
{
|
|
if (options & IO_BLOCK_RD)
|
|
pipe_options( usb_device.endpoints[ sinfo->rx ].pipe, IO_BLOCK_RD );
|
|
else
|
|
pipe_options( usb_device.endpoints[ sinfo->rx ].pipe, 0 );
|
|
};
|
|
if (sinfo->tx != -1)
|
|
{
|
|
if (options & IO_BLOCK_WR)
|
|
pipe_options( usb_device.endpoints[ sinfo->tx ].pipe, IO_BLOCK_WR );
|
|
else
|
|
pipe_options( usb_device.endpoints[ sinfo->tx ].pipe, 0 );
|
|
};
|
|
|
|
#else
|
|
|
|
sinfo->options = options;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
};
|
|
*/
|
|
|