diff --git a/app/nano_shell_command.c b/app/nano_shell_command.c index 52f0e3d..a77c902 100644 --- a/app/nano_shell_command.c +++ b/app/nano_shell_command.c @@ -9,7 +9,9 @@ #include "app_common.h" #include "nano_shell_interface.h" #include "wm_gpio_afsel.h" +#include "wm_cpu.h" +#include "wm_bt.h" #include "ble_modem.h" #include "ble_service.h" @@ -132,6 +134,35 @@ int _system(const shell_cmd_t *pcmd, int argc, char *const argv[]) uint32_t total_mem_size = (unsigned int)&__heap_end - (unsigned int)&__heap_start; shell_printf("Free OS heap : %u/%u byte(s)"NEW_LINE"tls heap size : %u/%u byte(s)"NEW_LINE, xPortGetFreeHeapSize(), configTOTAL_HEAP_SIZE, tls_mem_get_avail_heapsize(), total_mem_size); } + else if(strcmp(argv[1], "cpu_clock") == 0) + { + if(argc == 3) + { + uint8_t clock = strtoul(argv[2], NULL, 10); + if(clock < 2 || clock > 240) + { + shell_printf("Bad clock !"NEW_LINE + "Available options are :"NEW_LINE + "\t- 2, 40, 80, 160, 240"NEW_LINE); + } + else + { + uint8_t div = 480/clock; + tls_sys_clk_set(div); + tls_sys_clk sys_clk; + tls_sys_clk_get(&sys_clk); + + shell_printf("Clock set to %u : cpu(%u), wlan(%u) and APB(%u)"NEW_LINE, clock, sys_clk.cpuclk, sys_clk.wlanclk, sys_clk.apbclk); + } + } + else + { + tls_sys_clk sys_clk; + tls_sys_clk_get(&sys_clk); + + shell_printf("Clocks : cpu(%u), wlan(%u) and APB(%u)"NEW_LINE, sys_clk.cpuclk, sys_clk.wlanclk, sys_clk.apbclk); + } + } else { shell_printf("Unknown %s action"NEW_LINE, argv[0]); @@ -139,7 +170,10 @@ int _system(const shell_cmd_t *pcmd, int argc, char *const argv[]) } else { - shell_printf("List of system actions :"NEW_LINE"list_task"NEW_LINE"ram_usage"NEW_LINE); + shell_printf("List of system actions :"NEW_LINE + "list_task"NEW_LINE + "ram_usage"NEW_LINE + "cpu_clock 2|40|80|160|240"NEW_LINE); } return 0; } @@ -437,6 +471,27 @@ int _pmu(const shell_cmd_t *pcmd, int argc, char *const argv[]) shell_printf("Waking up out of standby mode"NEW_LINE); tls_pmu_timer0_stop(); } + else if(strcmp(argv[1], "periph_clock_en") == 0 && argc == 3) + { + if(strcmp(argv[2], "0")) + { + tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_LCD); + tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_I2S); + tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_PSRAM); + tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_TOUCH_SENSOR); + //tls_open_peripheral_clock(TLS_PERIPHERAL_TYPE_BT); + shell_printf("Open peripheral clocks"NEW_LINE); + } + else + { + tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_LCD); + tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_I2S); + tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_PSRAM); + tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_TOUCH_SENSOR); + //tls_close_peripheral_clock(TLS_PERIPHERAL_TYPE_BT); + shell_printf("Closed peripheral clocks"NEW_LINE); + } + } else { shell_printf("Unknown %s action"NEW_LINE, argv[0]); @@ -444,7 +499,8 @@ int _pmu(const shell_cmd_t *pcmd, int argc, char *const argv[]) } else { - shell_printf("List of pmu actions :"NEW_LINE"sleep "NEW_LINE"standby "NEW_LINE); + shell_printf("List of pmu actions :"NEW_LINE"sleep "NEW_LINE"standby "NEW_LINE + "periph_clock_en 0|1"NEW_LINE); } return 0; } @@ -533,7 +589,7 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[]) shell_printf("Enabling bluetooth modem with ble service : %d"NEW_LINE, result); if(result) - ble_service_nus_register_data_rx_cb(&(nus_data_rx_cb)); + ble_service_register_nus_data_rx_cb(&(nus_data_rx_cb)); } else { @@ -550,13 +606,13 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[]) shell_printf("Starting demo : %d"NEW_LINE"Use a BLE app to find the device"NEW_LINE, result /*demo_ble_server_on()*/); if(result) { - ble_service_nus_register_data_rx_cb(&(nus_data_rx_cb)); + ble_service_register_nus_data_rx_cb(&(nus_data_rx_cb)); } } else if(strcmp(argv[1], "stop_demo") == 0) { shell_printf("Stopping demo : %d"NEW_LINE, ble_service_stop() /*demo_ble_server_off()*/); - ble_service_nus_register_data_rx_cb(NULL); + ble_service_register_nus_data_rx_cb(NULL); } else if(strcmp(argv[1], "mtu_exch") == 0) { @@ -594,7 +650,7 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[]) if(found) { - shell_printf("Sending ble ntf with content : #%s# -> %s"NEW_LINE, cmd, ble_service_nus_send_data((const uint8_t *)cmd, strlen(cmd)) ? "success" : "failure"); + shell_printf("Sending ble ntf with content : #%s# -> %s"NEW_LINE, cmd, ble_service_send_nus_data((const uint8_t *)cmd, strlen(cmd)) ? "success" : "failure"); } else { @@ -618,15 +674,71 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[]) shell_printf("BLE connection update request : %d"NEW_LINE, ble_service_update_connection_parameters(itvl_min, itvl_max, latency, supervision_timeout, min_ce_len, max_ce_len)); } + else if(strcmp(argv[1], "ble_tx_power") == 0) + { + if(argc == 3) + { + int8_t tx_power = strtoul(argv[2], NULL, 10); + shell_printf("Setting BLE TX power to : %d -> %u"NEW_LINE, tx_power, tls_ble_set_tx_power(TLS_BLE_PWR_TYPE_DEFAULT, tx_power)); + } + else // We simply return the current tx_power + { + shell_printf("Current BLE TX power is : %d"NEW_LINE, tls_ble_get_tx_power(TLS_BLE_PWR_TYPE_DEFAULT)); + } + } + else if(strcmp(argv[1], "bt_tx_power") == 0) + { + if(argc == 3) + { + int8_t tx_power = strtoul(argv[2], NULL, 10); + shell_printf("Setting BT TX power to : %d -> %u"NEW_LINE, tx_power, tls_bredr_set_tx_power(tx_power, tx_power)); + } + else // We simply return the current tx_power + { + int8_t min_pow = 0, max_pow = 0; + tls_bredr_get_tx_power(&min_pow, &max_pow); + shell_printf("Current BT TX power is : min(%d) max(%d)"NEW_LINE, min_pow, max_pow); + } + } + else if(strcmp(argv[1], "ble_modem_sleep") == 0) + { + if(argc == 3) + { + bool sleeping = strtoul(argv[2], NULL, 10); + shell_printf("BLE modem set to sleeping : %d"NEW_LINE, tls_bt_ctrl_sleep(sleeping)); + } + } + else if(strcmp(argv[1], "ble_modem_wake") == 0) + { + shell_printf("BLE modem waking up : %d"NEW_LINE, tls_bt_ctrl_wakeup()); + } + else if(strcmp(argv[1], "ble_modem_mode") == 0) + { + if(strcmp(argv[2], "bt") == 0) + { + tls_rf_bt_mode(1); + shell_printf("BLE modem set to bt only mode"NEW_LINE); + } + else + { + tls_rf_bt_mode(0); + shell_printf("BLE modem set to bt/wifi"NEW_LINE); + } + } else { shell_printf("Unknown %s action"NEW_LINE, argv[1]); } - } + } else { shell_printf("List of bluetooth actions :"NEW_LINE"enable"NEW_LINE"disable"NEW_LINE"start_demo"NEW_LINE"stop_demo"NEW_LINE"send_ble_notif toast \"msg\"|bat \"%%\"|findPhone|music|notify"NEW_LINE"mtu_exch"NEW_LINE - "up_conn_param itvl_min itvl_max latency supervision_timeout min_ce_len max_ce_len"NEW_LINE); + "up_conn_param itvl_min itvl_max latency supervision_timeout min_ce_len max_ce_len"NEW_LINE + "ble_tx_power 1|2|3|4|5"NEW_LINE + "bt_tx_power 1|2|3|4|5"NEW_LINE + "ble_modem_sleep 1|0"NEW_LINE + "ble_modem_wake"NEW_LINE + "ble_modem_mode bt|bt_wifi"NEW_LINE); } return 0; }