parent
8dcdaf9236
commit
a60b736834
@ -1,328 +0,0 @@ |
||||
--- Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c (date 1511202099000) |
||||
+++ Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c (revision ) |
||||
@@ -59,6 +59,7 @@ |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
+#include "usbd_msc.h" // for rejecting bad control messages |
||||
#include "usbd_cdc.h" |
||||
#include "usbd_desc.h" |
||||
#include "usbd_ctlreq.h" |
||||
@@ -103,34 +104,7 @@ |
||||
* @{ |
||||
*/ |
||||
|
||||
- |
||||
-static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, |
||||
- uint8_t cfgidx); |
||||
- |
||||
-static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, |
||||
- uint8_t cfgidx); |
||||
- |
||||
-static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, |
||||
- USBD_SetupReqTypedef *req); |
||||
- |
||||
-static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, |
||||
- uint8_t epnum); |
||||
- |
||||
-static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, |
||||
- uint8_t epnum); |
||||
- |
||||
-static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev); |
||||
- |
||||
-static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length); |
||||
- |
||||
-static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length); |
||||
- |
||||
-static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); |
||||
- |
||||
-static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); |
||||
- |
||||
-uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length); |
||||
- |
||||
+#ifndef CDC_COMPOSITE |
||||
/* USB Standard Device Descriptor */ |
||||
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = |
||||
{ |
||||
@@ -156,7 +130,7 @@ |
||||
|
||||
|
||||
/* CDC interface class callbacks structure */ |
||||
-USBD_ClassTypeDef USBD_CDC = |
||||
+USBD_ClassTypeDef USBD_CDC = |
||||
{ |
||||
USBD_CDC_Init, |
||||
USBD_CDC_DeInit, |
||||
@@ -172,6 +146,7 @@ |
||||
USBD_CDC_GetFSCfgDesc, |
||||
USBD_CDC_GetOtherSpeedCfgDesc, |
||||
USBD_CDC_GetDeviceQualifierDescriptor, |
||||
+ NULL |
||||
}; |
||||
|
||||
/* USB CDC device Configuration Descriptor */ |
||||
@@ -456,6 +431,7 @@ |
||||
0x00, |
||||
0x00 /* bInterval */ |
||||
}; |
||||
+#endif |
||||
|
||||
/** |
||||
* @} |
||||
@@ -463,7 +439,7 @@ |
||||
|
||||
/** @defgroup USBD_CDC_Private_Functions |
||||
* @{ |
||||
- */ |
||||
+ */ |
||||
|
||||
/** |
||||
* @brief USBD_CDC_Init |
||||
@@ -472,7 +448,7 @@ |
||||
* @param cfgidx: Configuration index |
||||
* @retval status |
||||
*/ |
||||
-static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, |
||||
+uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, |
||||
uint8_t cfgidx) |
||||
{ |
||||
uint8_t ret = 0; |
||||
@@ -514,18 +490,18 @@ |
||||
CDC_CMD_PACKET_SIZE); |
||||
|
||||
|
||||
- pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef)); |
||||
+ pdev->pClassData2 = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef)); |
||||
|
||||
- if(pdev->pClassData == NULL) |
||||
+ if(pdev->pClassData2 == NULL) |
||||
{ |
||||
ret = 1; |
||||
} |
||||
else |
||||
{ |
||||
- hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
||||
+ hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData2; |
||||
|
||||
/* Init physical Interface components */ |
||||
- ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init(); |
||||
+ ((USBD_CDC_ItfTypeDef *)pdev->pUserData2)->Init(); |
||||
|
||||
/* Init Xfer states */ |
||||
hcdc->TxState =0; |
||||
@@ -560,7 +536,7 @@ |
||||
* @param cfgidx: Configuration index |
||||
* @retval status |
||||
*/ |
||||
-static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, |
||||
+uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, |
||||
uint8_t cfgidx) |
||||
{ |
||||
uint8_t ret = 0; |
||||
@@ -579,11 +555,11 @@ |
||||
|
||||
|
||||
/* DeInit physical Interface components */ |
||||
- if(pdev->pClassData != NULL) |
||||
+ if(pdev->pClassData2 != NULL) |
||||
{ |
||||
- ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit(); |
||||
- USBD_free(pdev->pClassData); |
||||
- pdev->pClassData = NULL; |
||||
+ ((USBD_CDC_ItfTypeDef *)pdev->pUserData2)->DeInit(); |
||||
+ USBD_free(pdev->pClassData2); |
||||
+ pdev->pClassData2 = NULL; |
||||
} |
||||
|
||||
return ret; |
||||
@@ -596,20 +572,23 @@ |
||||
* @param req: usb requests |
||||
* @retval status |
||||
*/ |
||||
-static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, |
||||
+uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, |
||||
USBD_SetupReqTypedef *req) |
||||
{ |
||||
- USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
||||
+ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData2; |
||||
static uint8_t ifalt = 0; |
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK) |
||||
{ |
||||
case USB_REQ_TYPE_CLASS : |
||||
+ if (req->bRequest == BOT_GET_MAX_LUN) break; // Not ours! |
||||
+ if (req->bRequest == BOT_RESET) break; // Not ours! |
||||
+ |
||||
if (req->wLength) |
||||
{ |
||||
if (req->bmRequest & 0x80) |
||||
{ |
||||
- ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, |
||||
+ ((USBD_CDC_ItfTypeDef *)pdev->pUserData2)->Control(req->bRequest, |
||||
(uint8_t *)hcdc->data, |
||||
req->wLength); |
||||
USBD_CtlSendData (pdev, |
||||
@@ -629,7 +608,7 @@ |
||||
} |
||||
else |
||||
{ |
||||
- ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, |
||||
+ ((USBD_CDC_ItfTypeDef *)pdev->pUserData2)->Control(req->bRequest, |
||||
(uint8_t*)req, |
||||
0); |
||||
} |
||||
@@ -661,14 +640,15 @@ |
||||
* @param epnum: endpoint number |
||||
* @retval status |
||||
*/ |
||||
-static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) |
||||
+uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) |
||||
{ |
||||
- USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
||||
+ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData2; |
||||
|
||||
- if(pdev->pClassData != NULL) |
||||
+ if(pdev->pClassData2 != NULL) |
||||
{ |
||||
|
||||
hcdc->TxState = 0; |
||||
+ USBD_CDC_TransmitDone(pdev); |
||||
|
||||
return USBD_OK; |
||||
} |
||||
@@ -685,18 +665,18 @@ |
||||
* @param epnum: endpoint number |
||||
* @retval status |
||||
*/ |
||||
-static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) |
||||
+uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) |
||||
{ |
||||
- USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
||||
+ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData2; |
||||
|
||||
/* Get the received data length */ |
||||
hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum); |
||||
|
||||
/* USB data will be immediately processed, this allow next USB traffic being |
||||
NAKed till the end of the application Xfer */ |
||||
- if(pdev->pClassData != NULL) |
||||
+ if(pdev->pClassData2 != NULL) |
||||
{ |
||||
- ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength); |
||||
+ ((USBD_CDC_ItfTypeDef *)pdev->pUserData2)->Receive(hcdc->RxBuffer, &hcdc->RxLength); |
||||
|
||||
return USBD_OK; |
||||
} |
||||
@@ -715,13 +695,13 @@ |
||||
* @param epnum: endpoint number |
||||
* @retval status |
||||
*/ |
||||
-static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev) |
||||
+uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev) |
||||
{ |
||||
- USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
||||
+ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData2; |
||||
|
||||
- if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFF)) |
||||
+ if((pdev->pUserData2 != NULL) && (hcdc->CmdOpCode != 0xFF)) |
||||
{ |
||||
- ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode, |
||||
+ ((USBD_CDC_ItfTypeDef *)pdev->pUserData2)->Control(hcdc->CmdOpCode, |
||||
(uint8_t *)hcdc->data, |
||||
hcdc->CmdLength); |
||||
hcdc->CmdOpCode = 0xFF; |
||||
@@ -730,6 +710,7 @@ |
||||
return USBD_OK; |
||||
} |
||||
|
||||
+#ifndef CDC_COMPOSITE |
||||
/** |
||||
* @brief USBD_CDC_GetFSCfgDesc |
||||
* Return configuration descriptor |
||||
@@ -737,7 +718,7 @@ |
||||
* @param length : pointer data length |
||||
* @retval pointer to descriptor buffer |
||||
*/ |
||||
-static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length) |
||||
+uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length) |
||||
{ |
||||
*length = sizeof (USBD_CDC_CfgFSDesc); |
||||
return USBD_CDC_CfgFSDesc; |
||||
@@ -750,7 +731,7 @@ |
||||
* @param length : pointer data length |
||||
* @retval pointer to descriptor buffer |
||||
*/ |
||||
-static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length) |
||||
+uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length) |
||||
{ |
||||
*length = sizeof (USBD_CDC_CfgHSDesc); |
||||
return USBD_CDC_CfgHSDesc; |
||||
@@ -763,7 +744,7 @@ |
||||
* @param length : pointer data length |
||||
* @retval pointer to descriptor buffer |
||||
*/ |
||||
-static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length) |
||||
+uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length) |
||||
{ |
||||
*length = sizeof (USBD_CDC_OtherSpeedCfgDesc); |
||||
return USBD_CDC_OtherSpeedCfgDesc; |
||||
@@ -780,6 +761,7 @@ |
||||
*length = sizeof (USBD_CDC_DeviceQualifierDesc); |
||||
return USBD_CDC_DeviceQualifierDesc; |
||||
} |
||||
+#endif |
||||
|
||||
/** |
||||
* @brief USBD_CDC_RegisterInterface |
||||
@@ -794,7 +776,7 @@ |
||||
|
||||
if(fops != NULL) |
||||
{ |
||||
- pdev->pUserData= fops; |
||||
+ pdev->pUserData2= fops; |
||||
ret = USBD_OK; |
||||
} |
||||
|
||||
@@ -811,7 +793,7 @@ |
||||
uint8_t *pbuff, |
||||
uint16_t length) |
||||
{ |
||||
- USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
||||
+ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData2; |
||||
|
||||
hcdc->TxBuffer = pbuff; |
||||
hcdc->TxLength = length; |
||||
@@ -829,7 +811,7 @@ |
||||
uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev, |
||||
uint8_t *pbuff) |
||||
{ |
||||
- USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
||||
+ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData2; |
||||
|
||||
hcdc->RxBuffer = pbuff; |
||||
|
||||
@@ -845,9 +827,9 @@ |
||||
*/ |
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) |
||||
{ |
||||
- USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
||||
+ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData2; |
||||
|
||||
- if(pdev->pClassData != NULL) |
||||
+ if(pdev->pClassData2 != NULL) |
||||
{ |
||||
if(hcdc->TxState == 0) |
||||
{ |
||||
@@ -882,10 +864,10 @@ |
||||
*/ |
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) |
||||
{ |
||||
- USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
||||
+ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData2; |
||||
|
||||
/* Suspend or Resume USB Out process */ |
||||
- if(pdev->pClassData != NULL) |
||||
+ if(pdev->pClassData2 != NULL) |
||||
{ |
||||
if(pdev->dev_speed == USBD_SPEED_HIGH ) |
||||
{ |
@ -1,60 +0,0 @@ |
||||
--- Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h (date 1511202099000) |
||||
+++ Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h (revision ) |
||||
@@ -58,9 +58,10 @@ |
||||
#define BOT_RESET 0xFF |
||||
#define USB_MSC_CONFIG_DESC_SIZ 32 |
||||
|
||||
- |
||||
+#ifndef MSC_CUSTOM_EPS |
||||
#define MSC_EPIN_ADDR 0x81 |
||||
-#define MSC_EPOUT_ADDR 0x01 |
||||
+#define MSC_EPOUT_ADDR 0x01 |
||||
+#endif |
||||
|
||||
/** |
||||
* @} |
||||
@@ -107,7 +108,7 @@ |
||||
USBD_MSC_BOT_HandleTypeDef; |
||||
|
||||
/* Structure for MSC process */ |
||||
-extern USBD_ClassTypeDef USBD_MSC; |
||||
+extern USBD_ClassTypeDef USBD_MSC; |
||||
#define USBD_MSC_CLASS &USBD_MSC |
||||
|
||||
uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev, |
||||
@@ -118,8 +119,34 @@ |
||||
|
||||
/** |
||||
* @} |
||||
- */ |
||||
+ */ |
||||
|
||||
+// XXX "static" moved here for use in composite driver |
||||
+ |
||||
+uint8_t USBD_MSC_Init (USBD_HandleTypeDef *pdev, |
||||
+ uint8_t cfgidx); |
||||
+ |
||||
+uint8_t USBD_MSC_DeInit (USBD_HandleTypeDef *pdev, |
||||
+ uint8_t cfgidx); |
||||
+ |
||||
+uint8_t USBD_MSC_Setup (USBD_HandleTypeDef *pdev, |
||||
+ USBD_SetupReqTypedef *req); |
||||
+ |
||||
+uint8_t USBD_MSC_DataIn (USBD_HandleTypeDef *pdev, |
||||
+ uint8_t epnum); |
||||
+ |
||||
+ |
||||
+uint8_t USBD_MSC_DataOut (USBD_HandleTypeDef *pdev, |
||||
+ uint8_t epnum); |
||||
+ |
||||
+uint8_t *USBD_MSC_GetHSCfgDesc (uint16_t *length); |
||||
+ |
||||
+uint8_t *USBD_MSC_GetFSCfgDesc (uint16_t *length); |
||||
+ |
||||
+uint8_t *USBD_MSC_GetOtherSpeedCfgDesc (uint16_t *length); |
||||
+ |
||||
+uint8_t *USBD_MSC_GetDeviceQualifierDescriptor (uint16_t *length); |
||||
+ |
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
@ -1,35 +0,0 @@ |
||||
--- Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c (date 1511202099000) |
||||
+++ Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c (revision ) |
||||
@@ -116,7 +116,7 @@ |
||||
* @{ |
||||
*/ |
||||
|
||||
- |
||||
+#ifndef MSC_COMPOSITE |
||||
USBD_ClassTypeDef USBD_MSC = |
||||
{ |
||||
USBD_MSC_Init, |
||||
@@ -279,6 +279,7 @@ |
||||
0x01, |
||||
0x00, |
||||
}; |
||||
+#endif |
||||
/** |
||||
* @} |
||||
*/ |
||||
@@ -530,6 +531,7 @@ |
||||
return 0; |
||||
} |
||||
|
||||
+#ifndef MSC_COMPOSITE |
||||
/** |
||||
* @brief USBD_MSC_GetHSCfgDesc |
||||
* return configuration descriptor |
||||
@@ -576,6 +578,7 @@ |
||||
*length = sizeof (USBD_MSC_DeviceQualifierDesc); |
||||
return USBD_MSC_DeviceQualifierDesc; |
||||
} |
||||
+#endif |
||||
|
||||
/** |
||||
* @brief USBD_MSC_RegisterStorage |
@ -1,37 +0,0 @@ |
||||
--- Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c (date 1511202099000) |
||||
+++ Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c (revision ) |
||||
@@ -190,14 +190,27 @@ |
||||
INVALID_CDB); |
||||
return -1; |
||||
} |
||||
- |
||||
- if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) !=0 ) |
||||
+ |
||||
+ // XXX THIS SECTION IS MODIFIED FOR NOTIFY! |
||||
+ // https://www.microchip.com/forums/m401735.aspx |
||||
+ int8_t changeStatus = ((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun); |
||||
+ if(changeStatus != 0) |
||||
{ |
||||
- SCSI_SenseCode(pdev, |
||||
- lun, |
||||
- NOT_READY, |
||||
- MEDIUM_NOT_PRESENT); |
||||
- |
||||
+ if (changeStatus == -1) |
||||
+ { |
||||
+ SCSI_SenseCode(pdev, |
||||
+ lun, |
||||
+ UNIT_ATTENTION, |
||||
+ MEDIUM_HAVE_CHANGED); |
||||
+ } |
||||
+ else |
||||
+ { |
||||
+ SCSI_SenseCode(pdev, |
||||
+ lun, |
||||
+ NOT_READY, |
||||
+ MEDIUM_NOT_PRESENT); |
||||
+ } |
||||
+ |
||||
hmsc->bot_state = USBD_BOT_NO_DATA; |
||||
return -1; |
||||
} |
@ -1,62 +0,0 @@ |
||||
--- Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h (date 1511202099000) |
||||
+++ Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h (revision ) |
||||
@@ -99,6 +99,7 @@ |
||||
#define USB_DESC_TYPE_ENDPOINT 5 |
||||
#define USB_DESC_TYPE_DEVICE_QUALIFIER 6 |
||||
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7 |
||||
+#define USB_DESC_TYPE_IFACE_ASSOCIATION 11 |
||||
#define USB_DESC_TYPE_BOS 0x0F |
||||
|
||||
#define USB_CONFIG_REMOTE_WAKEUP 2 |
||||
@@ -147,7 +148,7 @@ |
||||
|
||||
typedef struct usb_setup_req |
||||
{ |
||||
- |
||||
+ |
||||
uint8_t bmRequest; |
||||
uint8_t bRequest; |
||||
uint16_t wValue; |
||||
@@ -230,7 +231,7 @@ |
||||
uint32_t dev_config_status; |
||||
USBD_SpeedTypeDef dev_speed; |
||||
USBD_EndpointTypeDef ep_in[15]; |
||||
- USBD_EndpointTypeDef ep_out[15]; |
||||
+ USBD_EndpointTypeDef ep_out[15]; |
||||
uint32_t ep0_state; |
||||
uint32_t ep0_data_len; |
||||
uint8_t dev_state; |
||||
@@ -242,10 +243,14 @@ |
||||
|
||||
USBD_SetupReqTypedef request; |
||||
USBD_DescriptorsTypeDef *pDesc; |
||||
- USBD_ClassTypeDef *pClass; |
||||
- void *pClassData; |
||||
- void *pUserData; |
||||
- void *pData; |
||||
+ USBD_ClassTypeDef *pClass; // the composite class |
||||
+ void *pClassData; |
||||
+ void *pUserData; |
||||
+ void *pClassData2; // used for secondary class |
||||
+ void *pUserData2; // used for secondary class |
||||
+ void *pClassData3; // used for tertiary class |
||||
+ void *pUserData3; // used for tertiary class |
||||
+ void *pData; // this is a pointer to the low level registers struct |
||||
} USBD_HandleTypeDef; |
||||
|
||||
/** |
||||
@@ -262,8 +267,14 @@ |
||||
|
||||
#define LOBYTE(x) ((uint8_t)(x & 0x00FF)) |
||||
#define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) |
||||
+ |
||||
+#ifndef MIN |
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) |
||||
+#endif |
||||
+ |
||||
+#ifndef MAX |
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
||||
+#endif |
||||
|
||||
|
||||
#if defined ( __GNUC__ ) |
@ -0,0 +1,299 @@ |
||||
//
|
||||
// Created by MightyPork on 2018/02/23.
|
||||
//
|
||||
|
||||
#include "cfg_utils.h" |
||||
#include "hw_utils.h" |
||||
#include "utils/avrlibc.h" |
||||
#include "utils/str_utils.h" |
||||
|
||||
/** Parse a string representation of a pin directly to a resource constant */ |
||||
Resource cfg_pinrsc_parse(const char *str, bool *suc) |
||||
{ |
||||
char pname; |
||||
uint8_t pnum; |
||||
|
||||
if (!cfg_portpin_parse(str, &pname, &pnum)) { |
||||
*suc = false; |
||||
return R_NONE; |
||||
} |
||||
|
||||
return rsc_portpin2rsc(pname, pnum, suc); |
||||
} |
||||
|
||||
/** Convert a resource to a pin name - uses a static buffer, result must not be stored! */ |
||||
char *cfg_pinrsc_encode(Resource rsc) |
||||
{ |
||||
static char buf[4]; |
||||
uint32_t index = rsc - R_PA0; |
||||
uint32_t portnum = (index/16); |
||||
uint8_t pinnum = (uint8_t) (index % 16); |
||||
if (portnum >= PORTS_COUNT) return ""; |
||||
buf[0] = (char) ('A' + portnum); |
||||
if (pinnum>9) { |
||||
buf[1] = '1'; |
||||
buf[2] = (char) ('0' + (pinnum - 10)); |
||||
buf[3] = 0; |
||||
} else { |
||||
buf[1] = (char) ('0' + pinnum); |
||||
buf[2] = 0; |
||||
} |
||||
return buf; |
||||
} |
||||
|
||||
/** Parse single pin */ |
||||
bool cfg_portpin_parse(const char *value, char *targetName, uint8_t *targetNumber) |
||||
{ |
||||
// discard leading 'P'
|
||||
if (value[0] == 'P') { |
||||
value++; |
||||
} |
||||
|
||||
size_t len = strlen(value); |
||||
if (len<2||len>3) return false; |
||||
|
||||
*targetName = (uint8_t) value[0]; |
||||
if (!(*targetName >= 'A' && *targetName <= 'H')) return false; |
||||
|
||||
// lets just hope it's OK
|
||||
*targetNumber = (uint8_t) avr_atoi(value + 1); |
||||
return true; |
||||
} |
||||
|
||||
/** Parse port name */ |
||||
bool cfg_port_parse(const char *value, char *targetName) |
||||
{ |
||||
*targetName = (uint8_t) value[0]; |
||||
if (!(*targetName >= 'A' && *targetName < 'A' + PORTS_COUNT)) return false; |
||||
return true; |
||||
} |
||||
|
||||
/** Parse a list of pin numbers with ranges and commans/semicolons to a bitmask */ |
||||
uint32_t cfg_pinmask_parse_32(const char *value, bool *suc) |
||||
{ |
||||
uint32_t bits = 0; |
||||
uint32_t acu = 0; |
||||
bool inrange = false; |
||||
uint32_t rangestart = 0; |
||||
|
||||
// shortcut if none are set
|
||||
if (value[0] == 0) return 0; |
||||
|
||||
char c; |
||||
do { |
||||
c = *value++; |
||||
if (c == ' ' || c == '\t') { |
||||
// skip
|
||||
} |
||||
else if (c >= '0' && c <= '9') { |
||||
acu = acu*10 + (c-'0'); |
||||
} |
||||
else if (c == ',' || c == ';' || c == 0) { |
||||
// end of number or range
|
||||
if (!inrange) rangestart = acu; |
||||
|
||||
// swap them if they're in the wrong order
|
||||
if (acu < rangestart) { |
||||
uint32_t swp = acu; |
||||
acu = rangestart; |
||||
rangestart = swp; |
||||
} |
||||
|
||||
if (rangestart > 31) rangestart = 31; |
||||
if (acu > 31) acu = 31; |
||||
|
||||
for(uint32_t i=rangestart; i <= acu; i++) { |
||||
bits |= 1<<i; |
||||
} |
||||
|
||||
inrange = false; |
||||
rangestart = 0; |
||||
acu = 0; |
||||
} |
||||
else if (c == '-' || c == ':') { |
||||
rangestart = acu; |
||||
inrange = true; |
||||
acu=0; |
||||
} else { |
||||
*suc = false; |
||||
} |
||||
} while (c != 0); |
||||
|
||||
return bits; |
||||
} |
||||
|
||||
/** Convert a pin bitmask to the ASCII format understood by str_parse_pinmask() */ |
||||
char *cfg_pinmask_encode(uint32_t pins, char *buffer, bool ascending) |
||||
{ |
||||
char *b = buffer; |
||||
uint32_t start = 0; |
||||
bool on = false; |
||||
bool first = true; |
||||
bool bit; |
||||
|
||||
// shortcut if none are set
|
||||
if (pins == 0) { |
||||
buffer[0] = 0; |
||||
return buffer; |
||||
} |
||||
|
||||
if (ascending) { |
||||
for (int32_t i = 0; i <= 32; i++) { |
||||
if (i == 32) { |
||||
bit = false; |
||||
} else { |
||||
bit = 0 != (pins & 1); |
||||
pins >>= 1; |
||||
} |
||||
|
||||
if (bit) { |
||||
if (!on) { |
||||
start = (uint32_t) i; |
||||
on = true; |
||||
} |
||||
} else { |
||||
if (on) { |
||||
if (!first) { |
||||
b += SPRINTF(b, ", "); |
||||
} |
||||
|
||||
if (start == (uint32_t)(i - 1)) { |
||||
b += SPRINTF(b, "%"PRIu32, start); |
||||
} else { |
||||
b += SPRINTF(b, "%"PRIu32"-%"PRIu32, start, i - 1); |
||||
} |
||||
|
||||
first = false; |
||||
on = false; |
||||
} |
||||
} |
||||
} |
||||
} else { |
||||
for (int32_t i = 31; i >= -1; i--) { |
||||
if (i == -1) { |
||||
bit = false; |
||||
} else { |
||||
bit = 0 != (pins & 0x80000000); |
||||
pins <<= 1; |
||||
} |
||||
|
||||
if (bit) { |
||||
if (!on) { |
||||
start = (uint32_t) i; |
||||
on = true; |
||||
} |
||||
} else { |
||||
if (on) { |
||||
if (!first) { |
||||
b += SPRINTF(b, ", "); |
||||
} |
||||
|
||||
if (start == (uint32_t) (i + 1)) { |
||||
b += SPRINTF(b, "%"PRIu32, start); |
||||
} else { |
||||
b += SPRINTF(b, "%"PRIu32"-%"PRIu32, start, i + 1); |
||||
} |
||||
|
||||
first = false; |
||||
on = false; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
return buffer; |
||||
} |
||||
|
||||
bool cfg_bool_parse(const char *str, bool *suc) |
||||
{ |
||||
// TODO implement strcasecmp without the locale crap from newlib and use it here
|
||||
if (streq(str, "Y")) return true; |
||||
if (streq(str, "N")) return false; |
||||
|
||||
if (streq(str, "1")) return true; |
||||
if (streq(str, "0")) return false; |
||||
|
||||
if (streq(str, "H")) return true; |
||||
if (streq(str, "L")) return false; |
||||
|
||||
if (streq(str, "YES")) return true; |
||||
if (streq(str, "NO")) return false; |
||||
|
||||
if (streq(str, "ON")) return true; |
||||
if (streq(str, "OFF")) return false; |
||||
|
||||
*suc = false; |
||||
return false; |
||||
} |
||||
|
||||
/** Convert number to one of 2 options */ |
||||
const char *cfg_enum2_encode(uint32_t n, |
||||
uint32_t na, const char *a, |
||||
uint32_t nb, const char *b) |
||||
{ |
||||
if (n == nb) return b; |
||||
return a; |
||||
} |
||||
|
||||
/** Convert number to one of 3 options */ |
||||
const char *cfg_enum3_encode(uint32_t n, |
||||
uint32_t na, const char *a, |
||||
uint32_t nb, const char *b, |
||||
uint32_t nc, const char *c) |
||||
{ |
||||
if (n == nb) return b; |
||||
if (n == nc) return c; |
||||
return a; |
||||
} |
||||
|
||||
/** Convert number to one of 4 options */ |
||||
const char *cfg_enum4_encode(uint32_t n, |
||||
uint32_t na, const char *a, |
||||
uint32_t nb, const char *b, |
||||
uint32_t nc, const char *c, |
||||
uint32_t nd, const char *d) |
||||
{ |
||||
if (n == nb) return b; |
||||
if (n == nc) return c; |
||||
if (n == nd) return d; |
||||
return a; |
||||
} |
||||
|
||||
uint32_t cfg_enum2_parse(const char *value, |
||||
const char *a, uint32_t na, |
||||
const char *b, uint32_t nb, |
||||
bool *suc) |
||||
{ |
||||
if (streq(value, a)) return na; |
||||
if (streq(value, b)) return nb; |
||||
*suc = false; |
||||
return na; |
||||
} |
||||
|
||||
uint32_t cfg_enum3_parse(const char *value, |
||||
const char *a, uint32_t na, |
||||
const char *b, uint32_t nb, |
||||
const char *c, uint32_t nc, |
||||
bool *suc) |
||||
{ |
||||
if (streq(value, a)) return na; |
||||
if (streq(value, b)) return nb; |
||||
if (streq(value, c)) return nc; |
||||
*suc = false; |
||||
return na; |
||||
} |
||||
|
||||
uint32_t cfg_enum4_parse(const char *value, |
||||
const char *a, uint32_t na, |
||||
const char *b, uint32_t nb, |
||||
const char *c, uint32_t nc, |
||||
const char *d, uint32_t nd, |
||||
bool *suc) |
||||
{ |
||||
if (streq(value, a)) return na; |
||||
if (streq(value, b)) return nb; |
||||
if (streq(value, c)) return nc; |
||||
if (streq(value, d)) return nd; |
||||
*suc = false; |
||||
return na; |
||||
} |
@ -0,0 +1,153 @@ |
||||
//
|
||||
// Created by MightyPork on 2018/02/23.
|
||||
//
|
||||
|
||||
#ifndef GEX_F072_CFG_UTILS_H |
||||
#define GEX_F072_CFG_UTILS_H |
||||
|
||||
#include "platform.h" |
||||
#include "rsc_enum.h" |
||||
#include "utils/avrlibc.h" |
||||
|
||||
/**
|
||||
* Parse a pin name (e.g. PA0 or A0) to port name and pin number |
||||
* |
||||
* @param str - source string |
||||
* @param targetName - output: port name (one character) |
||||
* @param targetNumber - output: pin number 0-15 |
||||
* @return success |
||||
*/ |
||||
bool cfg_portpin_parse(const char *str, char *targetName, uint8_t *targetNumber); |
||||
|
||||
/**
|
||||
* Parse a string representation of a pin directly to a resource constant |
||||
* |
||||
* @param[in] str - source string - e.g. PA0 or A0 |
||||
* @param[out] suc - written to false on failure |
||||
* @return the parsed resource |
||||
*/ |
||||
Resource cfg_pinrsc_parse(const char *str, bool *suc); |
||||
|
||||
/**
|
||||
* Convert a resource to a pin name - uses a static buffer, result must not be stored! |
||||
* |
||||
* @param[in] rsc - resource to print |
||||
* @return a pointer to a static buffer used for exporting the names |
||||
*/ |
||||
char *cfg_pinrsc_encode(Resource rsc); |
||||
|
||||
/**
|
||||
* Parse a port name (one character) - validates that it's within range |
||||
* |
||||
* @param value - source string |
||||
* @param targetName - output: port name (one character) |
||||
* @return success |
||||
*/ |
||||
bool cfg_port_parse(const char *value, char *targetName); |
||||
|
||||
/**
|
||||
* Parse a list of pin numbers with ranges and commands/semicolons to a bitmask. |
||||
* Supported syntax: |
||||
* - comma separated numbers |
||||
* - numbers connected by dash or colon form a range (can be in any order) |
||||
* |
||||
* @param value - source string |
||||
* @param suc - set to False if parsing failed |
||||
* @return the resulting bitmap |
||||
*/ |
||||
uint32_t cfg_pinmask_parse_32(const char *value, bool *suc); |
||||
|
||||
/** same as cfg_pinmask_parse_32(), but with a cast to u16 */ |
||||
static inline uint16_t cfg_pinmask_parse(const char *value, bool *suc) |
||||
{ |
||||
return (uint16_t) cfg_pinmask_parse_32(value, suc); |
||||
} |
||||
|
||||
/**
|
||||
* Convert a pin bitmap to the ASCII format understood by str_parse_pinmask() |
||||
* |
||||
* @param[in] pins - sparse pin map |
||||
* @param[out] buffer - output string buffer |
||||
* @param[in] ascending - use ordering 0..31 rather than 31..0 |
||||
* @return the output buffer |
||||
*/ |
||||
char *cfg_pinmask_encode(uint32_t pins, char *buffer, bool ascending); |
||||
|
||||
|
||||
/** Parse Y/N to bool */ |
||||
bool cfg_bool_parse(const char *str, bool *suc); |
||||
|
||||
/** Convert number to one of 4 options */ |
||||
const char *cfg_enum2_encode(uint32_t n, |
||||
uint32_t na, const char *a, |
||||
uint32_t nb, const char *b); |
||||
|
||||
/** Convert number to one of 4 options */ |
||||
const char *cfg_enum3_encode(uint32_t n, |
||||
uint32_t na, const char *a, |
||||
uint32_t nb, const char *b, |
||||
uint32_t nc, const char *c); |
||||
|
||||
/** Convert number to one of 4 options */ |
||||
const char *cfg_enum4_encode(uint32_t n, |
||||
uint32_t na, const char *a, |
||||
uint32_t nb, const char *b, |
||||
uint32_t nc, const char *c, |
||||
uint32_t nd, const char *d); |
||||
|
||||
/** Convert string to one of two numeric options */ |
||||
uint32_t cfg_enum2_parse(const char *tpl, |
||||
const char *a, uint32_t na, |
||||
const char *b, uint32_t nb, |
||||
bool *suc); |
||||
|
||||
/** Convert string to one of three numeric options */ |
||||
uint32_t cfg_enum3_parse(const char *tpl, |
||||
const char *a, uint32_t na, |
||||
const char *b, uint32_t nb, |
||||
const char *c, uint32_t nc, |
||||
bool *suc); |
||||
|
||||
/** Convert string to one of four numeric options */ |
||||
uint32_t cfg_enum4_parse(const char *tpl, |
||||
const char *a, uint32_t na, |
||||
const char *b, uint32_t nb, |
||||
const char *c, uint32_t nc, |
||||
const char *d, uint32_t nd, |
||||
bool *suc); |
||||
|
||||
/** Convert bool to a Y or N constant string */ |
||||
#define str_yn(cond) ((cond) ? ("Y") : ("N")) |
||||
|
||||
|
||||
static inline uint8_t cfg_u8_parse(const char *value, bool *suc) |
||||
{ |
||||
return (uint8_t) avr_atoi(value); |
||||
} |
||||
|
||||
static inline int8_t cfg_i8_parse(const char *value, bool *suc) |
||||
{ |
||||
return (int8_t) avr_atoi(value); |
||||
} |
||||
|
||||
static inline uint16_t cfg_u16_parse(const char *value, bool *suc) |
||||
{ |
||||
return (uint16_t) avr_atoi(value); |
||||
} |
||||
|
||||
static inline int16_t cfg_i16_parse(const char *value, bool *suc) |
||||
{ |
||||
return (int16_t) avr_atoi(value); |
||||
} |
||||
|
||||
static inline uint32_t cfg_u32_parse(const char *value, bool *suc) |
||||
{ |
||||
return (uint32_t) avr_atoi(value); |
||||
} |
||||
|
||||
static inline int32_t cfg_i32_parse(const char *value, bool *suc) |
||||
{ |
||||
return (int32_t) avr_atoi(value); |
||||
} |
||||
|
||||
#endif //GEX_F072_CFG_UTILS_H
|
@ -1,35 +0,0 @@ |
||||
/* Copyright (c) 2002, Marek Michalkiewicz
|
||||
All rights reserved. |
||||
|
||||
Redistribution and use in source and binary forms, with or without |
||||
modification, are permitted provided that the following conditions are met: |
||||
|
||||
* Redistributions of source code must retain the above copyright |
||||
notice, this list of conditions and the following disclaimer. |
||||
* 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. |
||||
* 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. |
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT OWNER 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. */ |
||||
|
||||
#include "avrlibc.h" |
||||
|
||||
int |
||||
avr_atoi(const char *p) |
||||
{ |
||||
return (int) avr_atol(p); |
||||
} |
@ -1,36 +0,0 @@ |
||||
/* Copyright (c) 2002, Marek Michalkiewicz
|
||||
All rights reserved. |
||||
|
||||
Redistribution and use in source and binary forms, with or without |
||||
modification, are permitted provided that the following conditions are met: |
||||
|
||||
* Redistributions of source code must retain the above copyright |
||||
notice, this list of conditions and the following disclaimer. |
||||
* 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. |
||||
* 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. |
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT OWNER 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. */ |
||||
|
||||
#include <stdlib.h> |
||||
#include "avrlibc.h" |
||||
|
||||
long |
||||
avr_atol(const char *p) |
||||
{ |
||||
return avr_strtol(p, (char **) NULL, 10); |
||||
} |
@ -0,0 +1,7 @@ |
||||
//
|
||||
// Created by MightyPork on 2018/02/23.
|
||||
//
|
||||
|
||||
#include <stdint.h> |
||||
|
||||
volatile int32_t avrlibc_errno = 0; |
Loading…
Reference in new issue