Getting started with TouchGFX || STM32F750

Started by tha, May 10, 2023, 07:32:38 AM

Previous topic - Next topic

tha

                                                                                   CubeMX Setup

The F750 discovery board มี a user button, ซึ่งถูกต่อกับ the pin PI11. ผมได้เปิดใช้งาน the pin PI11 เป็น the input pin.



The pin ถูกกำหนดค่าใน the input mode พร้อมด้วย the pull down. เมื่อ the button ถูกกด pin นี้จะถูก pulled high.

tha

ฉันจะแสดง the potentiometer values บน the UI. potentiometer นี้จะถูกต่อผ่านทาง the ADC.



The ADC3 channel 0 ถูกกำหนดค่าด้วยความละเอียด 12 bit. ทุกสิ่งทุกอย่างจะถูกเก็บไว้เป็นค่าเริ่มต้นใน the ADC configuration. เราจะใช้ the poll method เพื่ออ่าน the ADC values.

tha



ฉันได้สร้าง task ใหม่ขึ้น 2 tasks สำหรับ the ADC และ the button. ทั้งสอง the tasks มี the low priority.


tha



ฉันได้สร้าง 2 queues สำหรับ the inter task messaging ด้วย. พวกมันจะถูกใช้เพื่อส่ง the data ไปยัง the GUI task.

The adcqueue มี 10 items ของ 16 bit data size. พวกมันจะถูกใช้เพื่อเก็บ the ADC values.
The buttonqueue มี 2 items ของ 8 bit data size.

tha

                                                                            Some Insight into the CODE



ฉันได้สร้าง the Button_State variable เพื่อเก็บ the button state. The ADC_Value และ the converted_val จะถูกใช้เพื่อเก็บ the RAW ADC value และ the converted value (ย่าน 0 – 100).

The map function ถูกใช้เพื่อแปลง the RAW ADC values ไปเป็นย่านที่เราต้องการ (ในกรณีนี้ 0-100).



•   ที่นี่เราจะอ่าน the pin PI11 และเก็บค่าของมันไปยัง the Button_State variable.
•   จากนั้นส่งค่าของตัวแปรไปยัง the queue.
•   2 พารามิเตอร์สุดท้ายใน the osMessageQueuePut คือ the message priority และ the timeout.
•   ฉันได้คง the priority ไว้ที่ต่ำสุด (0), และ the timeout เป็น 0 หมายถึง the message จะถูกใส่ไปยัง the queue เฉพาะถ้ามีที่ว่าง
     ให้ใช้งานใน the queue.
        •   The function จะไม่รอสำหรับ the space มีให้ใช้งาน.
•   The button task จะรันทุกๆ 5ms.

tha



ใน the ADC task เราอ่าน the ADC data ง่ายๆและแม็ปมันให้เป็นค่าระหว่าง 0 ถึง 100.

จากนั้นค่าที่ถูกแม็ปจะถูกส่งไปยัง the adc queue.

tha



ใน the model header file ฉันได้กำหนดตัวแปร ADC_value และ Button_State.

tha




ที่นี่เราจะ include the RTOS header file และ the main header file ก่อน. เราจำเป็นต้อง define the queues ภายนอกด้วย.

•    ตอนนี้ใน the tick function ก่อนอื่นเราจะรับค่าจาก the adc queue, และเก็บมันใน the ADC_value variable.
•   The modelListener จะเรียก the function setADC ใน the presenter และส่ง the ADC_value เป็น the parameter ให้กับ
     ฟังชั่นนี้.
•   ในทำนองเดียวกันเราจะรับ the button state จาก the button queue และเก็บมันในตัวแปร Button_State.
•   อีกครั้ง the modelListener จะเรียก the function setAnimation ใน the presenter และส่ง the button state เป็น the
     parameter ของฟังชั่นนี้.