aboutsummaryrefslogtreecommitdiff
path: root/drivers/chibios/serial_usart.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/chibios/serial_usart.h')
-rw-r--r--drivers/chibios/serial_usart.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/drivers/chibios/serial_usart.h b/drivers/chibios/serial_usart.h
new file mode 100644
index 000000000..fee7b4d15
--- /dev/null
+++ b/drivers/chibios/serial_usart.h
@@ -0,0 +1,90 @@
1/* Copyright 2021 QMK
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include "quantum.h"
20#include "serial.h"
21#include "printf.h"
22
23#include <ch.h>
24#include <hal.h>
25
26#ifndef USART_CR1_M0
27# define USART_CR1_M0 USART_CR1_M // some platforms (f1xx) dont have this so
28#endif
29
30#ifndef SERIAL_USART_CR1
31# define SERIAL_USART_CR1 (USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0) // parity enable, odd parity, 9 bit length
32#endif
33
34#ifndef SERIAL_USART_CR2
35# define SERIAL_USART_CR2 (USART_CR2_STOP_1) // 2 stop bits
36#endif
37
38#ifndef SERIAL_USART_CR3
39# define SERIAL_USART_CR3 0
40#endif
41
42#if defined(USART1_REMAP)
43# define USART_REMAP \
44 do { \
45 (AFIO->MAPR |= AFIO_MAPR_USART1_REMAP); \
46 } while (0)
47#elif defined(USART2_REMAP)
48# define USART_REMAP \
49 do { \
50 (AFIO->MAPR |= AFIO_MAPR_USART2_REMAP); \
51 } while (0)
52#elif defined(USART3_PARTIALREMAP)
53# define USART_REMAP \
54 do { \
55 (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_PARTIALREMAP); \
56 } while (0)
57#elif defined(USART3_FULLREMAP)
58# define USART_REMAP \
59 do { \
60 (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); \
61 } while (0)
62#endif
63
64#ifndef SELECT_SOFT_SERIAL_SPEED
65# define SELECT_SOFT_SERIAL_SPEED 1
66#endif
67
68#ifdef SERIAL_USART_SPEED
69// Allow advanced users to directly set SERIAL_USART_SPEED
70#elif SELECT_SOFT_SERIAL_SPEED == 0
71# define SERIAL_USART_SPEED 460800
72#elif SELECT_SOFT_SERIAL_SPEED == 1
73# define SERIAL_USART_SPEED 230400
74#elif SELECT_SOFT_SERIAL_SPEED == 2
75# define SERIAL_USART_SPEED 115200
76#elif SELECT_SOFT_SERIAL_SPEED == 3
77# define SERIAL_USART_SPEED 57600
78#elif SELECT_SOFT_SERIAL_SPEED == 4
79# define SERIAL_USART_SPEED 38400
80#elif SELECT_SOFT_SERIAL_SPEED == 5
81# define SERIAL_USART_SPEED 19200
82#else
83# error invalid SELECT_SOFT_SERIAL_SPEED value
84#endif
85
86#ifndef SERIAL_USART_TIMEOUT
87# define SERIAL_USART_TIMEOUT 100
88#endif
89
90#define HANDSHAKE_MAGIC 7