static uint8_t _pin_pressed = 0;

void btnRisingIsrHandler(uint8_t btn_pin)
{
  _pin_pressed = btn_pin;
  /* Do other stuff for specific pin */
}

void LocalRegisterButton(uint8_t pin)
{
  /* I would like to simplize this function based on *pin* variable */
  pinMode(pin, INPUT_PULLUP);
  
  switch ( pin )
  {
    case 4:
      attachInterrupt(4,
        /* Lambda start */
        [] IRAM_ATTR ()  {
          /* The problem is that I must hard-code the number 4 here */
          /* I want to use *pin* variable to remove "case 5:" below */
          btnRisingIsrHandler(4);
        }
        /* Lambda end */
        ,
        RISING);
    break;

    case 5:
      attachInterrupt(5, []() IRAM_ATTR {
          btnRisingIsrHandler(5);
        },
        RISING);
    break;

    /* Other cases for all possible PIN numbers */
  }

}

void setup() {
  Serial.begin(115200);
  Serial.println("Hello, ESP32-S3!");
  LocalRegisterButton( 4 );
  LocalRegisterButton( 5 );
}

void loop() {
  if (_pin_pressed > 0) {
    Serial.printf("Pin pressed: %d\n", _pin_pressed);
    _pin_pressed = 0;
  }

  delay(10); // this speeds up the simulation
}
Loading
esp32-s3-devkitc-1