mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +03:00
Code tidy and addition of GPL headers
This commit is contained in:
parent
31b6e7e024
commit
a7a428a5bb
41 changed files with 424 additions and 180 deletions
|
@ -120,7 +120,7 @@ static uint8_t mspSerialChecksumBuf(uint8_t checksum, const uint8_t *data, int l
|
|||
|
||||
#define JUMBO_FRAME_SIZE_LIMIT 255
|
||||
|
||||
static void mspSerialEncode(mspPort_t *msp, mspPacket_t *packet)
|
||||
static int mspSerialEncode(mspPort_t *msp, mspPacket_t *packet)
|
||||
{
|
||||
serialBeginWrite(msp->port);
|
||||
const int len = sbufBytesRemaining(&packet->buf);
|
||||
|
@ -140,6 +140,7 @@ static void mspSerialEncode(mspPort_t *msp, mspPacket_t *packet)
|
|||
}
|
||||
serialWrite(msp->port, checksum);
|
||||
serialEndWrite(msp->port);
|
||||
return sizeof(hdr) + len + 1; // header, data, and checksum
|
||||
}
|
||||
|
||||
static mspPostProcessFnPtr mspSerialProcessReceivedCommand(mspPort_t *msp, mspProcessCommandFnPtr mspProcessCommandFn)
|
||||
|
@ -211,9 +212,10 @@ void mspSerialInit(void)
|
|||
mspSerialAllocatePorts();
|
||||
}
|
||||
|
||||
void mspSerialPush(uint8_t cmd, uint8_t *data, int datalen)
|
||||
int mspSerialPush(uint8_t cmd, const uint8_t *data, int datalen)
|
||||
{
|
||||
static uint8_t pushBuf[30];
|
||||
int ret = 0;
|
||||
|
||||
mspPacket_t push = {
|
||||
.buf = { .ptr = pushBuf, .end = ARRAYEND(pushBuf), },
|
||||
|
@ -221,7 +223,7 @@ void mspSerialPush(uint8_t cmd, uint8_t *data, int datalen)
|
|||
.result = 0,
|
||||
};
|
||||
|
||||
for (uint8_t portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
|
||||
for (int portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
|
||||
mspPort_t * const mspPort = &mspPorts[portIndex];
|
||||
if (!mspPort->port) {
|
||||
continue;
|
||||
|
@ -236,15 +238,16 @@ void mspSerialPush(uint8_t cmd, uint8_t *data, int datalen)
|
|||
|
||||
sbufSwitchToReader(&push.buf, pushBuf);
|
||||
|
||||
mspSerialEncode(mspPort, &push);
|
||||
ret = mspSerialEncode(mspPort, &push);
|
||||
}
|
||||
return ret; // return the number of bytes written
|
||||
}
|
||||
|
||||
uint32_t mspSerialTxBytesFree()
|
||||
{
|
||||
uint32_t minroom = UINT16_MAX;
|
||||
uint32_t ret = UINT32_MAX;
|
||||
|
||||
for (uint8_t portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
|
||||
for (int portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
|
||||
mspPort_t * const mspPort = &mspPorts[portIndex];
|
||||
if (!mspPort->port) {
|
||||
continue;
|
||||
|
@ -255,12 +258,11 @@ uint32_t mspSerialTxBytesFree()
|
|||
continue;
|
||||
}
|
||||
|
||||
uint32_t room = serialTxBytesFree(mspPort->port);
|
||||
|
||||
if (room < minroom) {
|
||||
minroom = room;
|
||||
const uint32_t bytesFree = serialTxBytesFree(mspPort->port);
|
||||
if (bytesFree < ret) {
|
||||
ret = bytesFree;
|
||||
}
|
||||
}
|
||||
|
||||
return minroom;
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue