use cdc_linecoding and line state for ftdi
This commit is contained in:
35
class/vendor/usbh_ftdi.c
vendored
35
class/vendor/usbh_ftdi.c
vendored
@@ -82,7 +82,7 @@ int usbh_ftdi_reset(struct usbh_ftdi *ftdi_class)
|
||||
return usbh_control_transfer(ftdi_class->hport, setup, NULL);
|
||||
}
|
||||
|
||||
int usbh_ftdi_set_modem(struct usbh_ftdi *ftdi_class, uint16_t value)
|
||||
static int usbh_ftdi_set_modem(struct usbh_ftdi *ftdi_class, uint16_t value)
|
||||
{
|
||||
struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
||||
|
||||
@@ -95,7 +95,7 @@ int usbh_ftdi_set_modem(struct usbh_ftdi *ftdi_class, uint16_t value)
|
||||
return usbh_control_transfer(ftdi_class->hport, setup, NULL);
|
||||
}
|
||||
|
||||
int usbh_ftdi_set_baudrate(struct usbh_ftdi *ftdi_class, uint32_t baudrate)
|
||||
static int usbh_ftdi_set_baudrate(struct usbh_ftdi *ftdi_class, uint32_t baudrate)
|
||||
{
|
||||
struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
||||
uint32_t itdf_divisor;
|
||||
@@ -115,7 +115,7 @@ int usbh_ftdi_set_baudrate(struct usbh_ftdi *ftdi_class, uint32_t baudrate)
|
||||
return usbh_control_transfer(ftdi_class->hport, setup, NULL);
|
||||
}
|
||||
|
||||
int usbh_ftdi_set_data(struct usbh_ftdi *ftdi_class, uint8_t databits, uint8_t parity, uint8_t stopbits, uint8_t isbreak)
|
||||
static int usbh_ftdi_set_data_format(struct usbh_ftdi *ftdi_class, uint8_t databits, uint8_t parity, uint8_t stopbits)
|
||||
{
|
||||
/**
|
||||
* D0-D7 databits BITS_7=7, BITS_8=8
|
||||
@@ -124,6 +124,7 @@ int usbh_ftdi_set_data(struct usbh_ftdi *ftdi_class, uint8_t databits, uint8_t p
|
||||
* D14 BREAK_OFF=0, BREAK_ON=1
|
||||
**/
|
||||
|
||||
uint8_t isbreak = 0;
|
||||
uint16_t value = (databits & 0x0F) | ((parity & 0x03) << 8) | ((stopbits & 0x03) << 11) | ((isbreak & 0x01) << 14);
|
||||
|
||||
struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
||||
@@ -137,6 +138,31 @@ int usbh_ftdi_set_data(struct usbh_ftdi *ftdi_class, uint8_t databits, uint8_t p
|
||||
return usbh_control_transfer(ftdi_class->hport, setup, NULL);
|
||||
}
|
||||
|
||||
int usbh_ftdi_set_line_state(struct usbh_ftdi *ftdi_class, bool dtr, bool rts)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (dtr) {
|
||||
usbh_ftdi_set_modem(ftdi_class, SIO_SET_DTR_HIGH);
|
||||
} else {
|
||||
usbh_ftdi_set_modem(ftdi_class, SIO_SET_DTR_LOW);
|
||||
}
|
||||
|
||||
if (rts) {
|
||||
ret = usbh_ftdi_set_modem(ftdi_class, SIO_SET_RTS_HIGH);
|
||||
} else {
|
||||
ret = usbh_ftdi_set_modem(ftdi_class, SIO_SET_RTS_LOW);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usbh_ftdi_set_line_coding(struct usbh_ftdi *ftdi_class, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
usbh_ftdi_set_baudrate(ftdi_class, line_coding->dwDTERate);
|
||||
return usbh_ftdi_set_data_format(ftdi_class, line_coding->bDataBits, line_coding->bParityType, line_coding->bCharFormat);
|
||||
}
|
||||
|
||||
int usbh_ftdi_set_latency_timer(struct usbh_ftdi *ftdi_class, uint16_t value)
|
||||
{
|
||||
struct usb_setup_packet *setup = ftdi_class->hport->setup;
|
||||
@@ -201,8 +227,7 @@ static int usbh_ftdi_connect(struct usbh_hubport *hport, uint8_t intf)
|
||||
usbh_ftdi_reset(ftdi_class);
|
||||
usbh_ftdi_set_flow_ctrl(ftdi_class, SIO_DISABLE_FLOW_CTRL);
|
||||
usbh_ftdi_set_latency_timer(ftdi_class, 0x10);
|
||||
usbh_ftdi_set_modem(ftdi_class, SIO_SET_RTS_LOW);
|
||||
usbh_ftdi_set_modem(ftdi_class, SIO_SET_DTR_HIGH);
|
||||
usbh_ftdi_set_line_state(ftdi_class, true, false);
|
||||
usbh_ftdi_read_modem_status(ftdi_class);
|
||||
printf("modem status:%02x:%02x\r\n", ftdi_class->modem_status[0], ftdi_class->modem_status[1]);
|
||||
|
||||
|
||||
28
class/vendor/usbh_ftdi.h
vendored
28
class/vendor/usbh_ftdi.h
vendored
@@ -6,6 +6,8 @@
|
||||
#ifndef USBH_FTDI_H
|
||||
#define USBH_FTDI_H
|
||||
|
||||
#include "usb_cdc.h"
|
||||
|
||||
/* Requests */
|
||||
#define SIO_RESET_REQUEST 0x00 /* Reset the port */
|
||||
#define SIO_SET_MODEM_CTRL_REQUEST 0x01 /* Set the modem control register */
|
||||
@@ -54,31 +56,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
int usbh_ftdi_reset(struct usbh_ftdi *ftdi_class);
|
||||
/**
|
||||
* @brief set modem
|
||||
*
|
||||
* @param [in] value SIO_SET_DTR_HIGH or SIO_SET_DTR_LOW or SIO_SET_RTS_HIGH or SIO_SET_RTS_LOW
|
||||
*/
|
||||
int usbh_ftdi_set_modem(struct usbh_ftdi *ftdi_class, uint16_t value);
|
||||
/**
|
||||
* @brief set baudrate
|
||||
*
|
||||
* @param [in] baudrate less than 3M
|
||||
*/
|
||||
int usbh_ftdi_set_baudrate(struct usbh_ftdi *ftdi_class, uint32_t baudrate);
|
||||
/**
|
||||
* @brief set data
|
||||
*
|
||||
* @param [in] databits BITS_7=7, BITS_8=8
|
||||
* @param [in] parity NONE=0, ODD=1, EVEN=2, MARK=3, SPACE=4
|
||||
* @param [in] stopbits STOP_BIT_1=0, STOP_BIT_15=1, STOP_BIT_2=2
|
||||
* @param [in] isbreak BREAK_OFF=0, BREAK_ON=1
|
||||
*/
|
||||
int usbh_ftdi_set_data(struct usbh_ftdi *ftdi_class, uint8_t databits,
|
||||
uint8_t parity,
|
||||
uint8_t stopbits,
|
||||
uint8_t isbreak);
|
||||
int usbh_ftdi_set_flow_ctrl(struct usbh_ftdi *ftdi_class, uint16_t value);
|
||||
int usbh_ftdi_set_line_coding(struct usbh_ftdi *ftdi_class, struct cdc_line_coding *line_coding);
|
||||
int usbh_ftdi_set_line_state(struct usbh_ftdi *ftdi_class, bool dtr, bool rts);
|
||||
|
||||
/**
|
||||
* @brief start a bulk in transfer
|
||||
|
||||
Reference in New Issue
Block a user