diff options
| author | Dimitris Papavasiliou <dpapavas@protonmail.ch> | 2021-03-05 20:25:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-05 10:25:20 -0800 |
| commit | 73b8f85816c3209f6213e358a0d3737c7a73d45f (patch) | |
| tree | ccedda441d718021fcc2c366a5dd3bcf35f9adda /keyboards/handwired/lagrange/lagrange.c | |
| parent | aadea5ab97d4da9af1d75f39a15f5ce498034105 (diff) | |
| download | qmk_firmware-73b8f85816c3209f6213e358a0d3737c7a73d45f.tar.gz qmk_firmware-73b8f85816c3209f6213e358a0d3737c7a73d45f.zip | |
[Keyboard] Lagrange handwired keyboard (#11374)
* [Keyboard] Add the Lagrange keyboard
* Covert the master side to use the SPI driver.
Diffstat (limited to 'keyboards/handwired/lagrange/lagrange.c')
| -rw-r--r-- | keyboards/handwired/lagrange/lagrange.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/keyboards/handwired/lagrange/lagrange.c b/keyboards/handwired/lagrange/lagrange.c new file mode 100644 index 000000000..0c76512c5 --- /dev/null +++ b/keyboards/handwired/lagrange/lagrange.c | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | /* Copyright 2020 Dimitris Papavasiliou <dpapavas@protonmail.ch> | ||
| 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 <https://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <LUFA/Drivers/USB/USB.h> | ||
| 18 | |||
| 19 | #include "lagrange.h" | ||
| 20 | |||
| 21 | #ifndef SPLIT_USB_TIMEOUT_POLL | ||
| 22 | # define SPLIT_USB_TIMEOUT_POLL 10 | ||
| 23 | #endif | ||
| 24 | |||
| 25 | /* Instead of timing out, the slave waits indefinitely for the other | ||
| 26 | * side to signal that it has become master. This avoids both sides | ||
| 27 | * assuming the slave role when the USB port is powered but not | ||
| 28 | * otherwise active (e.g. when the host is turned off, or suspended). | ||
| 29 | * The SPI SS line is used for signaling. On power-up it is | ||
| 30 | * configured as input with pull-up enabled. When one side assumes | ||
| 31 | * the master role, it reconfigures the line for SPI, and pulls it low | ||
| 32 | * to select the slave, which doubles as the signal. */ | ||
| 33 | |||
| 34 | bool is_keyboard_master(void) { | ||
| 35 | static int8_t is_master = -1; | ||
| 36 | |||
| 37 | if (is_master < 0) { | ||
| 38 | while (readPin(SPI_SS_PIN)) { | ||
| 39 | if (USB_Device_IsAddressSet()) { | ||
| 40 | is_master = 1; | ||
| 41 | return is_master; | ||
| 42 | } | ||
| 43 | wait_ms(SPLIT_USB_TIMEOUT_POLL); | ||
| 44 | } | ||
| 45 | |||
| 46 | is_master = 0; | ||
| 47 | |||
| 48 | USB_Disable(); | ||
| 49 | USB_DeviceState = DEVICE_STATE_Unattached; | ||
| 50 | } | ||
| 51 | |||
| 52 | return is_master; | ||
| 53 | } | ||
| 54 | |||
| 55 | void keyboard_pre_init_kb(void) { | ||
| 56 | setPinInputHigh(SPI_SS_PIN); | ||
| 57 | |||
| 58 | keyboard_pre_init_user(); | ||
| 59 | } | ||
