Compare commits
45 Commits
Author | SHA1 | Date | |
---|---|---|---|
07c75feba3 | |||
b5aa5e4338 | |||
be8443b35b | |||
4b10235f67 | |||
6ef13f83e2 | |||
be2f5816b6 | |||
ff213d5fe1 | |||
3234118e52 | |||
a1ffc40b36 | |||
8fe5c718b4 | |||
38f14c4174 | |||
eb683c8c52 | |||
21799be1ca | |||
5cfc3ce02e | |||
724f20ed32 | |||
c61f016fa4 | |||
ea7e40bae1 | |||
974f83ec4b | |||
400ca2d035 | |||
e409fb47f2 | |||
ae74922d14 | |||
3349a8b49b | |||
b4ef72423e | |||
f4b67cde8a | |||
0a643be39e | |||
6c8e205fc0 | |||
7901006753 | |||
9bfa713421 | |||
b6fc3ad8e7 | |||
d1190df10b | |||
6add103827 | |||
7642075fc3 | |||
ca91dc594b | |||
26cb83b8c0 | |||
2392ddb76b | |||
6de77141a4 | |||
6f6c2e1c5c | |||
48cad94d7e | |||
90665aeec9 | |||
845953cc67 | |||
c3c2eb71e1 | |||
28a6a4a15b | |||
ccb37f673a | |||
781308507d | |||
3fe8d604a4 |
59
bin/qmk
59
bin/qmk
@ -4,38 +4,59 @@
|
||||
import os
|
||||
import sys
|
||||
from importlib.util import find_spec
|
||||
from pathlib import Path
|
||||
|
||||
# Add the QMK python libs to our path
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
qmk_dir = os.path.abspath(os.path.join(script_dir, '..'))
|
||||
python_lib_dir = os.path.abspath(os.path.join(qmk_dir, 'lib', 'python'))
|
||||
sys.path.append(python_lib_dir)
|
||||
script_dir = Path(os.path.realpath(__file__)).parent
|
||||
qmk_dir = script_dir.parent
|
||||
python_lib_dir = Path(qmk_dir / 'lib' / 'python').resolve()
|
||||
sys.path.append(str(python_lib_dir))
|
||||
|
||||
# Make sure our modules have been setup
|
||||
with open(os.path.join(qmk_dir, 'requirements.txt'), 'r') as fd:
|
||||
for line in fd.readlines():
|
||||
line = line.strip().replace('<', '=').replace('>', '=')
|
||||
|
||||
if line[0] == '#':
|
||||
continue
|
||||
def _check_modules(requirements):
|
||||
""" Check if the modules in the given requirements.txt are available.
|
||||
"""
|
||||
with Path(qmk_dir / requirements).open() as fd:
|
||||
for line in fd.readlines():
|
||||
line = line.strip().replace('<', '=').replace('>', '=')
|
||||
|
||||
if '#' in line:
|
||||
line = line.split('#')[0]
|
||||
if len(line) == 0 or line[0] == '#' or line.startswith('-r'):
|
||||
continue
|
||||
|
||||
module = line.split('=')[0] if '=' in line else line
|
||||
if '#' in line:
|
||||
line = line.split('#')[0]
|
||||
|
||||
module = dict()
|
||||
module['name'] = module['import'] = line.split('=')[0] if '=' in line else line
|
||||
|
||||
if module in ['pep8-naming']:
|
||||
# Not every module is importable by its own name.
|
||||
continue
|
||||
if module['name'] == "pep8-naming":
|
||||
module['import'] = "pep8ext_naming"
|
||||
|
||||
if not find_spec(module):
|
||||
print('Could not find module %s!' % module)
|
||||
print('Please run `pip3 install -r requirements.txt` to install the python dependencies.')
|
||||
exit(255)
|
||||
if not find_spec(module['import']):
|
||||
print('Could not find module %s!' % module['name'])
|
||||
print('Please run `python3 -m pip install -r %s` to install required python dependencies.' % str(qmk_dir / requirements))
|
||||
if developer:
|
||||
print('You can also turn off developer mode: qmk config user.developer=None')
|
||||
print()
|
||||
exit(255)
|
||||
|
||||
|
||||
developer = False
|
||||
# Make sure our modules have been setup
|
||||
_check_modules('requirements.txt')
|
||||
|
||||
# Setup the CLI
|
||||
import milc # noqa
|
||||
|
||||
# For developers additional modules are needed
|
||||
if milc.cli.config.user.developer:
|
||||
# Do not run the check for 'config',
|
||||
# so users can turn off developer mode
|
||||
if len(sys.argv) == 1 or (len(sys.argv) > 1 and 'config' != sys.argv[1]):
|
||||
developer = True
|
||||
_check_modules('requirements-dev.txt')
|
||||
|
||||
milc.EMOJI_LOGLEVELS['INFO'] = '{fg_blue}Ψ{style_reset_all}'
|
||||
|
||||
|
||||
|
@ -121,6 +121,7 @@
|
||||
* [Drivers](hardware_drivers.md)
|
||||
* [ADC Driver](adc_driver.md)
|
||||
* [I2C Driver](i2c_driver.md)
|
||||
* [SPI Driver](spi_driver.md)
|
||||
* [WS2812 Driver](ws2812_driver.md)
|
||||
* [EEPROM Driver](eeprom_driver.md)
|
||||
* [GPIO Controls](internals_gpio_control.md)
|
||||
|
@ -1,38 +1,6 @@
|
||||
# QMK CLI Commands
|
||||
|
||||
# CLI Commands
|
||||
|
||||
## `qmk cformat`
|
||||
|
||||
This command formats C code using clang-format.
|
||||
|
||||
Run it with no arguments to format all core code that has been changed. Default checks `origin/master` with `git diff`, branch can be changed using `-b <branch_name>`
|
||||
|
||||
Run it with `-a` to format all core code, or pass filenames on the command line to run it on specific files.
|
||||
|
||||
**Usage for specified files**:
|
||||
|
||||
```
|
||||
qmk cformat [file1] [file2] [...] [fileN]
|
||||
```
|
||||
|
||||
**Usage for all core files**:
|
||||
|
||||
```
|
||||
qmk cformat -a
|
||||
```
|
||||
|
||||
**Usage for only changed files against origin/master**:
|
||||
|
||||
```
|
||||
qmk cformat
|
||||
```
|
||||
|
||||
**Usage for only changed files against branch_name**:
|
||||
|
||||
```
|
||||
qmk cformat -b branch_name
|
||||
```
|
||||
# User Commands
|
||||
|
||||
## `qmk compile`
|
||||
|
||||
@ -136,16 +104,6 @@ This command lets you configure the behavior of QMK. For the full `qmk config` d
|
||||
qmk config [-ro] [config_token1] [config_token2] [...] [config_tokenN]
|
||||
```
|
||||
|
||||
## `qmk docs`
|
||||
|
||||
This command starts a local HTTP server which you can use for browsing or improving the docs. Default port is 8936.
|
||||
|
||||
**Usage**:
|
||||
|
||||
```
|
||||
qmk docs [-p PORT]
|
||||
```
|
||||
|
||||
## `qmk doctor`
|
||||
|
||||
This command examines your environment and alerts you to potential build or flash problems. It can fix many of them if you want it to.
|
||||
@ -180,28 +138,6 @@ Creates a keymap.c from a QMK Configurator export.
|
||||
qmk json2c [-o OUTPUT] filename
|
||||
```
|
||||
|
||||
## `qmk kle2json`
|
||||
|
||||
This command allows you to convert from raw KLE data to QMK Configurator JSON. It accepts either an absolute file path, or a file name in the current directory. By default it will not overwrite `info.json` if it is already present. Use the `-f` or `--force` flag to overwrite.
|
||||
|
||||
**Usage**:
|
||||
|
||||
```
|
||||
qmk kle2json [-f] <filename>
|
||||
```
|
||||
|
||||
**Examples**:
|
||||
|
||||
```
|
||||
$ qmk kle2json kle.txt
|
||||
☒ File info.json already exists, use -f or --force to overwrite.
|
||||
```
|
||||
|
||||
```
|
||||
$ qmk kle2json -f kle.txt -f
|
||||
Ψ Wrote out to info.json
|
||||
```
|
||||
|
||||
## `qmk list-keyboards`
|
||||
|
||||
This command lists all the keyboards currently defined in `qmk_firmware`
|
||||
@ -232,6 +168,74 @@ This command creates a new keymap based on a keyboard's existing default keymap.
|
||||
qmk new-keymap [-kb KEYBOARD] [-km KEYMAP]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Developer Commands
|
||||
|
||||
## `qmk cformat`
|
||||
|
||||
This command formats C code using clang-format.
|
||||
|
||||
Run it with no arguments to format all core code that has been changed. Default checks `origin/master` with `git diff`, branch can be changed using `-b <branch_name>`
|
||||
|
||||
Run it with `-a` to format all core code, or pass filenames on the command line to run it on specific files.
|
||||
|
||||
**Usage for specified files**:
|
||||
|
||||
```
|
||||
qmk cformat [file1] [file2] [...] [fileN]
|
||||
```
|
||||
|
||||
**Usage for all core files**:
|
||||
|
||||
```
|
||||
qmk cformat -a
|
||||
```
|
||||
|
||||
**Usage for only changed files against origin/master**:
|
||||
|
||||
```
|
||||
qmk cformat
|
||||
```
|
||||
|
||||
**Usage for only changed files against branch_name**:
|
||||
|
||||
```
|
||||
qmk cformat -b branch_name
|
||||
```
|
||||
|
||||
## `qmk docs`
|
||||
|
||||
This command starts a local HTTP server which you can use for browsing or improving the docs. Default port is 8936.
|
||||
|
||||
**Usage**:
|
||||
|
||||
```
|
||||
qmk docs [-p PORT]
|
||||
```
|
||||
|
||||
## `qmk kle2json`
|
||||
|
||||
This command allows you to convert from raw KLE data to QMK Configurator JSON. It accepts either an absolute file path, or a file name in the current directory. By default it will not overwrite `info.json` if it is already present. Use the `-f` or `--force` flag to overwrite.
|
||||
|
||||
**Usage**:
|
||||
|
||||
```
|
||||
qmk kle2json [-f] <filename>
|
||||
```
|
||||
|
||||
**Examples**:
|
||||
|
||||
```
|
||||
$ qmk kle2json kle.txt
|
||||
☒ File info.json already exists, use -f or --force to overwrite.
|
||||
```
|
||||
|
||||
```
|
||||
$ qmk kle2json -f kle.txt -f
|
||||
Ψ Wrote out to info.json
|
||||
```
|
||||
|
||||
## `qmk pyformat`
|
||||
|
||||
This command formats python code in `qmk_firmware`.
|
||||
@ -251,3 +255,4 @@ This command runs the python test suite. If you make changes to python code you
|
||||
```
|
||||
qmk pytest
|
||||
```
|
||||
|
||||
|
@ -6,6 +6,18 @@ This document has useful information for developers wishing to write new `qmk` s
|
||||
|
||||
The QMK CLI operates using the subcommand pattern made famous by git. The main `qmk` script is simply there to setup the environment and pick the correct entrypoint to run. Each subcommand is a self-contained module with an entrypoint (decorated by `@cli.subcommand()`) that performs some action and returns a shell returncode, or None.
|
||||
|
||||
## Developer mode:
|
||||
|
||||
If you intend to maintain keyboards and/or contribute to QMK, you can enable the CLI's "Developer" mode:
|
||||
|
||||
`qmk config user.developer=True`
|
||||
|
||||
This will allow you to see all available subcommands.
|
||||
**Note:** You will have to install additional requirements:
|
||||
```bash
|
||||
python3 -m pip install -r requirements-dev.txt
|
||||
```
|
||||
|
||||
# Subcommands
|
||||
|
||||
[MILC](https://github.com/clueboard/milc) is the CLI framework `qmk` uses to handle argument parsing, configuration, logging, and many other features. It lets you focus on writing your tool without wasting your time writing glue code.
|
||||
|
@ -20,11 +20,11 @@ Most of our style is pretty easy to pick up on, but right now it's not entirely
|
||||
* We accept both forms of preprocessor if's: `#ifdef DEFINED` and `#if defined(DEFINED)`
|
||||
* If you are not sure which to prefer use the `#if defined(DEFINED)` form.
|
||||
* Do not change existing code from one style to the other, except when moving to a multiple condition `#if`.
|
||||
* Do not put whitespace between `#` and `if`.
|
||||
* When deciding how (or if) to indent directives keep these points in mind:
|
||||
* Readability is more important than consistency.
|
||||
* Follow the file's existing style. If the file is mixed follow the style that makes sense for the section you are modifying.
|
||||
* When choosing to indent you can follow the indention level of the surrounding C code, or preprocessor directives can have their own indent level. Choose the style that best communicates the intent of your code.
|
||||
* When deciding how (or if) to indent preprocessor directives, keep these points in mind:
|
||||
* Readability is more important than consistency.
|
||||
* Follow the file's existing style. If the file is mixed, follow the style that makes sense for the section you are modifying.
|
||||
* When indenting, keep the hash at the start of the line and add whitespace between `#` and `if`, starting with 4 spaces after the `#`.
|
||||
* You can follow the indention level of the surrounding C code, or preprocessor directives can have their own indentation levels. Choose the style that best communicates the intent of your code.
|
||||
|
||||
Here is an example for easy reference:
|
||||
|
||||
|
@ -115,9 +115,9 @@ If you define these options you will disable the associated feature, which can s
|
||||
* `#define NO_ACTION_ONESHOT`
|
||||
* disable one-shot modifiers
|
||||
* `#define NO_ACTION_MACRO`
|
||||
* disable old style macro handling: MACRO() & action_get_macro
|
||||
* disable old-style macro handling using `MACRO()`, `action_get_macro()` _(deprecated)_
|
||||
* `#define NO_ACTION_FUNCTION`
|
||||
* disable calling of action_function() from the fn_actions array (deprecated)
|
||||
* disable old-style function handling using `fn_actions`, `action_function()` _(deprecated)_
|
||||
|
||||
## Features That Can Be Enabled
|
||||
|
||||
@ -317,10 +317,10 @@ This is a [make](https://www.gnu.org/software/make/manual/make.html) file that i
|
||||
* `LAYOUTS`
|
||||
* A list of [layouts](feature_layouts.md) this keyboard supports.
|
||||
* `LINK_TIME_OPTIMIZATION_ENABLE`
|
||||
* Enables Link Time Optimization (`LTO`) when compiling the keyboard. This makes the process take longer, but can significantly reduce the compiled size (and since the firmware is small, the added time is not noticeable). However, this will automatically disable the old Macros and Functions features automatically, as these break when `LTO` is enabled.
|
||||
It does this by automatically defining `NO_ACTION_MACRO` and `NO_ACTION_FUNCTION`
|
||||
* Enables Link Time Optimization (LTO) when compiling the keyboard. This makes the process take longer, but it can significantly reduce the compiled size (and since the firmware is small, the added time is not noticeable).
|
||||
However, this will automatically disable the legacy TMK Macros and Functions features, as these break when LTO is enabled. It does this by automatically defining `NO_ACTION_MACRO` and `NO_ACTION_FUNCTION`. (Note: This does not affect QMK [Macros](feature_macros.md) and [Layers](feature_layers.md).)
|
||||
* `LTO_ENABLE`
|
||||
* It has the same meaning as LINK_TIME_OPTIMIZATION_ENABLE. You can use `LTO_ENABLE` instead of `LINK_TIME_OPTIMIZATION_ENABLE`.
|
||||
* Has the same meaning as `LINK_TIME_OPTIMIZATION_ENABLE`. You can use `LTO_ENABLE` instead of `LINK_TIME_OPTIMIZATION_ENABLE`.
|
||||
|
||||
## AVR MCU Options
|
||||
* `MCU = atmega32u4`
|
||||
|
@ -98,6 +98,7 @@
|
||||
* [ISP Flashing Guide](de/isp_flashing_guide.md)
|
||||
* [ARM Debugging Guide](de/arm_debugging.md)
|
||||
* [I2C Driver](de/i2c_driver.md)
|
||||
* [SPI Driver](de/spi_driver.md)
|
||||
* [GPIO Controls](de/internals_gpio_control.md)
|
||||
* [Proton C Conversion](de/proton_c_conversion.md)
|
||||
|
||||
|
@ -98,6 +98,7 @@
|
||||
* [Guía de flasheado de ISP](es/isp_flashing_guide.md)
|
||||
* [Guía de depuración de ARM](es/arm_debugging.md)
|
||||
* [Driver I2C](es/i2c_driver.md)
|
||||
* [Driver SPI](es/spi_driver.md)
|
||||
* [Controles GPIO](es/internals_gpio_control.md)
|
||||
* [Conversión Proton C](es/proton_c_conversion.md)
|
||||
|
||||
|
@ -266,6 +266,25 @@ To reverse the scroll axes you can put:
|
||||
|
||||
into config.h.
|
||||
|
||||
### Rotate Mouse Axes :id=rotate-mouse-axes
|
||||
|
||||
Transform the output of the device with a clockwise rotation of 90, 180, or 270
|
||||
degrees.
|
||||
|
||||
When compensating for device orientation, rotate the output the same amount in
|
||||
the opposite direction. E.g. if the normal device orientation is considered to
|
||||
be North-facing, compensate as follows:
|
||||
|
||||
```c
|
||||
#define PS2_MOUSE_ROTATE 270 /* Compensate for East-facing device orientation. */
|
||||
```
|
||||
```c
|
||||
#define PS2_MOUSE_ROTATE 180 /* Compensate for South-facing device orientation. */
|
||||
```
|
||||
```c
|
||||
#define PS2_MOUSE_ROTATE 90 /* Compensate for West-facing device orientation. */
|
||||
```
|
||||
|
||||
### Debug Settings :id=debug-settings
|
||||
|
||||
To debug the mouse, add `debug_mouse = true` or enable via bootmagic.
|
||||
|
@ -101,7 +101,8 @@
|
||||
* [Guide des claviers soudés à la main](fr-fr/hand_wire.md)
|
||||
* [Guide de flash de l’ISP](fr-fr/isp_flashing_guide.md)
|
||||
* [Guide du débogage ARM](fr-fr/arm_debugging.md)
|
||||
* [Drivers i2c](fr-fr/i2c_driver.md)
|
||||
* [Drivers I2C](fr-fr/i2c_driver.md)
|
||||
* [Drivers SPI](fr-fr/spi_driver.md)
|
||||
* [Contrôles des GPIO](fr-fr/internals_gpio_control.md)
|
||||
* [Conversion en Proton C](fr-fr/proton_c_conversion.md)
|
||||
|
||||
|
@ -114,6 +114,7 @@
|
||||
* [מדריך לצריבת ISP](he-il/isp_flashing_guide.md)
|
||||
* [מדריך לדיבאגינג ARM](he-il/arm_debugging.md)
|
||||
* [מנהל התקן I2C](he-il/i2c_driver.md)
|
||||
* [מנהל התקן SPI](he-il/spi_driver.md)
|
||||
* [בקרת GPIO](he-il/internals_gpio_control.md)
|
||||
* [המרת Proton C](he-il/proton_c_conversion.md)
|
||||
|
||||
|
@ -121,6 +121,7 @@
|
||||
* [ドライバ](ja/hardware_drivers.md)
|
||||
* [ADC ドライバ](ja/adc_driver.md)
|
||||
* [I2C ドライバ](ja/i2c_driver.md)
|
||||
* [SPI ドライバ](ja/spi_driver.md)
|
||||
* [WS2812 ドライバ](ja/ws2812_driver.md)
|
||||
* [EEPROM ドライバ](ja/eeprom_driver.md)
|
||||
* [GPIO コントロール](ja/internals_gpio_control.md)
|
||||
|
@ -98,6 +98,7 @@
|
||||
* [ISP Flashing Guide](pt-br/isp_flashing_guide.md)
|
||||
* [ARM Debugging Guide](pt-br/arm_debugging.md)
|
||||
* [I2C Driver](pt-br/i2c_driver.md)
|
||||
* [SPI Driver](pt-br/spi_driver.md)
|
||||
* [GPIO Controls](pt-br/internals_gpio_control.md)
|
||||
* [Proton C Conversion](pt-br/proton_c_conversion.md)
|
||||
|
||||
|
@ -99,6 +99,7 @@
|
||||
* [ISP Flashing Guide](ru-ru/isp_flashing_guide.md)
|
||||
* [ARM Debugging Guide](ru-ru/arm_debugging.md)
|
||||
* [I2C Driver](ru-ru/i2c_driver.md)
|
||||
* [SPI Driver](ru-ru/spi_driver.md)
|
||||
* [WS2812 Driver](ru-ru/ws2812_driver.md)
|
||||
* [GPIO Controls](ru-ru/internals_gpio_control.md)
|
||||
* [Proton C Conversion](ru-ru/proton_c_conversion.md)
|
||||
|
128
docs/spi_driver.md
Normal file
128
docs/spi_driver.md
Normal file
@ -0,0 +1,128 @@
|
||||
# SPI Master Driver
|
||||
|
||||
The SPI Master drivers used in QMK have a set of common functions to allow portability between MCUs.
|
||||
|
||||
## AVR Configuration
|
||||
|
||||
No special setup is required - just connect the `SS`, `SCK`, `MOSI` and `MISO` pins of your SPI devices to the matching pins on the MCU:
|
||||
|
||||
|MCU |`SS`|`SCK`|`MOSI`|`MISO`|
|
||||
|---------------|----|-----|------|------|
|
||||
|ATMega16/32U2/4|`B0`|`B1` |`B2` |`B3` |
|
||||
|AT90USB64/128 |`B0`|`B1` |`B2` |`B3` |
|
||||
|ATmega32A |`B4`|`B7` |`B5` |`B6` |
|
||||
|ATmega328P |`B2`|`B5` |`B3` |`B4` |
|
||||
|
||||
You may use more than one slave select pin, not just the `SS` pin. This is useful when you have multiple devices connected and need to communicate with them individually.
|
||||
`SPI_SS_PIN` can be passed to `spi_start()` to refer to `SS`.
|
||||
|
||||
## ARM Configuration
|
||||
|
||||
ARM support for this driver is not ready yet. Check back later!
|
||||
|
||||
## Functions
|
||||
|
||||
### `void spi_init(void)`
|
||||
|
||||
Initialize the SPI driver. This function must be called only once, before any of the below functions can be called.
|
||||
|
||||
---
|
||||
|
||||
### `void spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint8_t divisor)`
|
||||
|
||||
Start an SPI transaction.
|
||||
|
||||
#### Arguments
|
||||
|
||||
- `pin_t slavePin`
|
||||
The QMK pin to assert as the slave select pin, eg. `B4`.
|
||||
- `bool lsbFirst`
|
||||
Determines the endianness of the transmission. If `true`, the least significant bit of each byte is sent first.
|
||||
- `uint8_t mode`
|
||||
The SPI mode to use:
|
||||
|
||||
|Mode|Clock Polarity |Clock Phase |
|
||||
|----|--------------------|-----------------------|
|
||||
|`0` |Leading edge rising |Sample on leading edge |
|
||||
|`1` |Leading edge rising |Sample on trailing edge|
|
||||
|`2` |Leading edge falling|Sample on leading edge |
|
||||
|`3` |Leading edge falling|Sample on trailing edge|
|
||||
|
||||
- `uint8_t divisor`
|
||||
The SPI clock divisor, will be rounded up to the nearest power of two. This number can be calculated by dividing the MCU's clock speed by the desired SPI clock speed. For example, an MCU running at 8 MHz wanting to talk to an SPI device at 4 MHz would set the divisor to `2`.
|
||||
|
||||
---
|
||||
|
||||
### `spi_status_t spi_write(uint8_t data, uint16_t timeout)`
|
||||
|
||||
Write a byte to the selected SPI device.
|
||||
|
||||
#### Arguments
|
||||
|
||||
- `uint8_t data`
|
||||
The byte to write.
|
||||
- `uint16_t timeout`
|
||||
The amount of time to wait, in milliseconds, before timing out.
|
||||
|
||||
#### Return Value
|
||||
|
||||
`SPI_STATUS_TIMEOUT` if the timeout period elapses, or `SPI_STATUS_SUCCESS`.
|
||||
|
||||
---
|
||||
|
||||
### `spi_status_t spi_read(uint16_t timeout)`
|
||||
|
||||
Read a byte from the selected SPI device.
|
||||
|
||||
#### Arguments
|
||||
|
||||
- `uint16_t timeout`
|
||||
The amount of time to wait, in milliseconds, before timing out.
|
||||
|
||||
#### Return Value
|
||||
|
||||
`SPI_STATUS_TIMEOUT` if the timeout period elapses, or the byte read from the device.
|
||||
|
||||
---
|
||||
|
||||
### `spi_status_t spi_transmit(const uint8_t *data, uint16_t length, uint16_t timeout)`
|
||||
|
||||
Send multiple bytes to the selected SPI device.
|
||||
|
||||
#### Arguments
|
||||
|
||||
- `const uint8_t *data`
|
||||
A pointer to the data to write from.
|
||||
- `uint16_t length`
|
||||
The number of bytes to write. Take care not to overrun the length of `data`.
|
||||
- `uint16_t timeout`
|
||||
The amount of time to wait, in milliseconds, before timing out.
|
||||
|
||||
#### Return Value
|
||||
|
||||
`SPI_STATUS_TIMEOUT` if the timeout period elapses, `SPI_STATUS_SUCCESS` on success, or `SPI_STATUS_ERROR` otherwise.
|
||||
|
||||
---
|
||||
|
||||
### `spi_status_t spi_receive(uint8_t *data, uint16_t length, uint16_t timeout)`
|
||||
|
||||
Receive multiple bytes from the selected SPI device.
|
||||
|
||||
#### Arguments
|
||||
|
||||
- `uint8_t *data`
|
||||
A pointer to the buffer to read into.
|
||||
- `uint16_t length`
|
||||
The number of bytes to read. Take care not to overrun the length of `data`.
|
||||
- `uint16_t timeout`
|
||||
The amount of time to wait, in milliseconds, before timing out.
|
||||
|
||||
#### Return Value
|
||||
|
||||
`SPI_STATUS_TIMEOUT` if the timeout period elapses, `SPI_STATUS_SUCCESS` on success, or `SPI_STATUS_ERROR` otherwise.
|
||||
|
||||
---
|
||||
|
||||
### `void spi_stop(void)`
|
||||
|
||||
End the current SPI transaction. This will deassert the slave select pin and reset the endianness, mode and divisor configured by `spi_start()`.
|
@ -104,6 +104,7 @@
|
||||
* [ARM调试指南](zh-cn/arm_debugging.md)
|
||||
* [ADC设备](zh-cn/adc_driver.md)
|
||||
* [I2C设备](zh-cn/i2c_driver.md)
|
||||
* [SPI设备](zh-cn/spi_driver.md)
|
||||
* [WS2812设备](zh-cn/ws2812_driver.md)
|
||||
* [EEPROM设备](zh-cn/eeprom_driver.md)
|
||||
* [GPIO控制](zh-cn/internals_gpio_control.md)
|
||||
|
163
drivers/avr/spi_master.c
Normal file
163
drivers/avr/spi_master.c
Normal file
@ -0,0 +1,163 @@
|
||||
/* Copyright 2020
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "spi_master.h"
|
||||
#include "quantum.h"
|
||||
#include "timer.h"
|
||||
|
||||
#if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||
# define SPI_SCK_PIN B1
|
||||
# define SPI_MOSI_PIN B2
|
||||
# define SPI_MISO_PIN B3
|
||||
#elif defined(__AVR_ATmega32A__)
|
||||
# define SPI_SCK_PIN B7
|
||||
# define SPI_MOSI_PIN B5
|
||||
# define SPI_MISO_PIN B6
|
||||
#elif defined(__AVR_ATmega328P__)
|
||||
# define SPI_SCK_PIN B5
|
||||
# define SPI_MOSI_PIN B3
|
||||
# define SPI_MISO_PIN B4
|
||||
#endif
|
||||
|
||||
static pin_t currentSlavePin = NO_PIN;
|
||||
static uint8_t currentSlaveConfig = 0;
|
||||
static bool currentSlave2X = false;
|
||||
|
||||
void spi_init(void) {
|
||||
writePinHigh(SPI_SS_PIN);
|
||||
setPinOutput(SPI_SCK_PIN);
|
||||
setPinOutput(SPI_MOSI_PIN);
|
||||
setPinInput(SPI_MISO_PIN);
|
||||
|
||||
SPCR = (_BV(SPE) | _BV(MSTR));
|
||||
}
|
||||
|
||||
void spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint8_t divisor) {
|
||||
if (currentSlavePin == NO_PIN && slavePin != NO_PIN) {
|
||||
if (lsbFirst) {
|
||||
currentSlaveConfig |= _BV(DORD);
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case 1:
|
||||
currentSlaveConfig |= _BV(CPHA);
|
||||
break;
|
||||
case 2:
|
||||
currentSlaveConfig |= _BV(CPOL);
|
||||
break;
|
||||
case 3:
|
||||
currentSlaveConfig |= (_BV(CPOL) | _BV(CPHA));
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t roundedDivisor = 1;
|
||||
while (roundedDivisor < divisor) {
|
||||
roundedDivisor <<= 1;
|
||||
}
|
||||
|
||||
switch (roundedDivisor) {
|
||||
case 16:
|
||||
currentSlaveConfig |= _BV(SPR0);
|
||||
break;
|
||||
case 64:
|
||||
currentSlaveConfig |= _BV(SPR1);
|
||||
break;
|
||||
case 128:
|
||||
currentSlaveConfig |= (_BV(SPR1) | _BV(SPR0));
|
||||
break;
|
||||
case 2:
|
||||
currentSlave2X = true;
|
||||
break;
|
||||
case 8:
|
||||
currentSlave2X = true;
|
||||
currentSlaveConfig |= _BV(SPR0);
|
||||
break;
|
||||
case 32:
|
||||
currentSlave2X = true;
|
||||
currentSlaveConfig |= _BV(SPR1);
|
||||
break;
|
||||
}
|
||||
|
||||
SPSR |= currentSlaveConfig;
|
||||
currentSlavePin = slavePin;
|
||||
setPinOutput(currentSlavePin);
|
||||
writePinLow(currentSlavePin);
|
||||
}
|
||||
}
|
||||
|
||||
spi_status_t spi_write(uint8_t data, uint16_t timeout) {
|
||||
SPDR = data;
|
||||
|
||||
uint16_t timeout_timer = timer_read();
|
||||
while (!(SPSR & _BV(SPIF))) {
|
||||
if ((timeout != SPI_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
|
||||
return SPI_STATUS_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return SPDR;
|
||||
}
|
||||
|
||||
spi_status_t spi_read(uint16_t timeout) {
|
||||
SPDR = 0x00; // Dummy
|
||||
|
||||
uint16_t timeout_timer = timer_read();
|
||||
while (!(SPSR & _BV(SPIF))) {
|
||||
if ((timeout != SPI_TIMEOUT_INFINITE) && ((timer_read() - timeout_timer) >= timeout)) {
|
||||
return SPI_STATUS_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return SPDR;
|
||||
}
|
||||
|
||||
spi_status_t spi_transmit(const uint8_t *data, uint16_t length, uint16_t timeout) {
|
||||
spi_status_t status = SPI_STATUS_ERROR;
|
||||
|
||||
for (uint16_t i = 0; i < length; i++) {
|
||||
status = spi_write(data[i], timeout);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
spi_status_t spi_receive(uint8_t *data, uint16_t length, uint16_t timeout) {
|
||||
spi_status_t status = SPI_STATUS_ERROR;
|
||||
|
||||
for (uint16_t i = 0; i < length; i++) {
|
||||
status = spi_read(timeout);
|
||||
|
||||
if (status > 0) {
|
||||
data[i] = status;
|
||||
}
|
||||
}
|
||||
|
||||
return (status < 0) ? status : SPI_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void spi_stop(void) {
|
||||
if (currentSlavePin != NO_PIN) {
|
||||
setPinOutput(currentSlavePin);
|
||||
writePinHigh(currentSlavePin);
|
||||
currentSlavePin = NO_PIN;
|
||||
SPCR &= ~(currentSlaveConfig);
|
||||
currentSlaveConfig = 0;
|
||||
SPSR = 0;
|
||||
currentSlave2X = false;
|
||||
}
|
||||
}
|
57
drivers/avr/spi_master.h
Normal file
57
drivers/avr/spi_master.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* Copyright 2020
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "quantum.h"
|
||||
|
||||
typedef int16_t spi_status_t;
|
||||
|
||||
// Hardware SS pin is defined in the header so that user code can refer to it
|
||||
#if defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__)
|
||||
# define SPI_SS_PIN B0
|
||||
#elif defined(__AVR_ATmega32A__)
|
||||
# define SPI_SS_PIN B4
|
||||
#elif defined(__AVR_ATmega328P__)
|
||||
# define SPI_SS_PIN B2
|
||||
#endif
|
||||
|
||||
#define SPI_STATUS_SUCCESS (0)
|
||||
#define SPI_STATUS_ERROR (-1)
|
||||
#define SPI_STATUS_TIMEOUT (-2)
|
||||
|
||||
#define SPI_TIMEOUT_IMMEDIATE (0)
|
||||
#define SPI_TIMEOUT_INFINITE (0xFFFF)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void spi_init(void);
|
||||
|
||||
void spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint8_t divisor);
|
||||
|
||||
spi_status_t spi_write(uint8_t data, uint16_t timeout);
|
||||
|
||||
spi_status_t spi_read(uint16_t timeout);
|
||||
|
||||
spi_status_t spi_transmit(const uint8_t *data, uint16_t length, uint16_t timeout);
|
||||
|
||||
spi_status_t spi_receive(uint8_t *data, uint16_t length, uint16_t timeout);
|
||||
|
||||
void spi_stop(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -331,7 +331,7 @@
|
||||
* @note The default is @p TRUE.
|
||||
*/
|
||||
#if !defined(CH_CFG_USE_MEMCORE)
|
||||
#define CH_CFG_USE_MEMCORE FALSE
|
||||
#define CH_CFG_USE_MEMCORE TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -331,7 +331,7 @@
|
||||
* @note The default is @p TRUE.
|
||||
*/
|
||||
#if !defined(CH_CFG_USE_MEMCORE)
|
||||
#define CH_CFG_USE_MEMCORE FALSE
|
||||
#define CH_CFG_USE_MEMCORE TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -331,7 +331,7 @@
|
||||
* @note The default is @p TRUE.
|
||||
*/
|
||||
#if !defined(CH_CFG_USE_MEMCORE)
|
||||
#define CH_CFG_USE_MEMCORE FALSE
|
||||
#define CH_CFG_USE_MEMCORE TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -19,8 +19,8 @@
|
||||
#include "config_common.h"
|
||||
|
||||
/* USB Device descriptor parameter */
|
||||
#define VENDOR_ID 0xFEED
|
||||
#define PRODUCT_ID 0x424D
|
||||
#define VENDOR_ID 0x4B50 // "KP"
|
||||
#define PRODUCT_ID 0x016A
|
||||
#define DEVICE_VER 0x0001
|
||||
#define MANUFACTURER KPrepublic
|
||||
#define PRODUCT bm16a
|
||||
|
51
keyboards/bm16a/keymaps/via/keymap.c
Normal file
51
keyboards/bm16a/keymaps/via/keymap.c
Normal file
@ -0,0 +1,51 @@
|
||||
/* Copyright 2019
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
#include QMK_KEYBOARD_H
|
||||
|
||||
enum layers {
|
||||
_BASE = 0,
|
||||
_FN1,
|
||||
_FN2,
|
||||
};
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
|
||||
[0] = LAYOUT_ortho_4x4(
|
||||
KC_PGUP, KC_HOME, KC_UP, KC_END ,
|
||||
KC_PGDN, KC_LEFT, KC_DOWN, KC_RGHT,
|
||||
KC_DOT, KC_VOLU, KC_MPLY, KC_MPRV,
|
||||
MO(1), KC_VOLD, KC_MUTE, KC_MNXT
|
||||
),
|
||||
[1] = LAYOUT_ortho_4x4(
|
||||
RESET, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
|
||||
),
|
||||
[2] = LAYOUT_ortho_4x4(
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
|
||||
),
|
||||
|
||||
[3] = LAYOUT_ortho_4x4(
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
|
||||
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
|
||||
)
|
||||
};
|
1
keyboards/bm16a/keymaps/via/readme.md
Normal file
1
keyboards/bm16a/keymaps/via/readme.md
Normal file
@ -0,0 +1 @@
|
||||
# Via keymap for bm16a
|
2
keyboards/bm16a/keymaps/via/rules.mk
Normal file
2
keyboards/bm16a/keymaps/via/rules.mk
Normal file
@ -0,0 +1,2 @@
|
||||
VIA_ENABLE = yes
|
||||
LTO_ENABLE = yes
|
11
keyboards/butterstick/keymaps/dennytom/README.md
Normal file
11
keyboards/butterstick/keymaps/dennytom/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# # Dennytom's Butterstick Layout
|
||||
|
||||
This keymap is using a custom chording engine. Head out to my (DennyTom) user space to find the source files and details.
|
||||
|
||||
To make a real keymap from the JSON file, run
|
||||
|
||||
```sh
|
||||
python3 parser.py keymap_def.json keymap.c
|
||||
```
|
||||
|
||||
Somehow it fits the whole keyboard on 20 keys. For longer typing sessions, use the ASET NIOP mode.
|
1418
keyboards/butterstick/keymaps/dennytom/keymap.c
Normal file
1418
keyboards/butterstick/keymaps/dennytom/keymap.c
Normal file
File diff suppressed because it is too large
Load Diff
309
keyboards/butterstick/keymaps/dennytom/keymap_def.json
Normal file
309
keyboards/butterstick/keymaps/dennytom/keymap_def.json
Normal file
File diff suppressed because it is too large
Load Diff
8
keyboards/butterstick/keymaps/dennytom/rules.mk
Normal file
8
keyboards/butterstick/keymaps/dennytom/rules.mk
Normal file
@ -0,0 +1,8 @@
|
||||
MOUSEKEY_ENABLE = yes
|
||||
EXTRAKEY_ENABLE = yes
|
||||
CONSOLE_ENABLE = no
|
||||
# COMMAND_ENABLE = no
|
||||
NKRO_ENABLE = yes
|
||||
|
||||
TMPVAR := $(SRC)
|
||||
SRC = $(filter-out sten.c, $(TMPVAR))
|
@ -331,7 +331,7 @@
|
||||
* @note The default is @p TRUE.
|
||||
*/
|
||||
#if !defined(CH_CFG_USE_MEMCORE)
|
||||
#define CH_CFG_USE_MEMCORE FALSE
|
||||
#define CH_CFG_USE_MEMCORE TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user