Начало

This commit is contained in:
cfif 2025-09-23 17:12:43 +03:00
commit 95a70bd52f
3 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,19 @@
//
// Created by cfif on 03.10.22.
//
#ifndef MODULE_SERIALPORTHALFDUPLEXIO_H
#define MODULE_SERIALPORTHALFDUPLEXIO_H
#include "stdint.h"
#include "SerialPortIO.h"
#include "GpioPin.h"
typedef struct {
tSerialPortIO *serialPortIo;
tGpioPin *de;
} tSerialPortHalfDuplex;
tSerialPortHalfDuplex vSerialPortHalfDuplexInit(tSerialPortIO *serialPortIo, tGpioPin *de);
tSerialPortIO vSerialPortHalfDuplexGetIo(tSerialPortHalfDuplex *serialPortHalfDuplex);
#endif //MODULE_SERIALPORTHALFDUPLEXIO_H

View File

@ -0,0 +1,55 @@
//
// Created by cfif on 03.10.22.
//
#include "SerialPortHalfDuplexIO.h"
#include "SystemDelayInterface.h"
static uint16_t vSerialPortHalfDuplexReceive(tSerialPortHalfDuplex *io, uint8_t *data, uint16_t size,
uint32_t timeout) {
GpioPinSet(io->de, false);
uint16_t result = io->serialPortIo->receive(io->serialPortIo->env, data, size, timeout);
return result;
}
static uint16_t vSerialPortHalfDuplexTransmit(tSerialPortHalfDuplex *io, uint8_t *data, uint16_t size, uint32_t timeout) {
GpioPinSet(io->de, true);
uint16_t result = io->serialPortIo->transmit(io->serialPortIo->env, data, size, timeout);
#ifndef HALF_DUPLEX_NO_DELAY
// SystemDelayMs(5);
#else
#endif
GpioPinSet(io->de, false);
return result;
}
tSerialPortHalfDuplex vSerialPortHalfDuplexInit(
tSerialPortIO *serialPortIo, tGpioPin *de
) {
tSerialPortHalfDuplex port = {
.serialPortIo = serialPortIo,
.de = de,
};
return port;
}
tSerialPortIO vSerialPortHalfDuplexGetIo(tSerialPortHalfDuplex *serialPortHalfDuplex) {
tSerialPortIO io = {
.env = serialPortHalfDuplex,
.receive = (SerialPortIOTransaction) vSerialPortHalfDuplexReceive,
.transmit = (SerialPortIOTransaction) vSerialPortHalfDuplexTransmit
};
return io;
}

17
modular.json Normal file
View File

@ -0,0 +1,17 @@
{
"dep": [
{
"type": "git",
"provider": "HVAC_DEV",
"repo": "SerialPortInterface"
}
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}