summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmir Hammad <amir.hammad@hotmail.com>2016-09-11 09:33:34 +0200
committerAmir Hammad <amir.hammad@hotmail.com>2016-09-11 13:31:48 +0200
commitd7f23c7a8fab589ef35690e4cdaab7ce3ef72b74 (patch)
treed0f2bd244b0c17d89c2a08944bd53573bff6fafb
parent8946cb522b10465d3fe3a9846158dbff4e924240 (diff)
downloadsecure-hid-d7f23c7a8fab589ef35690e4cdaab7ce3ef72b74.tar.gz
secure-hid-d7f23c7a8fab589ef35690e4cdaab7ce3ef72b74.tar.bz2
secure-hid-d7f23c7a8fab589ef35690e4cdaab7ce3ef72b74.zip
lld: simplify stm32f4_usbh_port_channel_setup
Signed-off-by: Amir Hammad <amir.hammad@hotmail.com>
-rw-r--r--src/usbh_lld_stm32f4.c59
1 files changed, 23 insertions, 36 deletions
diff --git a/src/usbh_lld_stm32f4.c b/src/usbh_lld_stm32f4.c
index 5ac26e1..38b46e7 100644
--- a/src/usbh_lld_stm32f4.c
+++ b/src/usbh_lld_stm32f4.c
@@ -143,34 +143,31 @@ static void init(void *drvdata)
REBASE(OTG_GUSBCFG) |= OTG_GUSBCFG_PHYSEL;
}
-static void stm32f4_usbh_port_channel_setup(
- void *drvdata, uint32_t channel, uint32_t address,
- uint32_t eptyp, uint32_t epnum, uint32_t epdir,
- uint32_t max_packet_size)
+static uint32_t usbh_to_stm32_endpoint_type(enum USBH_ENDPOINT_TYPE usbh_eptyp)
{
- usbh_lld_stm32f4_driver_data_t *dev = drvdata;
- channel_t *channels = dev->channels;
-
- // TODO: maybe to function
- switch (eptyp) {
- case USBH_ENDPOINT_TYPE_CONTROL:
- eptyp = OTG_HCCHAR_EPTYP_CONTROL;
- break;
- case USBH_ENDPOINT_TYPE_BULK:
- eptyp = OTG_HCCHAR_EPTYP_BULK;
- break;
- case USBH_ENDPOINT_TYPE_INTERRUPT:
- // Use bulk transfer also for interrupt, since no difference is on protocol layer
- // Except different behaviour of the core
- eptyp = OTG_HCCHAR_EPTYP_BULK;
- break;
- case USBH_ENDPOINT_TYPE_ISOCHRONOUS:
- eptyp = OTG_HCCHAR_EPTYP_ISOCHRONOUS;
- break;
+ switch (usbh_eptyp) {
+ case USBH_ENDPOINT_TYPE_CONTROL: return OTG_HCCHAR_EPTYP_CONTROL;
+ case USBH_ENDPOINT_TYPE_BULK: return OTG_HCCHAR_EPTYP_BULK;
+
+ // Use bulk transfer also for interrupt, since no difference is on protocol layer
+ // Except different behaviour of the core
+ case USBH_ENDPOINT_TYPE_INTERRUPT: return OTG_HCCHAR_EPTYP_BULK;
+ case USBH_ENDPOINT_TYPE_ISOCHRONOUS: return OTG_HCCHAR_EPTYP_ISOCHRONOUS;
default:
LOG_PRINTF("\n\n\n\nWRONG EP TYPE\n\n\n\n\n");
- return;
+ return OTG_HCCHAR_EPTYP_CONTROL;
}
+}
+
+static void stm32f4_usbh_port_channel_setup(
+ void *drvdata, uint32_t channel, uint32_t epdir)
+{
+ usbh_lld_stm32f4_driver_data_t *dev = drvdata;
+ channel_t *channels = dev->channels;
+ uint32_t max_packet_size = channels[channel].packet.endpoint_size_max;
+ uint32_t address = channels[channel].packet.address;
+ uint32_t epnum = channels[channel].packet.endpoint_address;
+ uint32_t eptyp = usbh_to_stm32_endpoint_type(channels[channel].packet.endpoint_type);
uint32_t speed = 0;
if (channels[channel].packet.speed == USBH_SPEED_LOW) {
@@ -227,12 +224,7 @@ static void read(void *drvdata, usbh_packet_t *packet)
REBASE_CH(OTG_HCTSIZ, channel) = dpid | (num_packets << 19) | packet->datalen;
- stm32f4_usbh_port_channel_setup(dev, channel,
- packet->address,
- packet->endpoint_type,
- packet->endpoint_address,
- OTG_HCCHAR_EPDIR_IN,
- packet->endpoint_size_max);
+ stm32f4_usbh_port_channel_setup(dev, channel, OTG_HCCHAR_EPDIR_IN);
}
/**
@@ -284,12 +276,7 @@ static void write(void *drvdata, const usbh_packet_t *packet)
}
REBASE_CH(OTG_HCTSIZ, channel) = dpid | (num_packets << 19) | packet->datalen;
- stm32f4_usbh_port_channel_setup(dev, channel,
- packet->address,
- packet->endpoint_type,
- packet->endpoint_address,
- OTG_HCCHAR_EPDIR_OUT,
- packet->endpoint_size_max);
+ stm32f4_usbh_port_channel_setup(dev, channel, OTG_HCCHAR_EPDIR_OUT);
if (packet->endpoint_type == USBH_ENDPOINT_TYPE_CONTROL ||
packet->endpoint_type == USBH_ENDPOINT_TYPE_BULK) {