LinkIt Assist 2502开发笔记4: 样例程序解释


     本日志对LinkIt Assist 2502自带的样例程序进行注解,先给出英文注释,随着项目的开发,逐步翻译成中文。

1、Bluetooth(蓝牙)
    a、
BT_BLE_GATT_Client
    
This example demonstrates how to use BLE GATT client. In this example, it will discover nearby servers and connect to the first one found.  
    b、BT_BLE_GATT_Server
    
This example shows how to use BLE GATT server. In this example, you can use the example GATTClient to connect this server.  
    c、 BT_BLE_Profile_BAS
    
This example shows how to setup the BLE profile by implemeting the Battery Service (BAS) profile.  
    d、 BT_BLE_Profile_DIS
    
This example shows how to setup the BLE profile by implementing the Device Information Service (DIS) profile.  
    e、 BT_BLE_ReadRSSI
    
This example shows how to connect to a Bluetooth server as a GATT client and read the RSSI infomation.  
    f、 BT_Smartphone_Notification
    
This example demonstrates how to configure the BT service for notifications, how to receive the notifications from a smart phone and how to analyse the notification content.
    This example starts with a 5 second timer first. Then it tries to start the BT service (vm_bt_cm_switch_on()), set the BT name (vm_bt_cm_set_host_name()), set the BT visibility (vm_bt_cm_set_visibility()), register the notification event callback (vm_bt_ns_register_notification_callback()) and the BT status change callback (vm_bt_ns_register_connection_status_change_callback()). If LinkIt Assist 2502 is connected with a smart phone and the the smart phone has the notification, such as new SMS message or a missed call, the LinkIt Assist 2502 will receive the notification in the callback. To use this example, modify macro the BT_NAME to change the device name to something you like, upload the example and pair the device with an iOS or Android smart phone. For an iOS smart phone, download the "Mediatek SmartDevice" from the App store. For an Android smart phone, install the supplied APK file in SDK’s custom folder. If the smart phone has notification such as new SMS message or missed call, the device will receive the notification in the callback function.  
    g、 BT_SPP_Client
    
This example demonstrate how to setup a BT SPP client. It scans for BT devices, connects to BT device via SPP profile and write/read data to/from remote SPP device. This example starts a 5s timer. After 5s it will try to start BT service (vm_bt_cm_switch_on), scan and search for device whose name is BT_NAME (vm_bt_cm_search). If the device is found, start SPP service and connect to the device (vm_bt_spp_connect). Finally, it reads (vm_bt_spp_read) and writes(vm_bt_spp_write) from/to the device. Find a BT device with SPP profile, enable its BT device and modify the macro BT_NAME to match its name. You can check the result log it will show "Hello SPP!"  
    h、 BT_SPP_Server
    
This example demonstrates how to setup a Bluetooth SPP server. It turns on BT service as server, accepts BT device via SPP profile and write/read data to/from remote SPP device. Initially this example starts a 5s timer. After 5s it will try to start BT service with vm_bt_cm_switch_on, set host name with vm_bt_cm_set_host_name, and set visibility with vm_bt_cm_set_visibility. If other SPP device connects to the server, it will accept. After establishing a connection, it reads (vm_bt_spp_read) and writes (vm_bt_spp_write) from/to the device. Find a BT device with SPP profile, pair with the device and modify the macro BT_NAME to match its name. You can check the result log it will show "Hello SPP!"

2、Driver Common Layer(普通驱动层)          
    a、 DCL_ADC_ReadPinA0
    
This example is a demo of the analog-to-digital converter. It will show the digital value of pin A0 in the Monitor logs. 
    b、 DCL_EINT
    
This example shows how to configure EINT and interact with EINT in the callback. In this example, we will open EINT using vm_dcl_open() and configure it using vm_dcl_control(). We register EINT callback using vm_dcl_register_callback(). The pin of VM_PIN_SIMULATE is used to simulate the source of an external interrupt, and a  timer is used to pull up and down this pin. The FALLING edge VM_PIN_EINT will be formed in every 1.6 seconds, and the counter of g_count is pegged for every FALLING edge until the g_count reaches to 10000 and starts from 0 again. The number of g_count will be printed on the Monitor tool. This example runs on LinkIt ONE board and needs to connect VM_PIN_EINT and VM_PIN_SIMULATE with wires. After launching the example, the following AT commands can be issued through the Monitor tool to control the flow:
AT+[1000]Test01: opens EINT and prints "eint count = X", X will increase one by one.
AT+[1000]Test02: closes EINT and stops updating the outputs.  
    c、 DCL_GPIO_Input
    
This example shows how to read a digital pin. In this example, it will read the status from the pin D7, and write the same status to the pin D8.  
    d、 DCL_GPIO_Output
    
This example shows how to write the status to a digital pin. In this example, it will write to the pin D0 and switch the status between HIGH and LOW alternately every 1 second.  
    e、 DCL_I2C_MotionSensor
    
This example shows how to use I2C driver module control bmi055 motion sensor. It initializes motion sensor, and then creates a timer to get x,y,z data from sensor, and writes these data Monitor log. I2C operations are implemented in file MotionBmi055Qg.c. It calls vm_dcl_open() to open I2C, vm_dcl_control()to control I2C, and sends command VM_DCL_I2C_CMD_CONFIG to config I2C's slave address, transition mode, mode speed. It also sends command VM_DCL_I2C_CMD_SINGLE_WRITE and VM_DCL_I2C_CMD_WRITE_AND_READ to communicate with bmi055. To use this example, connect the sensor to I2C pins. Refer to pin-out diagram for the specification of I2C pins.Monitor shows "motion i2c init success" "motion i2c single write" "motion i2c write and read reg"    
    f、 DCL_PMU_Vibrator
    
This example shows how to control vibrator on/off on LinkIt Assist 2502. In this example, we will use vibrator LDO to control vibrator on/off. Use vm_dcl_open to open LDO and vm_dcl_control to make LDO enable or disable. This example run on LinkIt Assist 2502 board or others that have vibrator. LinkIt ONE does not have a vibrator. When launching the example, you can send command in monitor tool to control the flow like below: AT+[1000]Test01: vibrator on
AT+[1000]Test02: vibrator off  
    g、 DCL_PWM_PwmControlLed
    
This example shows how to use PWM module to control LED's brightness. 1) Configure pin mode with vm_dcl_config_pin_mode() and PIN2PWM to get the device. 2) Use vm_dcl_open() open the device to get the PWM device handle. 3) Call vm_dcl_control to control the device, use VM_PWM_CMD_START, VM_PWM_CMD_SET_CLOCK to prepare the initial state, and VM_PWM_CMD_SET_COUNTER_AND_THRESHOLD to control brightness of the LED. To use this example,For LinkIt Assist 2502, connect P0 to an LED. Then upload this app and observe the LED.  
    h、 DCL_SIO
    
This example demonstrates how to turn on UART1, configure and register read event, and write/read data to/from UART1. This example sets VM_PIN_P8/VM_PIN_P9 as pin mode to UART and then opens UART1 device. It sets UART settings such as baud rate, stop bits, and register read callback. When there are some data available to the device through UART1. It reads data with vm_dcl_read and then writes same data through UART1 with vm_dcl_write. To use this example, connect a UART cable to RX/TX pin according to pin-out diagram. You might need a USB-to-UART conversion cable to connect the UART cable to your computer.  
    i、 DCL_SPI_Nokia5110
    
This example shows how to display the text on Nokia 5110 display. In this example, it will show "Wish you prosperity!" on the screen. Connect the SPI interface according to the pin-out diagram first, before uploading this example.  
            
3、Framework(框架)
    a、Framework_Command
    
This example shows how to use AT command capability. In this example, we will open the command port first, using vm_cmd_open_port(). Then the application of this example can receive AT commands and display the AT commends in the Monitor tool. The AT command with Test02 uses the vm_cmd_close_port() to close the AT command port. After launching the example, the AT command can be issued through the Monitor tool as below: AT+[1000]Test01: writes an AT command and log it through the Monitor tool. AT+[1000]Test02: closes the AT command port.  
    b、 Framework_Firmware_FirmwareUpdate
    
This example shows how to use firmware update API. It uses vm_firmware_trigger_update() to trigger firmware update, calls vm_pwr_reboot() to reboot the board. After reboot, the bootloader will update the firmware and write result of the update process to file system. This example then read firmware update result from file system. To use this example, put the firmware update package image.bin on C:\  drive. The image.bin will replace the board's old firmware.  
    c、 Framework_Keypad
    
This example shows how to receive keypad event and keycode from the board. This example use vm_keypad_register_event_callback() to register keypad handler. When operate the key on the board, the key event and keycode will be sent to application to the keypad handler.  Upload this example application, and connect Monitor tool for log. On LinkIt Assist 2502,if K0 is pressed, the log shows "key event=2,key code=0".  
    d、 Framework_Power_Reboot
    
This example demonstrates how to use the vm_pwr_reboot() API. Calling this API will reboot the LinkIt Assist 2502 board.  
    e、 Framework_Power_Shutdown
    
This example demonstrates how to use the vm_pwr_shutdown() API. This API can be used to shutdown LinkIt Assist 2502 board. Please note, that this API is not applicable to LinkIt ONE board, as it is always on.  
    f、 Framework_Resource_Image
    
This example will show an image in the screen. In this example, it will init resource using vm_res_init , then load an image with vm_res_get_image and show it in the screen. vm_res_delete is then called to release the image resource, finally using m_res_release to release resources. After uploading the example application, it shows image in the display.  
    g、 Framework_Thread
    
This example demonstrates how to create a sub-thread and how to communicate between the main thread and the sub-thread. In this example, one sub-thread is created (vm_thread_create()) and the communication between the main thread and the sub-thread is established (via vm_thread_send_message()). It uses mutex (vm_mutex_lock()/vm_mutex_unlock()) and signal (vm_signal_wait()) for the global variable protection and thread synchronization. After launching the example, the following AT commands can be used in the Monitor Tool as below:
AT+[1000]Test01: This creates a sub-thread. If succeeds, it will log the "message for creating thread successfully" on the Monitor. Then it will wait for the AT command of "AT+1000]Test02".
AT+[1000]Test02: It logs "message for waiting signal successfully" on the Monitor  
    h、 Framework_Touch  
    
This example shows how to receive touch event and the x,y value from the board. This example uses vm_touch_register_event_callback() to register touch handler. When touch the LCD on the board, the touch event and (x,y) value will be sent to application to touch handler. Just run this application, and observe monitor log.  

4、
GPS(全球卫星定位系统)
    
This example will open the GPS device and receive the current position. Firstly it will open GPS with vm_gps_open. It then reads the GPS data and analyzes its GPGGA data. Before you run this example, you need to insert a GPS antenna. Once the position is fixed, the example prints the number of satellites, latitude and longitude to monitor tool.  

5、Graphic(图形)
    a、Graphic_LoadFont
    
This example sets a Chinese font file and shows a Chinese text. It initiates the resource to Chinese by API vm_res_init(), then load the text data by API vm_res_get_string(), after that sets the font file path in the phone storage by API vm_graphic_set_font(), at last, draw the text by API vm_graphic_draw_text(). Before run this application, you need to put a Chinese font file to EXTERNAL_FONT_PATH and set the EXTERNAL_FONT_SIZE which can be calculated by CheckMemSize.exe tool. Modify the macro SCREEN_WIDTH and SCREEN_HEIGHT to fit your display device.  
    b、 Graphic_SpinningLine
    
This example shows a line that keeps spinning on top of a gradient background image.
It decodes a PNG image resource into a frame buffer with vm_graphic_draw_image_memory, and draws a line with vm_graphic_draw_line, then start a timer with vm_timer_create_precise for animation. The timer runs every 1/10 secs, resulting in a 10 FPS animation. For each frame in the animation, vm_graphic_linear_transform is used to rotate the line, and then vm_graphic_blt_frame is called to composite the rotated line with the background image, and displays the result. Modify the macro SCREEN_WIDTH and SCREEN_HEIGHT to fit your display device.  

6、GSM(全球移动通信系统)
    a、GSM_Cellular
    
This example shows how to get the current and the neighboring cell information. In this example, it will outputs the cell information in the Monitor tool. Before launching this example, a SIM card needs to be inserted and the GSM antenna needs to be attached to the GSM ANT. After launching the example, the AT commands can be used through the Monitor tool to control the flow as below: AT+[1000]Test01: opens the cell. AT+[1000]Test02: shows the current cell information. AT+[1000]Test03: shows the total number of the neighboring cells and all cell info. AT+[1000]Test04: stops the cell.  
    b、 GSM_SMS_Interrupt
    
This example demonstrates how to set up callback functions to handle the new SMS messages with vm_gsm_sms_set_interrupt_event_handler(). This example registers a callback function to receive SMS event with vm_gsm_sms_set_interrupt_event_handler(), and prints out the new message content on the Monitor tool. Check the logs on the Monitor tool. This example requires a SIM card installed on the board.  
    c、 GSM_SMS_Receive
    
This example demonstrates how to receive an SMS and how to retrieve the content and the sender's phone number of an SMS. It reads an SMS message using the vm_gsm_sms_read_message() and analyses the SMS information inside the sms_read_sms_sample_callback(). Check the Monitor tool for logs of the SMS content. This example requires a SIM card to be installed and an SMS is sent to the board.  
    d、 GSM_SMS_Send
    
This example demonstrates how to send an SMS message using vm_gsm_sms_send().
This example sends an SMS message to a recipient's mobile number, which can be modified in sms_send_sms_test(), for example, replacing the "+8610086" with a valid mobile phone number. Check the Monitor tool for log and the mobile phone for the SMS sent. This example requires a SIM card installed on the board.  

7、
Multimedia(多媒体)   
    a、 Multimedia_Audio_Play
    
This example will play an mp3 file. In this example, it will play a file with vm_audio_play_open/vm_audio_play_start. The file name is audio.mp3 and is stored on the SD card or the flash storage. During the play back, the volume is set to 4 using vm_audio_set_volume. AT command can be used to control (pause, resume and stop) the playback. Before you run this example, you need to copy an mp3 file named audio.mp3 into the root directory of the SD card or the flash storage. After launching the example, you can use the AT command in monitor tool to control the flow as follows: AT+[1000]Test01: Start the playback of the mp3 file  AT+[1000]Test02: Pause  AT+[1000]Test03: Resume  AT+[1000]Test04: Stop and close       
    b、 Multimedia_Audio_Record
    
This example will record an AMR file. In this example, it will record a file(vm_audio_record_start) named audio.amr. The file will be stored either on the SD card or in the flash storage. During the recording, you can pause(vm_audio_record_pause), resume(vm_audio_record_resume), and stop(vm_audio_record_stop) the recording. 
When launching the example, you can send AT commands through the monitor tool to control the recording like below: AT+[1000]Test01: begin record file  AT+[1000]Test02: pause record  AT+[1000]Test03: resume record  AT+[1000]Test04: stop record  After Test04 you will find a file named audio.amr in the flash storage or the SD card.  
    c、 Multimedia_Audio_Stream_Play
    
This example will use bitstream play to play a file named audio.mp3 in the mass storage.  Firstly we open the bitstream(vm_audio_stream_play_open) so we can put data(vm_audio_stream_play_put_data) to its ring buffer (max size is 16K). Next is to play it(vm_audio_stream_play_start) after we put all the mp3 files data to the buffer. To finish it call vm_audio_stream_play_finish. During the playing, you can retrieve the play time(vm_audio_stream_play_get_play_time) and stop the playback (vm_audio_stream_play_stop/vm_audio_stream_play_close).  Before run this example, you need to copy an MP3 file named audio.mp3 onto the mass storage. While running this example, you are able to send commands through the monitor tool to control the flow: AT+[1000]Test01: start play mp3 file  AT+[1000]Test02: get current play time  AT+[1000]Test03: stop and close play
     

8、Network(网络)
    a、Network_BSD_MISC
    
This example gets the local address and peer address in network byte order.
It opens the bearer by vm_bearer_open(), after the bearer is opened, it will create a sub thread by vm_thread_create(). Within the sub thread, it will establish a connection to CONNECT_ADDRESS and after the connection is established, it will get the local and peer address by getsockname() and getpeername(). You can change the connect address by modify MACRO CONNECT_ADDRESS. Change the APN information according to your SIM card. You can see the local address and peer address by searching keywords "local address" and "peer address" in the log about 2 minutes after bootup.      
    b、 Network_BSD_TCPClient
    This example creates a TCP Client and sends an http request to a server and prints out the first 20 bytes of the data that is  received from server. It opens the bearer by vm_bearer_open() and after the bearer is opened creates a sub thread by vm_thread_create(). In the sub thread, it establishes a connection to CONNECT_ADDRESS. After the connection is established it sends the string by send() and receives the response by recv();  You can change the connect address by modify MACRO CONNECT_ADDRESS, change the APN information according to your SIM card.  
    c、 Network_BSD_TCPServer
    This example creates TCP blocking server listen the port 40000, after receiving the data, send the RESPONSE_STRING to client. It opens the WiFi bearer by vm_bearer_open(). Once the bearer is opened, it will create a sub thread by vm_thread_create(). In the sub thread, it will bind itself to port 40000 by bind() and start listening to requests. When a request is received, it will receive the data by recv() and send the response by send(); You need to change the WiFi SSID and PASSWORD by modify the macro AP_SSID and AP_PASSWORD. You can see the local ip in log, if send a request to the port 40000 of this ip, it will print the first 20 bytes of the request data out to log.  
    d、 Network_BSD_TCPServer_nonblock
    This example creates a non-blocking TCP server that listens to port 40000. When data is received it will send the RESPONSE_STRING to client. It opens the bearer by vm_bearer_open() and once the bearer is opened, it will create a sub thread by vm_thread_create(). Within the sub thread, it will bind the bearer to port 40000 by bind() and will start to listen for requests. Once requests are arriving, it will receive the data by recv() and send the response by send(); You need to change the WLAN information according to your WLAN AP used.  
    e、 Network_BSD_UDPServer
    
This sample creates a non-blocking UDP socket, after receiving a request, a response string is sent back. It open the bearer by vm_bearer_open() and after the bearer is opened, it will create a sub thread by vm_thread_create(). In the sub thread, it will create a socket by API socket() and bind it to port 40002 by bind(). Once it is created it will check if there a request by select(), after a request is detected, it will receive the data by recv() and send the response by send(); You need to change the WLAN information according to the WLAN AP you used.  
    f、 Network_DNS
    
This example gets the IP address of labs.mediatek.com  It calls the API vm_dns_get_host_by_name() to get the host address and print the result to log in callback function. Before run this example, please set the APN related macros first.  
    g、 Network_HTTP
    
This example connects to HTTP(not HTTPS) to retrieve index.html from labs.mediatek.com and print to vm_log. It calls the API vm_https_register_context_and_callback() to register the callback functions, then set the channel by vm_https_set_channel(). After the channel is established, it will send out the request by vm_https_send_request() and read the response by vm_https_read_content(). You can change the url by modify macro VMHTTPS_TEST_URL. Before run this example, please set the APN information first by modify macros.  
    h、 Network_HTTPS
    
This example connects securely to https://www.howsmyssl.com/a/check, retrieves results and prints it to vm_log. It calls the API vm_https_register_context_and_callback() to register the callback functions, then set the channel by vm_https_set_channel(). After the channel is established, it will send out the request by vm_https_send_request() and read the response by vm_https_read_content(). You can change the URL by modify macro VMHTTPS_TEST_URL. Before run this example, please set the APN information first by modify macros.  
    i、 Network_SSL
    
This sample executes an HTTPS request and prints the content of the request to the log.
It connects the port 443 of the host by API vm_ssl_connect(), a callback function is registered with this API. When the VM_SSL_EVENT_CAN_WRITE event is received, it will call vm_ssl_write() to send a HTTP request to get the URL. When the VM_SSL_EVENT_CAN_READ even is received, it will call vm_ssl_read() to read the content. Before running this application, you need to put the certificate of the certification authority of the host you want to connect to into the CERTIFICATE_PATH. You can change the URL, host and certificate path by modify the corresponding MACROs. Please set the APN information according to your SIM card.      
    j、 Network_TCP_Async
    
This example creates TCP Client and sends a HTTP request to an server and prints the first 20 bytes of the data received to the log on the Monitor. It connects the server by vm_tcp_connect(). After the connection is established, it will call vm_tcp_write() to send the request. When the response arrives, it calls vm_tcp_read() to read the data from the response.
The connection address can be changed by modifying the macro CONNECT. The APN should be set according to the SIM card information. This example requires a valid SIM card installed on the board.  
    k、 Network_TCP_Sync
    This example creates a TCP Client in synchronous way and sends a HTTP request to an address and reads the response. It creates a sub-thread by using vm_thread_create(). In the sub-thread, it connects a server by calling vm_tcp_connect_sync(). After the connection is established, it calls vm_tcp_write_sync() to send a request and calls vm_tcp_read_sync() to read the response. The connection address can be changed by modifying the macro HTTP_HOST and HTTP_URL. The cellular APN should be set according to the SIM card information.
This example requires a valid SIM card installed on the board.  
    l、 Network_UDP
    
This example gets the time data from NTP server by UDP. It creates a udp handle by vm_udp_create() to receive the udp messages, then calls vm_udp_send() to send a packet to a NTP server. When NTP server responsed it will call vm_udp_receive() to read the data. You can change the NTP server address by modify g_address. Before run this example, please set the APN information first by modify macros.  

9、Standard(标准)
    a、Standard_File_CopyFile
    
This example shows how to create and copy file. In this example, it will create the file test_file.txt in this path: C:\mre\fs_copy_file\, the content of this file is "example of create and copy file". After that, it will copy this file, the new file is in the same folder and the file name of the copies is "copy_of_test_file.txt".  
    b、 Standard_File_ListFile
    
This example shows how to list the files in a special folder. In this example, it will list all the files under the folder "C:\mre\fs_copy_file\", the name of these files will show in logs file.  
    c、 Standard_Timer
    This example demonstrates how to create precise, non-precise and hisr timer. Furthermore it shows how to compute the precise timers every period, and how to delete them. This example creates a precise timer(vm_timer_create_precise) and then creates a non-precise timer(vm_timer_create_non_precise). In the end it creates a hisr timer(vm_timer_create_hisr and vm_timer_set_hisr).  

10、
WLAN(无线网)
    a、WLAN_Connect
    
This example connects to an AP with SSID and password. It set the device to station mode first by API vm_wlan_mode_set(), after set mode successfully, it will call vm_wlan_connect() to connect the AP, then print the AP information in the callback function. Modify the macro AP_SSID, AP_PASSWORD and AP_AUTHORIZE_MODE to match your Wi-Fi AP.  
    b、 WLAN_Scan
    
This example scans the nearby APs and prints their information to log. It set the device to station mode by API vm_wlan_mode_set, then call vm_wlan_scan. The results are reported to the registered scan callback function.
 


原创性文章,转载请注明出处  http://user.qzone.qq.com/2756567163  
 
CSDN:http://blog.csdn.net/qingwufeiyang12346    

你可能感兴趣的:(assist,联发科,2502,开发笔记,linkit)