fn setup_write<'a, I>(
        &self,
        addr: I2cAddress,
        bytes: &[u8],
        start: bool,
        cmd_iterator: &mut I,
    ) -> Result<(), Error>
    where
        I: Iterator<Item = &'a COMD>,
    {
        // If start is true we need to send the address, too, which takes up a data
        // byte.
        let max_len = if start {
            I2C_CHUNK_SIZE
        } else {
            I2C_CHUNK_SIZE + 1
        };
        if bytes.len() > max_len {
            return Err(Error::FifoExceeded);
        }

        if start {
            add_cmd(cmd_iterator, Command::Start)?;
        }

        let write_len = if start { bytes.len() + 1 } else { bytes.len() };
        // don't issue write if there is no data to write
        if write_len > 0 {
            if cfg!(any(esp32, esp32s2)) {
                // try to place END at the same index
                if write_len < 2 {
                    add_cmd(
                        cmd_iterator,
                        Command::Write {
                            ack_exp: Ack::Ack,
                            ack_check_en: true,
                            length: write_len as u8,
                        },
                    )?;
                } else if start {
                    add_cmd(
                        cmd_iterator,
                        Command::Write {
                            ack_exp: Ack::Ack,
                            ack_check_en: true,
                            length: (write_len as u8) - 1,
                        },
                    )?;
                    add_cmd(
                        cmd_iterator,
                        Command::Write {
                            ack_exp: Ack::Ack,
                            ack_check_en: true,
                            length: 1,
                        },
                    )?;
                } else {
                    add_cmd(
                        cmd_iterator,
                        Command::Write {
                            ack_exp: Ack::Ack,
                            ack_check_en: true,
                            length: (write_len as u8) - 2,
                        },
                    )?;
                    add_cmd(
                        cmd_iterator,
                        Command::Write {
                            ack_exp: Ack::Ack,
                            ack_check_en: true,
                            length: 1,
                        },
                    )?;
                    add_cmd(
                        cmd_iterator,
                        Command::Write {
                            ack_exp: Ack::Ack,
                            ack_check_en: true,
                            length: 1,
                        },
                    )?;
                }
            } else {
                add_cmd(
                    cmd_iterator,
                    Command::Write {
                        ack_exp: Ack::Ack,
                        ack_check_en: true,
                        length: write_len as u8,
                    },
                )?;
            }
        }

        if start {
            // Load address and R/W bit into FIFO
            match addr {
                I2cAddress::SevenBit(addr) => {
                    write_fifo(self.regs(), (addr << 1) | OperationType::Write as u8);
                }
            }
        }
        for b in bytes {
            write_fifo(self.regs(), *b);
        }

        Ok(())
    }
Configures the I2C peripheral for a write operation.
- `addr` is the address of the slave device.
- `bytes` is the data two be sent.
- `start` indicates whether the operation should start by a START
condition and sending the address.
- `cmd_iterator` is an iterator over the command registers.
esp-hal/src/i2c/master/mod.rs