use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestination};
use crate::pio::{Instance, StateMachine};
impl<'d, PIO: Instance, const SM: usize> StateMachine<'d, PIO, SM> {
pub unsafe fn set_x(&mut self, value: u32) {
const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::X,
bit_count: 32,
}
.encode();
self.tx().push(value);
self.exec_instr(OUT);
}
pub unsafe fn get_x(&mut self) -> u32 {
const IN: u16 = InstructionOperands::IN {
source: InSource::X,
bit_count: 32,
}
.encode();
self.exec_instr(IN);
self.rx().pull()
}
pub unsafe fn set_y(&mut self, value: u32) {
const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::Y,
bit_count: 32,
}
.encode();
self.tx().push(value);
self.exec_instr(OUT);
}
pub unsafe fn get_y(&mut self) -> u32 {
const IN: u16 = InstructionOperands::IN {
source: InSource::Y,
bit_count: 32,
}
.encode();
self.exec_instr(IN);
self.rx().pull()
}
pub unsafe fn set_pindir(&mut self, data: u8) {
let set: u16 = InstructionOperands::SET {
destination: SetDestination::PINDIRS,
data,
}
.encode();
self.exec_instr(set);
}
pub unsafe fn set_pin(&mut self, data: u8) {
let set: u16 = InstructionOperands::SET {
destination: SetDestination::PINS,
data,
}
.encode();
self.exec_instr(set);
}
pub unsafe fn set_out_pin(&mut self, data: u32) {
const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::PINS,
bit_count: 32,
}
.encode();
self.tx().push(data);
self.exec_instr(OUT);
}
pub unsafe fn set_out_pindir(&mut self, data: u32) {
const OUT: u16 = InstructionOperands::OUT {
destination: OutDestination::PINDIRS,
bit_count: 32,
}
.encode();
self.tx().push(data);
self.exec_instr(OUT);
}
pub unsafe fn exec_jmp(&mut self, to_addr: u8) {
let jmp: u16 = InstructionOperands::JMP {
address: to_addr,
condition: JmpCondition::Always,
}
.encode();
self.exec_instr(jmp);
}
}