Hardware Interfacing Workshops

Part II: GPIO Hardware Integration


โค้ดโปรเจคสำหรับ GPIO-to-HMI Display

ขั้นตอนการดาวโหลดจาก Github Repo และรันโปรแกรมตัวแรก - Label Demo

ตัวอย่างการใช้ Eclipse ModusToolBox IDE

AIC-EEC GPIO API

LED Control API

Button API

Button Pin Configuration

Button
Macro
Pin
Pull-up
Active

USER Button 1

AIC_BTN_USER

P8_3 (SW2)

Internal

Active Low

USER Button 2

AIC_BTN_USER2

P8_7 (SW4)

Internal

Active Low

Note: ปุ่มเป็น Active Low = กดแล้วอ่านค่าเป็น 0 แต่ API จะ return true เมื่อกด

PWM API

Hardware Pin Configuration & PWM Limitation

สำคัญ: ไม่ใช่ทุก LED ที่ทำ PWM dimming ได้!

LED
Pin
PWM Support
หมายเหตุ

LED1 (Red)

P16_7

❌ GPIO only

ON/OFF เท่านั้น

LED2 (Green)

P16_6

❌ GPIO only

ON/OFF เท่านั้น

LED3 (Blue)

P16_5

✅ TCPWM0_LINE5

Dimming ได้

เหตุผล: ใน BSP (Board Support Package) เฉพาะ Blue LED (P16_5) ที่ถูก route ไปที่ PWM output (TCPWM0) ผ่าน HSIOM (High Speed I/O Matrix) ส่วน Green และ Red เป็น GPIO ธรรมดา ทำได้แค่ ON/OFF

ผลต่อตัวอย่าง:

  • Ex6: ปุ่ม ON/OFF ควบคุม Green LED, Slider ควบคุม Blue LED (PWM dimming)

  • Ex10: PWM Brightness ใช้ได้กับ Blue LED เท่านั้น

API Summary Table

Function
หน้าที่
Return

aic_gpio_init()

เริ่มต้น GPIO ทั้งหมด

void

aic_gpio_led_set(led, state)

ตั้งค่า LED

void

aic_gpio_led_toggle(led)

สลับสถานะ LED

void

aic_gpio_led_get(led)

อ่านสถานะ LED

true/false

aic_gpio_button_read(btn)

อ่านปุ่มกด

true=pressed

aic_gpio_pwm_set_brightness(led, val)

ตั้งความสว่าง

void


Last updated

Was this helpful?