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.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/drivers/chibios/serial_usart.h b/drivers/chibios/serial_usart.h
new file mode 100644
index 000000000..d35b5d12c
--- /dev/null
+++ b/drivers/chibios/serial_usart.h
@@ -0,0 +1,78 @@
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 do { (AFIO->MAPR |= AFIO_MAPR_USART1_REMAP); } while(0)
44#elif defined(USART2_REMAP)
45# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART2_REMAP); } while(0)
46#elif defined(USART3_PARTIALREMAP)
47# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_PARTIALREMAP); } while(0)
48#elif defined(USART3_FULLREMAP)
49# define USART_REMAP do { (AFIO->MAPR |= AFIO_MAPR_USART3_REMAP_FULLREMAP); } while(0)
50#endif
51
52#ifndef SELECT_SOFT_SERIAL_SPEED
53# define SELECT_SOFT_SERIAL_SPEED 1
54#endif
55
56#ifdef SERIAL_USART_SPEED
57// Allow advanced users to directly set SERIAL_USART_SPEED
58#elif SELECT_SOFT_SERIAL_SPEED == 0
59# define SERIAL_USART_SPEED 460800
60#elif SELECT_SOFT_SERIAL_SPEED == 1
61# define SERIAL_USART_SPEED 230400
62#elif SELECT_SOFT_SERIAL_SPEED == 2
63# define SERIAL_USART_SPEED 115200
64#elif SELECT_SOFT_SERIAL_SPEED == 3
65# define SERIAL_USART_SPEED 57600
66#elif SELECT_SOFT_SERIAL_SPEED == 4
67# define SERIAL_USART_SPEED 38400
68#elif SELECT_SOFT_SERIAL_SPEED == 5
69# define SERIAL_USART_SPEED 19200
70#else
71# error invalid SELECT_SOFT_SERIAL_SPEED value
72#endif
73
74#ifndef SERIAL_USART_TIMEOUT
75# define SERIAL_USART_TIMEOUT 100
76#endif
77
78#define HANDSHAKE_MAGIC 7