initial
This commit is contained in:
commit
554a66b0b4
|
|
@ -0,0 +1,16 @@
|
|||
#[target.thumbv7em-none-eabihf]
|
||||
#runner = 'probe-rs run --chip nRF52840_xxAA'
|
||||
|
||||
#[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
#runner = "probe-rs run --no-location --chip nRF52840_xxAA"
|
||||
|
||||
[build]
|
||||
target = "thumbv7em-none-eabihf"
|
||||
#target = "thumbv7em-none-eabi"
|
||||
|
||||
[env]
|
||||
DEFMT_LOG = "trace"
|
||||
|
||||
[unstable]
|
||||
build-std = ["core"]
|
||||
build-std-features = ["panic_immediate_abort"]
|
||||
|
|
@ -0,0 +1 @@
|
|||
/target
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="McpProjectServerCommands">
|
||||
<commands />
|
||||
<urls />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/odesa.iml" filepath="$PROJECT_DIR$/.idea/odesa.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="EMPTY_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,54 @@
|
|||
# This file was automatically generated.
|
||||
|
||||
[package]
|
||||
edition = "2024"
|
||||
name = "odesa"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = { version = "0.7.7", features = ["inline-asm", "critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.5"
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
defmt-rtt = { version = "1.1.0", optional = true }
|
||||
embassy-executor = { version = "0.9.1", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
|
||||
embassy-futures = "0.1.2"
|
||||
embassy-nrf = { version = "0.9.0", features = ["nrf52840", "gpiote", "time-driver-rtc1", "defmt", "unstable-pac", "time", "nfc-pins-as-gpio"] }
|
||||
embassy-sync = { version = "0.7.2", features = ["defmt"] }
|
||||
embassy-time = { version = "0.5.0", features = ["tick-hz-32_768", "defmt", "defmt-timestamp-uptime"] }
|
||||
panic-halt = "1.0.0"
|
||||
panic-probe = { version = "1.0.0", features = ["print-defmt"], optional = true }
|
||||
nrf-softdevice = { version = "0.1.0", features = ["s140", "ble-peripheral", "nrf52840"] }
|
||||
|
||||
[[bin]]
|
||||
name = "odesa"
|
||||
test = false
|
||||
bench = false
|
||||
|
||||
[profile.dev]
|
||||
debug = true
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
incremental = true
|
||||
|
||||
[profile.release]
|
||||
debug = false
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
incremental = true
|
||||
|
||||
[features]
|
||||
defmt = ["dep:defmt"]
|
||||
defmt-rtt = ["dep:defmt-rtt"]
|
||||
panic-probe = ["dep:panic-probe"]
|
||||
default = ["debug"]
|
||||
debug = [
|
||||
"defmt",
|
||||
"defmt-rtt",
|
||||
"panic-probe",
|
||||
"embassy-executor/defmt",
|
||||
"embassy-sync/defmt",
|
||||
"embassy-futures/defmt",
|
||||
"embassy-time/defmt",
|
||||
"embassy-time/defmt-timestamp-uptime",
|
||||
"embassy-nrf/defmt",
|
||||
]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# This file was automatically generated.
|
||||
|
||||
[default.general]
|
||||
chip = "nRF52840_xxAA"
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
// This file was automatically generated.
|
||||
|
||||
//! This build script copies the `memory.x` file from the crate root into
|
||||
//! a directory where the linker can always find it at build time.
|
||||
//! For many projects this is optional, as the linker always searches the
|
||||
//! project root directory -- wherever `Cargo.toml` is. However, if you
|
||||
//! are using a workspace or have a more complicated build setup, this
|
||||
//! build script becomes required. Additionally, by requesting that
|
||||
//! Cargo re-run the build script whenever `memory.x` is changed,
|
||||
//! updating `memory.x` ensures a rebuild of the application with the
|
||||
//! new memory settings.
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
// Put `memory.x` in our output directory and ensure it's
|
||||
// on the linker search path.
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
File::create(out.join("memory.x"))
|
||||
.unwrap()
|
||||
.write_all(include_bytes!("memory.x"))
|
||||
.unwrap();
|
||||
println!("cargo:rustc-link-search={}", out.display());
|
||||
|
||||
// By default, Cargo will re-run a build script whenever
|
||||
// any file in the project changes. By specifying `memory.x`
|
||||
// here, we ensure the build script is only re-run when
|
||||
// `memory.x` is changed.
|
||||
println!("cargo:rerun-if-changed=memory.x");
|
||||
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
#[cfg(feature = "defmt")]
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x00000000 + 156K, LENGTH = 1024K - 156K
|
||||
RAM : ORIGIN = 0x20000000 + 31K, LENGTH = 256K - 31K
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "1.90"
|
||||
components = ["rust-src", "rustfmt"]
|
||||
targets = ["thumbv7em-none-eabihf", "thumbv7em-none-eabi"]
|
||||
|
|
@ -0,0 +1,241 @@
|
|||
// This file was automatically generated.
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
macro_rules! assert {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
::core::assert!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::assert!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! assert_eq {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
::core::assert_eq!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::assert_eq!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! assert_ne {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
::core::assert_ne!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::assert_ne!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! debug_assert {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
::core::debug_assert!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::debug_assert!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! debug_assert_eq {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
::core::debug_assert_eq!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::debug_assert_eq!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! debug_assert_ne {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
::core::debug_assert_ne!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::debug_assert_ne!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! todo {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
::core::todo!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::todo!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
macro_rules! unreachable {
|
||||
($($x:tt)*) => {
|
||||
::core::unreachable!($($x)*)
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "defmt")]
|
||||
macro_rules! unreachable {
|
||||
($($x:tt)*) => {
|
||||
::defmt::unreachable!($($x)*)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! panic {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
::core::panic!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::panic!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! trace {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
{
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::trace!($s $(, $x)*);
|
||||
#[cfg(feature="defmt")]
|
||||
let _ = ($( & $x ),*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! debug {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
{
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::debug!($s $(, $x)*);
|
||||
#[cfg(not(feature="defmt"))]
|
||||
let _ = ($( & $x ),*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! info {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
{
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::info!($s $(, $x)*);
|
||||
#[cfg(not(feature="defmt"))]
|
||||
let _ = ($( & $x ),*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! _warn {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
{
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::warn!($s $(, $x)*);
|
||||
#[cfg(not(feature="defmt"))]
|
||||
let _ = ($( & $x ),*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! error {
|
||||
($s:literal $(, $x:expr)* $(,)?) => {
|
||||
{
|
||||
#[cfg(feature = "defmt")]
|
||||
::defmt::error!($s $(, $x)*);
|
||||
#[cfg(not(feature="defmt"))]
|
||||
let _ = ($( & $x ),*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "defmt")]
|
||||
macro_rules! unwrap {
|
||||
($($x:tt)*) => {
|
||||
::defmt::unwrap!($($x)*)
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
macro_rules! unwrap {
|
||||
($arg:expr) => {
|
||||
match $crate::fmt::Try::into_result($arg) {
|
||||
::core::result::Result::Ok(t) => t,
|
||||
::core::result::Result::Err(_) => {
|
||||
::core::panic!();
|
||||
}
|
||||
}
|
||||
};
|
||||
($arg:expr, $($msg:expr),+ $(,)? ) => {
|
||||
match $crate::fmt::Try::into_result($arg) {
|
||||
::core::result::Result::Ok(t) => t,
|
||||
::core::result::Result::Err(_) => {
|
||||
::core::panic!();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub struct NoneError;
|
||||
|
||||
pub trait Try {
|
||||
type Ok;
|
||||
type Error;
|
||||
fn into_result(self) -> Result<Self::Ok, Self::Error>;
|
||||
}
|
||||
|
||||
impl<T> Try for Option<T> {
|
||||
type Ok = T;
|
||||
type Error = NoneError;
|
||||
|
||||
#[inline]
|
||||
fn into_result(self) -> Result<T, NoneError> {
|
||||
self.ok_or(NoneError)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> Try for Result<T, E> {
|
||||
type Ok = T;
|
||||
type Error = E;
|
||||
|
||||
#[inline]
|
||||
fn into_result(self) -> Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Bytes<'a>(pub &'a [u8]);
|
||||
|
||||
#[cfg(feature = "defmt")]
|
||||
impl defmt::Format for Bytes<'_> {
|
||||
fn format(&self, fmt: defmt::Formatter) {
|
||||
defmt::write!(fmt, "{:02x}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) use _warn as warn;
|
||||
pub(crate) use assert;
|
||||
pub(crate) use assert_eq;
|
||||
pub(crate) use assert_ne;
|
||||
pub(crate) use debug;
|
||||
pub(crate) use debug_assert;
|
||||
pub(crate) use debug_assert_eq;
|
||||
pub(crate) use debug_assert_ne;
|
||||
pub(crate) use error;
|
||||
pub(crate) use info;
|
||||
pub(crate) use panic;
|
||||
pub(crate) use todo;
|
||||
pub(crate) use trace;
|
||||
pub(crate) use unreachable;
|
||||
pub(crate) use unwrap;
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
mod fmt;
|
||||
|
||||
use core::mem;
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
use panic_halt as _;
|
||||
#[cfg(feature = "defmt")]
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
#[cfg(feature = "defmt")]
|
||||
use defmt::warn;
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::join::join;
|
||||
use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull};
|
||||
use embassy_nrf::pac::PWM0;
|
||||
use embassy_nrf::pwm::{DutyCycle, Prescaler, SimplePwm};
|
||||
use embassy_nrf::Peri;
|
||||
use embassy_nrf::peripherals::PWM0;
|
||||
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
||||
use embassy_sync::signal::Signal;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use nrf_softdevice::{raw, Softdevice};
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
enum SysAction {
|
||||
Off,
|
||||
Moving,
|
||||
ConstantOn,
|
||||
}
|
||||
|
||||
static SYS_SIGNAL: Signal<ThreadModeRawMutex, SysAction> = Signal::new();
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let config = nrf_softdevice::Config {
|
||||
clock: Some(raw::nrf_clock_lf_cfg_t {
|
||||
source: raw::NRF_CLOCK_LF_SRC_RC as u8,
|
||||
rc_ctiv: 16,
|
||||
rc_temp_ctiv: 2,
|
||||
accuracy: raw::NRF_CLOCK_LF_ACCURACY_500_PPM as u8,
|
||||
}),
|
||||
conn_gap: Some(raw::ble_gap_conn_cfg_t {
|
||||
conn_count: 6,
|
||||
event_length: 24,
|
||||
}),
|
||||
conn_gatt: Some(raw::ble_gatt_conn_cfg_t { att_mtu: 256 }),
|
||||
gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t {
|
||||
attr_tab_size: raw::BLE_GATTS_ATTR_TAB_SIZE_DEFAULT,
|
||||
}),
|
||||
gap_role_count: Some(raw::ble_gap_cfg_role_count_t {
|
||||
adv_set_count: 1,
|
||||
periph_role_count: 3,
|
||||
central_role_count: 3,
|
||||
central_sec_count: 0,
|
||||
_bitfield_1: raw::ble_gap_cfg_role_count_t::new_bitfield_1(0),
|
||||
}),
|
||||
gap_device_name: Some(raw::ble_gap_cfg_device_name_t {
|
||||
p_value: b"HelloRust" as *const u8 as _,
|
||||
current_len: 9,
|
||||
max_len: 9,
|
||||
write_perm: unsafe { mem::zeroed() },
|
||||
_bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8),
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let _sd = Softdevice::enable(&config);
|
||||
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut led1_red = Output::new(p.P0_31, Level::High, OutputDrive::Standard);
|
||||
let mut led1_green = Output::new(p.P0_29, Level::High, OutputDrive::Standard);
|
||||
let mut led1_blue = Output::new(p.P0_02, Level::High, OutputDrive::Standard);
|
||||
led1_red.set_high();
|
||||
led1_green.set_high();
|
||||
led1_blue.set_high();
|
||||
|
||||
// let mut led_red = Output::new(p.P1_15, Level::High, OutputDrive::Standard);
|
||||
// let mut led_green = Output::new(p.P1_13, Level::High, OutputDrive::Standard);
|
||||
// let mut led_blue = Output::new(p.P1_11, Level::High, OutputDrive::Standard);
|
||||
// led_red.set_high();
|
||||
// led_green.set_high();
|
||||
// led_blue.set_high();
|
||||
|
||||
let pwm = SimplePwm::new_3ch(p.PWM0, p.P1_15, p.P1_13, p.P1_11, &Default::default());
|
||||
|
||||
join(touch_button(p.P0_20.into()), light_task(pwm)).await;
|
||||
//
|
||||
// loop {
|
||||
// warn!("Hello, World!");
|
||||
// led_red.set_low();
|
||||
// Timer::after_millis(500).await;
|
||||
// led_red.set_high();
|
||||
// Timer::after_millis(500).await;
|
||||
//
|
||||
// warn!("Hello, World!");
|
||||
// led_green.set_low();
|
||||
// Timer::after_millis(500).await;
|
||||
// led_green.set_high();
|
||||
// Timer::after_millis(500).await;
|
||||
//
|
||||
// warn!("Hello, World!");
|
||||
// led_blue.set_low();
|
||||
// Timer::after_millis(500).await;
|
||||
// led_blue.set_high();
|
||||
// Timer::after_millis(500).await;
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
async fn touch_button(pin: Peri<'static, AnyPin>) {
|
||||
let mut button = Input::new(pin, Pull::Down);
|
||||
loop {
|
||||
button.wait_for_low().await;
|
||||
SYS_SIGNAL.signal(SysAction::Off);
|
||||
Timer::after_millis(320).await;
|
||||
button.wait_for_high().await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn light_task(pwm: SimplePwm<'static>) {
|
||||
pwm.set_prescaler(Prescaler::Div1);
|
||||
pwm.set_max_duty(32767);
|
||||
|
||||
loop {
|
||||
|
||||
}
|
||||
}
|
||||
//
|
||||
// async fn fade_between(pwm: &Pwm, pin: &Output<'_, P0_11>, start: u16, end: u16) {
|
||||
// let steps = 100;
|
||||
// let step_duration = Duration::from_millis(50);
|
||||
//
|
||||
// // Gradually transition between start and end values
|
||||
// for i in 0..steps {
|
||||
// let value = start + ((end - start) * i) / steps as u16;
|
||||
// pwm.set_duty(value); // Update PWM duty cycle
|
||||
// pin.set_level(Level::Low); // Ensure the LED is on
|
||||
// Timer::after(step_duration).await;
|
||||
// }
|
||||
// }
|
||||
Loading…
Reference in New Issue