firmware.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * firmware.c
  3. *
  4. * Copyright (C) 2019 Sylvain Munaut
  5. * All rights reserved.
  6. *
  7. * LGPL v3+, see LICENSE.lgpl3
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. */
  23. #include <stdint.h>
  24. #include <stdbool.h>
  25. #include <string.h>
  26. #include "console.h"
  27. #include "led.h"
  28. #include "usb.h"
  29. void main()
  30. {
  31. bool usb_active = false;
  32. int cmd = 0;
  33. /* Init console IO */
  34. console_init();
  35. puts("Booting..\n");
  36. /* LED */
  37. led_init();
  38. led_color(48, 96, 5);
  39. led_blink(true, 200, 1000);
  40. led_breathe(true, 100, 200);
  41. led_state(true);
  42. /* SPI */
  43. spi_init();
  44. printf("Flash ID: %08x\n", flash_id());
  45. /* Main loop */
  46. while (1)
  47. {
  48. /* Prompt ? */
  49. if (cmd >= 0)
  50. puts("\nCommand> ");
  51. /* Poll for command */
  52. cmd = getchar_nowait();
  53. if (cmd >= 0) {
  54. if (cmd > 32 && cmd < 127)
  55. putchar(cmd);
  56. switch (cmd)
  57. {
  58. case 'd':
  59. usb_debug_print();
  60. break;
  61. case 'u':
  62. usb_active = true;
  63. usb_init();
  64. break;
  65. default:
  66. break;
  67. }
  68. }
  69. /* USB poll */
  70. if (usb_active)
  71. usb_poll();
  72. }
  73. }