usb_cdc: Add support for usb_send_ep0_progmem()
Add support for explicitly sending to the ep0 pipe from constant "progmem" memory on the AVR. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
92aea93500
commit
731236cf20
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#define NEED_PROGMEM 1
|
||||||
|
|
||||||
#define READP(VAR) ({ \
|
#define READP(VAR) ({ \
|
||||||
_Pragma("GCC diagnostic push"); \
|
_Pragma("GCC diagnostic push"); \
|
||||||
_Pragma("GCC diagnostic ignored \"-Wint-to-pointer-cast\""); \
|
_Pragma("GCC diagnostic ignored \"-Wint-to-pointer-cast\""); \
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// This header provides wrappers for the AVR specific "PROGMEM"
|
// This header provides wrappers for the AVR specific "PROGMEM"
|
||||||
// declarations on non-avr platforms.
|
// declarations on non-avr platforms.
|
||||||
|
|
||||||
|
#define NEED_PROGMEM 0
|
||||||
#define PROGMEM
|
#define PROGMEM
|
||||||
#define PSTR(S) S
|
#define PSTR(S) S
|
||||||
#define READP(VAR) VAR
|
#define READP(VAR) VAR
|
||||||
|
|
|
@ -290,7 +290,7 @@ static const struct descriptor_s {
|
||||||
|
|
||||||
// State tracking
|
// State tracking
|
||||||
enum {
|
enum {
|
||||||
UX_READ = 1<<0, UX_SEND = 1<<1, UX_SEND_ZLP = 1<<2
|
UX_READ = 1<<0, UX_SEND = 1<<1, UX_SEND_PROGMEM = 1<<2, UX_SEND_ZLP = 1<<3
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *usb_xfer_data;
|
static void *usb_xfer_data;
|
||||||
|
@ -315,6 +315,8 @@ usb_do_xfer(void *data, uint_fast8_t size, uint_fast8_t flags)
|
||||||
int_fast8_t ret;
|
int_fast8_t ret;
|
||||||
if (flags & UX_READ)
|
if (flags & UX_READ)
|
||||||
ret = usb_read_ep0(data, xs);
|
ret = usb_read_ep0(data, xs);
|
||||||
|
else if (NEED_PROGMEM && flags & UX_SEND_PROGMEM)
|
||||||
|
ret = usb_send_ep0_progmem(data, xs);
|
||||||
else
|
else
|
||||||
ret = usb_send_ep0(data, xs);
|
ret = usb_send_ep0(data, xs);
|
||||||
if (ret == xs) {
|
if (ret == xs) {
|
||||||
|
@ -359,7 +361,8 @@ usb_req_get_descriptor(struct usb_ctrlrequest *req)
|
||||||
const struct descriptor_s *d = &cdc_descriptors[i];
|
const struct descriptor_s *d = &cdc_descriptors[i];
|
||||||
if (READP(d->wValue) == req->wValue
|
if (READP(d->wValue) == req->wValue
|
||||||
&& READP(d->wIndex) == req->wIndex) {
|
&& READP(d->wIndex) == req->wIndex) {
|
||||||
uint_fast8_t size = READP(d->size), flags = UX_SEND;
|
uint_fast8_t size = READP(d->size);
|
||||||
|
uint_fast8_t flags = NEED_PROGMEM ? UX_SEND_PROGMEM : UX_SEND;
|
||||||
if (size > req->wLength)
|
if (size > req->wLength)
|
||||||
size = req->wLength;
|
size = req->wLength;
|
||||||
else if (size < req->wLength)
|
else if (size < req->wLength)
|
||||||
|
|
|
@ -16,6 +16,7 @@ int_fast8_t usb_read_bulk_out(void *data, uint_fast8_t max_len);
|
||||||
int_fast8_t usb_send_bulk_in(void *data, uint_fast8_t len);
|
int_fast8_t usb_send_bulk_in(void *data, uint_fast8_t len);
|
||||||
int_fast8_t usb_read_ep0(void *data, uint_fast8_t max_len);
|
int_fast8_t usb_read_ep0(void *data, uint_fast8_t max_len);
|
||||||
int_fast8_t usb_send_ep0(const void *data, uint_fast8_t len);
|
int_fast8_t usb_send_ep0(const void *data, uint_fast8_t len);
|
||||||
|
int_fast8_t usb_send_ep0_progmem(const void *data, uint_fast8_t len);
|
||||||
void usb_stall_ep0(void);
|
void usb_stall_ep0(void);
|
||||||
void usb_set_address(uint_fast8_t addr);
|
void usb_set_address(uint_fast8_t addr);
|
||||||
void usb_set_configure(void);
|
void usb_set_configure(void);
|
||||||
|
|
Loading…
Reference in New Issue