/* Get the MODBUS slave address from the hardware pins. */
static int32_t modbus_setup_get_slave_addr(struct modbus_slave *dev, struct modbus_slave_init_param *init_param, uint8_t *id)
/* Get the MODBUS slave address from the hardware pins. */
static int32_t modbus_setup_get_slave_addr(struct modbus_slave *dev, struct modbus_slave_init_param *init_param, uint8_t *id)
{
	int16_t i;
	struct gpio_desc *temp_gpio;
	uint16_t gpio_value;
	int32_t ret;
	*id = 0;
	for(i = 0; i < SLAVE_ID_BITS_NUMBER; i++) {
		ret = gpio_get(&temp_gpio, init_param->slave_id_gpio[i]);
		if(ret < 0)
			return ret;
		ret = gpio_direction_input(temp_gpio);
		if(ret < 0)
			return ret;
		ret = gpio_get_value(temp_gpio, &gpio_value);
		if(ret < 0)
			return ret;
		if(gpio_value != GPIO_LOW)
			*id |= (uint8_t)((uint8_t)1 << i);
		else
			continue;
		ret = gpio_remove(temp_gpio);
		if(ret < 0)
			return ret;
	}
	*id += 1;
	return ret;
}