1 /* Copyright 2018 Espressif Systems (Shanghai) PTE LTD
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "esp_err.h"                // for esp_err_t
17 #include "mbc_master.h"             // for master interface define
18 #include "esp_modbus_master.h"      // for public slave defines
19 #include "mbc_serial_master.h"      // for public interface defines
20 
21 /**
22  * Initialization of Modbus master serial
23  */
mbc_master_init(mb_port_type_t port_type,void ** handler)24 esp_err_t mbc_master_init(mb_port_type_t port_type, void** handler)
25 {
26     void* port_handler = NULL;
27     esp_err_t error = ESP_ERR_NOT_SUPPORTED;
28     switch(port_type)
29     {
30     case MB_PORT_SERIAL_MASTER:
31         error = mbc_serial_master_create(&port_handler);
32         break;
33     default:
34         return ESP_ERR_NOT_SUPPORTED;
35     }
36     if ((port_handler != NULL) && (error == ESP_OK)) {
37         mbc_master_init_iface(port_handler);
38         *handler = port_handler;
39     }
40     return error;
41 }
42