Skip to content

Commit

Permalink
validate pin in [0,64)
Browse files Browse the repository at this point in the history
  • Loading branch information
gvaradarajan committed Oct 22, 2024
1 parent a2f0da4 commit 150638f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions micro-rdk/src/esp32/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ fn install_gpio_isr_service() -> Result<(), BoardError> {
fn is_valid_gpio_pin(pin: i32) -> Result<(), BoardError> {
// Do this masking in 64-bit space because it works for both esp32
// where the mask is 32 bits and esp32s3 where it is 64.
if (pin < 0) || (pin >= 64) {
return Err(BoardError::InvalidGpioNumber(pin as u32))
}
match (1_u64 << (pin as u64)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK {
0 => Err(BoardError::InvalidGpioNumber(pin as u32)),
_ => Ok(()),
Expand Down

0 comments on commit 150638f

Please sign in to comment.