|
|
@@ -71,7 +71,12 @@ static void usbh_ftdi_caculate_baudrate(uint32_t *itdf_divisor, uint32_t actual_
|
|
|
|
|
|
int usbh_ftdi_reset(struct usbh_ftdi *ftdi_class)
|
|
|
{
|
|
|
- struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
|
|
+ struct usb_setup_packet *setup;
|
|
|
+
|
|
|
+ if (!ftdi_class || !ftdi_class->hport) {
|
|
|
+ return -USB_ERR_INVAL;
|
|
|
+ }
|
|
|
+ setup = ftdi_class->hport->setup;
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
setup->bRequest = SIO_RESET_REQUEST;
|
|
|
@@ -84,7 +89,12 @@ int usbh_ftdi_reset(struct usbh_ftdi *ftdi_class)
|
|
|
|
|
|
static int usbh_ftdi_set_modem(struct usbh_ftdi *ftdi_class, uint16_t value)
|
|
|
{
|
|
|
- struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
|
|
+ struct usb_setup_packet *setup;
|
|
|
+
|
|
|
+ if (!ftdi_class || !ftdi_class->hport) {
|
|
|
+ return -USB_ERR_INVAL;
|
|
|
+ }
|
|
|
+ setup = ftdi_class->hport->setup;
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
setup->bRequest = SIO_SET_MODEM_CTRL_REQUEST;
|
|
|
@@ -97,11 +107,16 @@ static int usbh_ftdi_set_modem(struct usbh_ftdi *ftdi_class, uint16_t value)
|
|
|
|
|
|
static int usbh_ftdi_set_baudrate(struct usbh_ftdi *ftdi_class, uint32_t baudrate)
|
|
|
{
|
|
|
- struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
|
|
+ struct usb_setup_packet *setup;
|
|
|
uint32_t itdf_divisor;
|
|
|
uint16_t value;
|
|
|
uint8_t baudrate_high;
|
|
|
|
|
|
+ if (!ftdi_class || !ftdi_class->hport) {
|
|
|
+ return -USB_ERR_INVAL;
|
|
|
+ }
|
|
|
+ setup = ftdi_class->hport->setup;
|
|
|
+
|
|
|
usbh_ftdi_caculate_baudrate(&itdf_divisor, baudrate);
|
|
|
value = itdf_divisor & 0xFFFF;
|
|
|
baudrate_high = (itdf_divisor >> 16) & 0xff;
|
|
|
@@ -123,10 +138,15 @@ static int usbh_ftdi_set_data_format(struct usbh_ftdi *ftdi_class, uint8_t datab
|
|
|
* D11-D12 STOP_BIT_1=0, STOP_BIT_15=1, STOP_BIT_2=2
|
|
|
* D14 BREAK_OFF=0, BREAK_ON=1
|
|
|
**/
|
|
|
+ struct usb_setup_packet *setup;
|
|
|
+ uint16_t value;
|
|
|
|
|
|
- uint16_t value = ((isbreak & 0x01) << 14) | ((stopbits & 0x03) << 11) | ((parity & 0x0f) << 8) | (databits & 0x0f);
|
|
|
+ if (!ftdi_class || !ftdi_class->hport) {
|
|
|
+ return -USB_ERR_INVAL;
|
|
|
+ }
|
|
|
+ setup = ftdi_class->hport->setup;
|
|
|
|
|
|
- struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
|
|
+ value = ((isbreak & 0x01) << 14) | ((stopbits & 0x03) << 11) | ((parity & 0x0f) << 8) | (databits & 0x0f);
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
setup->bRequest = SIO_SET_DATA_REQUEST;
|
|
|
@@ -139,7 +159,12 @@ static int usbh_ftdi_set_data_format(struct usbh_ftdi *ftdi_class, uint8_t datab
|
|
|
|
|
|
static int usbh_ftdi_set_latency_timer(struct usbh_ftdi *ftdi_class, uint16_t value)
|
|
|
{
|
|
|
- struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
|
|
+ struct usb_setup_packet *setup;
|
|
|
+
|
|
|
+ if (!ftdi_class || !ftdi_class->hport) {
|
|
|
+ return -USB_ERR_INVAL;
|
|
|
+ }
|
|
|
+ setup = ftdi_class->hport->setup;
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
setup->bRequest = SIO_SET_LATENCY_TIMER_REQUEST;
|
|
|
@@ -152,7 +177,12 @@ static int usbh_ftdi_set_latency_timer(struct usbh_ftdi *ftdi_class, uint16_t va
|
|
|
|
|
|
static int usbh_ftdi_set_flow_ctrl(struct usbh_ftdi *ftdi_class, uint16_t value)
|
|
|
{
|
|
|
- struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
|
|
+ struct usb_setup_packet *setup;
|
|
|
+
|
|
|
+ if (!ftdi_class || !ftdi_class->hport) {
|
|
|
+ return -USB_ERR_INVAL;
|
|
|
+ }
|
|
|
+ setup = ftdi_class->hport->setup;
|
|
|
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
setup->bRequest = SIO_SET_FLOW_CTRL_REQUEST;
|
|
|
@@ -165,9 +195,14 @@ static int usbh_ftdi_set_flow_ctrl(struct usbh_ftdi *ftdi_class, uint16_t value)
|
|
|
|
|
|
static int usbh_ftdi_read_modem_status(struct usbh_ftdi *ftdi_class)
|
|
|
{
|
|
|
- struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
|
|
+ struct usb_setup_packet *setup;
|
|
|
int ret;
|
|
|
|
|
|
+ if (!ftdi_class || !ftdi_class->hport) {
|
|
|
+ return -USB_ERR_INVAL;
|
|
|
+ }
|
|
|
+ setup = ftdi_class->hport->setup;
|
|
|
+
|
|
|
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_VENDOR | USB_REQUEST_RECIPIENT_DEVICE;
|
|
|
setup->bRequest = SIO_POLL_MODEM_STATUS_REQUEST;
|
|
|
setup->wValue = 0x0000;
|