2022-07-27 22:45:46 +02:00
|
|
|
use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestination};
|
|
|
|
|
2023-05-03 10:18:24 +02:00
|
|
|
use crate::pio::{PioInstance, PioStateMachine};
|
2022-07-27 22:45:46 +02:00
|
|
|
|
2023-05-03 10:18:24 +02:00
|
|
|
pub fn set_x<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, value: u32) {
|
2022-07-27 22:45:46 +02:00
|
|
|
const OUT: u16 = InstructionOperands::OUT {
|
|
|
|
destination: OutDestination::X,
|
|
|
|
bit_count: 32,
|
|
|
|
}
|
|
|
|
.encode();
|
2023-05-03 12:49:55 +02:00
|
|
|
sm.tx().push(value);
|
2022-07-27 22:45:46 +02:00
|
|
|
sm.exec_instr(OUT);
|
|
|
|
}
|
|
|
|
|
2023-05-03 10:18:24 +02:00
|
|
|
pub fn get_x<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>) -> u32 {
|
2022-07-27 22:45:46 +02:00
|
|
|
const IN: u16 = InstructionOperands::IN {
|
|
|
|
source: InSource::X,
|
|
|
|
bit_count: 32,
|
|
|
|
}
|
|
|
|
.encode();
|
|
|
|
sm.exec_instr(IN);
|
2023-05-03 12:49:55 +02:00
|
|
|
sm.rx().pull()
|
2022-07-27 22:45:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-03 10:18:24 +02:00
|
|
|
pub fn set_y<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, value: u32) {
|
2022-07-27 22:45:46 +02:00
|
|
|
const OUT: u16 = InstructionOperands::OUT {
|
|
|
|
destination: OutDestination::Y,
|
|
|
|
bit_count: 32,
|
|
|
|
}
|
|
|
|
.encode();
|
2023-05-03 12:49:55 +02:00
|
|
|
sm.tx().push(value);
|
2022-07-27 22:45:46 +02:00
|
|
|
sm.exec_instr(OUT);
|
|
|
|
}
|
|
|
|
|
2023-05-03 10:18:24 +02:00
|
|
|
pub fn get_y<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>) -> u32 {
|
2022-07-27 22:45:46 +02:00
|
|
|
const IN: u16 = InstructionOperands::IN {
|
|
|
|
source: InSource::Y,
|
|
|
|
bit_count: 32,
|
|
|
|
}
|
|
|
|
.encode();
|
|
|
|
sm.exec_instr(IN);
|
|
|
|
|
2023-05-03 12:49:55 +02:00
|
|
|
sm.rx().pull()
|
2022-07-27 22:45:46 +02:00
|
|
|
}
|
|
|
|
|
2023-05-03 10:18:24 +02:00
|
|
|
pub fn set_pindir<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, data: u8) {
|
2022-07-27 22:45:46 +02:00
|
|
|
let set: u16 = InstructionOperands::SET {
|
|
|
|
destination: SetDestination::PINDIRS,
|
|
|
|
data,
|
|
|
|
}
|
|
|
|
.encode();
|
|
|
|
sm.exec_instr(set);
|
|
|
|
}
|
|
|
|
|
2023-05-03 10:18:24 +02:00
|
|
|
pub fn set_pin<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, data: u8) {
|
2022-07-27 22:45:46 +02:00
|
|
|
let set: u16 = InstructionOperands::SET {
|
|
|
|
destination: SetDestination::PINS,
|
|
|
|
data,
|
|
|
|
}
|
|
|
|
.encode();
|
|
|
|
sm.exec_instr(set);
|
|
|
|
}
|
|
|
|
|
2023-05-03 10:18:24 +02:00
|
|
|
pub fn set_out_pin<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, data: u32) {
|
2022-07-27 22:45:46 +02:00
|
|
|
const OUT: u16 = InstructionOperands::OUT {
|
|
|
|
destination: OutDestination::PINS,
|
|
|
|
bit_count: 32,
|
|
|
|
}
|
|
|
|
.encode();
|
2023-05-03 12:49:55 +02:00
|
|
|
sm.tx().push(data);
|
2022-07-27 22:45:46 +02:00
|
|
|
sm.exec_instr(OUT);
|
|
|
|
}
|
2023-05-03 10:18:24 +02:00
|
|
|
pub fn set_out_pindir<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, data: u32) {
|
2022-07-27 22:45:46 +02:00
|
|
|
const OUT: u16 = InstructionOperands::OUT {
|
|
|
|
destination: OutDestination::PINDIRS,
|
|
|
|
bit_count: 32,
|
|
|
|
}
|
|
|
|
.encode();
|
2023-05-03 12:49:55 +02:00
|
|
|
sm.tx().push(data);
|
2022-07-27 22:45:46 +02:00
|
|
|
sm.exec_instr(OUT);
|
|
|
|
}
|
|
|
|
|
2023-05-03 10:18:24 +02:00
|
|
|
pub fn exec_jmp<PIO: PioInstance, const SM: usize>(sm: &mut PioStateMachine<PIO, SM>, to_addr: u8) {
|
2022-07-27 22:45:46 +02:00
|
|
|
let jmp: u16 = InstructionOperands::JMP {
|
|
|
|
address: to_addr,
|
|
|
|
condition: JmpCondition::Always,
|
|
|
|
}
|
|
|
|
.encode();
|
|
|
|
sm.exec_instr(jmp);
|
|
|
|
}
|