main.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #include "ch.h"
  14. #include "hal.h"
  15. #define I2S_BUF_SIZE 256
  16. static uint16_t i2s_rx_buf[I2S_BUF_SIZE];
  17. static void i2scallback(I2SDriver *i2sp);
  18. static const I2SConfig i2scfg = {
  19. NULL,
  20. i2s_rx_buf,
  21. I2S_BUF_SIZE,
  22. i2scallback,
  23. 0,
  24. 16
  25. };
  26. static void i2scallback(I2SDriver *i2sp) {
  27. if (i2sIsBufferComplete(i2sp)) {
  28. /* 2nd buffer half processing.*/
  29. }
  30. else {
  31. /* 1st buffer half processing.*/
  32. }
  33. }
  34. /*
  35. * Application entry point.
  36. */
  37. int main(void) {
  38. /*
  39. * System initializations.
  40. * - HAL initialization, this also initializes the configured device drivers
  41. * and performs the board-specific initializations.
  42. * - Kernel initialization, the main() function becomes a thread and the
  43. * RTOS is active.
  44. */
  45. halInit();
  46. chSysInit();
  47. /*
  48. * Starting and configuring the I2S driver 2.
  49. */
  50. i2sStart(&I2SD2, &i2scfg);
  51. palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(5));
  52. palSetPadMode(GPIOC, 3, PAL_MODE_ALTERNATE(5));
  53. /*
  54. * Starting continuous I2S transfer.
  55. */
  56. i2sStartExchange(&I2SD2);
  57. /*
  58. * Normal main() thread activity, if the button is pressed then the I2S
  59. * transfer is stopped.
  60. */
  61. while (true) {
  62. if (palReadPad(GPIOA, GPIOA_BUTTON))
  63. i2sStopExchange(&I2SD2);
  64. chThdSleepMilliseconds(500);
  65. }
  66. return 0;
  67. }