Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SN32: Add UART support #384

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions keyboards/handwired/splittest/sn32f240b/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 Dimitris Mantzouranis (@dexter93)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#define SPLIT_HAND_PIN A7

#if !(defined(USE_SDI0) || defined(USE_SDI1) || defined(USE_SDI2))
#define USE_SDI0
#endif
13 changes: 13 additions & 0 deletions keyboards/handwired/splittest/sn32f240b/halconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2024 Dimitris Mantzouranis (@dexter93)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

/* Needed for serial bitbang, half-duplex and full-duplex */
#define HAL_USE_PAL TRUE
// Needed for serial bitbang
//#define PAL_USE_WAIT TRUE
//#define PAL_USE_CALLBACKS TRUE
#include_next <halconf.h>
#undef HAL_USE_PWM
#define HAL_USE_PWM FALSE
15 changes: 15 additions & 0 deletions keyboards/handwired/splittest/sn32f240b/keyboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"matrix_pins": {
"cols": ["B1"],
"rows": ["B10"]
},
"diode_direction": "COL2ROW",
"processor": "SN32F248BF",
"bootloader": "sn32-dfu",
"features": {
"bootmagic": false,
"mousekey": false,
"extrakey": false,
"console": true
}
}
18 changes: 18 additions & 0 deletions keyboards/handwired/splittest/sn32f240b/mcuconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2024 Dimitris Mantzouranis (@dexter93)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include_next <mcuconf.h>

// These are needed if the communication is on the SD0 UART, either with standard or alternate pins
#undef SN32_SERIAL_USE_UART0
#define SN32_SERIAL_USE_UART0 TRUE

// These are needed if the communication is on the SD1 UART, either with standard or alternate pins
//#undef SN32_SERIAL_USE_UART1
//#define SN32_SERIAL_USE_UART1 TRUE

// These are needed if the communication is on the SD2 UART, either with standard or alternate pins
//#undef SN32_SERIAL_USE_UART2
//#define SN32_SERIAL_USE_UART2 TRUE
26 changes: 26 additions & 0 deletions keyboards/handwired/splittest/sn32f240b/post_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 Dimitris Mantzouranis (@dexter93)
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#if defined(SPLIT_SERIAL_FULLDUPLEX)
# define SERIAL_USART_FULL_DUPLEX // Enable full duplex operation mode.
#endif
#if defined(SPLIT_SERIAL_HALFDUPLEX) || defined(SPLIT_SERIAL_FULLDUPLEX)
# if defined(USE_SDI0)
# define SOFT_SERIAL_PIN A10
# define SERIAL_USART_RX_PIN A11 // USART RX pin
# define SERIAL_USART_DRIVER SD0
# elif defined(USE_SDI1)
# define SOFT_SERIAL_PIN B9
# define SERIAL_USART_RX_PIN B8 // USART RX pin
# elif defined(USE_SDI2)
# define SOFT_SERIAL_PIN A1
# define SERIAL_USART_RX_PIN A0 // USART RX pin
# define SERIAL_USART_DRIVER SD2 // USART driver of TX and RX pin. default: SD1
# else
# error "splittest serial keymap is missing a configuration"
# endif
#else // defined(SPLIT_BITBANG)
# define SOFT_SERIAL_PIN B8
#endif
66 changes: 66 additions & 0 deletions keyboards/handwired/splittest/sn32f240b/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# sn32f240b splittest

This is the splittest example for the sn32f240b MCU.
To trigger keypress, short together pins _B10_ and _B1_.

## Keyboard Configuration

The type of communication (bitbang, serial (half/full duplex)) is set by the keymap `config.h` file with variables with `SPLIT_` prefix.
So this example uses:

- `config.h` to set which SDI to use for serial. Either define `USE_SDI0`, `USE_SDI1` or `USE_SDI2` before the `#ifdef` that configures the default case when none of these variable is defined.
- `post_config.h` for defining the communication pins between the halves once the keymap is configured.

On your keyboard, you most likely will only use `config.h` because you'd have already chosen your communication scheme: serial type, SDI, pins.

## Wiring

### Switches

- Add switches to both sn32f240b across B10 and B1 pins

### Handedness

Have a look at the [handedness documentation](https://docs.qmk.fm/#/feature_split_keyboard?id=setting-handedness)

- Add pull-up resistor to left side between VCC and A7
- Add pull-down resistors to right side between GND and A7

### Send power to the other half

- Connect the following pins on both sides together: GND, VCC

### Halves data connection

Choose one of the connection type

#### serial - bitbang

- Connect the B8 pins on both sides together
- Note that bitbang functionality requires strict timings. Currently not supported.

#### serial - usart half duplex

Check the [documentation](https://docs.qmk.fm/#/serial_driver?id=usart-half-duplex) to determine the pull-up resistor.

- To use the default usart (UART0),
- Connect the A10, A11 pins on both sides together and to add a pull-up resistor on one of these pins
- Define USE_SDI0 in config.h
- To use the second usart (UART1),
- Connect the B8, B9 pins on both sides together and to add a pull-up resistor on one of these pins
- Define USE_SDI1 in config.h
- To use the third usart (UART2),
- Connect the A0, A1 pins on both sides together and to add a pull-up resistor on one of these pins
- Define USE_SDI1 in config.h

#### serial - usart full duplex

- To use the default usart (UART0),
- Connect the pins on A10, A11 one to the other on each side
- Define USE_SDI0 in config.h
- To use the second usart (UART1),
- Connect the pins B8, B9 one to the other on each side
- Define USE_SDI1 in config.h
- To use the third usart2 (UART2) pins,
- Connect the pins A0, A1 one to the other on each side
- Define USE_SDI2 in config.h
24 changes: 24 additions & 0 deletions platforms/chibios/drivers/serial_usart.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 QMK

Check failure on line 1 in platforms/chibios/drivers/serial_usart.c

View workflow job for this annotation

GitHub Actions / lint

Requires Formatting
// Copyright 2022 Stefan Kerkmann
// SPDX-License-Identifier: GPL-2.0-or-later

Expand Down Expand Up @@ -35,6 +35,23 @@
.UARTDMACR = 0U
};
// clang-format on
#elif defined(MCU_SN32) /* SN32F2 MCUs */
// clang-format off
static QMKSerialConfig serial_config = {
.speed = (SERIAL_USART_SPEED),
.UART_WordLength = (UART_WordLength_8b),
.UART_StopBits = (UART_StopBits_Two),
.UART_Parity = (UART_Parity_Enable|UART_Parity_Even),
.UART_FIFOControl = (UART_RxFIFOThreshold_1),
.UART_AutoBaudControl = (UART_AutoBaudControl_None),
.UART_Oversampling = (UART_Oversample_8),
# if !defined(SERIAL_USART_FULL_DUPLEX)
.UART_HalfDuplexMode = (UART_HalfDuplexEnable)
# else
.UART_HalfDuplexMode = (UART_FullDuplexEnable)
# endif
};
// clang-format on
#else
# error MCU Familiy not supported by default, supply your own serial_config by defining SERIAL_USART_CONFIG in your keyboard files.
#endif
Expand Down Expand Up @@ -172,6 +189,10 @@
# endif
# elif defined(MCU_RP) /* Raspberry Pi MCUs */
# error Half-duplex with the SIO driver is not supported due to hardware limitations on the RP2040, switch to the PIO driver which has half-duplex support.
# elif defined(MCU_SN32) /* SN32F2 MCUs */
// Hardware limitations, we can use one wire, but both TX and RX pins should be connected
// SN32 family autoconfigures the TX pin
palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT);
# else
# pragma message "usart_init: MCU Familiy not supported by default, please supply your own init code by implementing usart_init() in your keyboard files."
# endif
Expand All @@ -198,6 +219,9 @@
# elif defined(MCU_RP) /* Raspberry Pi MCUs */
palSetLineMode(SERIAL_USART_TX_PIN, PAL_MODE_ALTERNATE_UART);
palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_ALTERNATE_UART);
# elif defined(MCU_SN32) /* SN32F2 MCUs */
// SN32 family autoconfigures the TX pin
palSetLineMode(SERIAL_USART_RX_PIN, PAL_MODE_INPUT);
# else
# pragma message "usart_init: MCU Familiy not supported by default, please supply your own init code by implementing usart_init() in your keyboard files."
# endif
Expand Down
Loading