Initial commit

This commit is contained in:
hodasemi 2023-01-31 09:59:52 +01:00
commit 75f626ef02
8 changed files with 220 additions and 0 deletions

29
.cargo/config.toml Normal file
View file

@ -0,0 +1,29 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# Choose a default "cargo run" tool:
# - probe-run provides flashing and defmt via a hardware debugger
# - cargo embed offers flashing, rtt, defmt and a gdb server via a hardware debugger
# it is configured via the Embed.toml in the root of this project
# - elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode
# runner = "probe-run --chip RP2040"
# runner = "cargo embed"
runner = "elf2uf2-rs -d"
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
# Code-size optimizations.
# trap unreachable can save a lot of space, but requires nightly compiler.
# uncomment the next line if you wish to enable it
# "-Z", "trap-unreachable=no",
"-C", "inline-threshold=5",
"-C", "no-vectorize-loops",
]
[build]
target = "thumbv6m-none-eabi"
[env]
DEFMT_LOG = "debug"

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
Cargo.lock

8
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,8 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#0B341F",
"titleBar.activeBackground": "#10492C",
"titleBar.activeForeground": "#F2FCF7"
},
"rust-analyzer.check.allTargets": false,
}

13
Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "mouse_hid"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cortex-m = "0.7.2"
cortex-m-rt = "0.7.2"
rp-pico = "0.6.0"
panic-halt = "0.2.0"
defmt = "0.3.0"

82
Embed.toml Normal file
View file

@ -0,0 +1,82 @@
[default.probe]
# USB vendor ID
# usb_vid = "1337"
# USB product ID
# usb_pid = "1337"
# Serial number
# serial = "12345678"
# The protocol to be used for communicating with the target.
protocol = "Swd"
# The speed in kHz of the data link to the target.
speed = 20000
[default.flashing]
# Whether or not the target should be flashed.
enabled = true
# Whether or not the target should be halted after reset.
# DEPRECATED, moved to reset section
halt_afterwards = false
# Whether or not bytes erased but not rewritten with data from the ELF
# should be restored with their contents before erasing.
restore_unwritten_bytes = false
# The path where an SVG of the assembled flash layout should be written to.
# flash_layout_output_path = "out.svg"
# Triggers a full chip erase instead of a page by page erase.
do_chip_erase = false
[default.reset]
# Whether or not the target should be reset.
# When flashing is enabled as well, the target will be reset after flashing.
enabled = true
# Whether or not the target should be halted after reset.
halt_afterwards = false
[default.general]
# The chip name of the chip to be debugged.
chip = "RP2040"
# A list of chip descriptions to be loaded during runtime.
chip_descriptions = []
# The default log level to be used. Possible values are one of:
# "OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"
log_level = "WARN"
# Use this flag to assert the nreset & ntrst pins during attaching the probe to the chip.
connect_under_reset = false
[default.rtt]
# Whether or not an RTTUI should be opened after flashing.
enabled = true
# How the target handles RTT outputs that won't fit in the buffer. This can be
# overridden per-channel. If left unset, the firmware will determine the default
# for each RTT up channel.
# NoBlockSkip - Skip writing the data completely if it doesn't fit in its
# entirety.
# NoBlockTrim - Write as much as possible of the data and ignore the rest.
# BlockIfFull - Spin until the host reads data. Can result in app freezing.
#
up_mode = "NoBlockSkip"
# A list of channel associations to be displayed. If left empty, all channels are displayed.
# up, down (Optional) - RTT channel numbers
# name (Optional) - String to be displayed in the RTTUI tab
# up_mode (Optional) - RTT channel specific as described above
# format (Required) - How to interpret data from target firmware. One of:
# String - Directly show output from the target
# Defmt - Format output on the host, see https://defmt.ferrous-systems.com/
# BinaryLE - Display as raw hex
channels = [
{ up = 0, down = 0, name = "name", up_mode = "NoBlockSkip", format = "Defmt" },
]
# The duration in ms for which the logger should retry to attach to RTT.
timeout = 3000
# Whether timestamps in the RTTUI are enabled
show_timestamps = true
# Whether to save rtt history buffer on exit.
log_enabled = false
# Where to save rtt history buffer relative to manifest path.
log_path = "./logs"
[default.gdb]
# Whether or not a GDB server should be opened after flashing.
enabled = false
# The connection string in host:port format wher the GDB server will open a socket.
gdb_connection_string = "127.0.0.1:1337"

15
memory.x Normal file
View file

@ -0,0 +1,15 @@
MEMORY {
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
RAM : ORIGIN = 0x20000000, LENGTH = 256K
}
EXTERN(BOOT2_FIRMWARE)
SECTIONS {
/* ### Boot loader */
.boot2 ORIGIN(BOOT2) :
{
KEEP(*(.boot2));
} > BOOT2
} INSERT BEFORE .text;

4
rust-toolchain.toml Normal file
View file

@ -0,0 +1,4 @@
[toolchain]
channel = "stable"
components = ["rustfmt"]
targets = ["thumbv6m-none-eabi"]

67
src/main.rs Normal file
View file

@ -0,0 +1,67 @@
#![no_std]
#![no_main]
// Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked)
use panic_halt as _;
// Pull in any important traits
use rp_pico::{
entry,
hal::{self, pac, prelude::*},
};
/// Entry point to our bare-metal application.
///
/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function
/// as soon as all global variables are initialised.
///
/// The function configures the RP2040 peripherals, then blinks the LED in an
/// infinite loop.
#[entry]
fn main() -> ! {
// Grab our singleton objects
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();
// Set up the watchdog driver - needed by the clock setup code
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);
// Configure the clocks
//
// The default is to generate a 125 MHz system clock
let clocks = hal::clocks::init_clocks_and_plls(
rp_pico::XOSC_CRYSTAL_FREQ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();
// The delay object lets us wait for specified amounts of time (in
// milliseconds)
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
// The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO);
// Set the pins up according to their function on this particular board
let pins = rp_pico::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
// Set the LED to be an output
let mut led_pin = pins.led.into_push_pull_output();
// Blink the LED at 1 Hz
loop {}
}
// End of file