diff --git a/port/stm32-f4discovery-usb/Makefile b/port/stm32-f4discovery-usb/Makefile index e480cd69b..249ffb918 100644 --- a/port/stm32-f4discovery-usb/Makefile +++ b/port/stm32-f4discovery-usb/Makefile @@ -38,6 +38,7 @@ BTSTACK_ROOT ?= ../.. ###################################### # C sources C_SOURCES = \ +port/usbh_bluetooth.c \ Core/Src/main.c \ Core/Src/stm32f4xx_it.c \ Core/Src/stm32f4xx_hal_msp.c \ diff --git a/port/stm32-f4discovery-usb/USB_HOST/App/usb_host.c b/port/stm32-f4discovery-usb/USB_HOST/App/usb_host.c index 5e80c12a8..6ee4d9180 100644 --- a/port/stm32-f4discovery-usb/USB_HOST/App/usb_host.c +++ b/port/stm32-f4discovery-usb/USB_HOST/App/usb_host.c @@ -23,9 +23,9 @@ #include "usb_host.h" #include "usbh_core.h" -#include "usbh_hid.h" /* USER CODE BEGIN Includes */ +#include "usbh_bluetooth.h" /* USER CODE END Includes */ @@ -77,7 +77,7 @@ void MX_USB_HOST_Init(void) { Error_Handler(); } - if (USBH_RegisterClass(&hUsbHostFS, USBH_HID_CLASS) != USBH_OK) + if (USBH_RegisterClass(&hUsbHostFS, USBH_BLUETOOTH_CLASS) != USBH_OK) { Error_Handler(); } diff --git a/port/stm32-f4discovery-usb/port/usbh_bluetooth.c b/port/stm32-f4discovery-usb/port/usbh_bluetooth.c new file mode 100644 index 000000000..4f39bfdd0 --- /dev/null +++ b/port/stm32-f4discovery-usb/port/usbh_bluetooth.c @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2020 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +#define BTSTACK_FILE__ "usbh_bluetooth.c" + +#include "usbh_bluetooth.h" + +#define log_info puts + +USBH_StatusTypeDef USBH_Bluetooth_InterfaceInit(USBH_HandleTypeDef *phost){ + log_info("USBH_Bluetooth_InterfaceInit"); + // dump everything + uint8_t num_interfaces = phost->device.CfgDesc.bNumInterfaces; + uint8_t interface_index; + for (interface_index=0;interface_indexdevice.CfgDesc.Itf_Desc[interface_index]; + uint8_t num_endpoints = interface->bNumEndpoints; + uint8_t ep_index; + for (ep_index=0;ep_indexEp_Desc[ep_index]; + printf("Interface %u, endpoint #%u: address 0x%02x, attributes 0x%02x\n", interface_index, ep_index, ep_desc->bEndpointAddress, ep_desc->bmAttributes); + // type interrupt, direction incoming + if (((ep_desc->bEndpointAddress & USB_EP_DIR_MSK) == USB_EP_DIR_MSK) && (ep_desc->bmAttributes == USB_EP_TYPE_INTR)){ + puts("-> HCI Event"); + } + // type bulk, direction incoming + if (((ep_desc->bEndpointAddress & USB_EP_DIR_MSK) == USB_EP_DIR_MSK) && (ep_desc->bmAttributes == USB_EP_TYPE_BULK)){ + puts("-> HCI ACL IN"); + } + // type bulk, direction incoming + if (((ep_desc->bEndpointAddress & USB_EP_DIR_MSK) == 0) && (ep_desc->bmAttributes == USB_EP_TYPE_BULK)){ + puts("-> HCI ACL OUT"); + } + } + } + return USBH_OK; +} +USBH_StatusTypeDef USBH_Bluetooth_InterfaceDeInit(USBH_HandleTypeDef *phost){ + log_info("USBH_Bluetooth_InterfaceDeInit"); + return USBH_OK; +} +USBH_StatusTypeDef USBH_Bluetooth_ClassRequest(USBH_HandleTypeDef *phost){ + log_info("USBH_Bluetooth_ClassRequest"); + return USBH_OK; +} +USBH_StatusTypeDef USBH_Bluetooth_Process(USBH_HandleTypeDef *phost){ + // log_info("USBH_Bluetooth_Process"); + return USBH_OK; +} +USBH_StatusTypeDef USBH_Bluetooth_SOFProcess(USBH_HandleTypeDef *phost){ + // log_info("USBH_Bluetooth_SOFProcess"); + return USBH_OK; +} + +USBH_ClassTypeDef Bluetooth_Class = { + "Bluetooth", + USB_BLUETOOTH_CLASS, + USBH_Bluetooth_InterfaceInit, + USBH_Bluetooth_InterfaceDeInit, + USBH_Bluetooth_ClassRequest, + USBH_Bluetooth_Process, + USBH_Bluetooth_SOFProcess, + NULL, +}; + diff --git a/port/stm32-f4discovery-usb/port/usbh_bluetooth.h b/port/stm32-f4discovery-usb/port/usbh_bluetooth.h new file mode 100644 index 000000000..575c645d5 --- /dev/null +++ b/port/stm32-f4discovery-usb/port/usbh_bluetooth.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2020 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +// ***************************************************************************** +// +// USB Bluetooth Host Class for STM32Cube USB Host Library +// +// ***************************************************************************** + +#ifndef USBH_BLUETOOTH_H +#define USBH_BLUETOOTH_H + +#include "btstack_config.h" +// #include "btstack_bool.h" + +#include + +#include "usbh_core.h" + +#if defined __cplusplus +extern "C" { +#endif + +/* Bluetooth Class Codes */ +#define USB_BLUETOOTH_CLASS 0xE0U + +extern USBH_ClassTypeDef Bluetooth_Class; +#define USBH_BLUETOOTH_CLASS &Bluetooth_Class + +#endif \ No newline at end of file