Added some helper functions to St7735IO
This commit is contained in:
parent
74fd69dec8
commit
ca92459649
|
@ -332,18 +332,40 @@ impl St7735 {
|
||||||
-> St7735IO<SPIAddr, GPIOAddr>
|
-> St7735IO<SPIAddr, GPIOAddr>
|
||||||
where SPIAddr: Location,
|
where SPIAddr: Location,
|
||||||
GPIOAddr: Location {
|
GPIOAddr: Location {
|
||||||
St7735IO {
|
St7735IO::start(self, spi, gpio)
|
||||||
st7735: self,
|
|
||||||
spi : spi,
|
|
||||||
gpio : gpio
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<SPIAddr, GPIOAddr> St7735IO<SPIAddr, GPIOAddr>
|
impl<SPIAddr, GPIOAddr> St7735IO<SPIAddr, GPIOAddr>
|
||||||
where SPIAddr: Location,
|
where SPIAddr: Location,
|
||||||
GPIOAddr: Location {
|
GPIOAddr: Location {
|
||||||
|
|
||||||
|
pub fn start(st7735 : St7735, mut spi : PeripheralRef<spi::SPI, SPIAddr>, gpio : PeripheralRef<gpio::GPIO, GPIOAddr>)
|
||||||
|
-> St7735IO<SPIAddr, GPIOAddr>
|
||||||
|
where SPIAddr: Location,
|
||||||
|
GPIOAddr: Location {
|
||||||
|
|
||||||
|
spi.configure(|s| {
|
||||||
|
s.set_enabled(true)
|
||||||
|
.set_master_mode(true)
|
||||||
|
.set_software_slave_select(true)
|
||||||
|
.set_clock_divider(128)
|
||||||
|
// required for master mode, even if ss is done manually
|
||||||
|
.set_slave_select_output_enabled(true)
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut io = St7735IO {
|
||||||
|
st7735: st7735,
|
||||||
|
spi : spi,
|
||||||
|
gpio : gpio
|
||||||
|
};
|
||||||
|
|
||||||
|
io.set_cs();
|
||||||
|
|
||||||
|
io
|
||||||
|
}
|
||||||
|
|
||||||
fn set_rs(&mut self) {
|
fn set_rs(&mut self) {
|
||||||
self.gpio.set_bit(self.st7735.rs_pin);
|
self.gpio.set_bit(self.st7735.rs_pin);
|
||||||
}
|
}
|
||||||
|
@ -386,11 +408,39 @@ impl<SPIAddr, GPIOAddr> St7735IO<SPIAddr, GPIOAddr>
|
||||||
delay_ms(500);
|
delay_ms(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_byte(&mut self, byte : u8) {
|
||||||
|
self.spi.set_data(byte as u32);
|
||||||
|
while self.spi.busy() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_data_byte(&mut self, data : u8) {
|
||||||
|
self.set_rs();
|
||||||
|
|
||||||
|
self.reset_cs();
|
||||||
|
self.write_byte(data);
|
||||||
|
self.set_cs();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_command_byte(&mut self, cmd : u8) {
|
||||||
|
self.set_rs();
|
||||||
|
|
||||||
|
self.reset_cs();
|
||||||
|
self.write_byte(cmd);
|
||||||
|
self.set_cs();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_command(&mut self, cmd : Command) {
|
||||||
|
let cmd_byte = command_to_byte(cmd);
|
||||||
|
self.write_command_byte(cmd_byte);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init(&mut self) {
|
pub fn init(&mut self) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn done(self) -> (St7735, PeripheralRef<spi::SPI, SPIAddr>, PeripheralRef<gpio::GPIO, GPIOAddr>) {
|
pub fn done(mut self) -> (St7735, PeripheralRef<spi::SPI, SPIAddr>, PeripheralRef<gpio::GPIO, GPIOAddr>) {
|
||||||
|
self.set_cs();
|
||||||
|
self.spi.set_enabled(false);
|
||||||
(self.st7735, self.spi, self.gpio)
|
(self.st7735, self.spi, self.gpio)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue