first commit

main
Miroito 2 years ago
commit 7c3d307d0a

@ -0,0 +1,21 @@
[target.riscv32imc-unknown-none-elf]
runner = "espflash flash --monitor"
[env]
ESP_LOGLEVEL="INFO"
[build]
rustflags = [
"-C", "link-arg=-Tlinkall.x",
"-C", "link-arg=-Trom_functions.x",
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
# NOTE: May negatively impact performance of produced code
"-C", "force-frame-pointers",
]
target = "riscv32imc-unknown-none-elf"
[unstable]
build-std = ["core"]

10
.gitignore vendored

@ -0,0 +1,10 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

1190
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,54 @@
[package]
name = "esp-spot"
version = "0.1.0"
authors = ["Miroito <alban.vachette@gmail.com>"]
edition = "2021"
license = "MIT OR Apache-2.0"
[dependencies]
esp-backtrace = { version = "0.11.0", features = [
"esp32c3",
"exception-handler",
"panic-handler",
"println",
] }
esp-hal = { version = "0.16.0", features = [ "esp32c3" ] }
esp-println = { version = "0.9.0", features = ["esp32c3", "log"] }
log = { version = "0.4.20" }
embedded-svc = { version = "0.26.1", default-features = false, features = [] }
embedded-io = "0.6.1"
esp-wifi = { version = "0.4.0", features = [
"esp32c3",
"phy-enable-usb",
"utils",
"wifi-default",
"ble",
"coex",
] }
heapless = { version = "0.8.0", default-features = false }
smoltcp = { version = "0.10.0", default-features = false, features = [
"medium-ethernet",
"proto-dhcpv4",
"proto-igmp",
"proto-ipv4",
"socket-dhcpv4",
"socket-icmp",
"socket-raw",
"socket-tcp",
"socket-udp",
] }
esp-hal-smartled = { version = "0.9.0", features = ["esp32c3"] }
smart-leds = "0.4.0"
[profile.dev]
# Rust debug is too slow.
# For debug builds always builds with some optimization
opt-level = "s"
[profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread
debug = 2
debug-assertions = false
incremental = false
lto = 'fat'
opt-level = 's'
overflow-checks = false

@ -0,0 +1,25 @@
Copyright [year] [fullname]
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

@ -0,0 +1,5 @@
[toolchain]
channel = "nightly"
components = ["rust-src"]
targets = ["riscv32imc-unknown-none-elf"]

@ -0,0 +1,82 @@
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl, delay::Delay, gpio::IO, peripherals::Peripherals, prelude::*, rmt::Rmt,
};
use esp_println::println;
use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter};
use smart_leds::{
brightness, gamma,
hsv::{hsv2rgb, Hsv},
SmartLedsWrite,
};
use esp_wifi::{initialize, EspWifiInitFor};
use esp_hal::{systimer::SystemTimer, Rng};
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::max(system.clock_control).freeze();
let mut delay = Delay::new(&clocks);
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let led_pin = io.pins.gpio8;
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations
let rmt_buffer = smartLedBuffer!(1);
let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap();
let mut led = SmartLedsAdapter::new(rmt.channel0, led_pin, rmt_buffer, &clocks);
// Initialize the Delay peripheral, and use it to toggle the LED state in a
// loop.
let mut delay = Delay::new(&clocks);
let mut color = Hsv {
hue: 0,
sat: 255,
val: 255,
};
let mut data;
// setup logger
// To change the log_level change the env section in .cargo/config.toml
// or remove it and set ESP_LOGLEVEL manually before running cargo run
// this requires a clean rebuild because of https://github.com/rust-lang/cargo/issues/10358
esp_println::logger::init_logger_from_env();
log::info!("Logger is setup");
println!("Hello world!");
let timer = SystemTimer::new(peripherals.SYSTIMER).alarm0;
let _init = initialize(
EspWifiInitFor::WifiBle,
timer,
Rng::new(peripherals.RNG),
system.radio_clock_control,
&clocks,
)
.unwrap();
loop {
println!("Loop...");
delay.delay_ms(500u32);
for hue in 0..=255 {
color.hue = hue;
// Convert from the HSV color space (where we can easily transition from one
// color to the other) to the RGB color space that we can then send to the LED
data = [hsv2rgb(color)];
// When sending to the LED, we do a gamma correction first (see smart_leds
// documentation for details) and then limit the brightness to 10 out of 255 so
// that the output it's not too bright.
led.write(brightness(gamma(data.iter().cloned()), 10))
.unwrap();
delay.delay_ms(20u32);
}
}
}
Loading…
Cancel
Save