diff --git a/2.Firmware/HelloWord-Dynamic-fw/.idea/workspace.xml b/2.Firmware/HelloWord-Dynamic-fw/.idea/workspace.xml index 79f158a..0b8f315 100644 --- a/2.Firmware/HelloWord-Dynamic-fw/.idea/workspace.xml +++ b/2.Firmware/HelloWord-Dynamic-fw/.idea/workspace.xml @@ -1,5 +1,8 @@ + @@ -18,10 +21,6 @@ - - - - @@ -87,9 +89,19 @@ - + + + - @@ -132,16 +144,6 @@ - - diff --git a/2.Firmware/HelloWord-Keyboard-fw/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h b/2.Firmware/HelloWord-Keyboard-fw/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h index cfe18be..29ee2f4 100644 --- a/2.Firmware/HelloWord-Keyboard-fw/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h +++ b/2.Firmware/HelloWord-Keyboard-fw/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Inc/usbd_customhid.h @@ -44,7 +44,7 @@ extern "C" { #define CUSTOM_HID_EPIN_ADDR 0x81U #define CUSTOM_HID_EPIN_SIZE 64U -#define CUSTOM_HID_EPOUT_ADDR 0x01U +#define CUSTOM_HID_EPOUT_ADDR 0x02U #define CUSTOM_HID_EPOUT_SIZE 64U #define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U diff --git a/2.Firmware/HelloWord-Keyboard-fw/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c b/2.Firmware/HelloWord-Keyboard-fw/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c index eb8f0ff..1bb3aa4 100644 --- a/2.Firmware/HelloWord-Keyboard-fw/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c +++ b/2.Firmware/HelloWord-Keyboard-fw/Middlewares/ST/STM32_USB_Device_Library/Class/CustomHID/Src/usbd_customhid.c @@ -632,7 +632,7 @@ static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, * @param epnum: endpoint index * @retval status */ -void HID_RxCpltCallback(uint8_t* _data); + static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) @@ -640,9 +640,9 @@ static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassData; -// ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0], -// hhid->Report_buf[1]); - HID_RxCpltCallback( hhid->Report_buf); + ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData)->OutEvent(hhid->Report_buf[0], + hhid->Report_buf[1]); + USBD_LL_PrepareReceive(pdev, CUSTOM_HID_EPOUT_ADDR, hhid->Report_buf, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE); diff --git a/2.Firmware/HelloWord-Keyboard-fw/USB_DEVICE/App/usbd_custom_hid_if.c b/2.Firmware/HelloWord-Keyboard-fw/USB_DEVICE/App/usbd_custom_hid_if.c index a71fc51..8f2fea6 100644 --- a/2.Firmware/HelloWord-Keyboard-fw/USB_DEVICE/App/usbd_custom_hid_if.c +++ b/2.Firmware/HelloWord-Keyboard-fw/USB_DEVICE/App/usbd_custom_hid_if.c @@ -32,7 +32,7 @@ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ - +void HID_RxCpltCallback(uint8_t* _data); /* USER CODE END PV */ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY diff --git a/2.Firmware/HelloWord-Keyboard-fw/UserApp/main.cpp b/2.Firmware/HelloWord-Keyboard-fw/UserApp/main.cpp index 0d71652..d410fc2 100644 --- a/2.Firmware/HelloWord-Keyboard-fw/UserApp/main.cpp +++ b/2.Firmware/HelloWord-Keyboard-fw/UserApp/main.cpp @@ -7,7 +7,8 @@ KeyboardConfig_t config; HWKeyboard keyboard(&hspi1); - +static bool isSoftWareControlColor = false; +static bool isReceiveSuccess = false; /* Main Entry ----------------------------------------------------------------*/ void Main() { @@ -39,12 +40,19 @@ void Main() if (t > 250) fadeDir = false; else if (t < 1) fadeDir = true; - for (uint8_t i = 0; i < HWKeyboard::LED_NUMBER; i++) - keyboard.SetRgbBufferByID(i, HWKeyboard::Color_t{(uint8_t) t, 50, 0}); - /*-----------------------------------*/ - - // Send RGB buffers to LEDs - keyboard.SyncLights(); + if(isReceiveSuccess){ + keyboard.SyncLights(); + isReceiveSuccess = false; + } + if(!isSoftWareControlColor) + { + + /*---- This is a demo RGB effect ----*/ + for (uint8_t i = 0; i < HWKeyboard::LED_NUMBER; i++) + keyboard.SetRgbBufferByID(i, HWKeyboard::Color_t{(uint8_t)t, 50, 20}); + /*-----------------------------------*/ + keyboard.SyncLights(); + } } } @@ -80,5 +88,17 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef* hspi) extern "C" void HID_RxCpltCallback(uint8_t* _data) { - + if(_data[1] == 0xbd) isSoftWareControlColor= false; + if(_data[1] == 0xac) { + isSoftWareControlColor = true; + uint8_t pageIndex = _data[2]; + for (uint8_t i = 0; i < 10; i++) { + if(i+pageIndex*10>=HWKeyboard::LED_NUMBER) { + isReceiveSuccess = true; + break; + } + keyboard.SetRgbBufferByID(i+pageIndex*10, + HWKeyboard::Color_t{_data[3+i*3], _data[4+i*3], _data[5+i*3]}); + } + } } \ No newline at end of file