Random progress on board + kscan ideas.

This commit is contained in:
Pete Johanson 2020-04-25 22:41:20 -04:00
parent 85c8be89de
commit 5b4e43cebd
14 changed files with 527 additions and 28 deletions

View file

@ -1,40 +1,17 @@
# Find Zephyr. This also loads Zephyr's build system.
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr)
list(APPEND BOARD_ROOT .)
get_filename_component(ZEPHYR_RUST ${CMAKE_CURRENT_SOURCE_DIR}/zephyr-rust ABSOLUTE)
list(APPEND ZEPHYR_EXTRA_MODULES ${ZEPHYR_RUST})
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
find_package(Zephyr)
project(zmk)
# Add your source file to the "app" target. This must come after
# find_package(Zephyr) which defines the target.
target_sources(app PRIVATE src/main.c)
include(ExternalProject)
# Add rust_example as a CMake target
ExternalProject_Add(
zmk_crate
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND cargo build --target thumbv7m-none-eabi COMMAND cargo build --release --target thumbv7m-none-eabi
BINARY_DIR "${CMAKE_SOURCE_DIR}/zmk"
INSTALL_COMMAND ""
BUILD_BYPRODUCTS "${CMAKE_SOURCE_DIR}/zmk/target/thumbv7m-none-eabi/release/libzmk.a"
LOG_BUILD ON)
# Create a wrapper CMake library that our app can link with
add_library(zmk_lib STATIC IMPORTED GLOBAL)
add_dependencies(
zmk_lib
zmk_crate
)
set_target_properties(zmk_lib PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/zmk/target/thumbv7m-none-eabi/release/libzmk.a)
# target_link_libraries(zmk_lib
# debug "${CMAKE_SOURCE_DIR}/target/debug/zmk.a"
# optimized "${CMAKE_SOURCE_DIR}/target/release/zmk.a")
target_link_libraries(app PUBLIC zmk_lib)

126
Cargo.lock generated Normal file
View file

@ -0,0 +1,126 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aligned"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb1ce8b3382016136ab1d31a1b5ce807144f8b7eb2d5f16b2108f0f07edceb94"
dependencies = [
"as-slice",
]
[[package]]
name = "as-slice"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37dfb65bc03b2bc85ee827004f14a6817e04160e3b1a28931986a666a9290e70"
dependencies = [
"generic-array 0.12.3",
"generic-array 0.13.2",
"stable_deref_trait",
]
[[package]]
name = "bare-metal"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3"
dependencies = [
"rustc_version",
]
[[package]]
name = "cortex-m"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763"
dependencies = [
"aligned",
"bare-metal",
"volatile-register",
]
[[package]]
name = "generic-array"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
dependencies = [
"typenum",
]
[[package]]
name = "generic-array"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ed1e761351b56f54eb9dcd0cfaca9fd0daecf93918e1cfc01c8a3d26ee7adcd"
dependencies = [
"typenum",
]
[[package]]
name = "panic-itm"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98830d17a95587207e41edaa3009b143d326ce134b0e3538ac98246a67d66cc3"
dependencies = [
"cortex-m",
]
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "stable_deref_trait"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
[[package]]
name = "typenum"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]]
name = "vcell"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "876e32dcadfe563a4289e994f7cb391197f362b6315dc45e8ba4aa6f564a4b3c"
[[package]]
name = "volatile-register"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286"
dependencies = [
"vcell",
]
[[package]]
name = "zmk"
version = "0.1.0"
dependencies = [
"panic-itm",
]

8
Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "app"
version = "0.1.0"
authors = ["Pete Johanson <peter@peterjohanson.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
list(APPEND EXTRA_DTC_FLAGS "-qq")
if(CONFIG_PINMUX)
zephyr_library()
zephyr_library_sources(pinmux.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers)
endif()

View file

@ -0,0 +1,8 @@
# STM32F3DISCOVERY board configuration
# Copyright (c) 2017 I-SENSE group of ICCS
# SPDX-License-Identifier: Apache-2.0
config BOARD_STM32F3_DISCO
bool "STM32F3DISCOVERY Development Board"
depends on SOC_STM32F303XC

View file

@ -0,0 +1,39 @@
# Planck keyboard configuration
# Copyright (c) 2017 I-SENSE group of ICCS
# SPDX-License-Identifier: Apache-2.0
if BOARD_PLANCK_REV6
config BOARD
default "planck_rev6"
config UART_1
default y
depends on UART_CONSOLE
if I2C
config I2C_1
default y
config I2C_2
default y
endif # I2C
if SPI
config SPI_1
default y
config SPI_2
default y
endif # SPI
config CAN_1
default y
depends on CAN
endif # BOARD_PLANCK_REV6

View file

@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
board_runner_args(jlink "--device=STM32F303VC" "--speed=4000")
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)

View file

@ -0,0 +1,69 @@
/*
* Copyright (c) 2017 I-SENSE group of ICCS
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <device.h>
#include <init.h>
#include <drivers/pinmux.h>
#include <sys/sys_io.h>
#include <pinmux/stm32/pinmux_stm32.h>
/* pin assignments for STM32F3DISCOVERY board */
static const struct pin_config pinconf[] = {
#ifdef CONFIG_UART_1
{STM32_PIN_PC4, STM32F3_PINMUX_FUNC_PC4_USART1_TX},
{STM32_PIN_PC5, STM32F3_PINMUX_FUNC_PC5_USART1_RX},
#endif /* CONFIG_UART_1 */
#ifdef CONFIG_UART_2
{STM32_PIN_PA2, STM32F3_PINMUX_FUNC_PA2_USART2_TX},
{STM32_PIN_PA3, STM32F3_PINMUX_FUNC_PA3_USART2_RX},
#endif /* CONFIG_UART_2 */
#ifdef CONFIG_I2C_1
{STM32_PIN_PB6, STM32F3_PINMUX_FUNC_PB6_I2C1_SCL},
{STM32_PIN_PB7, STM32F3_PINMUX_FUNC_PB7_I2C1_SDA},
#endif /* CONFIG_I2C_1 */
#ifdef CONFIG_I2C_2
{STM32_PIN_PA9, STM32F3_PINMUX_FUNC_PA9_I2C2_SCL},
{STM32_PIN_PA10, STM32F3_PINMUX_FUNC_PA10_I2C2_SDA},
#endif /* CONFIG_I2C_2 */
#ifdef CONFIG_SPI_1
#ifdef CONFIG_SPI_STM32_USE_HW_SS
{STM32_PIN_PA4, STM32F3_PINMUX_FUNC_PA4_SPI1_NSS},
#endif /* CONFIG_SPI_STM32_USE_HW_SS */
{STM32_PIN_PA5, STM32F3_PINMUX_FUNC_PA5_SPI1_SCK},
{STM32_PIN_PA6, STM32F3_PINMUX_FUNC_PA6_SPI1_MISO},
{STM32_PIN_PA7, STM32F3_PINMUX_FUNC_PA7_SPI1_MOSI},
#endif /* CONFIG_SPI_1 */
#ifdef CONFIG_SPI_2
#ifdef CONFIG_SPI_STM32_USE_HW_SS
{STM32_PIN_PB12, STM32F3_PINMUX_FUNC_PB12_SPI2_NSS},
#endif /* CONFIG_SPI_STM32_USE_HW_SS */
{STM32_PIN_PB13, STM32F3_PINMUX_FUNC_PB13_SPI2_SCK},
{STM32_PIN_PB14, STM32F3_PINMUX_FUNC_PB14_SPI2_MISO},
{STM32_PIN_PB15, STM32F3_PINMUX_FUNC_PB15_SPI2_MOSI},
#endif /* CONFIG_SPI_2 */
#ifdef CONFIG_USB_DC_STM32
{STM32_PIN_PA11, STM32F3_PINMUX_FUNC_PA11_USB_DM},
{STM32_PIN_PA12, STM32F3_PINMUX_FUNC_PA12_USB_DP},
#endif /* CONFIG_USB_DC_STM32 */
#ifdef CONFIG_CAN_1
{STM32_PIN_PD0, STM32F3_PINMUX_FUNC_PD0_CAN1_RX},
{STM32_PIN_PD1, STM32F3_PINMUX_FUNC_PD1_CAN1_TX},
#endif /* CONFIG_CAN_1 */
};
static int pinmux_stm32_init(struct device *port)
{
ARG_UNUSED(port);
stm32_setup_pins(pinconf, ARRAY_SIZE(pinconf));
return 0;
}
SYS_INIT(pinmux_stm32_init, PRE_KERNEL_1,
CONFIG_PINMUX_STM32_DEVICE_INITIALIZATION_PRIORITY);

View file

@ -0,0 +1,165 @@
/*
* Copyright (c) 2017 I-SENSE group of ICCS
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <st/f3/stm32f303.dtsi>
/ {
model = "Plack PCD, rev6";
compatible = "planck,rev6", "st,stm32f303";
chosen {
zephyr,console = &usart1;
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zmk,matrix = &matrix0;
};
leds {
compatible = "gpio-leds";
red_led_3: led_3 {
gpios = <&gpioe 9 GPIO_ACTIVE_HIGH>;
label = "User LD3";
};
blue_led_4: led_4 {
gpios = <&gpioe 8 GPIO_ACTIVE_HIGH>;
label = "User LD4";
};
orange_led_5: led_5 {
gpios = <&gpioe 10 GPIO_ACTIVE_HIGH>;
label = "User LD5";
};
green_led_6: led_6 {
gpios = <&gpioe 15 GPIO_ACTIVE_HIGH>;
label = "User LD6";
};
green_led_7: led_7 {
gpios = <&gpioe 11 GPIO_ACTIVE_HIGH>;
label = "User LD7";
};
orange_led_8: led_8 {
gpios = <&gpioe 14 GPIO_ACTIVE_HIGH>;
label = "User LD8";
};
blue_led_9: led_9 {
gpios = <&gpioe 12 GPIO_ACTIVE_HIGH>;
label = "User LD9";
};
red_led_10: led_10 {
gpios = <&gpioe 13 GPIO_ACTIVE_HIGH>;
label = "User LD10";
};
};
matrix0: kscan_matrix {
rows {
gpio-map = <0 0 &gpioa 10 0>,
<1 0 &gpioa 9 0>,
<2 0 &gpioa 8 0>,
<3 0 &gpiob 15 0>,
<4 0 &gpioc 13 0>,
<5 0 &gpioc 14 0>,
<6 0 &gpioc 15 0>,
<7 0 &gpioa 2 0>;
};
columns {
gpio-map = <0 0 &gpiob 11 0>,
<1 0 &gpiob 10 0>,
<2 0 &gpiob 2 0>,
<3 0 &gpiob 1 0>,
<4 0 &gpioa 7 0>,
<5 0 &gpiob 0 0>;
};
};
gpio_keys {
compatible = "gpio-keys";
user_button: button {
label = "User";
gpios = <&gpioa 0 GPIO_ACTIVE_LOW>;
};
};
aliases {
led0 = &green_led_6;
led1 = &green_led_7;
sw0 = &user_button;
can-primary = &can1;
};
};
&usart1 {
current-speed = <115200>;
status = "okay";
};
&usart2 {
current-speed = <115200>;
status = "okay";
};
&i2c1 {
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
lsm303dlhc-magn@1e {
compatible = "st,lsm303dlhc-magn";
reg = <0x1e>;
label = "LSM303DLHC-MAGN";
};
lsm303dlhc-accel@19 {
compatible = "st,lis2dh", "st,lsm303dlhc-accel";
reg = <0x19>;
irq-gpios = <&gpioe 4 GPIO_ACTIVE_HIGH>,
<&gpioe 5 GPIO_ACTIVE_HIGH>;
label = "LSM303DLHC-ACCEL";
};
};
&i2c2 {
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
};
&spi1 {
status = "okay";
};
&spi2 {
status = "okay";
};
&usb {
status = "okay";
};
&rtc {
status = "okay";
};
&can1 {
status = "okay";
};
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
/* Set 6Kb of storage at the end of the 256Kb of flash */
storage_partition: partition@3e800 {
label = "storage";
reg = <0x0003e800 0x00001800>;
};
};
};

View file

@ -0,0 +1,19 @@
identifier: planck_rev6
name: PLANKREV6
type: keyboard
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
ram: 40
supported:
- gpio
- i2c
- counter
- spi
- usb_device
- lsm303dlhc
- nvs
- can
- kscan

View file

@ -0,0 +1,50 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_STM32F3X=y
CONFIG_SOC_STM32F303XC=y
# 72MHz system clock
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=72000000
# Floating Point Options
CONFIG_FLOAT=y
# enable uart driver
CONFIG_SERIAL=y
# enable console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
#enable I2C
CONFIG_I2C=y
#enable SPI
CONFIG_SPI=y
# enable pinmux
CONFIG_PINMUX=y
# enable GPIO
CONFIG_GPIO=y
# clock configuration
CONFIG_CLOCK_CONTROL=y
# kscan matrix
CONFIG_KSCAN=y
CONFIG_KSCAN_GPIO=y
# Clock configuration for Cube Clock control driver
CONFIG_CLOCK_STM32_HSE_CLOCK=8000000
CONFIG_CLOCK_STM32_SYSCLK_SRC_PLL=y
# use HSE as PLL input
CONFIG_CLOCK_STM32_PLL_SRC_HSE=y
# however, the board does not have an external oscillator, so just use
# the 8MHz clock signal coming from integrated STLink
CONFIG_CLOCK_STM32_HSE_BYPASS=y
# produce 72MHz clock at PLL output
CONFIG_CLOCK_STM32_PLL_PREDIV=1
CONFIG_CLOCK_STM32_PLL_MULTIPLIER=9
CONFIG_CLOCK_STM32_AHB_PRESCALER=1
CONFIG_CLOCK_STM32_APB1_PRESCALER=2
CONFIG_CLOCK_STM32_APB2_PRESCALER=1

4
prj.conf Normal file
View file

@ -0,0 +1,4 @@
CONFIG_RUST=y
CONFIG_RUST_ALLOC_POOL=y
CONFIG_KSCAN=y
CONFIG_KSCAN_GPIO=y

11
src/lib.rs Normal file
View file

@ -0,0 +1,11 @@
#[no_mangle]
pub extern "C" fn zmk_run() {
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}

View file

@ -8,6 +8,7 @@
#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>
#include <drivers/kscan.h>
#include "zmk_lib.h"
@ -15,6 +16,7 @@
#define SLEEP_TIME_MS 1000
/* The devicetree node identifier for the "led0" alias. */
/*
#define LED0_NODE DT_ALIAS(led0)
#if DT_HAS_NODE(LED0_NODE)
@ -24,7 +26,9 @@
#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)
#endif
#else
*/
/* A build error here means your board isn't set up to blink an LED. */
/*
#error "Unsupported board: led0 devicetree alias is not defined"
#define LED0 ""
#define PIN 0
@ -34,9 +38,12 @@
#define FLAGS 0
#endif
*/
void main(void)
{
/*
struct device *dev;
bool led_is_on = true;
int ret;
@ -50,6 +57,7 @@ void main(void)
if (ret < 0) {
return;
}
*/
zmk_run();
// while (1) {