-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Witty-Wizard
committed
Jun 30, 2024
1 parent
331d488
commit d43bc71
Showing
11 changed files
with
231 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# FrSky F.Port {#frskyfport} | ||
|
||
FrSky F.Port is a protocol developed by FrSky Electronic Co., Ltd., designed for communication between receivers and connected devices like servos or sensors. It is a one-line bus system that supports both control and data transmission, operating at a higher speed (115200 baud per second) compared to its predecessor, S.Port. | ||
|
||
## Specifications | ||
|
||
- [Physical Layer](#physical_fport) | ||
- [Message Format](#format_fport) | ||
|
||
### Physical Layer {#physical_fport} | ||
|
||
The physical layer of the FrSky F.Port protocol utilizes UART (Universal Asynchronous Receiver-Transmitter) communication at a baud rate of 115200. | ||
|
||
#### Uart Configuration | ||
|
||
When it comes to the configuration of the UART communication for SBus, it uses the following format: | ||
|
||
- **8 bits of data**: Each data frame consists of 8 bits, representing the information being transmitted. | ||
- **No parity**: It does not use parity bit instead it uses a checksum at the end of the whole packet. | ||
- **1 stop bits**: Following the data bits and the parity bit, there are 1 stop bits. Stop bits indicate the end of a data frame and provide timing for the receiving device to process the data. | ||
|
||
### Message Format {#format_fport} | ||
For the data format and more details go to [this link](https://github.com/betaflight/betaflight/files/1491056/F.Port.protocol.betaFlight.V2.1.2017.11.21.pdf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*! | ||
* @file fport.cpp | ||
* @brief Source file for the F.Port implementations | ||
* @author Witty-Wizard | ||
*/ | ||
|
||
#include "fport.h" | ||
|
||
fport::fport(Stream *rxPort, int rxPin, int txPin, bool inverted) | ||
: SerialIO(rxPort, rxPin, txPin, inverted) {} | ||
|
||
void fport::begin() { | ||
|
||
// Initialize the serial port | ||
#if defined(ARDUINO_ARCH_ESP32) | ||
HardwareSerial *serialPort = (HardwareSerial *)_rxPort; | ||
serialPort->begin(FPORT_BAUDRATE, SERIAL_8N1, _rxPin, _txPin, _inverted); | ||
#elif defined(ARDUINO_ARCH_RP2040) | ||
SerialUART *serialPort = (SerialUART *)_rxPort; | ||
serialPort->setPinout(_txPin, _rxPin); | ||
serialPort->begin(FPORT_BAUDRATE, SERIAL_8N1); | ||
#else | ||
#warning "Unsupported hardware platform." | ||
#endif | ||
} | ||
|
||
void fport::processIncoming() { | ||
while (_rxPort->available()) { | ||
_rx_buffer[FPORT_MAX_PACKET_SIZE - 1] = _rxPort->read(); | ||
if (_rx_buffer[0] == 0x7E && | ||
_rx_buffer[FPORT_MAX_PACKET_SIZE - 1] == 0x7E) { | ||
memcpy(&_channelData, &_rx_buffer[4], sizeof(_channelData)); | ||
} else { | ||
leftShift(_rx_buffer, sizeof(_rx_buffer)); | ||
} | ||
} | ||
} | ||
|
||
void fport::getChannel(void *channelData) {} | ||
|
||
void fport::leftShift(uint8_t arr[], size_t size) { | ||
memmove(arr, arr + 1, (size - 1)); | ||
arr[size - 1] = 0xFF; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*! | ||
* @file fport.h | ||
* @brief Header file for the FPort Protocol definations | ||
* @author Witty-Wizard | ||
*/ | ||
|
||
#pragma once | ||
#ifndef FPORT_H | ||
#define FPORT_H | ||
|
||
#include "../SerialIO.h" | ||
|
||
#define FPORT_BAUDRATE 115200 ///< F.Port baudrate | ||
#define FPORT_MAX_PACKET_SIZE 29 ///< F.Port maximum packet length | ||
|
||
typedef struct fport_channels_s { | ||
unsigned channel1 : 11; | ||
unsigned channel2 : 11; | ||
unsigned channel3 : 11; | ||
unsigned channel4 : 11; | ||
unsigned channel5 : 11; | ||
unsigned channel6 : 11; | ||
unsigned channel7 : 11; | ||
unsigned channel8 : 11; | ||
unsigned channel9 : 11; | ||
unsigned channel10 : 11; | ||
unsigned channel11 : 11; | ||
unsigned channel12 : 11; | ||
unsigned channel13 : 11; | ||
unsigned channel14 : 11; | ||
unsigned channel15 : 11; | ||
unsigned channel16 : 11; | ||
} PACKED fport_channels_t; | ||
|
||
class fport : public SerialIO { | ||
private: | ||
uint8_t _rx_buffer[FPORT_MAX_PACKET_SIZE]; | ||
fport_channels_t _channelData; | ||
|
||
public: | ||
explicit fport(Stream *rxPort, int rxPin = -1, int txPin = -1, | ||
bool inverted = true); | ||
void begin() override; | ||
void processIncoming() override; | ||
void getChannel(void *channelData) override; | ||
void leftShift(uint8_t arr[],size_t size); | ||
}; | ||
#endif |
Oops, something went wrong.