Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 4-fix-card10-l0dable-on-crates-io
  • 5-implement-client-c-in-plain-rust
  • api
  • build-from-root
  • master
  • no-str_to_cstr
  • card10-alloc-0.1.0
  • card10-alloc-0.1.1
  • card10-l0dable-0.2.0
  • card10-l0dable-0.3.0
  • card10-sys-1.10.0
  • card10-sys-1.9.0
12 results

Target

Select target project
  • astro/rust-card10
  • rnestler/rust-card10
  • dbrgn/rust-card10
  • toon/rust-card10
  • mwall/rust-card10
  • puzzlewolf/rust-card10
  • rnd/rust-card10
  • lilpep/rust-card10
  • rafael/rust-card10
  • squeed/rust-card10
  • arist/rust-card10
11 results
Select Git revision
  • 4-fix-card10-l0dable-on-crates-io
  • 5-implement-client-c-in-plain-rust
  • build-from-root
  • master
4 results
Show changes
Showing
with 15579 additions and 212 deletions
File moved
let
mozillaOverlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
pkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
in
{ mozillaOverlay ? import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz),
pkgs ? import <nixpkgs> { overlays = [ mozillaOverlay ]; },
firmwareSrc ? ./card10-sys/firmware,
}:
with pkgs;
let
openocd = callPackage ./openocd.nix {};
rust = rustChannelOfTargets "nightly" null [ "thumbv7em-none-eabi" ];
rustPlatform = makeRustPlatform {
rustc = rust;
......@@ -12,7 +11,7 @@ let
};
epic-stubs = stdenv.mkDerivation {
name = "epic-stubs";
src = ./c;
src = firmwareSrc;
buildInputs = [ gcc python3 ];
buildPhase = ''
${python3}/bin/python epicardium/api/genapi.py -H epicardium/epicardium.h -c client.c -s server.c
......@@ -22,27 +21,34 @@ let
cp client.c server.c $out/
'';
};
firmware = rustPlatform.buildRustPackage rec {
l0dables = rustPlatform.buildRustPackage rec {
name = "rust-card10";
version = "0.0.0";
src = ./.;
cargoSha256 = "10qv30p3kr570glnyn37b6r8pgx48zj0mr9qf84m4wk4sjp3wxsd";
buildInputs = [ pkgsCross.arm-embedded.stdenv.cc glibc_multi ];
cargoSha256 = "16vchzfk50crr7kbiy84d1spq072ywa7s5jz886nvh7hah94w4a1";
buildInputs = [ pkgsCross.arm-embedded.stdenv.cc ];
prePatch = ''
cp ${epic-stubs}/client.c l0dable/src/
cp ${epic-stubs}/client.c card10-sys/vendor/
'' + lib.optionalString (firmwareSrc != ./card10-sys/firmware) ''
rm -r card10-sys/firmware
cp -r ${firmwareSrc} card10-sys/firmware
'';
NIX_DEBUG=1;
LIBCLANG_PATH="${llvmPackages.libclang}/lib";
CARGO_HOME="$(mktemp -d cargo-home.XXX)";
preBuild = ''
export LIBCLANG_PATH=${llvmPackages.libclang}/lib
export CPATH=${glibc_multi.dev}/include
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
cd example
export CPATH="${glibc_multi.dev}/include:${stdenv.cc.cc}/lib/gcc/$(cc -dumpmachine)/${lib.getVersion pkgsCross.arm-embedded.stdenv.cc.cc}/include"
'';
doCheck = false;
installPhase = ''
mkdir -p $out/lib
cp target/thumbv7em-none-eabi/release/example $out/lib/example.elf
mkdir -p $out/apps
for f in target/thumbv7em-none-eabi/release/* ; do
if [ -x $f ] && [ ! -d $f ] ; then
cp $f $out/apps/$(basename $f).elf
fi
done
'';
};
in {
inherit rust rustPlatform firmware epic-stubs;
inherit rust rustPlatform l0dables epic-stubs;
}
[package]
edition = "2018"
name = "l0dable"
name = "draw-image"
version = "0.0.0"
authors = ["Astro <astro@spaceboyz.net>"]
authors = ["Rafael Caricio <crates.rs@caric.io>"]
edition = "2018"
[dependencies]
r0 = "0.2"
panic-abort = "0.3"
card10-l0dable = { path = "../card10-l0dable" }
embedded-graphics = { version = "0.5.2" }
[build-dependencies]
cc = "1.0"
bindgen = "0.51"
\ No newline at end of file
[[bin]]
name = "draw-image"
path = "src/main.rs"
Draw Image
==========
Images need to be converted to a bitmap of 16BPP for inclusion with `include_bytes!()`. You can convert an image using:
```
convert image.png -flip -type truecolor -define bmp:subtype=RGB565 -depth 16 -strip image.bmp
```
then
```
tail -c $bytes image.bmp > image.raw // where $bytes is w * h * 2
```
This will remove the BMP header leaving the raw pixel data E.g 160x80 image will have 160 * 80 * 2 bytes of raw data.
\ No newline at end of file
File added
#![no_std]
#![no_main]
use card10_l0dable::*;
use embedded_graphics::prelude::*;
use embedded_graphics::image::Image16BPP;
use embedded_graphics::pixelcolor::Rgb565;
main!(main);
fn main() {
let mut display = Display::open();
let mut framebuffer = display.framebuffer();
let image: Image16BPP<Rgb565> =
Image16BPP::new(include_bytes!("applewatch-160x80.raw"), 160, 80);
framebuffer.draw(&image);
framebuffer.send();
loop {
let buttons = Buttons::read();
if buttons.left_top() {
break;
}
}
}
......@@ -5,7 +5,8 @@ version = "0.0.0"
authors = ["Astro <astro@spaceboyz.net>"]
[dependencies]
l0dable = { path = "../l0dable" }
card10-l0dable = { path = "../card10-l0dable" }
card10-alloc = { path = "../card10-alloc" }
[build-dependencies]
cc = "1.0"
......
#![no_std]
#![no_main]
use core::fmt::Write;
use l0dable::*;
use core::fmt::{self, Write};
use card10_l0dable::*;
/// Allows you to `use alloc::*;`
extern crate alloc;
main!(main);
fn main() {
writeln!(UART, "Hello from Rust\r").unwrap();
let heap_size = card10_alloc::init(4096);
println!("Heap size: {}", heap_size);
let result = run();
if let Err(error) = result {
writeln!(UART, "error: {}\r", error).unwrap();
}
}
fn run() -> Result<(), Error> {
writeln!(UART, "Hello from Rust\r")?;
let bme = BME680::start();
let a = BHI160::<Accelerometer>::start();
let g = BHI160::<Gyroscope>::start();
let o = BHI160::<Orientation>::start();
let a = BHI160::<Accelerometer>::start()?;
let g = BHI160::<Gyroscope>::start()?;
let o = BHI160::<Orientation>::start()?;
set_rocket(Rocket::Blue, 20);
set_rocket(Rocket::Yellow, 20);
set_rocket(Rocket::Green, 10);
let display = Display::open();
let light = LightSensor::start();
for t in 0..Display::W {
writeln!(UART, "BME: {:?}\r", bme.read()).unwrap();
writeln!(UART, "A:\r").unwrap();
for d in &a.read() {
writeln!(UART, " - {:?}\r", d).unwrap();
writeln!(UART, "BME: {:?}\r", bme.read())?;
writeln!(UART, "A:\r")?;
for d in &a.read()? {
writeln!(UART, " - {:?}\r", d)?;
}
writeln!(UART, "O:\r").unwrap();
for d in &o.read() {
writeln!(UART, " - {:?}\r", d).unwrap();
writeln!(UART, "O:\r")?;
for d in &o.read()? {
writeln!(UART, " - {:?}\r", d)?;
}
writeln!(UART, "G:\r").unwrap();
for d in &g.read() {
writeln!(UART, " - {:?}\r", d).unwrap();
writeln!(UART, "G:\r")?;
for d in &g.read()? {
writeln!(UART, " - {:?}\r", d)?;
}
display.clear(Color::yellow());
display.print(160 - t, 10, b"Hello Rust\0", Color::white(), Color::black());
display!(display, 160 - t, 10, Color::white(), Color::black(), "Hello Rust {}", t);
let b = Buttons::read();
if b.left_bottom() {
display.print(0, 60, b"LB\0", Color::red(), Color::black());
display!(display, 0, 60, Color::red(), Color::black(), "LB");
vibra::set(true);
}
if b.right_bottom() {
display.print(80, 60, b"RB\0", Color::red(), Color::black());
display!(display, 80, 60, Color::red(), Color::black(), "RB");
vibra::set(false);
}
if b.left_top() {
display.print(0, 10, b"LT\0", Color::red(), Color::black());
display!(display, 0, 10, Color::red(), Color::black(), "LT");
}
if b.right_top() {
display.print(80, 10, b"RT\0", Color::red(), Color::black());
display!(display, 80, 10, Color::red(), Color::black(), "RT");
}
if b.right_top() {
display.print(80, 30, b"Reset\0", Color::red(), Color::black());
display!(display, 80, 30, Color::red(), Color::black(), "Reset");
}
writeln!(UART, "Light: {:?}\r", light.get()).unwrap();
writeln!(UART, "Light: {:?}\r", light.get())?;
display.update();
}
Ok(())
}
// -----------------------------------------------------------------------------
// Error
// -----------------------------------------------------------------------------
#[derive(Debug)]
pub enum Error {
UartWriteFailed(fmt::Error),
SensorInteractionFailed(BHI160Error),
}
impl From<fmt::Error> for Error {
fn from(error: fmt::Error) -> Self {
Error::UartWriteFailed(error)
}
}
impl From<BHI160Error> for Error {
fn from(error: BHI160Error) -> Self {
Error::SensorInteractionFailed(error)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::UartWriteFailed(error) => error.fmt(f),
Error::SensorInteractionFailed(error) => error.fmt(f),
}
}
}
{ pkgs ? import <nixpkgs> {},
src ? ./.,
srcPath ? "card10-sys/firmware",
}:
with pkgs;
let
cSrc = stdenv.mkDerivation rec {
name = "card10-src";
inherit src;
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
nativeBuildInputs = [ git ];
prePatch = "cd ${srcPath}";
patches = [
./0001-hack-epicardium-reduce-init-delay-from-2s-to-0.1s.patch
];
postPatch = ''
VERSION="$(git -C ${src} describe --always)"
GITHASH="$(git -C ${src} rev-parse HEAD)"
substituteInPlace tools/version-header.sh \
--replace "\$VERSION" "$VERSION" \
--replace "\$GITHASH" "$GITHASH" \
--replace "git -C" echo
'';
installPhase = ''
cp -ar . $out
mkdir -p $out/nix-support
for f in $out/*.bin ; do
echo file binary-dist $f >> $out/nix-support/hydra-build-products
done
'';
};
firmware = lib.makeOverridable (attrs: {
inherit (attrs) src;
firmware = import attrs.src;
}) { src = cSrc; };
in firmware
Source diff could not be displayed: it is too large. Options to address this: view the blob.
{ pkgs ? import <nixpkgs> {},
cFirmware ? <c-firmware>,
rkanoid ? <rkanoid>,
}:
with pkgs;
let
l0dables = buildEnv {
name = "l0dables";
paths = [ rkanoid ];
pathsToLink = [ "/apps" ];
};
release = import ../release.nix {
inherit cFirmware;
rustL0dables = l0dables;
};
releaseZip = stdenv.mkDerivation {
name = "card10-combined.zip";
nativeBuildInputs = [ release zip ];
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/nix-support
cd ${release}/
zip -9r $out/firmware.zip .
echo file binary-dist $out/firmware.zip >> $out/nix-support/hydra-build-products
'';
};
in {
release = lib.hydraJob release;
release-zip = lib.hydraJob releaseZip;
}
{ pkgs ? import <nixpkgs> {},
}:
with pkgs;
let
firmwareSrc = import ../firmware.nix {
inherit pkgs;
src = <firmware>;
srcPath = ".";
};
firmwareGit = firmwareSrc.override (oldArgs: {
src = oldArgs.src.overrideAttrs (oldAttrs: {
name = "${oldAttrs.name}-git";
# no more git, .git is dropped by Hydra
nativeBuildInputs = [];
postPatch = ''
VERSION="0.0-git"
GITHASH="0000000000000000000000000000000000000000"
substituteInPlace tools/version-header.sh \
--replace "\$VERSION" "$VERSION" \
--replace "\$GITHASH" "$GITHASH" \
--replace "git -C" echo
'';
});
});
firmware = firmwareGit.firmware.overrideAttrs (oldAttrs: {
buildCommand = ''
${oldAttrs.buildCommand}
mkdir -p $out/nix-support
for f in $out/**/*.elf $out/card10/*.bin ; do
echo file binary-dist $f >> $out/nix-support/hydra-build-products
done
'';
});
firmwareZip = stdenv.mkDerivation {
name = "card10-firmware.zip";
nativeBuildInputs = [ firmware zip ];
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/nix-support
cd ${firmware}/card10/
zip -9r $out/firmware.zip .
echo file binary-dist $out/firmware.zip >> $out/nix-support/hydra-build-products
'';
};
in {
firmware = lib.hydraJob firmware;
firmware-zip = lib.hydraJob firmwareZip;
}
{
"enabled": 1,
"type": 0,
"hidden": true,
"description": "Jobsets",
"nixexprinput": "rust-card10",
"nixexprpath": "hydra/hydra.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "astro@spaceboyz.net",
"keepnr": 30,
"inputs": {
"nixpkgs": { "type": "git", "value": "https://github.com/NixOS/nixpkgs-channels nixos-19.09", "emailresponsible": false },
"rust-card10": { "type": "git", "value": "https://git.card10.badge.events.ccc.de/astro/rust-card10.git", "emailresponsible": false }
}
}
{ pkgs ? import <nixpkgs> {} }:
let
jobsets = {
c-firmware = {
enabled = 1;
type = 0;
hidden = false;
description = "card10 C firmware";
nixexprinput = "rust-card10";
nixexprpath = "hydra/firmware.nix";
checkinterval = 300;
schedulingshares = 100;
enableemail = true;
emailoverride = "astro@spaceboyz.net";
keepnr = 3;
inputs = {
firmware = { type = "git"; value = "https://git.card10.badge.events.ccc.de/card10/firmware.git"; emailresponsible = false; };
rust-card10 = { type = "git"; value = "https://git.card10.badge.events.ccc.de/astro/rust-card10.git"; emailresponsible = false; };
nixpkgs = { type = "git"; value = "git://github.com/NixOS/nixpkgs.git release-19.09"; emailresponsible = false; };
};
};
rust-l0dables = {
enabled = 1;
type = 0;
hidden = false;
description = "card10 Rust l0dable examples";
nixexprinput = "rust-card10";
nixexprpath = "hydra/l0dables.nix";
checkinterval = 300;
schedulingshares = 100;
enableemail = true;
emailoverride = "astro@spaceboyz.net";
keepnr = 3;
inputs = {
firmware = { type = "git"; value = "https://git.card10.badge.events.ccc.de/card10/firmware.git"; emailresponsible = false; };
rust-card10 = { type = "git"; value = "https://git.card10.badge.events.ccc.de/astro/rust-card10.git"; emailresponsible = false; };
nixpkgs = { type = "git"; value = "git://github.com/NixOS/nixpkgs.git release-19.09"; emailresponsible = false; };
mozillaOverlay = { type = "git"; value = "git://github.com/mozilla/nixpkgs-mozilla.git"; emailresponsible = false; };
};
};
firmware-combined = {
enabled = 1;
type = 0;
hidden = false;
description = "Prepared firmware with Rust l0dables";
nixexprinput = "rust-card10";
nixexprpath = "hydra/combined.nix";
checkinterval = 300;
schedulingshares = 100;
enableemail = true;
emailoverride = "astro@spaceboyz.net";
keepnr = 3;
inputs = {
rust-card10 = { type = "git"; value = "https://git.card10.badge.events.ccc.de/astro/rust-card10.git"; emailresponsible = false; };
c-firmware = { type = "build"; value = "rust-card10:c-firmware:firmware"; emailresponsible = false; };
rkanoid = { type = "build"; value = "rust-card10:rust-l0dables:rkanoid"; emailresponsible = false; };
nixpkgs = { type = "git"; value = "git://github.com/NixOS/nixpkgs.git release-19.09"; emailresponsible = false; };
};
};
};
jobsetsJson = pkgs.writeText "jobsets.json" (builtins.toJSON jobsets );
in
{
jobsets = pkgs.runCommand "rust-card10.json" {} ''
cp ${jobsetsJson} $out
'';
}
{ rustManifest ? ./channel-rust-nightly.toml,
}:
let
mozillaOverlay = import <mozillaOverlay>;
manifestOverlay = self: super: {
rustChannelOfTargets = _channel: _date: targets:
(super.lib.rustLib.fromManifestFile rustManifest {
inherit (super) stdenv fetchurl patchelf;
}).rust.override { inherit targets; };
};
pkgs = (import <nixpkgs> { overlays = [ mozillaOverlay manifestOverlay ]; });
project = import ../default.nix {
inherit pkgs mozillaOverlay;
firmwareSrc = <firmware>;
};
l0dable = crate: project.l0dables.overrideAttrs (oldAttrs: {
name = "${oldAttrs.name}-${crate}";
buildPhase = ''
pushd ${crate}
${oldAttrs.buildPhase}
popd
'';
installPhase = ''
${oldAttrs.installPhase}
mkdir -p $out/nix-support
for f in $out/apps/*.elf ; do
echo file binary-dist $f >> $out/nix-support/hydra-build-products
done
'';
});
crates =
pkgs.lib.filterAttrs (crate: type:
type == "directory" &&
builtins.pathExists (<rust-card10> + "/${crate}/Cargo.toml")
) (builtins.readDir <rust-card10>);
in
builtins.mapAttrs (crate: type:
pkgs.lib.hydraJob (l0dable crate)
) crates
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
// Linker script
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("l0dable.ld"))
.unwrap()
.write_all(include_bytes!("l0dable.ld"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rerun-if-changed=l0dable.ld");
// Link against C code
cc::Build::new()
.target("thumbv7em-none-eabi")
.compiler("arm-none-eabi-gcc")
.define("TARGET", "MAX32665")
.define("TARGET_UC", "MAX32665")
.define("TARGET_LC", "max32665")
.define("TARGET_REV", "0x4131")
.define("BOARD", "card10")
.opt_level_str("s")
.debug(true)
.flag("-fPIE").flag("-pie")
.include("../c/epicardium")
.include("../c/lib/sdk/Libraries/CMSIS/Device/Maxim/MAX32665/Include")
.include("../c/lib/sdk/Libraries/CMSIS/Include")
.include("../c/lib/sdk/Libraries/MAX32665PeriphDriver/Include")
.file("../c/lib/sdk/Libraries/MAX32665PeriphDriver/Source/sema.c")
.file("../c/lib/sdk/Libraries/MAX32665PeriphDriver/Source/mxc_assert.c")
.file("../c/l0dables/lib/hardware.c")
.file("../c/epicardium/api/caller.c")
.file("src/client.c")
.compile("card10");
println!("cargo:rerun-if-changed=src/client.rs");
// Generate bindings to C code
let bindings = bindgen::Builder::default()
.clang_args(&[
"-Isrc",
"-I../c/epicardium",
"-I../c/lib/sdk/Libraries/CMSIS/Device/Maxim/MAX32665/Include",
"-I../c/lib/sdk/Libraries/CMSIS/Include",
"-I../c/lib/sdk/Libraries/MAX32665PeriphDriver/Include",
])
.header("src/bindings.h")
.use_core()
.ctypes_prefix("super::ctypes")
.generate()
.expect("Unable to generate bindings");
println!("cargo:rerun-if-changed=src/bindings.h");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
#![no_std]
#![feature(global_asm)]
use panic_abort as _;
global_asm!(include_str!("crt.s"));
/// Type check the user-supplied entry function.
#[macro_export]
macro_rules! main {
($path:path) => {
#[export_name = "main"]
pub unsafe fn __main() {
// type check the given path
let f: fn() = $path;
f()
}
};
}
#[link_section = ".text.boot"]
#[no_mangle]
pub unsafe extern "C" fn Reset_Handler() -> ! {
extern "C" {
fn SystemInit();
// Boundaries of the .bss section, provided by the linker script
static mut __bss_start: u64;
static mut __bss_end: u64;
}
// Zeroes the .bss section
r0::zero_bss(&mut __bss_start, &mut __bss_end);
SystemInit();
extern "Rust" {
fn main();
}
main();
exit(0);
}
pub mod ctypes {
#![allow(non_camel_case_types)]
pub type c_short = i16;
pub type c_ushort = u16;
pub type c_int = i32;
pub type c_uint = u32;
pub type c_long = i32;
pub type c_ulong = u32;
pub type c_longlong = i64;
pub type c_ulonglong = u64;
pub type c_char = u8;
pub type c_schar = i8;
pub type c_uchar = u8;
pub use core::ffi::c_void;
}
pub mod bindings {
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}
mod os;
pub use os::*;
mod display;
pub use display::{Display, Color, LineStyle, FillStyle};
mod buttons;
pub use buttons::Buttons;
pub mod uart;
pub const UART: uart::Uart = uart::Uart;
mod light_sensor;
pub use light_sensor::LightSensor;
pub mod vibra;
pub mod trng;
mod utime;
pub use utime::time;
mod fmt_buffer;
pub use fmt_buffer::{FmtBuffer, str_to_cstr};
mod bme680;
pub use bme680::BME680;
mod bhi160;
pub use bhi160::{Sensor as BHI160, Accelerometer, Orientation, Gyroscope, SensorData as BHI160Data};
pub mod fs;
use core::fmt::Write;
use super::bindings::*;
pub struct Uart;
impl Write for Uart {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
unsafe {
epic_uart_write_str(s.as_ptr(), s.len() as isize);
}
Ok(())
}
}
use super::bindings::*;
pub fn time() -> u32 {
unsafe { epic_rtc_get_seconds() }
}