Skip to content

Commit

Permalink
chore: kampela-system: bump substrate-parser, minimal cleanup (#26)
Browse files Browse the repository at this point in the history
* chore: bump substrate-parser, minimal cleanup

* chore: moved to modern deps, separated simulator

* chore: deps, cleanup

* fix: update screen calibration tool

* fix: now compatible with siltti
  • Loading branch information
varovainen authored Jul 24, 2024
1 parent 0eb0626 commit 0860510
Show file tree
Hide file tree
Showing 30 changed files with 2,225 additions and 5,452 deletions.
1,259 changes: 157 additions & 1,102 deletions kampela-screen-calibration/Cargo.lock

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions kampela-screen-calibration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
[package]
authors = ["Vera Abramova <[email protected]>"]
edition = "2021"
name = "app"
name = "screen-calibration-app"
version = "0.1.0"

[dependencies]
bitvec = {version = "1.0.1", default-features = false, features = ["alloc"]}
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7.2"
cortex-m-semihosting = "0.3.3"
efm32pg23_fix = {path = "../kampela_experiments_efm32pg23/efm32pg23_fix", features = ["critical-section", "rt"]}
embedded-alloc = "0.5.0" # embedded-alloc required nightly!
embedded-graphics = "0.7.1"
embedded-graphics-core = "0.3.3"
embedded-text = {version = "0.5.0", default-features = false}
kampela-system = { path = "../kampela-system" }
kampela-display-common = { path = "../kampela-display-common" }
kolibri = {path = "../kolibri", default-features = false}
panic-halt = "0.2.0"
rand_core = {version = "0.6.4", default-features = false}

[profile.release]
codegen-units = 1
Expand Down
26 changes: 24 additions & 2 deletions kampela-screen-calibration/binarize.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#!/bin/bash

set -e

echo "Building..."

cargo build --release
mv target/thumbv8m.main-none-eabihf/release/app target/thumbv8m.main-none-eabihf/release/app.elf
arm-none-eabi-objcopy -O binary target/thumbv8m.main-none-eabihf/release/app.elf target/thumbv8m.main-none-eabihf/release/app.bin

BUILD_DIRECTORY="target/thumbv8m.main-none-eabihf"
EXECUTABLE="$BUILD_DIRECTORY/release/screen-calibration-app"
FIRMWARE="$BUILD_DIRECTORY/release/screen-calibration-app.bin"

echo "Preparing binary file..."

arm-none-eabi-objcopy -O binary "$EXECUTABLE" "$FIRMWARE"

echo "Flashing..."

if [[ -z "$1" || "$1" == "--pilkki" ]]; then
pilkki write -i "$FIRMWARE"
elif [ "$1" == "--segger" ]; then
commander flash "$FIRMWARE" --device EFM32PG23B200F512IM40 --address 0x08000000
else
echo "What means \"$1\"? Usage:"
echo "$0 [--pilkki|--segger]"
exit -1
fi
120 changes: 55 additions & 65 deletions kampela-screen-calibration/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
#![no_main]
#![no_std]
#![feature(alloc_error_handler)]
#![deny(unused_crate_dependencies)]

extern crate alloc;
extern crate core;

use alloc::format;
use core::{alloc::Layout, panic::PanicInfo};
use cortex_m::peripheral::syst::SystClkSource;
use cortex_m_rt::{entry, exception};
use embedded_alloc::Heap;
use embedded_graphics::prelude::Point;

use cortex_m::interrupt::free;
use cortex_m_rt::entry;
use efm32pg23_fix::Peripherals;

use embedded_alloc::Heap;
use embedded_graphics::{
pixelcolor::BinaryColor,
prelude::{Point, Primitive},
primitives::{Circle, PrimitiveStyle},
Drawable,
};
use kampela_display_common::display_def::SCREEN_SIZE_X;
use kampela_system::{
devices::{
se_rng::SeRng,
touch::{ft6336_read_at, FT6X36_REG_NUM_TOUCHES, LEN_NUM_TOUCHES},
touch::{Read, FT6X36_REG_NUM_TOUCHES, LEN_NUM_TOUCHES},
},
draw::{highlight_point, FrameBuffer},
init::init_peripherals,
COUNT,
draw::{burning_tank, FrameBuffer},
parallel::Operation,
peripherals::{cmu::init_cmu, gpio_pins::init_gpio, i2c::init_i2c, usart::init_usart},
PERIPHERALS,
};
use kolibri::uistate::UIState;

#[global_allocator]
static HEAP: Heap = Heap::empty();

#[alloc_error_handler]
fn oom(_: Layout) -> ! {
loop {}
fn oom(layout: Layout) -> ! {
panic!("Out of memory! {layout:?}")
}

#[panic_handler]
fn panic(_panic: &PanicInfo<'_>) -> ! {
fn panic(panic: &PanicInfo<'_>) -> ! {
let mut peripherals = unsafe { Peripherals::steal() };
burning_tank(&mut peripherals, format!("{:?}", panic));
loop {}
}

#[allow(non_snake_case)]
#[exception]
fn SysTick() {
unsafe {
COUNT = COUNT.wrapping_add(1);
}
}
/// Initialize peripherals for screen calibration
pub fn init_peripherals_calibration(peripherals: &mut Peripherals) {
// first, start clocking
init_cmu(&mut peripherals.CMU_S);

// map GPIO pins to their functions and set their starting values
init_gpio(&mut peripherals.GPIO_S);

fn init_systick(cortex_periph: &mut cortex_m::Peripherals) {
let syst = &mut cortex_periph.SYST;
const DEFAULT_HZ: u32 = 14_000_000u32;
// Setting up USART0, for epaper display and flash memory
init_usart(peripherals);

syst.set_clock_source(SystClkSource::Core);
syst.set_reload(DEFAULT_HZ / 1_000u32);
syst.clear_current();
syst.enable_counter();
syst.enable_interrupt();
// set up i2c line to communicate with touch pad
init_i2c(peripherals);
}

#[entry]
Expand All @@ -66,33 +70,26 @@ fn main() -> ! {
unsafe { HEAP.init(HEAP_MEM.as_ptr() as usize, HEAP_SIZE) }
}

let mut cortex_periph = cortex_m::Peripherals::take().unwrap();
init_systick(&mut cortex_periph);

let mut peripherals = Peripherals::take().unwrap();
init_peripherals_calibration(&mut peripherals);

init_peripherals(&mut peripherals);
free(|cs| {
PERIPHERALS.borrow(cs).replace(Some(peripherals));
});

let mut do_update = true;
let mut state = UIState::init(&mut SeRng {
peripherals: &mut peripherals,
});
let mut state = UIState::init(&mut SeRng {});

let mut reader = Read::<LEN_NUM_TOUCHES, FT6X36_REG_NUM_TOUCHES>::new();

let measured_affine = loop {
if do_update {
let mut display = FrameBuffer::new_white();
state.render(&mut display).unwrap();
display.apply(&mut peripherals);
let mut frame_buffer = FrameBuffer::new_white();
state.render(&mut frame_buffer).unwrap();
frame_buffer.request_full();
while !frame_buffer.advance(20000i32) {}
do_update = false;
} else if peripherals.GPIO_S.if_.read().extif0().bit_is_set() {
peripherals
.GPIO_S
.if_
.write(|w_reg| w_reg.extif0().clear_bit());

let touch_data =
ft6336_read_at::<LEN_NUM_TOUCHES>(&mut peripherals, FT6X36_REG_NUM_TOUCHES)
.unwrap();
} else if let Some(touch_data) = reader.advance(()).unwrap() {
if touch_data[0] == 1 {
if let UIState::Complete(a) = state {
break a;
Expand All @@ -105,29 +102,16 @@ fn main() -> ! {
x: SCREEN_SIZE_X as i32 - detected_x as i32,
y: detected_y as i32,
};
do_update = state
.process_touch(
point,
&mut SeRng {
peripherals: &mut peripherals,
},
)
.unwrap();
do_update = state.process_touch(point, &mut SeRng {}).unwrap();
}
}
}
};

let mut reader = Read::<LEN_NUM_TOUCHES, FT6X36_REG_NUM_TOUCHES>::new();

loop {
if peripherals.GPIO_S.if_.read().extif0().bit_is_set() {
peripherals
.GPIO_S
.if_
.write(|w_reg| w_reg.extif0().clear_bit());

let touch_data =
ft6336_read_at::<LEN_NUM_TOUCHES>(&mut peripherals, FT6X36_REG_NUM_TOUCHES)
.unwrap();
if let Some(touch_data) = reader.advance(()).unwrap() {
if touch_data[0] == 1 {
let detected_y = ((touch_data[1] as u16 & 0b00001111) << 8) | touch_data[2] as u16;
let detected_x = ((touch_data[3] as u16 & 0b00001111) << 8) | touch_data[4] as u16;
Expand All @@ -136,7 +120,13 @@ fn main() -> ! {
y: detected_y as i32,
};
let point_on_display = measured_affine.transform(&point);
highlight_point(&mut peripherals, point_on_display);
let mut frame_buffer = FrameBuffer::new_white();
Circle::with_center(point_on_display, 20)
.into_styled(PrimitiveStyle::with_fill(BinaryColor::On))
.draw(&mut frame_buffer)
.unwrap();
frame_buffer.request_full();
while !frame_buffer.advance(20000i32) {}
}
}
}
Expand Down
23 changes: 6 additions & 17 deletions kampela-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,19 @@ version = "0.1.0"
[dependencies]
bitvec = {version = "1.0.1", default-features = false, features = ["alloc"]}
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7.2"
cortex-m-semihosting = "0.3.3"
efm32pg23_fix = {path = "../kampela_experiments_efm32pg23/efm32pg23_fix", features = ["critical-section", "rt"]}
rand_core = {version = "0.6.4", default-features = false}
patches = {path = "../kampela_experiments_efm32pg23/patches"}
embedded-alloc = "0.5.0" # embedded-alloc required nightly!
embedded-graphics = "0.7.1"
embedded-graphics-core = "0.3.3"
embedded-text = {version = "0.5.0", default-features = false}
panic-halt = "0.2.0"
ux = { version = "0.1.3", default_features = false }
rand = { version = "0.8.5", default_features = false }
external-memory-tools = {version = "0.1.1", default-features = false}
kampela-display-common = { path = "../kampela-display-common" }
lazy_static = { version = "1.4.0", default_features = false, features = ["spin_no_std"]}

blake2-rfc = {version = "0.2.18", default-features = false}
frame-metadata = {version = "16.0.0", default-features = false, features = ["current", "decode"]}
hex = {version = "0.4.3", default-features = false, features = ["alloc"]}
lt-codes = {git = "https://github.com/Alzymologist/LT-codes", default-features = false}
parity-scale-codec = {version = "3.6.4", default-features = false, features = ["derive", "bit-vec"]}
qrcodegen-no-heap = { version = "1.8.1" }
rand_core = {version = "0.6.4", default-features = false}
scale-info = {version = "2.9.0", default-features = false}
substrate_parser = { git = "https://github.com/Alzymologist/substrate-parser", default-features = false, features = ["embed-display"], rev = "632f621a595fa7161a3352c1f6a05ffcc5f2dcc8" }
kampela-display-common = { path = "../kampela-display-common" }

lt-codes = {git = "https://github.com/Alzymologist/LT-codes", default-features = false}
qrcodegen-noheap = {git = "https://github.com/Slesarew/QR-Code-generator", branch = "patch-1"}
substrate_parser = {git = "https://github.com/Alzymologist/substrate-parser", default-features = false, rev = "65de6a4fe207a64f9857247af4e9f7509fa6de4f"}

[profile.release]
codegen-units = 1
Expand Down
2 changes: 0 additions & 2 deletions kampela-system/rust-toolchain.toml

This file was deleted.

Loading

0 comments on commit 0860510

Please sign in to comment.