Skip to content
Snippets Groups Projects
Commit 2d5c2192 authored by Benjamin Koch's avatar Benjamin Koch
Browse files

add simple Rust program with mostly the pinout, so far

parent d9c3c73b
No related branches found
No related tags found
No related merge requests found
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::gpio;
use embassy_time::{Duration, Timer};
use embassy_rp::gpio::{Input, Level, Output, Pull};
use embassy_rp::i2c::{self};
use embassy_rp::interrupt;
use embedded_hal_async::i2c::I2c;
use embassy_rp::peripherals::UART0;
use embassy_rp::uart::{self, Async, UartRx, UartTx, Parity};
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
// pinout:
let mut drive1 = Output::new(p.PIN_0, Level::Low);
let mut drive2 = Output::new(p.PIN_1, Level::Low);
//let LED_W = p.PIN_2;
let ws2812_display = p.PIN_2;
//let LED_Y = p.PIN_3;
let mut en_measure_current = Output::new(p.PIN_3, Level::Low);
let mut led_b = Output::new(p.PIN_4, Level::Low);
let mut led_g = Output::new(p.PIN_5, Level::Low);
let mut led_r = Output::new(p.PIN_6, Level::Low);
let matrix_in1 = Input::new(p.PIN_7, Pull::Up);
let sbu1 = p.PIN_8;
let sbu2 = p.PIN_9;
let vbus_det = p.PIN_10;
let button_boot2 = Input::new(p.PIN_11, Pull::Up);
let sda = p.PIN_12;
let scl = p.PIN_13;
let ws2811_red_in = Input::new(p.PIN_14, Pull::None);
let tx_en = p.PIN_15;
let tx = p.PIN_16;
let rx = p.PIN_17;
let matrix_in2 = Input::new(p.PIN_18, Pull::Up);
let reed3 = Input::new(p.PIN_19, Pull::Up);
let reed4 = Input::new(p.PIN_20, Pull::Up);
let reed2 = Input::new(p.PIN_21, Pull::Up);
let reed1 = Input::new(p.PIN_22, Pull::Up);
let matrix_in3 = Input::new(p.PIN_23, Pull::Up);
let digout1 = p.PIN_24;
let digout2 = p.PIN_25;
let analog_in1 = p.PIN_26;
let current2 = p.PIN_27;
let current1 = p.PIN_28;
let measure_vcc = p.PIN_29;
info!("set up i2c ");
let i2c_irq = interrupt::take!(I2C0_IRQ);
let mut i2c_config = i2c::Config::default();
i2c_config.frequency = 400_000;
let mut i2c = i2c::I2c::new_async(p.I2C0, scl, sda, i2c_irq, i2c_config);
// use 19200 baud in 8E1 mode - not great but Modbus default
let mut uart_config = uart::Config::default();
uart_config.baudrate = 19200;
uart_config.parity = Parity::ParityEven;
let uart_rx = UartRx::new(
p.UART0,
rx,
interrupt::take!(UART0_IRQ),
p.DMA_CH1,
uart_config,
);
loop {
info!("led on!");
led_b.set_high();
Timer::after(Duration::from_secs(1)).await;
info!("led off!");
led_b.set_low();
Timer::after(Duration::from_secs(1)).await;
}
// dummy read to fix Mode paraemter of UartRx
let buf = [0; 1];
let x = uart_rx.read(&mut buf).await;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment