diff --git a/keyboards/handwired/splittest/sn32f240b/config.h b/keyboards/handwired/splittest/sn32f240b/config.h new file mode 100644 index 000000000000..7a2ba5ab1496 --- /dev/null +++ b/keyboards/handwired/splittest/sn32f240b/config.h @@ -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 \ No newline at end of file diff --git a/keyboards/handwired/splittest/sn32f240b/halconf.h b/keyboards/handwired/splittest/sn32f240b/halconf.h new file mode 100644 index 000000000000..ecbe196c6363 --- /dev/null +++ b/keyboards/handwired/splittest/sn32f240b/halconf.h @@ -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 +#undef HAL_USE_PWM +#define HAL_USE_PWM FALSE \ No newline at end of file diff --git a/keyboards/handwired/splittest/sn32f240b/keyboard.json b/keyboards/handwired/splittest/sn32f240b/keyboard.json new file mode 100644 index 000000000000..ed3fc7cc8c7d --- /dev/null +++ b/keyboards/handwired/splittest/sn32f240b/keyboard.json @@ -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 + } +} \ No newline at end of file diff --git a/keyboards/handwired/splittest/sn32f240b/mcuconf.h b/keyboards/handwired/splittest/sn32f240b/mcuconf.h new file mode 100644 index 000000000000..51ef4a47ffb4 --- /dev/null +++ b/keyboards/handwired/splittest/sn32f240b/mcuconf.h @@ -0,0 +1,18 @@ +// Copyright 2024 Dimitris Mantzouranis (@dexter93) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include_next + +// 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 \ No newline at end of file diff --git a/keyboards/handwired/splittest/sn32f240b/post_config.h b/keyboards/handwired/splittest/sn32f240b/post_config.h new file mode 100644 index 000000000000..29165cc42694 --- /dev/null +++ b/keyboards/handwired/splittest/sn32f240b/post_config.h @@ -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 \ No newline at end of file diff --git a/keyboards/handwired/splittest/sn32f240b/readme.md b/keyboards/handwired/splittest/sn32f240b/readme.md new file mode 100644 index 000000000000..c579e9557d6e --- /dev/null +++ b/keyboards/handwired/splittest/sn32f240b/readme.md @@ -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 \ No newline at end of file diff --git a/platforms/chibios/drivers/serial_usart.c b/platforms/chibios/drivers/serial_usart.c index 767ef8726fc3..f4cfcb445ece 100644 --- a/platforms/chibios/drivers/serial_usart.c +++ b/platforms/chibios/drivers/serial_usart.c @@ -35,6 +35,23 @@ static QMKSerialConfig serial_config = { .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 @@ -172,6 +189,10 @@ __attribute__((weak)) void usart_init(void) { # 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 @@ -198,6 +219,9 @@ __attribute__((weak)) void usart_init(void) { # 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