main.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2006-2025, RT-Thread Development Team
  3. * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2019-10-24 Magicoe first version
  10. * 2020-01-10 Kevin/Karl Add PS demo
  11. * 2020-09-21 supperthomas fix the main.c
  12. * 2025-08-18 Alex Yang Add P1_7 button with LED blink control
  13. *
  14. */
  15. #include <rtdevice.h>
  16. #include "drv_pin.h"
  17. #define LED_PIN ((3*32)+18) /* Original LED pin */
  18. #define BUTTON_PIN ((1*32)+7) /* P1_7 button pin */
  19. static rt_bool_t led_state = RT_FALSE; /* Current LED state */
  20. /* Button interrupt callback function */
  21. void button_irq_callback(void *args)
  22. {
  23. rt_kprintf("SW2 pressed\n");
  24. }
  25. int main(void)
  26. {
  27. #if defined(__CC_ARM)
  28. rt_kprintf("using armcc, version: %d\n", __ARMCC_VERSION);
  29. #elif defined(__clang__)
  30. rt_kprintf("using armclang, version: %d\n", __ARMCC_VERSION);
  31. #elif defined(__ICCARM__)
  32. rt_kprintf("using iccarm, version: %d\n", __VER__);
  33. #elif defined(__GNUC__)
  34. rt_kprintf("using gcc, version: %d.%d\n", __GNUC__, __GNUC_MINOR__);
  35. #endif
  36. rt_kprintf("FRDM-MCXA346\r\n");
  37. /* Configure LED pin as output */
  38. rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
  39. rt_pin_write(LED_PIN, PIN_LOW);
  40. /* Configure button pin as input with pull-up */
  41. rt_pin_mode(BUTTON_PIN, PIN_MODE_INPUT_PULLUP);
  42. /* Attach interrupt to button pin */
  43. rt_pin_attach_irq(BUTTON_PIN, PIN_IRQ_MODE_FALLING, button_irq_callback, RT_NULL);
  44. rt_pin_irq_enable(BUTTON_PIN, PIN_IRQ_ENABLE);
  45. while (1)
  46. {
  47. /* Toggle LED state */
  48. led_state = !led_state;
  49. rt_pin_write(LED_PIN, led_state ? PIN_HIGH : PIN_LOW);
  50. rt_thread_mdelay(500);
  51. }
  52. }