diff --git a/src/backends/dummy.rs b/src/backends/dummy.rs index c0d5072..1bf19fa 100644 --- a/src/backends/dummy.rs +++ b/src/backends/dummy.rs @@ -22,12 +22,14 @@ pub const OUTPUT_MEMORY_SIZE: usize = 1; /// /// Both bit masks are active-high. #[cfg(any(chuni, amdaemon))] +#[inline(always)] pub fn jvs_poll(_input: &[u8]) -> (u8, u8) { (0, 0) } /// Checks the current state of the coin button (if there is one). #[cfg(any(chuni, amdaemon))] +#[inline(always)] pub fn is_coin_button_pressed(_input: &[u8]) -> bool { false } @@ -51,13 +53,23 @@ pub fn is_coin_button_pressed(_input: &[u8]) -> bool { /// ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ /// ``` #[cfg(any(chuni, chusanapp))] +#[inline(always)] pub fn read_pressure_data(_input: &[u8]) -> [u8; 32] { [0u8; 32] } +/// Do some one-time initialization to the USB out buffer +/// (e.g. set magic bytes). +#[cfg(any(chuni, chusanapp))] +#[inline(always)] +pub fn init_output_buffer(_output: &mut [u8]) { + +} + /// Update the RGB lighting on the slider. A slice `rgb` is provided, alternating /// between 16 touch pad pixels and 15 divider pixels, going from right to left. #[cfg(any(chuni, chusanapp))] +#[inline(always)] pub fn set_slider_leds( _device: &DeviceHandle, _output: &mut [u8], @@ -77,6 +89,7 @@ pub fn set_slider_leds( /// Note that billboard strips have alternating direction (bottom to top, top /// to bottom...) #[cfg(any(chuni, chusanapp))] +#[inline(always)] pub fn set_led_colors( _device: &DeviceHandle, _output: &mut [u8], diff --git a/src/backends/tasoller_v1.rs b/src/backends/tasoller_v1.rs index 425b3d1..01cd608 100644 --- a/src/backends/tasoller_v1.rs +++ b/src/backends/tasoller_v1.rs @@ -32,7 +32,8 @@ //! - Content length: 240 bytes //! - Bytes 0..3: magic bytes [0x42, 0x4C, 0x00] //! - Bytes 3..96: Slider LED (GRB order, right -> left) -//! - Bytes 96..240: Nothing. +//! - Bytes 96..168: Left tower LED (GRB) +//! - Bytes 168..240: Right tower LED (GRB) #[cfg(any(chuni, chusanapp))] use anyhow::Result; @@ -100,6 +101,14 @@ pub fn read_pressure_data(input: &[u8]) -> [u8; 32] { pressure } +#[cfg(any(chuni, chusanapp))] +#[inline(always)] +pub fn init_output_buffer(output: &mut [u8]) { + output[0] = 0x42; + output[1] = 0x4C; + output[2] = 0; +} + #[cfg(any(chuni, chusanapp))] #[inline(always)] pub fn set_slider_leds( @@ -107,10 +116,6 @@ pub fn set_slider_leds( output: &mut [u8], rgb: &[u8], ) -> Result<()> { - output[0] = 0x42; - output[1] = 0x4C; - output[2] = 0; - for (buf_chunk, state_chunk) in output[3..96].chunks_mut(3).take(31).zip(rgb.chunks(3)) { buf_chunk[0] = state_chunk[1]; buf_chunk[1] = state_chunk[0]; @@ -134,10 +139,6 @@ pub fn set_led_colors( return Ok(()); } - output[0] = 0x42; - output[1] = 0x4C; - output[2] = 0; - let air_rgb = if board == 0 { 0x96 } else { 0xB4 }; let output_start = if board == 0 { 96 } else { 168 }; diff --git a/src/backends/tasoller_v2.rs b/src/backends/tasoller_v2.rs index 375d2df..f084df7 100644 --- a/src/backends/tasoller_v2.rs +++ b/src/backends/tasoller_v2.rs @@ -19,7 +19,8 @@ //! - Content length: 240 bytes //! - Bytes 0..3: magic bytes [0x42, 0x4C, 0x00] //! - Bytes 3..96: Slider LED (GRB order, right -> left) -//! - Bytes 96..240: Nothing. +//! - Bytes 96..168: Left tower LED (GRB) +//! - Bytes 168..240: Right tower LED (GRB) #[cfg(any(chuni, chusanapp))] use anyhow::Result; @@ -65,6 +66,14 @@ pub fn read_pressure_data(input: &[u8]) -> [u8; 32] { pressure } +#[cfg(any(chuni, chusanapp))] +#[inline(always)] +pub fn init_output_buffer(output: &mut [u8]) { + output[0] = 0x42; + output[1] = 0x4C; + output[2] = 0; +} + #[cfg(any(chuni, chusanapp))] #[inline(always)] pub fn set_slider_leds( @@ -72,10 +81,6 @@ pub fn set_slider_leds( output: &mut [u8], rgb: &[u8], ) -> Result<()> { - output[0] = 0x42; - output[1] = 0x4C; - output[2] = 0; - for (buf_chunk, state_chunk) in output[3..96].chunks_mut(3).take(31).zip(rgb.chunks(3)) { buf_chunk[0] = state_chunk[1]; buf_chunk[1] = state_chunk[0]; @@ -99,10 +104,6 @@ pub fn set_led_colors( return Ok(()); } - output[0] = 0x42; - output[1] = 0x4C; - output[2] = 0; - let air_rgb = if board == 0 { 0x96 } else { 0xB4 }; let output_start = if board == 0 { 96 } else { 168 }; diff --git a/src/backends/yubideck_v3.rs b/src/backends/yubideck_v3.rs index 47259c3..8984011 100644 --- a/src/backends/yubideck_v3.rs +++ b/src/backends/yubideck_v3.rs @@ -46,16 +46,19 @@ pub const INPUT_MEMORY_SIZE: usize = 45; pub const OUTPUT_MEMORY_SIZE: usize = 122; #[cfg(any(chuni, amdaemon))] +#[inline(always)] pub fn jvs_poll(input: &[u8]) -> (u8, u8) { (input[1] & 3, input[0]) } #[cfg(any(chuni, amdaemon))] +#[inline(always)] pub fn is_coin_button_pressed(input: &[u8]) -> bool { (input[1] & 4) != 0 } #[cfg(any(chuni, chusanapp))] +#[inline(always)] pub fn read_pressure_data(input: &[u8]) -> [u8; 32] { let mut pressure = [0u8; 32]; @@ -67,14 +70,19 @@ pub fn read_pressure_data(input: &[u8]) -> [u8; 32] { } #[cfg(any(chuni, chusanapp))] +#[inline(always)] +pub fn init_output_buffer(output: &mut [u8]) { + output[0] = 0; + output[61] = 1; +} + +#[cfg(any(chuni, chusanapp))] +#[inline(always)] pub fn set_slider_leds( device: &DeviceHandle, output: &mut [u8], rgb: &[u8], ) -> Result<()> { - output[0] = 0; - output[61] = 1; - for (buf_chunk, state_chunk) in output[1..61].chunks_mut(3).zip(rgb.chunks(3).take(20)) { buf_chunk[0] = state_chunk[0]; buf_chunk[1] = state_chunk[1]; @@ -97,6 +105,7 @@ pub fn set_slider_leds( } #[cfg(any(chuni, chusanapp))] +#[inline(always)] pub fn set_led_colors( device: &DeviceHandle, output: &mut [u8], @@ -107,8 +116,6 @@ pub fn set_led_colors( return Ok(()); } - output[61] = 1; - match board { 0 => { output[95] = rgb[150]; diff --git a/src/lib.rs b/src/lib.rs index b678796..4c6f261 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -296,6 +296,17 @@ pub unsafe extern "C" fn chuni_io_slider_set_leds(rgb: *const u8) { pub extern "C" fn chuni_io_slider_set_leds(_rgb: *const u8) {} #[no_mangle] +#[cfg(any(chuni, chusanapp))] +pub extern "C" fn chuni_io_led_init() -> HRESULT { + let mut output = SLIDER_OUTPUT.write(); + + con_impl::init_output_buffer(output.as_mut_slice()); + + S_OK +} + +#[no_mangle] +#[cfg(amdaemon)] pub extern "C" fn chuni_io_led_init() -> HRESULT { S_OK }