rp/pio: configure state machines with Config struct
the many individual sets aren't very efficient, and almost no checks were done to ensure that the configuration written to the hardware was actually valid. this adresses both of these.
This commit is contained in:
@ -4,11 +4,12 @@
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
use embassy_embedded_hal::SetConfig;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_rp::dma::{AnyChannel, Channel};
|
||||
use embassy_rp::peripherals::PIO0;
|
||||
use embassy_rp::pio::{Direction, FifoJoin, Pio, PioPin, ShiftDirection, StateMachine};
|
||||
use embassy_rp::pwm::{Config, Pwm};
|
||||
use embassy_rp::pio::{Config, Direction, FifoJoin, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine};
|
||||
use embassy_rp::pwm::{self, Pwm};
|
||||
use embassy_rp::relocate::RelocatedProgram;
|
||||
use embassy_rp::{into_ref, Peripheral, PeripheralRef};
|
||||
use embassy_time::{Duration, Instant, Timer};
|
||||
@ -29,7 +30,7 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
|
||||
let _pwm = Pwm::new_output_b(p.PWM_CH7, p.PIN_15, {
|
||||
let mut c = Config::default();
|
||||
let mut c = pwm::Config::default();
|
||||
c.divider = 125.into();
|
||||
c.top = 100;
|
||||
c.compare_b = 50;
|
||||
@ -83,7 +84,6 @@ impl<'l> HD44780<'l> {
|
||||
) -> HD44780<'l> {
|
||||
into_ref!(dma);
|
||||
|
||||
let db7pin = db7.pin();
|
||||
let Pio {
|
||||
mut common,
|
||||
mut irq0,
|
||||
@ -118,13 +118,17 @@ impl<'l> HD44780<'l> {
|
||||
sm0.set_pin_dirs(Direction::Out, &[&rs, &rw, &e, &db4, &db5, &db6, &db7]);
|
||||
|
||||
let relocated = RelocatedProgram::new(&prg.program);
|
||||
sm0.use_program(&common.load_program(&relocated), &[&e]);
|
||||
sm0.set_clkdiv(125 * 256);
|
||||
sm0.set_out_pins(&[&db4, &db5, &db6, &db7]);
|
||||
sm0.set_out_shift_dir(ShiftDirection::Left);
|
||||
sm0.set_fifo_join(FifoJoin::TxOnly);
|
||||
sm0.set_autopull(true);
|
||||
sm0.set_pull_threshold(32);
|
||||
let mut cfg = Config::default();
|
||||
cfg.use_program(&common.load_program(&relocated), &[&e]);
|
||||
cfg.clock_divider = 125u8.into();
|
||||
cfg.set_out_pins(&[&db4, &db5, &db6, &db7]);
|
||||
cfg.shift_out = ShiftConfig {
|
||||
auto_fill: true,
|
||||
direction: ShiftDirection::Left,
|
||||
threshold: 32,
|
||||
};
|
||||
cfg.fifo_join = FifoJoin::TxOnly;
|
||||
sm0.set_config(&cfg);
|
||||
|
||||
sm0.set_enable(true);
|
||||
// init to 8 bit thrice
|
||||
@ -188,13 +192,15 @@ impl<'l> HD44780<'l> {
|
||||
);
|
||||
|
||||
let relocated = RelocatedProgram::new(&prg.program);
|
||||
sm0.use_program(&common.load_program(&relocated), &[&e]);
|
||||
sm0.set_clkdiv(8 * 256); // ~64ns/insn
|
||||
sm0.set_jmp_pin(db7pin);
|
||||
sm0.set_set_pins(&[&rs, &rw]);
|
||||
sm0.set_out_pins(&[&db4, &db5, &db6, &db7]);
|
||||
sm0.set_out_shift_dir(ShiftDirection::Left);
|
||||
sm0.set_fifo_join(FifoJoin::TxOnly);
|
||||
let mut cfg = Config::default();
|
||||
cfg.use_program(&common.load_program(&relocated), &[&e]);
|
||||
cfg.clock_divider = 8u8.into(); // ~64ns/insn
|
||||
cfg.set_jmp_pin(&db7);
|
||||
cfg.set_set_pins(&[&rs, &rw]);
|
||||
cfg.set_out_pins(&[&db4, &db5, &db6, &db7]);
|
||||
cfg.shift_out.direction = ShiftDirection::Left;
|
||||
cfg.fifo_join = FifoJoin::TxOnly;
|
||||
sm0.set_config(&cfg);
|
||||
|
||||
sm0.set_enable(true);
|
||||
|
||||
|
Reference in New Issue
Block a user