|
| 1 | +use display_interface::{DataFormat, DisplayError, WriteOnlyDataCommand}; |
| 2 | + |
| 3 | +use super::{Lcd, SubBank}; |
| 4 | + |
| 5 | +impl<S> WriteOnlyDataCommand for Lcd<S> |
| 6 | +where |
| 7 | + S: SubBank, |
| 8 | +{ |
| 9 | + fn send_commands(&mut self, cmd: DataFormat<'_>) -> Result<(), DisplayError> { |
| 10 | + match cmd { |
| 11 | + DataFormat::U8(slice) => { |
| 12 | + for value in slice { |
| 13 | + self.write_command(u16::from(*value)); |
| 14 | + } |
| 15 | + } |
| 16 | + DataFormat::U16(slice) => { |
| 17 | + for value in slice { |
| 18 | + self.write_command(*value); |
| 19 | + } |
| 20 | + } |
| 21 | + DataFormat::U16BE(slice) | DataFormat::U16LE(slice) => { |
| 22 | + // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
| 23 | + for value in slice { |
| 24 | + self.write_command(*value); |
| 25 | + } |
| 26 | + } |
| 27 | + DataFormat::U8Iter(iter) => { |
| 28 | + for value in iter { |
| 29 | + self.write_command(u16::from(value)); |
| 30 | + } |
| 31 | + } |
| 32 | + DataFormat::U16BEIter(iter) | DataFormat::U16LEIter(iter) => { |
| 33 | + // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
| 34 | + for value in iter { |
| 35 | + self.write_command(value); |
| 36 | + } |
| 37 | + } |
| 38 | + _ => return Err(DisplayError::DataFormatNotImplemented), |
| 39 | + } |
| 40 | + Ok(()) |
| 41 | + } |
| 42 | + |
| 43 | + fn send_data(&mut self, buf: DataFormat<'_>) -> Result<(), DisplayError> { |
| 44 | + match buf { |
| 45 | + DataFormat::U8(slice) => { |
| 46 | + for value in slice { |
| 47 | + self.write_data(u16::from(*value)); |
| 48 | + } |
| 49 | + } |
| 50 | + DataFormat::U16(slice) => { |
| 51 | + for value in slice { |
| 52 | + self.write_data(*value); |
| 53 | + } |
| 54 | + } |
| 55 | + DataFormat::U16BE(slice) | DataFormat::U16LE(slice) => { |
| 56 | + // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
| 57 | + for value in slice { |
| 58 | + self.write_data(*value); |
| 59 | + } |
| 60 | + } |
| 61 | + DataFormat::U8Iter(iter) => { |
| 62 | + for value in iter { |
| 63 | + self.write_data(u16::from(value)); |
| 64 | + } |
| 65 | + } |
| 66 | + DataFormat::U16BEIter(iter) | DataFormat::U16LEIter(iter) => { |
| 67 | + // As long as the data bus is 16 bits wide, the byte order doesn't matter. |
| 68 | + for value in iter { |
| 69 | + self.write_data(value); |
| 70 | + } |
| 71 | + } |
| 72 | + _ => return Err(DisplayError::DataFormatNotImplemented), |
| 73 | + } |
| 74 | + Ok(()) |
| 75 | + } |
| 76 | +} |
0 commit comments