```rust fn set_mode(&self, pin: SaksPins, pin_mode: PinMode) { let bcm_pin_num = u32::from(pin); // bcm2711-peripherals.pdf page 66, each GPFSEL${N} register every 3 bit manage a GPIO's pin_mode // eg. Buzzer=12 need register GPFSEL1 to set pin_mode, offset to mmap is 1 let gpfsel_index = bcm_pin_num / 10; // eg. GPFSEL1 bit [6..=8] is the bit_mask to set Buzzer=12 pin_mode let pin_mode_shift = (bcm_pin_num % 10) * 3;
let reg_ptr = unsafe { self.mapped_addr .add(GPFSEL0 + gpfsel_index as usize) };
let mut reg_val = unsafe { *reg_ptr }; // eg. bit_mask to set GPFSEL1's [6..=8] bit to zero let bit_mask_to_clear_bcm_pin_num_pin_mode = !(0b111 << pin_mode_shift); reg_val &= bit_mask_to_clear_bcm_pin_num_pin_mode; // eg. set GPFSEL1's [6..=8] bit to pin_mode arg reg_val |= (u32::from(pin_mode)) << pin_mode_shift;