commit 95a70bd52f9c4aebe872aa571a4116ee6031bccb Author: cfif Date: Tue Sep 23 17:12:43 2025 +0300 Начало diff --git a/Inc/SerialPortHalfDuplexIO.h b/Inc/SerialPortHalfDuplexIO.h new file mode 100644 index 0000000..f6cd8ba --- /dev/null +++ b/Inc/SerialPortHalfDuplexIO.h @@ -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 diff --git a/Src/SerialPortHalfDuplexIO.c b/Src/SerialPortHalfDuplexIO.c new file mode 100644 index 0000000..684e892 --- /dev/null +++ b/Src/SerialPortHalfDuplexIO.c @@ -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; +} \ No newline at end of file diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..4f3ef15 --- /dev/null +++ b/modular.json @@ -0,0 +1,17 @@ +{ + "dep": [ + { + "type": "git", + "provider": "HVAC_DEV", + "repo": "SerialPortInterface" + } + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file