led.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. *
  9. */
  10. #include <MK64F12.h>
  11. #include "led.h"
  12. const rt_uint32_t led_mask[] = {1 << 21, 1 << 22, 1 << 26};
  13. void rt_hw_led_init(void)
  14. {
  15. SIM->SCGC5 |= (1 << SIM_SCGC5_PORTB_SHIFT);
  16. SIM->SCGC5 |= (1 << SIM_SCGC5_PORTE_SHIFT);
  17. PORTB->PCR[21] &= ~PORT_PCR_MUX_MASK;
  18. PORTB->PCR[21] |= PORT_PCR_MUX(1); //PTB21 is GPIO pin
  19. PORTB->PCR[22] &= ~PORT_PCR_MUX_MASK;
  20. PORTB->PCR[22] |= PORT_PCR_MUX(1); //PTB22 is GPIO pin
  21. PORTE->PCR[26] &= ~PORT_PCR_MUX_MASK;
  22. PORTE->PCR[26] |= PORT_PCR_MUX(1); //PTE26 is GPIO pin
  23. /* Switch LEDs off and enable output*/
  24. PTB->PDDR |= GPIO_PDDR_PDD(led_mask[1] | led_mask[0]);
  25. PTE->PDDR |= GPIO_PDDR_PDD(led_mask[2]);
  26. rt_hw_led_off(LED_RED);
  27. rt_hw_led_off(LED_GREEN);
  28. rt_hw_led_off(LED_BLUE);
  29. }
  30. void rt_hw_led_uninit(void)
  31. {
  32. PORTB->PCR[21] &= ~PORT_PCR_MUX_MASK;
  33. PORTB->PCR[22] &= ~PORT_PCR_MUX_MASK;
  34. PORTE->PCR[26] &= ~PORT_PCR_MUX_MASK;
  35. }
  36. void rt_hw_led_on(rt_uint32_t n)
  37. {
  38. if (n != LED_GREEN)
  39. {
  40. PTB->PCOR |= led_mask[n];
  41. }
  42. else
  43. {
  44. PTE->PCOR |= led_mask[n];
  45. }
  46. }
  47. void rt_hw_led_off(rt_uint32_t n)
  48. {
  49. if (n != LED_GREEN)
  50. {
  51. PTB->PSOR |= led_mask[n];
  52. }
  53. else
  54. {
  55. PTE->PSOR |= led_mask[n];
  56. }
  57. }