esp_modbus_master_serial.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include "esp_err.h" // for esp_err_t
  16. #include "mbc_master.h" // for master interface define
  17. #include "esp_modbus_master.h" // for public slave defines
  18. #include "mbc_serial_master.h" // for public interface defines
  19. /**
  20. * Initialization of Modbus master serial
  21. */
  22. esp_err_t mbc_master_init(mb_port_type_t port_type, void** handler)
  23. {
  24. void* port_handler = NULL;
  25. esp_err_t error = ESP_ERR_NOT_SUPPORTED;
  26. switch(port_type)
  27. {
  28. case MB_PORT_SERIAL_MASTER:
  29. error = mbc_serial_master_create(&port_handler);
  30. break;
  31. default:
  32. return ESP_ERR_NOT_SUPPORTED;
  33. }
  34. if ((port_handler != NULL) && (error == ESP_OK)) {
  35. mbc_master_init_iface(port_handler);
  36. *handler = port_handler;
  37. }
  38. return error;
  39. }