Skip to content

Commit

Permalink
capsules: update to new write_continue format
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Jan 16, 2024
1 parent 2522da1 commit 43f0e35
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
6 changes: 5 additions & 1 deletion capsules/extra/src/lpm013m126.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ where
ret
}

fn write(&self, data: SubSliceMut<'static, u8>) -> Result<(), ErrorCode> {
fn write(
&self,
data: SubSliceMut<'static, u8>,
_continue_write: bool,
) -> Result<(), ErrorCode> {
let len = data.len();
let buffer = data.take();

Expand Down
6 changes: 3 additions & 3 deletions capsules/extra/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'a> Screen<'a> {
if len > 0 {
let mut data = SubSliceMut::new(buffer);
data.slice(..len);
self.screen.write(data)
self.screen.write(data, false)
} else {
self.buffer.replace(buffer);
self.run_next_command(kernel::errorcode::into_statuscode(Ok(())), 0, 0);
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<'a> Screen<'a> {
if len > 0 {
let mut data = SubSliceMut::new(buffer);
data.slice(..len);
self.screen.write(data)
self.screen.write(data, false)
} else {
self.buffer.replace(buffer);
self.run_next_command(kernel::errorcode::into_statuscode(Ok(())), 0, 0);
Expand Down Expand Up @@ -434,7 +434,7 @@ impl<'a> hil::screen::ScreenClient for Screen<'a> {
if r == Ok(()) && len > 0 {
let mut data = SubSliceMut::new(buffer);
data.slice(..len);
let _ = self.screen.write(data);
let _ = self.screen.write(data, true);
} else {
self.buffer.replace(buffer);
self.run_next_command(kernel::errorcode::into_statuscode(r), 0, 0);
Expand Down
42 changes: 26 additions & 16 deletions capsules/extra/src/st77xx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,28 +790,38 @@ impl<'a, A: Alarm<'a>, B: Bus<'a>, P: Pin> screen::Screen<'a> for ST77XX<'a, A,
}
}

fn write(&self, data: SubSliceMut<'static, u8>) -> Result<(), ErrorCode> {
fn write(&self, data: SubSliceMut<'static, u8>, continue_write: bool) -> Result<(), ErrorCode> {
if self.status.get() == Status::Idle {
self.setup_command.set(false);
let len = data.len();
self.write_buffer.replace(data.take());
let buffer_len = self.buffer.map_or_else(
|| panic!("st77xx: buffer is not available"),
|buffer| buffer.len(),
);
if buffer_len > 0 {
// set buffer
self.sequence_buffer.map_or_else(
|| panic!("st77xx: write no sequence buffer"),
|sequence| {
sequence[0] = SendCommand::Slice(&WRITE_RAM, len);
self.sequence_len.set(1);
},

if continue_write == false {
// Writing new data for the first time, make sure to reset
// the screen buffer location to the beginning.

let buffer_len = self.buffer.map_or_else(
|| panic!("st77xx: buffer is not available"),
|buffer| buffer.len(),
);
let _ = self.send_sequence_buffer();
Ok(())
if buffer_len > 0 {
// set buffer
self.sequence_buffer.map_or_else(
|| panic!("st77xx: write no sequence buffer"),
|sequence| {
sequence[0] = SendCommand::Slice(&WRITE_RAM, len);
self.sequence_len.set(1);
},
);
let _ = self.send_sequence_buffer();
Ok(())
} else {
Err(ErrorCode::NOMEM)
}
} else {
Err(ErrorCode::NOMEM)
// Continuing the previous write.
self.send_parameters_slice(len);
Ok(())
}
} else {
Err(ErrorCode::BUSY)
Expand Down

0 comments on commit 43f0e35

Please sign in to comment.