This commit is contained in:
cfif 2025-06-02 13:26:40 +03:00
commit f69ed3402e
3 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,20 @@
//
// 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 *transmitePin;
tGpioPin *recivePin;
} tSerialPortHalfDuplex;
tSerialPortHalfDuplex vSerialPortHalfDuplexInit(tSerialPortIO *serialPortIo, tGpioPin *transmitePin, tGpioPin *recivePin);
tSerialPortIO vSerialPortHalfDuplexGetIo(tSerialPortHalfDuplex *serialPortHalfDuplex);
#endif //MODULE_SERIALPORTHALFDUPLEXIO_H

View File

@ -0,0 +1,75 @@
//
// 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) {
// tSerialPortHalfDuplex *serialPortHalfDuplex = (void *) io;
GpioPinSet(io->transmitePin, false);
GpioPinSet(io->recivePin, true);
uint16_t result = io->serialPortIo->receive(io->serialPortIo->env, data, size, timeout);
return result;
}
/*
static uint16_t vSerialPortHalfDuplexTransmit(tSerialPortIO *io, uint8_t *data, uint16_t size, uint32_t timeout) {
tSerialPortHalfDuplex *serialPortHalfDuplex = io->env;
GpioPinSet(serialPortHalfDuplex->transmitePin, true);
GpioPinSet(serialPortHalfDuplex->recivePin, false);
uint16_t result = serialPortHalfDuplex->serialPortIo->transmit(serialPortHalfDuplex->serialPortIo->env, data, size, timeout);
return result;
}
*/
static uint16_t vSerialPortHalfDuplexTransmit(tSerialPortHalfDuplex *io, uint8_t *data, uint16_t size, uint32_t timeout) {
// tSerialPortHalfDuplex *serialPortHalfDuplex = (void *) io;
GpioPinSet(io->recivePin, false);
GpioPinSet(io->transmitePin, true);
uint16_t result = io->serialPortIo->transmit(io->serialPortIo->env, data, size, timeout);
#ifndef HALF_DUPLEX_NO_DELAY
SystemDelayMs(5);
#else
#endif
GpioPinSet(io->transmitePin, false);
GpioPinSet(io->recivePin, true);
return result;
}
tSerialPortHalfDuplex vSerialPortHalfDuplexInit(
tSerialPortIO *serialPortIo, tGpioPin *transmitePin, tGpioPin *recivePin
) {
tSerialPortHalfDuplex port = {
.serialPortIo = serialPortIo,
.transmitePin = transmitePin,
.recivePin = recivePin
};
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": "Smart_Components_Aurus",
"repo": "SerialPortInterface"
}
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}