SatCat5
i2c_sc18s602.h
1 // Copyright 2023-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // Device driver for the NXP SC18IS602B I2C-to-SPI bridge.
6 
7 #pragma once
8 
9 #include <satcat5/cfg_i2c.h>
10 #include <satcat5/cfg_spi.h>
11 
12 namespace satcat5 {
13  namespace device {
14  namespace i2c {
23  class Sc18is602
26  {
27  public:
29  Sc18is602(
30  satcat5::cfg::I2cGeneric* i2c, // Parent interface
31  const satcat5::util::I2cAddr& devaddr); // Device address
32 
34  bool configure(unsigned spi_mode);
35 
37  bool busy() override;
38 
41  bool exchange(
42  u8 devidx, const u8* wrdata, u8 rwbytes,
43  satcat5::cfg::SpiEventListener* callback = 0) override;
44 
47  bool query(
48  u8 devidx, const u8* wrdata, u8 wrbytes, u8 rdbytes,
49  satcat5::cfg::SpiEventListener* callback = 0) override;
50 
51  protected:
52  // I2C callback handler.
53  void i2c_done(
54  bool noack, const satcat5::util::I2cAddr& devaddr,
55  u32 regaddr, unsigned nread, const u8* rdata) override;
56 
57  // Execute a series of I2C commands.
58  bool execute(u8 devidx, const u8* wrdata, u8 rwbytes, u8 skip);
59 
60  // Pointer to the parent interface.
61  satcat5::cfg::I2cGeneric* const m_parent;
62  const satcat5::util::I2cAddr m_devaddr;
63 
64  // Current command state.
66  u8 m_busy;
67  u8 m_skip;
68  };
69  }
70  }
71 }
Callback interface for cfg::I2cGeneric events.
Definition: cfg_i2c.h:78
Polymorphic API for a generic I2C interface.
Definition: cfg_i2c.h:95
SPI Event Handler callback for use with SpiGeneric.
Definition: cfg_spi.h:15
Polymorphic API for a generic SPI interface.
Definition: cfg_spi.h:26
Device driver for the NXP SC18IS602B I2C-to-SPI bridge.
Definition: i2c_sc18s602.h:26
bool exchange(u8 devidx, const u8 *wrdata, u8 rwbytes, satcat5::cfg::SpiEventListener *callback=0) override
Queue a read-and-write SPI bus transaction.
Definition: i2c_sc18s602.cc:53
bool configure(unsigned spi_mode)
Configure the SPI mode (0/1/2/3 sets CPOL, CPHA)
Definition: i2c_sc18s602.cc:35
Sc18is602(satcat5::cfg::I2cGeneric *i2c, const satcat5::util::I2cAddr &devaddr)
Constructor links to specified control register.
Definition: i2c_sc18s602.cc:25
bool query(u8 devidx, const u8 *wrdata, u8 wrbytes, u8 rdbytes, satcat5::cfg::SpiEventListener *callback=0) override
Queue a write-then-read SPI bus transaction.
Definition: i2c_sc18s602.cc:70
bool busy() override
Is the SPI controller currently busy?
Definition: i2c_sc18s602.cc:48
Conversion function for I2C device addresses.
Definition: cfg_i2c.h:30