mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 17:25:20 +03:00
Moved serial_4way to new IO, added temp fix for F4 targets
This commit is contained in:
parent
5d385d0019
commit
f7c182bf3d
4 changed files with 49 additions and 62 deletions
|
@ -147,7 +147,8 @@ static void usbVcpBeginWrite(serialPort_t *instance)
|
||||||
port->buffering = true;
|
port->buffering = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t usbTxBytesFree() {
|
uint8_t usbTxBytesFree()
|
||||||
|
{
|
||||||
// Because we block upon transmit and don't buffer bytes, our "buffer" capacity is effectively unlimited.
|
// Because we block upon transmit and don't buffer bytes, our "buffer" capacity is effectively unlimited.
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
@ -194,6 +195,7 @@ serialPort_t *usbVcpOpen(void)
|
||||||
|
|
||||||
return (serialPort_t *)s;
|
return (serialPort_t *)s;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t usbVcpGetBaudRate(serialPort_t *instance)
|
uint32_t usbVcpGetBaudRate(serialPort_t *instance)
|
||||||
{
|
{
|
||||||
UNUSED(instance);
|
UNUSED(instance);
|
||||||
|
|
|
@ -100,43 +100,32 @@ static void setDisconnected(void)
|
||||||
|
|
||||||
bool isEscHi(uint8_t selEsc)
|
bool isEscHi(uint8_t selEsc)
|
||||||
{
|
{
|
||||||
return (digitalIn(escHardware[selEsc].gpio, escHardware[selEsc].pin) != Bit_RESET);
|
return (IORead(escHardware[selEsc].io) != Bit_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isEscLo(uint8_t selEsc)
|
bool isEscLo(uint8_t selEsc)
|
||||||
{
|
{
|
||||||
return (digitalIn(escHardware[selEsc].gpio, escHardware[selEsc].pin) == Bit_RESET);
|
return (IORead(escHardware[selEsc].io) == Bit_RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEscHi(uint8_t selEsc)
|
void setEscHi(uint8_t selEsc)
|
||||||
{
|
{
|
||||||
digitalHi(escHardware[selEsc].gpio, escHardware[selEsc].pin);
|
IOHi(escHardware[selEsc].io);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEscLo(uint8_t selEsc)
|
void setEscLo(uint8_t selEsc)
|
||||||
{
|
{
|
||||||
digitalLo(escHardware[selEsc].gpio, escHardware[selEsc].pin);
|
IOLo(escHardware[selEsc].io);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEscInput(uint8_t selEsc)
|
void setEscInput(uint8_t selEsc)
|
||||||
{
|
{
|
||||||
gpioInit(escHardware[selEsc].gpio, &escHardware[selEsc].gpio_config_INPUT);
|
IOConfigGPIO(escHardware[selEsc].io, IOCFG_IPU);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEscOutput(uint8_t selEsc)
|
void setEscOutput(uint8_t selEsc)
|
||||||
{
|
{
|
||||||
gpioInit(escHardware[selEsc].gpio, &escHardware[selEsc].gpio_config_OUTPUT);
|
IOConfigGPIO(escHardware[selEsc].io, IOCFG_OUT_PP);
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t getPinPos(uint32_t pin)
|
|
||||||
{
|
|
||||||
for (int pinPos = 0; pinPos < 16; pinPos++) {
|
|
||||||
uint32_t pinMask = (0x1 << pinPos);
|
|
||||||
if (pin & pinMask) {
|
|
||||||
return pinPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize 4way ESC interface
|
// Initialize 4way ESC interface
|
||||||
|
@ -151,14 +140,7 @@ int esc4wayInit(void)
|
||||||
for (volatile uint8_t i = 0; i < pwmOutputConfiguration->outputCount; i++) {
|
for (volatile uint8_t i = 0; i < pwmOutputConfiguration->outputCount; i++) {
|
||||||
if ((pwmOutputConfiguration->portConfigurations[i].flags & PWM_PF_MOTOR) == PWM_PF_MOTOR) {
|
if ((pwmOutputConfiguration->portConfigurations[i].flags & PWM_PF_MOTOR) == PWM_PF_MOTOR) {
|
||||||
if(motor[pwmOutputConfiguration->portConfigurations[i].index] > 0) {
|
if(motor[pwmOutputConfiguration->portConfigurations[i].index] > 0) {
|
||||||
escHardware[escIdx].gpio = IO_GPIO(IOGetByTag(pwmOutputConfiguration->portConfigurations[i].timerHardware->pin));
|
escHardware[escIdx].io = IOGetByTag(pwmOutputConfiguration->portConfigurations[i].timerHardware->pin);
|
||||||
escHardware[escIdx].pin = IO_Pin(IOGetByTag(pwmOutputConfiguration->portConfigurations[i].timerHardware->pin));
|
|
||||||
escHardware[escIdx].pinpos = getPinPos(escHardware[escIdx].pin);
|
|
||||||
escHardware[escIdx].gpio_config_INPUT.pin = escHardware[escIdx].pin;
|
|
||||||
escHardware[escIdx].gpio_config_INPUT.speed = Speed_2MHz; // see pwmOutConfig()
|
|
||||||
escHardware[escIdx].gpio_config_INPUT.mode = Mode_IPU;
|
|
||||||
escHardware[escIdx].gpio_config_OUTPUT = escHardware[escIdx].gpio_config_INPUT;
|
|
||||||
escHardware[escIdx].gpio_config_OUTPUT.mode = Mode_Out_PP;
|
|
||||||
escIdx++;
|
escIdx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +165,7 @@ void esc4wayStart(void)
|
||||||
void esc4wayRelease(void)
|
void esc4wayRelease(void)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < escCount; i++) {
|
for(int i = 0; i < escCount; i++) {
|
||||||
escHardware[i].gpio_config_OUTPUT.mode = Mode_AF_PP; // see pwmOutConfig()
|
IOConfigGPIO(escHardware[i].io, IOCFG_AF_PP); // see pwmOutConfig()
|
||||||
setEscOutput(i);
|
setEscOutput(i);
|
||||||
setEscLo(i);
|
setEscLo(i);
|
||||||
}
|
}
|
||||||
|
@ -397,6 +379,10 @@ void esc4wayProcess(serialPort_t *serial)
|
||||||
writeByte(crcOut >> 8);
|
writeByte(crcOut >> 8);
|
||||||
writeByte(crcOut & 0xff);
|
writeByte(crcOut & 0xff);
|
||||||
serialEndWrite(port);
|
serialEndWrite(port);
|
||||||
|
|
||||||
|
#ifdef STM32F4
|
||||||
|
delay(50);
|
||||||
|
#endif
|
||||||
TX_LED_OFF;
|
TX_LED_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GPIO_TypeDef* gpio;
|
IO_t io;
|
||||||
uint16_t pinpos;
|
|
||||||
uint16_t pin;
|
|
||||||
gpio_config_t gpio_config_INPUT;
|
|
||||||
gpio_config_t gpio_config_OUTPUT;
|
|
||||||
} escHardware_t;
|
} escHardware_t;
|
||||||
|
|
||||||
extern uint8_t escSelected;
|
extern uint8_t escSelected;
|
||||||
|
|
|
@ -65,8 +65,8 @@ CDC_IF_Prop_TypeDef VCP_fops = {VCP_Init, VCP_DeInit, VCP_Ctrl, VCP_DataTx, VCP_
|
||||||
*/
|
*/
|
||||||
static uint16_t VCP_Init(void)
|
static uint16_t VCP_Init(void)
|
||||||
{
|
{
|
||||||
bDeviceState = CONFIGURED;
|
bDeviceState = CONFIGURED;
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,8 +77,8 @@ static uint16_t VCP_Init(void)
|
||||||
*/
|
*/
|
||||||
static uint16_t VCP_DeInit(void)
|
static uint16_t VCP_DeInit(void)
|
||||||
{
|
{
|
||||||
bDeviceState = UNCONNECTED;
|
bDeviceState = UNCONNECTED;
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ust_cpy(LINE_CODING* plc2, const LINE_CODING* plc1)
|
void ust_cpy(LINE_CODING* plc2, const LINE_CODING* plc1)
|
||||||
|
@ -99,12 +99,12 @@ void ust_cpy(LINE_CODING* plc2, const LINE_CODING* plc1)
|
||||||
*/
|
*/
|
||||||
static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||||
{
|
{
|
||||||
(void)Len;
|
(void)Len;
|
||||||
LINE_CODING* plc = (LINE_CODING*)Buf;
|
LINE_CODING* plc = (LINE_CODING*)Buf;
|
||||||
|
|
||||||
assert_param(Len>=sizeof(LINE_CODING));
|
assert_param(Len>=sizeof(LINE_CODING));
|
||||||
|
|
||||||
switch (Cmd) {
|
switch (Cmd) {
|
||||||
/* Not needed for this driver, AT modem commands */
|
/* Not needed for this driver, AT modem commands */
|
||||||
case SEND_ENCAPSULATED_COMMAND:
|
case SEND_ENCAPSULATED_COMMAND:
|
||||||
case GET_ENCAPSULATED_RESPONSE:
|
case GET_ENCAPSULATED_RESPONSE:
|
||||||
|
@ -139,9 +139,9 @@ static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
@ -153,12 +153,12 @@ static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength)
|
uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength)
|
||||||
{
|
{
|
||||||
if(USB_Tx_State!=1)
|
if(USB_Tx_State!=1)
|
||||||
{
|
{
|
||||||
VCP_DataTx(ptrBuffer,sendLength);
|
VCP_DataTx(ptrBuffer,sendLength);
|
||||||
return sendLength;
|
return sendLength;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,15 +176,15 @@ static uint16_t VCP_DataTx(uint8_t* Buf, uint32_t Len)
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i = 0; i < Len; i++)
|
for (i = 0; i < Len; i++)
|
||||||
APP_Rx_Buffer[ptr++ & (APP_RX_DATA_SIZE-1)] = Buf[i];
|
APP_Rx_Buffer[ptr++ & (APP_RX_DATA_SIZE-1)] = Buf[i];
|
||||||
|
|
||||||
APP_Rx_ptr_in = ptr % APP_RX_DATA_SIZE;
|
APP_Rx_ptr_in = ptr % APP_RX_DATA_SIZE;
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t usbAvailable(void)
|
||||||
uint8_t usbAvailable(void) {
|
{
|
||||||
return (usbData.rxBufHead != usbData.rxBufTail);
|
return (usbData.rxBufHead != usbData.rxBufTail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,13 +197,12 @@ uint8_t usbAvailable(void) {
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
uint32_t CDC_Receive_DATA(uint8_t* recvBuf, uint32_t len)
|
uint32_t CDC_Receive_DATA(uint8_t* recvBuf, uint32_t len)
|
||||||
{
|
{
|
||||||
(void)len;
|
uint32_t ch = 0;
|
||||||
uint8_t ch = 0;
|
|
||||||
|
|
||||||
if (usbAvailable()) {
|
while (usbAvailable() && ch < len) {
|
||||||
recvBuf[0] = usbData.rxBuf[usbData.rxBufTail];
|
recvBuf[ch] = usbData.rxBuf[usbData.rxBufTail];
|
||||||
usbData.rxBufTail = (usbData.rxBufTail + 1) % USB_RX_BUFSIZE;
|
usbData.rxBufTail = (usbData.rxBufTail + 1) % USB_RX_BUFSIZE;
|
||||||
ch=1;
|
ch++;
|
||||||
receiveLength--;
|
receiveLength--;
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
|
@ -231,13 +230,17 @@ static uint16_t VCP_DataRx(uint8_t* Buf, uint32_t Len)
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i = 0; i < Len; i++)
|
for (i = 0; i < Len; i++)
|
||||||
usbData.rxBuf[ptr++ & (USB_RX_BUFSIZE-1)] = Buf[i];
|
usbData.rxBuf[ptr++ & (USB_RX_BUFSIZE-1)] = Buf[i];
|
||||||
|
|
||||||
usbData.rxBufHead = ptr % USB_RX_BUFSIZE;
|
usbData.rxBufHead = ptr % USB_RX_BUFSIZE;
|
||||||
|
|
||||||
receiveLength = ((usbData.rxBufHead - usbData.rxBufTail)>0?(usbData.rxBufHead - usbData.rxBufTail):(usbData.rxBufHead + USB_RX_BUFSIZE - usbData.rxBufTail)) % USB_RX_BUFSIZE;
|
receiveLength = ((usbData.rxBufHead - usbData.rxBufTail) > 0 ?
|
||||||
if((receiveLength) > (USB_RX_BUFSIZE-1))
|
(usbData.rxBufHead - usbData.rxBufTail) :
|
||||||
return USBD_FAIL;
|
(usbData.rxBufHead + USB_RX_BUFSIZE - usbData.rxBufTail)) % USB_RX_BUFSIZE;
|
||||||
|
|
||||||
|
if(receiveLength > (USB_RX_BUFSIZE-1))
|
||||||
|
return USBD_FAIL;
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +277,7 @@ uint8_t usbIsConnected(void)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
uint32_t CDC_BaudRate(void)
|
uint32_t CDC_BaudRate(void)
|
||||||
{
|
{
|
||||||
return g_lc.bitrate;
|
return g_lc.bitrate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue