|
|
|
/* -*- mode: c++ -*-
|
|
|
|
* Kaleidoscope-Hardware-KBDFans-KBD4x -- KBD4x hardware support for Kaleidoscope
|
|
|
|
* Copyright (C) 2019, 2020 Keyboard.io, Inc
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of version 3 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifdef ARDUINO_AVR_KBD4X
|
|
|
|
|
|
|
|
#define KALEIDOSCOPE_BOOTLOADER_FLIP_WORKAROUND 1
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
#include "kaleidoscope/device/ATmega32U4Keyboard.h"
|
|
|
|
#include "kaleidoscope/driver/bootloader/avr/FLIP.h"
|
|
|
|
#include "kaleidoscope/driver/keyscanner/ATmega.h"
|
|
|
|
|
|
|
|
namespace kaleidoscope {
|
|
|
|
namespace device {
|
|
|
|
namespace kbdfans {
|
|
|
|
|
|
|
|
struct KBD4xProps : kaleidoscope::device::ATmega32U4KeyboardProps {
|
|
|
|
struct MCUProps : public kaleidoscope::driver::mcu::ATmega32U4Props {
|
|
|
|
static constexpr bool disable_jtag = true;
|
Introduce MCU Properties
This introduces MCU properties, so that MCU drivers can change their behaviour
and/or setup tasks based on them, without having to write a `setup()` method or
a custom constructor for the top-level device.
In practice, this allows us to tell the MCU driver to - for example - disable
JTAG or clock division during setup, and thus, we won't need to do that in code
in the device constructor.
This is a breaking change, kind of, because the `mcu::Base` and
`mcu::ATmega32U4` drivers changed APIs. However, no device was using those
directly, only via `ATmega32U4Keyboard`, and those parts remain compatible.
While there, updated the `KBD4x` and `Splitography` devices to use the new
properties instead of a custom constructor.
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
5 years ago
|
|
|
static constexpr bool disable_clock_division = true;
|
|
|
|
};
|
|
|
|
typedef kaleidoscope::driver::mcu::ATmega32U4<MCUProps> MCU;
|
|
|
|
struct KeyScannerProps : public kaleidoscope::driver::keyscanner::ATmegaProps {
|
|
|
|
static constexpr uint8_t matrix_rows = 4;
|
|
|
|
static constexpr uint8_t matrix_columns = 12;
|
|
|
|
typedef MatrixAddr<matrix_rows, matrix_columns> KeyAddr;
|
|
|
|
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
|
|
|
|
static constexpr uint8_t matrix_row_pins[matrix_rows] = {PIN_D0, PIN_D1, PIN_D2, PIN_D3};
|
|
|
|
static constexpr uint8_t matrix_col_pins[matrix_columns] = {PIN_F0, PIN_F1, PIN_F4, PIN_F5, PIN_F6, PIN_F7, PIN_B3, PIN_B1, PIN_B0, PIN_D5, PIN_B7, PIN_C7};
|
|
|
|
#endif // KALEIDOSCOPE_VIRTUAL_BUILD
|
|
|
|
};
|
|
|
|
typedef kaleidoscope::driver::keyscanner::ATmega<KeyScannerProps> KeyScanner;
|
|
|
|
typedef kaleidoscope::driver::bootloader::avr::FLIP Bootloader;
|
|
|
|
static constexpr const char *short_name = "kbd4x";
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD
|
|
|
|
class KBD4x : public kaleidoscope::device::ATmega32U4Keyboard<KBD4xProps> {};
|
|
|
|
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
|
|
|
|
/* Device definition omitted for virtual device builds.
|
|
|
|
* We need to forward declare the device name, though, as there are
|
|
|
|
* some legacy extern references to boards whose definition
|
|
|
|
* depends on this.
|
|
|
|
*/
|
|
|
|
class KBD4x;
|
|
|
|
|
|
|
|
#endif // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
#define PER_KEY_DATA(dflt, \
|
|
|
|
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, \
|
|
|
|
R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \
|
|
|
|
R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \
|
|
|
|
R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C7, R3C8, R3C9, R3C10, R3C11 \
|
|
|
|
) \
|
|
|
|
R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, \
|
|
|
|
R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, \
|
|
|
|
R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \
|
|
|
|
R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C5, R3C7, R3C8, R3C9, R3C10, R3C11
|
|
|
|
// clang-format on
|
Standardize namespace block closing comments
This standardizes namespace closing brackets for namespace blocks. Each one is
on its own line, with a comment clearly marking which namespace it closes.
Consecutive lines closing namespace blocks have no whitespace between them, but
there is one blank line before and after a set of namespace block closing lines.
To generate the namespace comments, I used clang-format, with
`FixNamespaceComments: true`. But since clang-format can't exactly duplicate
our astyle formatting, it made lots of other changes, too. To isolate the
namespace comments from the other formatting changes, I first ran clang-format
with `FixNamespaceComments: false`, committed those changes, then ran it again
to generate the namespace comments. Then I stashed the namespace comments,
reset `HEAD` to remove the other changes, applied the stashed namespace
comments, and committed the results (after examining them and making a few minor
adjustments by hand).
Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
3 years ago
|
|
|
|
|
|
|
} // namespace kbdfans
|
|
|
|
} // namespace device
|
Redesign how the hardware objects are defined
Instead of having to define `HARDWARE_IMPLEMENTATION` to the class name of the
device, and define `KeyboardHardware` from within the plugin, let all devices
set `kaleidoscope::Device` to their own class via a typedef. Furthermore,
instead of `KeyboardHardware`, use `Kaleidoscope.device()` instead. This makes
device plugins a little bit simpler, and our naming more consistent.
Because some parts of the firmware need to access the device object before the
`Kaleidoscope` object is available, we can't make it a member of that. For this
reason, the device object is `kaleidoscope_internal::device`, and
`Kaleidoscope.device()` wraps it. In general, the wrapper should be used. But if
access to the device is required before `Kaleidoscope` is available, then that's
also available.
The `Kaleidoscope` object grew a few more wrappers: `storage()` and
`serialPort()`, so that one doesn't need to use `Kaleidoscope.device()`
directly, but can use the wrappers, which are noticably shorter to write.
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
5 years ago
|
|
|
|
|
|
|
EXPORT_DEVICE(kaleidoscope::device::kbdfans::KBD4x)
|
Redesign how the hardware objects are defined
Instead of having to define `HARDWARE_IMPLEMENTATION` to the class name of the
device, and define `KeyboardHardware` from within the plugin, let all devices
set `kaleidoscope::Device` to their own class via a typedef. Furthermore,
instead of `KeyboardHardware`, use `Kaleidoscope.device()` instead. This makes
device plugins a little bit simpler, and our naming more consistent.
Because some parts of the firmware need to access the device object before the
`Kaleidoscope` object is available, we can't make it a member of that. For this
reason, the device object is `kaleidoscope_internal::device`, and
`Kaleidoscope.device()` wraps it. In general, the wrapper should be used. But if
access to the device is required before `Kaleidoscope` is available, then that's
also available.
The `Kaleidoscope` object grew a few more wrappers: `storage()` and
`serialPort()`, so that one doesn't need to use `Kaleidoscope.device()`
directly, but can use the wrappers, which are noticably shorter to write.
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
5 years ago
|
|
|
|
Standardize namespace block closing comments
This standardizes namespace closing brackets for namespace blocks. Each one is
on its own line, with a comment clearly marking which namespace it closes.
Consecutive lines closing namespace blocks have no whitespace between them, but
there is one blank line before and after a set of namespace block closing lines.
To generate the namespace comments, I used clang-format, with
`FixNamespaceComments: true`. But since clang-format can't exactly duplicate
our astyle formatting, it made lots of other changes, too. To isolate the
namespace comments from the other formatting changes, I first ran clang-format
with `FixNamespaceComments: false`, committed those changes, then ran it again
to generate the namespace comments. Then I stashed the namespace comments,
reset `HEAD` to remove the other changes, applied the stashed namespace
comments, and committed the results (after examining them and making a few minor
adjustments by hand).
Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
3 years ago
|
|
|
} // namespace kaleidoscope
|
|
|
|
|
|
|
|
#endif
|