mirror of
https://github.com/manuelbl/ttn-esp32.git
synced 2025-06-15 12:24:27 +02:00
Configuration of UART
This commit is contained in:
parent
53d4be5de4
commit
585c4b80bb
2
.vscode/c_cpp_properties.json
vendored
2
.vscode/c_cpp_properties.json
vendored
@ -16,7 +16,9 @@
|
||||
"${IDF_PATH}/components/soc/include",
|
||||
"${IDF_PATH}/components/soc/esp32/include",
|
||||
"${IDF_PATH}/components/tcpip_adapter/include",
|
||||
"${workspaceRoot}/examples/provisioning/build/include",
|
||||
"${workspaceRoot}/examples/hello_world/build/include",
|
||||
"${workspaceRoot}/examples/send_recv/build/include",
|
||||
"${workspaceRoot}/include",
|
||||
"${workspaceRoot}/src"
|
||||
],
|
||||
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -3,6 +3,7 @@
|
||||
"provisioning.h": "c",
|
||||
"config.h": "c",
|
||||
"sdkconfig.h": "c",
|
||||
"oslmic.h": "c"
|
||||
"oslmic.h": "c",
|
||||
"hal_esp32.h": "c"
|
||||
}
|
||||
}
|
42
Kconfig
42
Kconfig
@ -88,21 +88,6 @@ config TTN_PROVISION_UART_NONE
|
||||
bool "None"
|
||||
endchoice
|
||||
|
||||
choice TTN_PROVISION_UART_INIT
|
||||
prompt "Initialize UART"
|
||||
default TTN_PROVISION_UART_INIT_NO
|
||||
depends on !TTN_PROVISION_UART_NONE
|
||||
help
|
||||
Select whether to initialize the UART, i.e. set the baud rate, the RX and TX
|
||||
pins. If the UART is shared with other features (e.g. the console), it
|
||||
should not be initialized.
|
||||
|
||||
config TTN_PROVISION_UART_INIT_NO
|
||||
bool "No"
|
||||
config TTN_PROVISION_UART_INIT_YES
|
||||
bool "Yes"
|
||||
endchoice
|
||||
|
||||
choice TTN_PROVISION_UART_NUM
|
||||
prompt "UART peripheral for provisioning (0-1)"
|
||||
depends on TTN_PROVISION_UART_CUSTOM
|
||||
@ -114,6 +99,21 @@ config TTN_PROVISION_UART_CUSTOM_NUM_1
|
||||
bool "UART1"
|
||||
endchoice
|
||||
|
||||
choice TTN_PROVISION_UART_CONFIG
|
||||
prompt "Configure UART settings"
|
||||
default TTN_PROVISION_UART_CONFIG_NO
|
||||
depends on TTN_PROVISION_UART_CUSTOM
|
||||
help
|
||||
Select whether to configure the UART, i.e. set the baud rate, the RX and TX
|
||||
pins. If the UART is shared with other features (e.g. the console), it
|
||||
should not be configured.
|
||||
|
||||
config TTN_PROVISION_UART_CONFIG_NO
|
||||
bool "No"
|
||||
config TTN_PROVISION_UART_CONFIG_YES
|
||||
bool "Yes"
|
||||
endchoice
|
||||
|
||||
config TTN_PROVISION_UART_NUM
|
||||
int
|
||||
default 0 if TTN_PROVISION_UART_DEFAULT || TTN_PROVISION_UART_NONE
|
||||
@ -122,21 +122,21 @@ config TTN_PROVISION_UART_NUM
|
||||
|
||||
config TTN_PROVISION_UART_TX_GPIO
|
||||
int "Provisioning UART TX on GPIO#"
|
||||
depends on TTN_PROVISION_UART_CUSTOM && TTN_PROVISION_UART_INIT_YES
|
||||
depends on TTN_PROVISION_UART_CONFIG_YES
|
||||
range 0 33
|
||||
default 19
|
||||
default 1
|
||||
|
||||
config TTN_PROVISION_UART_RX_GPIO
|
||||
int "Provisioning UART RX on GPIO#"
|
||||
depends on TTN_PROVISION_UART_CUSTOM && TTN_PROVISION_UART_INIT_YES
|
||||
depends on TTN_PROVISION_UART_CONFIG_YES
|
||||
range 0 39
|
||||
default 21
|
||||
default 3
|
||||
|
||||
config TTN_PROVISION_UART_BAUDRATE
|
||||
int "Provisioning UART baud rate"
|
||||
depends on TTN_PROVISION_UART_CUSTOM && TTN_PROVISION_UART_INIT_YES
|
||||
default 115200
|
||||
depends on TTN_PROVISION_UART_CONFIG_YES
|
||||
range 1200 4000000
|
||||
default 115200
|
||||
|
||||
|
||||
endmenu
|
||||
|
@ -53,8 +53,8 @@ static bool have_keys = false;
|
||||
static bool quit_task = false;
|
||||
|
||||
|
||||
#if defined(CONFIG_TTN_PROVISION_UART_INIT_YES)
|
||||
static void provisioning_init_uart();
|
||||
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
||||
static void provisioning_config_uart();
|
||||
#endif
|
||||
|
||||
|
||||
@ -88,8 +88,8 @@ void os_getDevKey (u1_t* buf)
|
||||
|
||||
void provisioning_start_task()
|
||||
{
|
||||
#if defined(CONFIG_TTN_PROVISION_UART_INIT_YES)
|
||||
provisioning_init_uart();
|
||||
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
||||
provisioning_config_uart();
|
||||
#endif
|
||||
|
||||
esp_err_t err = uart_driver_install(UART_NUM, 2048, 2048, 20, &uart_queue, 0);
|
||||
@ -244,11 +244,24 @@ void provisioning_process_line()
|
||||
uart_write_bytes(UART_NUM, is_ok ? "OK\r\n" : "ERROR\r\n", is_ok ? 4 : 7);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_TTN_PROVISION_UART_INIT_YES)
|
||||
#if defined(CONFIG_TTN_PROVISION_UART_CONFIG_YES)
|
||||
|
||||
void provisioning_init_uart()
|
||||
void provisioning_config_uart()
|
||||
{
|
||||
esp_err_t err;
|
||||
|
||||
uart_config_t uart_config = {
|
||||
.baud_rate = CONFIG_TTN_PROVISION_UART_BAUDRATE,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
|
||||
};
|
||||
err = uart_param_config(UART_NUM, &uart_config);
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
err = uart_set_pin(UART_NUM, CONFIG_TTN_PROVISION_UART_TX_GPIO, CONFIG_TTN_PROVISION_UART_RX_GPIO, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
|
||||
ESP_ERROR_CHECK(err);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user