You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.1 KiB

  1. try:
  2. from adafruit_shell import Shell
  3. except ImportError:
  4. raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
  5. shell = Shell()
  6. def main():
  7. shell.clear()
  8. print("""This script downloads and installs
  9. I2S microphone support.
  10. """)
  11. if not shell.is_raspberry_pi():
  12. shell.bail("Non-Raspberry Pi board detected.")
  13. pi_model = shell.get_board_model()
  14. print("{} detected.\n".format(pi_model))
  15. if pi_model in ("RASPBERRY_PI_ZERO", "RASPBERRY_PI_ZERO_W"):
  16. pimodel_select = 0
  17. elif pi_model in ("RASPBERRY_PI_2B", "RASPBERRY_PI_3B", "RASPBERRY_PI_3B_PLUS", "RASPBERRY_PI_3A_PLUS"):
  18. pimodel_select = 1
  19. elif pi_model in ("RASPBERRY_PI_4B", ):
  20. pimodel_select = 2
  21. else:
  22. shell.bail("Unsupported Pi board detected.")
  23. auto_load = shell.prompt("Auto load module at boot?")
  24. print("""
  25. Installing...""")
  26. # Get needed packages
  27. shell.run_command("apt-get -y install git raspberrypi-kernel-headers")
  28. # Clone the repo
  29. shell.run_command("git clone https://github.com/adafruit/Raspberry-Pi-Installer-Scripts.git")
  30. # Build and install the module
  31. shell.chdir("Raspberry-Pi-Installer-Scripts/i2s_mic_module")
  32. shell.run_command("make clean")
  33. shell.run_command("make")
  34. shell.run_command("make install")
  35. # Setup auto load at boot if selected
  36. if auto_load:
  37. shell.write_text_file(
  38. "/etc/modules-load.d/snd-i2smic-rpi.conf",
  39. "snd-i2smic-rpi"
  40. )
  41. shell.write_text_file(
  42. "/etc/modules-load.d/snd-i2smic-rpi.conf",
  43. "options snd-i2smic-rpi rpi_platform_generation={}".format(pimodel_select)
  44. )
  45. # Enable I2S overlay
  46. shell.run_command("sed -i -e 's/#dtparam=i2s/dtparam=i2s/g' /boot/config.txt")
  47. # Done
  48. print("""DONE.
  49. Settings take effect on next boot.
  50. """)
  51. if not shell.prompt("REBOOT NOW?", default="n"):
  52. print("Exiting without reboot.")
  53. shell.exit()
  54. print("Reboot started...")
  55. shell.reboot()
  56. shell.exit()
  57. # Main function
  58. if __name__ == "__main__":
  59. shell.require_root()
  60. main()