glib.c 632 B

12345678910111213141516171819202122232425262728
  1. #include "glib.h"
  2. #include "string.h"
  3. /**
  4. * @brief 这个函数让蜂鸣器发声,目前仅用于真机调试。未来将移除,请勿依赖此函数。
  5. *
  6. * @param times 发声循环多少遍
  7. */
  8. void __experimental_beep(uint64_t times)
  9. {
  10. io_out8(0x43, 182&0xff);
  11. io_out8(0x42, 2280&0xff);
  12. io_out8(0x42, (2280>>8)&0xff);
  13. uint32_t x = io_in8(0x61)&0xff;
  14. x |= 3;
  15. io_out8(0x61, x&0xff);
  16. times *= 10000;
  17. for(uint64_t i=0;i<times;++i)
  18. pause();
  19. x = io_in8(0x61);
  20. x &= 0xfc;
  21. io_out8(0x61, x&0xff);
  22. // 延迟一段时间
  23. for(uint64_t i=0;i<times;++i)
  24. pause();
  25. }