led.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. * 2013-07-11 reynolds port to TWR-K60F120M
  13. */
  14. #include <MK60F12.H>
  15. #include "led.h"
  16. const rt_uint32_t led_mask[] = { 1 << 11, 1 << 28, 1 << 29, 1 << 10 };
  17. void rt_hw_led_init(void)
  18. {
  19. SIM->SCGC5 |= (1UL << 9); //Enable Port A Clock
  20. PORTA->PCR[10] = (1UL << 8); //PTA10 is GPIO pin
  21. PORTA->PCR[11] = (1UL << 8); //PTA11 is GPIO pin
  22. PORTA->PCR[28] = (1UL << 8); //PTA28 is GPIO pin
  23. PORTA->PCR[29] = (1UL << 8); //PTA29 is GPIO pin
  24. /* Switch LEDs off and enable output*/
  25. PTA->PDOR = (led_mask[3] | led_mask[2] | led_mask[1] | led_mask[0]);
  26. PTA->PDDR = (led_mask[3] | led_mask[2] | led_mask[1] | led_mask[0]);
  27. }
  28. void rt_hw_led_uninit(void)
  29. {
  30. PORTA->PCR[10] = 0; //PTA10 is at reset state
  31. PORTA->PCR[11] = 0; //PTA11 is at reset state
  32. PORTA->PCR[28] = 0; //PTA28 is at reset state
  33. PORTA->PCR[29] = 0; //PTA29 is at reset state
  34. }
  35. void rt_hw_led_on(rt_uint32_t n)
  36. {
  37. if (n < LED_MAX)
  38. {
  39. PTA->PCOR = led_mask[n];
  40. }
  41. }
  42. void rt_hw_led_off(rt_uint32_t n)
  43. {
  44. if (n < LED_MAX) {
  45. PTA->PSOR = led_mask[n];
  46. }
  47. }