bowen liu
/
mbed-os-example-blinky
ex
Fork of mbed-os-example-mbed5-blinky by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 // Copyright (2016) Baidu Inc. All rights reserved. 00002 /** 00003 * File: main.cpp 00004 * Desc: Sample code for startup DuerOS 00005 */ 00006 00007 #include "mbed.h" 00008 #include "baidu_media_manager.h" 00009 #include "duer_app.h" 00010 #include "events.h" 00011 #include "duer_log.h" 00012 #if defined(TARGET_UNO_91H) 00013 #include "SDMMCFileSystem.h" 00014 #include "WiFiStackInterface.h" 00015 #include "factory_test.h" 00016 #include "gpadckey.h" 00017 #ifdef RDA_SMART_CONFIG 00018 #include "rda5981_smartconfig.h" 00019 #endif // RDA_SMART_CONFIG 00020 #elif defined(TARGET_K64F) 00021 #include "SDFileSystem.h" 00022 #include "EthernetInterface.h" 00023 #else 00024 #error "Not supported" 00025 #endif // TARGET_UNO_91H 00026 00027 #if defined(TARGET_UNO_91H) 00028 00029 // TODO: Configure your AP 00030 #ifndef CUSTOM_SSID 00031 #define CUSTOM_SSID ("TP-LINK_69DA") 00032 #endif // CUSTOM_SSID 00033 00034 #ifndef CUSTOM_PASSWD 00035 #define CUSTOM_PASSWD ("qwertyuiop") 00036 #endif // CUSTOM_PASSWD 00037 00038 GpadcKey key_up(KEY_A3); 00039 GpadcKey key_down(KEY_A4); 00040 00041 // Initialize SD card 00042 SDMMCFileSystem g_sd(GPIO_PIN9, GPIO_PIN0, GPIO_PIN3, GPIO_PIN7, GPIO_PIN12, GPIO_PIN13, "sd"); 00043 00044 static WiFiStackInterface s_net_stack; 00045 #else 00046 SDFileSystem g_sd = SDFileSystem(D11, D12, D13, D10, "sd"); 00047 static EthernetInterface s_net_stack; 00048 #endif // TARGET_UNO_91H 00049 00050 static unsigned char s_volume = 8; 00051 00052 void* baidu_get_netstack_instance(void) { 00053 return (void*)&s_net_stack; 00054 } 00055 00056 void voice_up() { 00057 if (s_volume < 15) { 00058 duer::MediaManager::instance().set_volume(++s_volume); 00059 } 00060 } 00061 00062 void voice_down() { 00063 if (s_volume > 0) { 00064 duer::MediaManager::instance().set_volume(--s_volume); 00065 } 00066 } 00067 00068 // main() runs in its own thread in the OS 00069 int main() { 00070 #if defined(TARGET_UNO_91H) 00071 // Initialize RDA FLASH 00072 const unsigned int RDA_FLASH_SIZE = 0x400000; // Flash Size 00073 const unsigned int RDA_SYS_DATA_ADDR = 0x18204000; // System Data Area, fixed size 4KB 00074 const unsigned int RDA_USER_DATA_ADDR = 0x18205000; // User Data Area start address 00075 const unsigned int RDA_USER_DATA_LENG = 0x3000; // User Data Area Length 00076 00077 rda5981_set_flash_size(RDA_FLASH_SIZE); 00078 rda5981_set_user_data_addr(RDA_SYS_DATA_ADDR, RDA_USER_DATA_ADDR, RDA_USER_DATA_LENG); 00079 00080 // Test added by RDA 00081 factory_test(); 00082 #endif 00083 00084 DUER_LOGI("\nEntry Tinydu Main>>>>\n"); 00085 00086 duer::MediaManager::instance().initialize(); 00087 00088 #if defined(TARGET_UNO_91H) 00089 key_up.fall(&voice_up); 00090 key_down.fall(&voice_down); 00091 #endif 00092 00093 // Brings up the network interface 00094 #ifdef RDA_SMART_CONFIG 00095 typedef void (*dummy_func)(); 00096 mbed::GpadcKey key_erase = mbed::GpadcKey(KEY_A2); 00097 key_erase.fall((dummy_func)rda5981_flash_erase_smartconfig_data); 00098 00099 if (s_net_stack.connect(NULL, NULL, NSAPI_SECURITY_NONE) == 0) { 00100 #elif defined(TARGET_UNO_91H) 00101 if (s_net_stack.connect(CUSTOM_SSID, CUSTOM_PASSWD, NSAPI_SECURITY_NONE) == 0) { 00102 #else 00103 if (s_net_stack.connect() == 0) { 00104 #endif // RDA_SMART_CONFIG 00105 const char* ip = s_net_stack.get_ip_address(); 00106 const char* mac = s_net_stack.get_mac_address(); 00107 DUER_LOGI("IP address is: %s", ip ? ip : "No IP"); 00108 DUER_LOGI("MAC address is: %s", mac ? mac : "No MAC"); 00109 } else { 00110 DUER_LOGE("Network initial failed...."); 00111 Thread::wait(osWaitForever); 00112 } 00113 00114 duer::SocketAdapter::set_network_interface(&s_net_stack); 00115 00116 duer::MediaManager::instance().set_volume(s_volume); 00117 00118 duer::DuerApp app; 00119 app.start(); 00120 00121 duer::event_loop(); 00122 }
Generated on Tue Jul 12 2022 16:28:53 by 1.7.2