diff options
-rw-r--r-- | include/driver/usbh_device_driver.h | 9 | ||||
-rw-r--r-- | src/usbh_core.c | 10 | ||||
-rw-r--r-- | src/usbh_driver_ac_midi.c | 4 | ||||
-rw-r--r-- | src/usbh_driver_gp_xbox.c | 2 | ||||
-rw-r--r-- | src/usbh_driver_hid_mouse.c | 2 | ||||
-rw-r--r-- | src/usbh_driver_hub.c | 2 | ||||
-rw-r--r-- | src/usbh_lld_stm32f4.c | 8 |
7 files changed, 20 insertions, 17 deletions
diff --git a/include/driver/usbh_device_driver.h b/include/driver/usbh_device_driver.h index 6dd53c3..76e2619 100644 --- a/include/driver/usbh_device_driver.h +++ b/include/driver/usbh_device_driver.h @@ -129,7 +129,10 @@ typedef void (*usbh_packet_callback_t)(usbh_device_t *dev, usbh_packet_callback_ struct _usbh_packet { /// pointer to data - void *data; + union { + const void *out; + void *in; + } data; /// length of the data (up to 1023) uint16_t datalen; @@ -234,8 +237,8 @@ void usbh_write(usbh_device_t *dev, const usbh_packet_t *packet); /* Helper functions used by device drivers */ void device_xfer_control_read(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev); -void device_xfer_control_write_setup(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev); -void device_xfer_control_write_data(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev); +void device_xfer_control_write_setup(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev); +void device_xfer_control_write_data(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev); END_DECLS diff --git a/src/usbh_core.c b/src/usbh_core.c index cd631a4..60baf64 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -196,11 +196,11 @@ void usbh_init(const void *low_level_drivers[], const usbh_dev_driver_t * const * NEW ENUMERATE * */ -void device_xfer_control_write_setup(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) +void device_xfer_control_write_setup(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) { usbh_packet_t packet; - packet.data = data; + packet.data.out = data; packet.datalen = datalen; packet.address = dev->address; packet.endpoint_address = 0; @@ -216,11 +216,11 @@ void device_xfer_control_write_setup(void *data, uint16_t datalen, usbh_packet_c LOG_PRINTF("WR-setup@device...%d \n", dev->address); } -void device_xfer_control_write_data(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) +void device_xfer_control_write_data(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) { usbh_packet_t packet; - packet.data = data; + packet.data.out = data; packet.datalen = datalen; packet.address = dev->address; packet.endpoint_address = 0; @@ -240,7 +240,7 @@ void device_xfer_control_read(void *data, uint16_t datalen, usbh_packet_callback { usbh_packet_t packet; - packet.data = data; + packet.data.in = data; packet.datalen = datalen; packet.address = dev->address; packet.endpoint_address = 0; diff --git a/src/usbh_driver_ac_midi.c b/src/usbh_driver_ac_midi.c index 205c2a2..cea40df 100644 --- a/src/usbh_driver_ac_midi.c +++ b/src/usbh_driver_ac_midi.c @@ -242,7 +242,7 @@ static void read_midi_in(void *drvdata, const uint8_t nextstate) usbh_packet_t packet; packet.address = midi->usbh_device->address; - packet.data = &midi->buffer[0]; + packet.data.in = &midi->buffer[0]; packet.datalen = midi->endpoint_in_maxpacketsize; packet.endpoint_address = midi->endpoint_in_address; packet.endpoint_size_max = midi->endpoint_in_maxpacketsize; @@ -362,7 +362,7 @@ void usbh_midi_write(uint8_t device_id, const void *data, uint32_t length, midi_ midi->sending = true; midi->write_callback_user = callback; - midi->write_packet.data = (void*)data; // it is safe cast since we are writing and function usbh_write cannot modify data + midi->write_packet.data.out = data; midi->write_packet.datalen = length; midi->write_packet.address = dev->address; midi->write_packet.endpoint_address = midi->endpoint_out_address; diff --git a/src/usbh_driver_gp_xbox.c b/src/usbh_driver_gp_xbox.c index 1bc2498..f52621a 100644 --- a/src/usbh_driver_gp_xbox.c +++ b/src/usbh_driver_gp_xbox.c @@ -326,7 +326,7 @@ static void read_gp_xbox_in(gp_xbox_device_t *gp_xbox) usbh_packet_t packet; packet.address = gp_xbox->usbh_device->address; - packet.data = &gp_xbox->buffer[0]; + packet.data.in = &gp_xbox->buffer[0]; packet.datalen = gp_xbox->endpoint_in_maxpacketsize; packet.endpoint_address = gp_xbox->endpoint_in_address; packet.endpoint_size_max = gp_xbox->endpoint_in_maxpacketsize; diff --git a/src/usbh_driver_hid_mouse.c b/src/usbh_driver_hid_mouse.c index 9d438a9..b52392f 100644 --- a/src/usbh_driver_hid_mouse.c +++ b/src/usbh_driver_hid_mouse.c @@ -214,7 +214,7 @@ static void read_mouse_in(void *drvdata) usbh_packet_t packet; packet.address = mouse->usbh_device->address; - packet.data = &mouse->buffer[0]; + packet.data.in = &mouse->buffer[0]; packet.datalen = mouse->endpoint_in_maxpacketsize; packet.endpoint_address = mouse->endpoint_in_address; packet.endpoint_size_max = mouse->endpoint_in_maxpacketsize; diff --git a/src/usbh_driver_hub.c b/src/usbh_driver_hub.c index 29335a7..1beed01 100644 --- a/src/usbh_driver_hub.c +++ b/src/usbh_driver_hub.c @@ -738,7 +738,7 @@ static void read_ep1(void *drvdata) usbh_packet_t packet;
packet.address = hub->device[0]->address;
- packet.data = hub->buffer;
+ packet.data.in = hub->buffer;
packet.datalen = hub->endpoint_in_maxpacketsize;
packet.endpoint_address = hub->endpoint_in_address;
packet.endpoint_size_max = hub->endpoint_in_maxpacketsize;
diff --git a/src/usbh_lld_stm32f4.c b/src/usbh_lld_stm32f4.c index 9e81c09..08000a2 100644 --- a/src/usbh_lld_stm32f4.c +++ b/src/usbh_lld_stm32f4.c @@ -295,7 +295,7 @@ static void write(void *drvdata, const usbh_packet_t *packet) packet->endpoint_type == USBH_ENDPOINT_TYPE_BULK) {
volatile uint32_t *fifo = &REBASE_CH(OTG_FIFO, channel) + RX_FIFO_SIZE;
- const uint32_t * buf32 = packet->data;
+ const uint32_t * buf32 = packet->data.out;
int i;
LOG_PRINTF("\nSending[%d]: ", packet->datalen);
for(i = packet->datalen; i >= 4; i-=4) {
@@ -317,7 +317,7 @@ static void write(void *drvdata, const usbh_packet_t *packet) } else {
volatile uint32_t *fifo = &REBASE_CH(OTG_FIFO, channel) +
RX_FIFO_SIZE + TX_NP_FIFO_SIZE;
- const uint32_t * buf32 = packet->data;
+ const uint32_t * buf32 = packet->data.out;
int i;
for(i = packet->datalen; i > 0; i-=4) {
*fifo++ = *buf32++;
@@ -334,7 +334,7 @@ static void rxflvl_handle(void *drvdata) uint8_t channel = rxstsp&0xf;
uint32_t len = (rxstsp>>4) & 0x1ff;
if ((rxstsp&OTG_GRXSTSP_PKTSTS_MASK) == OTG_GRXSTSP_PKTSTS_IN) {
- uint8_t *data = channels[channel].packet.data;
+ uint8_t *data = channels[channel].packet.data.in;
uint32_t *buf32 = (uint32_t *)&data[channels[channel].data_index];
int32_t i;
@@ -366,7 +366,7 @@ static void rxflvl_handle(void *drvdata) uint32_t i;
LOG_PRINTF("\nDATA: ");
for (i = 0; i < channels[channel].data_index; i++) {
- uint8_t *data = channels[channel].packet.data;
+ uint8_t *data = channels[channel].packet.data.in;
LOG_PRINTF("%02X ", data[i]);
}
#endif
|