2021-03-19 14:05:04 -07:00
|
|
|
/**
|
|
|
|
* Implementation for hardware-serial TunerStudio ports
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tunerstudio_io.h"
|
|
|
|
|
2023-01-23 05:04:41 -08:00
|
|
|
#if defined(TS_PRIMARY_UxART_PORT) || defined(TS_SECONDARY_UxART_PORT)
|
2021-03-19 14:05:04 -07:00
|
|
|
#if HAL_USE_SERIAL
|
|
|
|
void SerialTsChannel::start(uint32_t baud) {
|
|
|
|
SerialConfig cfg = {
|
|
|
|
#if EFI_PROD_CODE
|
|
|
|
.speed = baud,
|
|
|
|
.cr1 = 0,
|
2024-06-17 03:14:32 -07:00
|
|
|
.cr2 = USART_CR2_STOP1_BITS,
|
2021-03-19 14:05:04 -07:00
|
|
|
.cr3 = 0
|
|
|
|
#endif // EFI_PROD_CODE
|
|
|
|
};
|
|
|
|
|
|
|
|
sdStart(m_driver, &cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SerialTsChannel::stop() {
|
|
|
|
sdStop(m_driver);
|
|
|
|
}
|
|
|
|
|
2022-10-15 22:21:44 -07:00
|
|
|
void SerialTsChannel::write(const uint8_t* buffer, size_t size, bool /*isEndOfPacket*/) {
|
2023-03-16 10:25:25 -07:00
|
|
|
size_t transferred = chnWriteTimeout(m_driver, buffer, size, BINARY_IO_TIMEOUT);
|
|
|
|
bytesOut += transferred;
|
2021-03-19 14:05:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t SerialTsChannel::readTimeout(uint8_t* buffer, size_t size, int timeout) {
|
2023-03-16 10:25:25 -07:00
|
|
|
size_t transferred = chnReadTimeout(m_driver, buffer, size, timeout);
|
|
|
|
bytesIn += transferred;
|
|
|
|
return transferred;
|
2021-03-19 14:05:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAL_USE_SERIAL
|
|
|
|
|
|
|
|
#if HAL_USE_UART
|
2023-03-16 14:39:03 -07:00
|
|
|
|
2021-03-19 14:05:04 -07:00
|
|
|
void UartTsChannel::start(uint32_t baud) {
|
|
|
|
m_config = {
|
|
|
|
.txend1_cb = NULL,
|
|
|
|
.txend2_cb = NULL,
|
|
|
|
.rxend_cb = NULL,
|
|
|
|
.rxchar_cb = NULL,
|
|
|
|
.rxerr_cb = NULL,
|
|
|
|
.timeout_cb = NULL,
|
2023-06-20 17:43:09 -07:00
|
|
|
#if defined(STM32F7XX)
|
|
|
|
.timeout = 0,
|
|
|
|
#endif
|
2021-03-19 14:05:04 -07:00
|
|
|
.speed = baud,
|
|
|
|
.cr1 = 0,
|
2023-03-16 10:44:26 -07:00
|
|
|
.cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN,
|
2021-03-19 14:05:04 -07:00
|
|
|
.cr3 = 0,
|
2023-06-20 21:11:08 -07:00
|
|
|
#if defined(STM32F4XX) || defined(CPU_MKE16F512VLH16)
|
2021-03-19 14:05:04 -07:00
|
|
|
.rxhalf_cb = NULL
|
2023-06-20 17:43:09 -07:00
|
|
|
#endif
|
2021-03-19 14:05:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
uartStart(m_driver, &m_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UartTsChannel::stop() {
|
|
|
|
uartStop(m_driver);
|
|
|
|
}
|
|
|
|
|
2021-10-18 16:59:08 -07:00
|
|
|
void UartTsChannel::write(const uint8_t* buffer, size_t size, bool) {
|
2023-03-16 10:25:25 -07:00
|
|
|
size_t transferred = uartSendTimeout(m_driver, &size, buffer, BINARY_IO_TIMEOUT);
|
|
|
|
bytesOut += transferred;
|
2021-03-19 14:05:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t UartTsChannel::readTimeout(uint8_t* buffer, size_t size, int timeout) {
|
2023-03-16 10:25:25 -07:00
|
|
|
// nasty in/out parameter approach:
|
|
|
|
// in entry: number of data frames to receive
|
|
|
|
// on exit the number of frames actually received
|
2021-03-19 14:05:04 -07:00
|
|
|
uartReceiveTimeout(m_driver, &size, buffer, timeout);
|
2023-03-16 10:25:25 -07:00
|
|
|
bytesIn += size;
|
2021-03-19 14:05:04 -07:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
#endif // HAL_USE_UART
|
2023-01-23 05:04:41 -08:00
|
|
|
#endif // defined(TS_PRIMARY_UxART_PORT) || defined(TS_SECONDARY_UxART_PORT)
|