led.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * File : led.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. *
  13. */
  14. #include <MK64F12.h>
  15. #include "led.h"
  16. const rt_uint32_t led_mask[] = {1 << 21, 1 << 22, 1 << 26};
  17. void rt_hw_led_init(void)
  18. {
  19. SIM->SCGC5 |= (1 << SIM_SCGC5_PORTB_SHIFT);
  20. SIM->SCGC5 |= (1 << SIM_SCGC5_PORTE_SHIFT);
  21. PORTB->PCR[21] &= ~PORT_PCR_MUX_MASK;
  22. PORTB->PCR[21] |= PORT_PCR_MUX(1); //PTB21 is GPIO pin
  23. PORTB->PCR[22] &= ~PORT_PCR_MUX_MASK;
  24. PORTB->PCR[22] |= PORT_PCR_MUX(1); //PTB22 is GPIO pin
  25. PORTE->PCR[26] &= ~PORT_PCR_MUX_MASK;
  26. PORTE->PCR[26] |= PORT_PCR_MUX(1); //PTE26 is GPIO pin
  27. /* Switch LEDs off and enable output*/
  28. PTB->PDDR |= GPIO_PDDR_PDD(led_mask[1] | led_mask[0]);
  29. PTE->PDDR |= GPIO_PDDR_PDD(led_mask[2]);
  30. rt_hw_led_off(LED_RED);
  31. rt_hw_led_off(LED_GREEN);
  32. rt_hw_led_off(LED_BLUE);
  33. }
  34. void rt_hw_led_uninit(void)
  35. {
  36. PORTB->PCR[21] &= ~PORT_PCR_MUX_MASK;
  37. PORTB->PCR[22] &= ~PORT_PCR_MUX_MASK;
  38. PORTE->PCR[26] &= ~PORT_PCR_MUX_MASK;
  39. }
  40. void rt_hw_led_on(rt_uint32_t n)
  41. {
  42. if (n != LED_GREEN)
  43. {
  44. PTB->PCOR |= led_mask[n];
  45. }
  46. else
  47. {
  48. PTE->PCOR |= led_mask[n];
  49. }
  50. }
  51. void rt_hw_led_off(rt_uint32_t n)
  52. {
  53. if (n != LED_GREEN)
  54. {
  55. PTB->PSOR |= led_mask[n];
  56. }
  57. else
  58. {
  59. PTE->PSOR |= led_mask[n];
  60. }
  61. }