Firmware for the remote control translator
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.

main.c 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Remote Control Translator Firmware
  3. * Copyright (C) 2017 Clayton G. Hobbs <clay@lakeserv.net>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
  20. Licensed under the Apache License, Version 2.0 (the "License");
  21. you may not use this file except in compliance with the License.
  22. You may obtain a copy of the License at
  23. http://www.apache.org/licenses/LICENSE-2.0
  24. Unless required by applicable law or agreed to in writing, software
  25. distributed under the License is distributed on an "AS IS" BASIS,
  26. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  27. See the License for the specific language governing permissions and
  28. limitations under the License.
  29. */
  30. #include "ch.h"
  31. #include "hal.h"
  32. static PWMConfig pwmcfg = {
  33. 380000, /* 1MHz PWM clock frequency. */
  34. 10, /* Initial PWM period 1ms. */
  35. NULL,
  36. {
  37. {PWM_OUTPUT_ACTIVE_HIGH, NULL},
  38. {PWM_OUTPUT_DISABLED, NULL},
  39. {PWM_OUTPUT_DISABLED, NULL},
  40. {PWM_OUTPUT_DISABLED, NULL}
  41. },
  42. 0,
  43. 0
  44. };
  45. /*
  46. * Green LED blinker thread, times are in milliseconds.
  47. */
  48. static THD_WORKING_AREA(waThread1, 128);
  49. static THD_FUNCTION(Thread1, arg) {
  50. (void)arg;
  51. while (true) {
  52. palClearPad(GPIOC, GPIOC_LED);
  53. chThdSleepMilliseconds(500);
  54. palSetPad(GPIOC, GPIOC_LED);
  55. chThdSleepMilliseconds(500);
  56. }
  57. }
  58. /*
  59. * Application entry point.
  60. */
  61. int main(void) {
  62. /*
  63. * System initializations.
  64. * - HAL initialization, this also initializes the configured device drivers
  65. * and performs the board-specific initializations.
  66. * - Kernel initialization, the main() function becomes a thread and the
  67. * RTOS is active.
  68. */
  69. halInit();
  70. chSysInit();
  71. /*
  72. * Creates the blinker thread.
  73. */
  74. chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  75. pwmStart(&PWMD1, &pwmcfg);
  76. palSetPadMode(GPIOA, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
  77. pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
  78. /*
  79. * Normal main() thread activity, in this demo it does nothing except
  80. * sleeping in a loop and check the button state.
  81. */
  82. while (true) {
  83. chThdSleepMilliseconds(500);
  84. }
  85. }