-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbtt_skr_mini_e3_2.0.c
85 lines (59 loc) · 2.22 KB
/
btt_skr_mini_e3_2.0.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
btt_skr_mini_e3_2.0.c - driver code for STM32F103C8 ARM processors
Part of grblHAL
Copyright (c) 2021 Terje Io
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#include "driver.h"
#if TRINAMIC_ENABLE == 2209
#include <string.h>
#include "serial.h"
static io_stream_t tmc_uart;
TMC_uart_write_datagram_t *tmc_uart_read (trinamic_motor_t driver, TMC_uart_read_datagram_t *dgr)
{
static TMC_uart_write_datagram_t wdgr = {0};
volatile uint32_t dly = 50, ms = hal.get_elapsed_ticks();
tmc_uart.write_n((char *)dgr->data, sizeof(TMC_uart_read_datagram_t));
while(tmc_uart.get_tx_buffer_count());
while(--dly);
tmc_uart.reset_read_buffer();
// Wait for response with 3ms timeout
while(tmc_uart.get_rx_buffer_count() < 8) {
if(hal.get_elapsed_ticks() - ms >= 3)
break;
}
if(tmc_uart.get_rx_buffer_count() >= 8) {
wdgr.data[0] = tmc_uart.read();
wdgr.data[1] = tmc_uart.read();
wdgr.data[2] = tmc_uart.read();
wdgr.data[3] = tmc_uart.read();
wdgr.data[4] = tmc_uart.read();
wdgr.data[5] = tmc_uart.read();
wdgr.data[6] = tmc_uart.read();
wdgr.data[7] = tmc_uart.read();
} else
wdgr.msg.addr.value = 0xFF;
dly = 150;
while(--dly);
return &wdgr;
}
void tmc_uart_write (trinamic_motor_t driver, TMC_uart_write_datagram_t *dgr)
{
tmc_uart.write_n((char *)dgr->data, sizeof(TMC_uart_write_datagram_t));
while(tmc_uart.get_tx_buffer_count()); // Wait while the datagram is delivered
}
void board_init (void)
{
memcpy(&tmc_uart, serial2Init(), sizeof(io_stream_t));
tmc_uart.set_enqueue_rt_handler(stream_buffer_all);
}
#endif