aboutsummaryrefslogtreecommitdiffstats
path: root/testhal
diff options
context:
space:
mode:
authorDiego Ismirlian <dismirlian (at) google's mail.com>2017-07-09 18:30:46 -0300
committerDiego Ismirlian <dismirlian (at) google's mail.com>2017-07-09 18:30:46 -0300
commit025ca5345a8ffbb7de3b1c64fb0a5ddbbdacd3b0 (patch)
tree8b5fb3aa38faa39db8e35a1e59a6ef634b169974 /testhal
parentc9388668449f9d686b1e4df14f9143263cc0fafc (diff)
downloadChibiOS-Contrib-025ca5345a8ffbb7de3b1c64fb0a5ddbbdacd3b0.tar.gz
ChibiOS-Contrib-025ca5345a8ffbb7de3b1c64fb0a5ddbbdacd3b0.tar.bz2
ChibiOS-Contrib-025ca5345a8ffbb7de3b1c64fb0a5ddbbdacd3b0.zip
USBH: Added mechanism for out-of-tree class driver enumeration
Diffstat (limited to 'testhal')
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/Makefile2
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h2
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/usbh_additional_class_drivers.h38
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.c140
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.h83
5 files changed, 264 insertions, 1 deletions
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/Makefile b/testhal/STM32/STM32F4xx/USB_HOST/Makefile
index ca55953..c0cfc80 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/Makefile
+++ b/testhal/STM32/STM32F4xx/USB_HOST/Makefile
@@ -123,7 +123,7 @@ CSRC = $(STARTUPSRC) \
$(FATFSSRC) \
$(STREAMSSRC) \
$(SHELLSRC) \
- main.c
+ main.c usbh_custom_class_example.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h b/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h
index 51e9a8d..da9c7f8 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h
+++ b/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h
@@ -141,6 +141,8 @@
#define HAL_USBHHUB_MAX_INSTANCES 1
#define HAL_USBHHUB_MAX_PORTS 6
+#define HAL_USBH_USE_ADDITIONAL_CLASS_DRIVERS 1
+
/* debug */
#define USBH_DEBUG_ENABLE TRUE
#define USBH_DEBUG_USBHD USBHD1
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/usbh_additional_class_drivers.h b/testhal/STM32/STM32F4xx/USB_HOST/usbh_additional_class_drivers.h
new file mode 100644
index 0000000..ac9fc18
--- /dev/null
+++ b/testhal/STM32/STM32F4xx/USB_HOST/usbh_additional_class_drivers.h
@@ -0,0 +1,38 @@
+/*
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
+ Copyright (C) 2015..2017 Diego Ismirlian, (dismirlian (at) google's mail)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#ifndef USBH_ADDITIONAL_H_
+#define USBH_ADDITIONAL_H_
+
+#include "hal_usbh.h"
+
+#if HAL_USE_USBH && HAL_USBH_USE_ADDITIONAL_CLASS_DRIVERS
+
+/* Declarations */
+extern const usbh_classdriverinfo_t usbhCustomClassDriverInfo;
+
+
+
+/* Comma separated list of additional class drivers */
+#define HAL_USBH_ADDITIONAL_CLASS_DRIVERS \
+ &usbhCustomClassDriverInfo,
+
+
+
+#endif
+
+#endif /* USBH_ADDITIONAL_H_ */
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.c b/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.c
new file mode 100644
index 0000000..23d5559
--- /dev/null
+++ b/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.c
@@ -0,0 +1,140 @@
+/*
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
+ Copyright (C) 2015..2017 Diego Ismirlian, (dismirlian (at) google's mail)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "hal.h"
+#include "usbh/internal.h"
+#include "usbh_custom_class_example.h"
+#include <string.h>
+
+#if USBH_DEBUG_ENABLE_TRACE
+#define udbgf(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
+#define udbg(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
+#else
+#define udbgf(f, ...) do {} while(0)
+#define udbg(f, ...) do {} while(0)
+#endif
+
+#if USBH_DEBUG_ENABLE_INFO
+#define uinfof(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
+#define uinfo(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
+#else
+#define uinfof(f, ...) do {} while(0)
+#define uinfo(f, ...) do {} while(0)
+#endif
+
+#if USBH_DEBUG_ENABLE_WARNINGS
+#define uwarnf(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
+#define uwarn(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
+#else
+#define uwarnf(f, ...) do {} while(0)
+#define uwarn(f, ...) do {} while(0)
+#endif
+
+#if USBH_DEBUG_ENABLE_ERRORS
+#define uerrf(f, ...) usbDbgPrintf(f, ##__VA_ARGS__)
+#define uerr(f, ...) usbDbgPuts(f, ##__VA_ARGS__)
+#else
+#define uerrf(f, ...) do {} while(0)
+#define uerr(f, ...) do {} while(0)
+#endif
+
+/*===========================================================================*/
+/* USB Class driver loader for Custom Class Example */
+/*===========================================================================*/
+
+USBHCustomDriver USBHCUSTOMD[USBH_CUSTOM_CLASS_MAX_INSTANCES];
+
+static void _init(void);
+static usbh_baseclassdriver_t *_load(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem);
+static void _unload(usbh_baseclassdriver_t *drv);
+
+static const usbh_classdriver_vmt_t class_driver_vmt = {
+ _init,
+ _load,
+ _unload
+};
+
+const usbh_classdriverinfo_t usbhCustomClassDriverInfo = {
+ 0x54, -1, -1, "CUSTOM", &class_driver_vmt
+};
+
+static usbh_baseclassdriver_t *_load(usbh_device_t *dev, const uint8_t *descriptor, uint16_t rem) {
+ int i;
+ USBHCustomDriver *custp;
+ (void)dev;
+
+ if ((rem < descriptor[0]) || (descriptor[1] != USBH_DT_INTERFACE))
+ return NULL;
+
+ const usbh_interface_descriptor_t * const ifdesc = (const usbh_interface_descriptor_t *)descriptor;
+
+ /* alloc driver */
+ for (i = 0; i < USBH_CUSTOM_CLASS_MAX_INSTANCES; i++) {
+ if (USBHCUSTOMD[i].dev == NULL) {
+ custp = &USBHCUSTOMD[i];
+ goto alloc_ok;
+ }
+ }
+
+ uwarn("Can't alloc CUSTOM driver");
+
+ /* can't alloc */
+ return NULL;
+
+alloc_ok:
+ /* initialize the driver's variables */
+ custp->ifnum = ifdesc->bInterfaceNumber;
+
+ /* parse the configuration descriptor */
+ if_iterator_t iif;
+ generic_iterator_t iep;
+ iif.iad = 0;
+ iif.curr = descriptor;
+ iif.rem = rem;
+ for (ep_iter_init(&iep, &iif); iep.valid; ep_iter_next(&iep)) {
+ const usbh_endpoint_descriptor_t *const epdesc = ep_get(&iep);
+ if ((epdesc->bEndpointAddress & 0x80) && (epdesc->bmAttributes == USBH_EPTYPE_INT)) {
+ /* ... */
+ } else {
+ uinfof("unsupported endpoint found: bEndpointAddress=%02x, bmAttributes=%02x",
+ epdesc->bEndpointAddress, epdesc->bmAttributes);
+ }
+ }
+
+ custp->state = USBHCUSTOM_STATE_ACTIVE;
+
+ return (usbh_baseclassdriver_t *)custp;
+
+}
+
+static void _unload(usbh_baseclassdriver_t *drv) {
+ (void)drv;
+}
+
+static void _object_init(USBHCustomDriver *custp) {
+ osalDbgCheck(custp != NULL);
+ memset(custp, 0, sizeof(*custp));
+ custp->state = USBHCUSTOM_STATE_STOP;
+}
+
+static void _init(void) {
+ uint8_t i;
+ for (i = 0; i < USBH_CUSTOM_CLASS_MAX_INSTANCES; i++) {
+ _object_init(&USBHCUSTOMD[i]);
+ }
+}
+
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.h b/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.h
new file mode 100644
index 0000000..b84f2b7
--- /dev/null
+++ b/testhal/STM32/STM32F4xx/USB_HOST/usbh_custom_class_example.h
@@ -0,0 +1,83 @@
+/*
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
+ Copyright (C) 2015..2017 Diego Ismirlian, (dismirlian (at) google's mail)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#ifndef USBH_CUSTOM_H_
+#define USBH_CUSTOM_H_
+
+#include "hal_usbh.h"
+
+#if HAL_USE_USBH
+
+
+/*===========================================================================*/
+/* Driver pre-compile time settings. */
+/*===========================================================================*/
+#define USBH_CUSTOM_CLASS_MAX_INSTANCES 1
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+
+/*===========================================================================*/
+/* Driver data structures and types. */
+/*===========================================================================*/
+
+typedef enum {
+ USBHCUSTOM_STATE_UNINIT = 0,
+ USBHCUSTOM_STATE_STOP = 1,
+ USBHCUSTOM_STATE_ACTIVE = 2,
+ USBHCUSTOM_STATE_READY = 3
+} usbhcustom_state_t;
+
+typedef struct USBHCustomDriver USBHCustomDriver;
+
+struct USBHCustomDriver {
+ /* inherited from abstract class driver */
+ _usbh_base_classdriver_data
+
+ uint8_t ifnum;
+
+ usbhcustom_state_t state;
+};
+
+
+/*===========================================================================*/
+/* Driver macros. */
+/*===========================================================================*/
+
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+extern USBHCustomDriver USBHCUSTOMD[USBH_CUSTOM_CLASS_MAX_INSTANCES];
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ /* API goes here */
+
+ /* global initializer */
+ void usbhCustomInit(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif /* USBH_CUSTOM_H_ */