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 "sdkconfig.h"                  // for KConfig defines
18 #include "mbc_slave.h"                  // for slave interface define
19 #include "esp_modbus_slave.h"           // for public slave defines
20 #include "mbc_serial_slave.h"           // for public interface defines
21 
22 /**
23  * Initialization of Modbus Serial slave controller
24  */
mbc_slave_init(mb_port_type_t port_type,void ** handler)25 esp_err_t mbc_slave_init(mb_port_type_t port_type, void** handler)
26 {
27     void* port_handler = NULL;
28     esp_err_t error = ESP_ERR_NOT_SUPPORTED;
29     switch(port_type)
30     {
31         case MB_PORT_SERIAL_SLAVE:
32             // Call constructor function of actual port implementation
33             error = mbc_serial_slave_create(&port_handler);
34             break;
35         default:
36             return ESP_ERR_NOT_SUPPORTED;
37     }
38     if ((port_handler != NULL) && (error == ESP_OK)) {
39         mbc_slave_init_iface(port_handler);
40         *handler = port_handler;
41     }
42     return error;
43 }
44