Initial commit
This commit is contained in:
36
TMC2209/Tmc_uart.c
Normal file
36
TMC2209/Tmc_uart.c
Normal file
@@ -0,0 +1,36 @@
|
||||
// TMC_UART.c
|
||||
#include "TMC_uart.h"
|
||||
|
||||
|
||||
#define DEFAULT_UART_ID uart1
|
||||
#define DEFAULT_BAUD_RATE 115200
|
||||
#define DEFAULT_MOTOR_TX_PIN 4
|
||||
#define DEFAULT_MOTOR_RX_PIN 5
|
||||
|
||||
TMC_UART* tmc_Uart_Init(TMC_UART* tmc_uart, uart_inst_t *UART_ID, int BAUD_RATE, int MOTOR_TX_PIN, int MOTOR_RX_PIN) {
|
||||
|
||||
if (BAUD_RATE == -1) BAUD_RATE = DEFAULT_BAUD_RATE;
|
||||
if (MOTOR_TX_PIN == -1) MOTOR_TX_PIN = DEFAULT_MOTOR_TX_PIN;
|
||||
if (MOTOR_RX_PIN == -1) MOTOR_RX_PIN = DEFAULT_MOTOR_RX_PIN;
|
||||
|
||||
uart_init(UART_ID, BAUD_RATE);
|
||||
gpio_set_function(MOTOR_TX_PIN, GPIO_FUNC_UART);
|
||||
gpio_set_function(MOTOR_RX_PIN, GPIO_FUNC_UART);
|
||||
uart_set_hw_flow(UART_ID, false, false);
|
||||
uart_set_format(UART_ID, 8, 1, UART_PARITY_NONE);
|
||||
uart_set_fifo_enabled(UART_ID, false);
|
||||
|
||||
tmc_uart->UART_ID = UART_ID;
|
||||
tmc_uart->BAUD_RATE = BAUD_RATE;
|
||||
tmc_uart->MOTOR_TX_PIN = MOTOR_TX_PIN;
|
||||
tmc_uart->MOTOR_RX_PIN = MOTOR_RX_PIN;
|
||||
return tmc_uart;
|
||||
}
|
||||
|
||||
void TMC_UART_Write(TMC_UART* tmc_uart, int data) {
|
||||
uart_putc(tmc_uart->UART_ID, data);
|
||||
}
|
||||
|
||||
void TMC_UART_Destroy(TMC_UART* tmc_uart) {
|
||||
// Aucune opération nécessaire
|
||||
}
|
||||
Reference in New Issue
Block a user