diff --git a/Downstream/.settings/language.settings.xml b/Downstream/.settings/language.settings.xml index eddaa5a..72387b0 100644 --- a/Downstream/.settings/language.settings.xml +++ b/Downstream/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/Downstream/Inc/options.h b/Downstream/Inc/options.h new file mode 100644 index 0000000..325fb7e --- /dev/null +++ b/Downstream/Inc/options.h @@ -0,0 +1,24 @@ +/* + * options.h + * + * Created on: Jun 20, 2017 + * Author: Robert Fisk + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#ifndef INC_OPTIONS_H_ +#define INC_OPTIONS_H_ + + +#define ENABLE_MASS_STORAGE +#define ENABLE_KEYBOARD +#define ENABLE_MOUSE + +#define MASS_STORAGE_WRITES_PERMITTED + + + +#endif /* INC_OPTIONS_H_ */ diff --git a/Downstream/Inc/usb_host.h b/Downstream/Inc/usb_host.h index d324d0c..e198fc4 100644 --- a/Downstream/Inc/usb_host.h +++ b/Downstream/Inc/usb_host.h @@ -43,13 +43,6 @@ /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx.h" #include "stm32f4xx_hal.h" - -typedef enum { - APPLICATION_IDLE = 0, - APPLICATION_START, - APPLICATION_READY, - APPLICATION_DISCONNECT, -}ApplicationTypeDef; void USB_Host_Init(void); diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c index cbf4aa0..54e7bc0 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c @@ -43,8 +43,11 @@ /* Includes ------------------------------------------------------------------*/ #include "usbh_hid.h" +#include "options.h" +#if defined (ENABLE_KEYBOARD) || defined (ENABLE_MOUSE) + /** @addtogroup USBH_LIB * @{ */ @@ -158,15 +161,20 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost) HID_Handle->state = HID_ERROR; /*Decode Bootclass Protocol: Mouse or Keyboard*/ +#ifdef ENABLE_KEYBOARD if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE) { USBH_UsrLog ("KeyBoard device found!"); } - else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE) + else +#endif +#ifdef ENABLE_MOUSE + if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE) { USBH_UsrLog ("Mouse device found!"); } else +#endif { USBH_UsrLog ("Protocol not supported."); return USBH_FAIL; @@ -835,6 +843,9 @@ __weak void USBH_HID_EventCallback(USBH_HandleTypeDef *phost) { } + +#endif //#if defined (ENABLE_KEYBOARD) || defined (ENABLE_MOUSE) + /** * @} */ diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c index e5aff35..cf1c477 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c @@ -46,8 +46,10 @@ #include "usbh_msc_bot.h" #include "usbh_msc_scsi.h" #include "interrupts.h" +#include "options.h" +#ifdef ENABLE_MASS_STORAGE /** @addtogroup USBH_LIB * @{ */ @@ -785,6 +787,8 @@ USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost, return USBH_OK; } +#endif //#ifdef ENABLE_MASS_STORAGE + /** * @} */ diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c index 6a86325..0fab690 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_bot.c @@ -34,8 +34,10 @@ #include "downstream_spi.h" #include "downstream_msc.h" #include "downstream_statemachine.h" +#include "options.h" +#ifdef ENABLE_MASS_STORAGE static USBH_StatusTypeDef USBH_MSC_BOT_Abort(USBH_HandleTypeDef *phost, uint8_t lun, uint8_t dir); static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost); @@ -700,6 +702,7 @@ static BOT_CSWStatusTypeDef USBH_MSC_DecodeCSW(USBH_HandleTypeDef *phost) return status; } +#endif //#ifdef ENABLE_MASS_STORAGE /** * @} diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c index 6b9a6e4..79b3ee1 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc_scsi.c @@ -32,8 +32,11 @@ #include "usbh_msc.h" #include "usbh_msc_scsi.h" #include "usbh_msc_bot.h" +#include "options.h" +#ifdef ENABLE_MASS_STORAGE + /** @addtogroup USBH_LIB * @{ */ @@ -426,6 +429,7 @@ USBH_StatusTypeDef USBH_MSC_SCSI_Read(USBH_HandleTypeDef *phost, return error; } +#endif //#ifdef ENABLE_MASS_STORAGE /** * @} diff --git a/Downstream/Src/downstream_hid.c b/Downstream/Src/downstream_hid.c index effcf72..93bbe22 100644 --- a/Downstream/Src/downstream_hid.c +++ b/Downstream/Src/downstream_hid.c @@ -15,8 +15,11 @@ #include "downstream_statemachine.h" #include "usbh_hid.h" #include "stm32f4xx_hal.h" +#include "options.h" +#if defined (ENABLE_KEYBOARD) || defined (ENABLE_MOUSE) + extern USBH_HandleTypeDef hUsbHostFS; //Hard-link ourselves to usb_host.c extern InterfaceCommandClassTypeDef ConfiguredDeviceClass; //Do a cheap hard-link to downstream_statemachine.c, rather than keep a duplicate here @@ -51,6 +54,7 @@ InterfaceCommandClassTypeDef Downstream_HID_ApproveConnectedDevice(void) { HID_HandleTypeDef* HID_Handle = (HID_HandleTypeDef*)hUsbHostFS.pActiveClass->pData; +#ifdef ENABLE_MOUSE if (HID_Handle->Protocol == HID_MOUSE_BOOT_CODE) { if (Downstream_HID_Mouse_ParseReportDescriptor() == HAL_OK) @@ -58,18 +62,20 @@ InterfaceCommandClassTypeDef Downstream_HID_ApproveConnectedDevice(void) return COMMAND_CLASS_HID_MOUSE; //success! } } - +#endif +#ifdef ENABLE_KEYBOARD if (HID_Handle->Protocol == HID_KEYBRD_BOOT_CODE) { return COMMAND_CLASS_HID_KEYBOARD; //success! } +#endif //else: return COMMAND_CLASS_INTERFACE; //fail } - +#ifdef ENABLE_MOUSE static HAL_StatusTypeDef Downstream_HID_Mouse_ParseReportDescriptor(void) { uint32_t currentReportBitIndex = 0; @@ -223,7 +229,7 @@ static HAL_StatusTypeDef Downstream_HID_Mouse_ParseReportDescriptor(void) return HAL_OK; } - +#endif //Retrieves the next item in the HID report, and at most one of its associated data bytes. @@ -313,19 +319,24 @@ void Downstream_HID_InterruptReportCallback(USBH_StatusTypeDef result) if (result == USBH_OK) { //Data received from device +#ifdef ENABLE_MOUSE if (ConfiguredDeviceClass == COMMAND_CLASS_HID_MOUSE) { Downstream_HID_Mouse_ExtractDataFromReport(freePacket); freePacket->Length16 = ((HID_MOUSE_INPUT_DATA_LEN + 1) / 2) + DOWNSTREAM_PACKET_HEADER_LEN_16; } - else if (ConfiguredDeviceClass == COMMAND_CLASS_HID_KEYBOARD) + else +#endif +#ifdef ENABLE_KEYBOARD + if (ConfiguredDeviceClass == COMMAND_CLASS_HID_KEYBOARD) { Downstream_HID_Keyboard_ExtractDataFromReport(freePacket); freePacket->Length16 = ((HID_KEYBOARD_INPUT_DATA_LEN + 1) / 2) + DOWNSTREAM_PACKET_HEADER_LEN_16; } - //else if... - else +#endif + + //else if... { Downstream_PacketProcessor_FreakOut(); return; @@ -343,6 +354,7 @@ void Downstream_HID_InterruptReportCallback(USBH_StatusTypeDef result) } +#ifdef ENABLE_MOUSE static void Downstream_HID_Mouse_ExtractDataFromReport(DownstreamPacketTypeDef* packetToSend) { HID_HandleTypeDef* HID_Handle = (HID_HandleTypeDef*)hUsbHostFS.pActiveClass->pData; @@ -388,9 +400,10 @@ static uint8_t Downstream_HID_Mouse_Extract8BitValue(HID_HandleTypeDef* hidHandl if (readData > INT8_MAX) readData = INT8_MAX; return (int8_t)readData; } +#endif - +#ifdef ENABLE_KEYBOARD static void Downstream_HID_Keyboard_ExtractDataFromReport(DownstreamPacketTypeDef* packetToSend) { HID_HandleTypeDef* HID_Handle = (HID_HandleTypeDef*)hUsbHostFS.pActiveClass->pData; @@ -410,11 +423,14 @@ static void Downstream_HID_Keyboard_ExtractDataFromReport(DownstreamPacketTypeDe packetToSend->Data[i] = readData; } } +#endif void Downstream_HID_SendReportCallback(USBH_StatusTypeDef result) { + UNUSED(result); + DownstreamPacketTypeDef* freePacket; freePacket = Downstream_GetFreePacketImmediately(); @@ -424,3 +440,6 @@ void Downstream_HID_SendReportCallback(USBH_StatusTypeDef result) Downstream_PacketProcessor_ClassReply(freePacket); } + +#endif //#if defined (ENABLE_KEYBOARD) || defined (ENABLE_MOUSE) + diff --git a/Downstream/Src/downstream_msc.c b/Downstream/Src/downstream_msc.c index 8e81eb3..4a14a81 100644 --- a/Downstream/Src/downstream_msc.c +++ b/Downstream/Src/downstream_msc.c @@ -15,8 +15,11 @@ #include "downstream_statemachine.h" #include "downstream_spi.h" #include "usbh_msc.h" +#include "options.h" +#ifdef ENABLE_MASS_STORAGE + extern USBH_HandleTypeDef hUsbHostFS; //Hard-link ourselves to usb_host.c @@ -284,4 +287,5 @@ void Downstream_MSC_GetStreamDataPacketCallback(DownstreamPacketTypeDef* receive } +#endif //#ifdef ENABLE_MASS_STORAGE diff --git a/Downstream/Src/downstream_statemachine.c b/Downstream/Src/downstream_statemachine.c index 6ede375..acadc19 100644 --- a/Downstream/Src/downstream_statemachine.c +++ b/Downstream/Src/downstream_statemachine.c @@ -19,7 +19,7 @@ #include "usbh_msc.h" #include "usbh_hid.h" #include "led.h" - +#include "options.h" DownstreamStateTypeDef DownstreamState = STATE_DEVICE_NOT_READY; @@ -88,15 +88,22 @@ void Downstream_PacketProcessor(DownstreamPacketTypeDef* receivedPacket) switch (ConfiguredDeviceClass) { + +#ifdef ENABLE_MASS_STORAGE case COMMAND_CLASS_MASS_STORAGE: Downstream_MSC_PacketProcessor(receivedPacket); break; - +#endif +#ifdef ENABLE_MOUSE case COMMAND_CLASS_HID_MOUSE: + Downstream_HID_PacketProcessor(receivedPacket); + break; +#endif +#ifdef ENABLE_KEYBOARD case COMMAND_CLASS_HID_KEYBOARD: Downstream_HID_PacketProcessor(receivedPacket); break; - +#endif //Add other classes here... @@ -235,13 +242,16 @@ void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id) { switch (phost->pActiveClass->ClassCode) { +#ifdef ENABLE_MASS_STORAGE case USB_MSC_CLASS: newActiveClass = Downstream_MSC_ApproveConnectedDevice(); break; - +#endif +#if defined (ENABLE_KEYBOARD) || defined (ENABLE_MOUSE) case USB_HID_CLASS: newActiveClass = Downstream_HID_ApproveConnectedDevice(); break; +#endif //Add other classes here... diff --git a/Downstream/Src/usb_host.c b/Downstream/Src/usb_host.c index 5db673e..b8d5c05 100644 --- a/Downstream/Src/usb_host.c +++ b/Downstream/Src/usb_host.c @@ -40,6 +40,7 @@ #include "usbh_msc.h" #include "usbh_hid.h" #include "downstream_statemachine.h" +#include "options.h" /* USB Host Core handle declaration */ USBH_HandleTypeDef hUsbHostFS; @@ -51,8 +52,12 @@ void USB_Host_Init(void) /* Init Host Library,Add Supported Class and Start the library*/ USBH_Init(&hUsbHostFS, Downstream_HostUserCallback, HOST_FS); +#ifdef ENABLE_MASS_STORAGE USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS); +#endif +#if defined (ENABLE_KEYBOARD) || defined (ENABLE_MOUSE) USBH_RegisterClass(&hUsbHostFS, USBH_HID_CLASS); +#endif USBH_Start(&hUsbHostFS); } diff --git a/Upstream/.settings/language.settings.xml b/Upstream/.settings/language.settings.xml index fdfa0c9..b2c7cac 100755 --- a/Upstream/.settings/language.settings.xml +++ b/Upstream/.settings/language.settings.xml @@ -16,7 +16,7 @@ - +