Skip to content

Latest commit

 

History

History
77 lines (62 loc) · 2.46 KB

File metadata and controls

77 lines (62 loc) · 2.46 KB

Pico I2C Implementation

This module provides the hardware-specific implementation of the EmbeddedComm protocol for the Raspberry Pi Pico (RP2040/RP2350) using the I2C interface. It bridges the abstract GenericMaster and GenericSlave logic with the Raspberry Pi Pico C/C++ SDK.

Table of contents

  1. Main documentation
  2. picoMasterI2C
  3. picoSlaveI2C
  4. Usage

picoMasterI2C class

Parent: GenericMaster<uint8_t>

Implements the master-side driver. It wraps the standard hardware_i2c blocking API.

Constructor

picoMasterI2C(
    uint8_t scl, 
    uint8_t sda, 
    i2c_inst_t *i2c, 
    uint32_t i2cFreqKHz
);
  • scl: GPIO pin number for Serial Clock.
  • sda: GPIO pin number for Serial Data.
  • i2c: Pointer to the I2C instance (i2c0 or i2c1).
  • i2cFreqKHz: Bus frequency in kHz (e.g., 100, 400).

picoSlaveI2C class

Header: picoSlaveI2C.hpp
Parent: GenericSlave

Implements the slave-side driver using interrupt-driven I2C.

Initialization

void initialize(
    uint8_t scl, 
    uint8_t sda, 
    i2c_inst_t *i2c, 
    uint32_t i2cFreqKHz, 
    uint8_t i2c_address, 
    uint8_t *memory, 
    uint32_t memorySize
);
  • scl/sda: GPIO pins for I2C.
  • i2c: I2C instance (i2c0 or i2c1).
  • i2cFreqKHz: Bus frequency.
  • i2c_address: The 7-bit I2C address for this slave.
  • memory: Pointer to the buffer serving as the slave's memory map.
  • memorySize: Size of the memory buffer.

Interrupt Handling

The class uses a static context mapping system to route C-style hardware interrupts to the correct C++ object instance.

  • Limitation: You can create only one picoSlaveI2C object per hardware I2C block (i2c0 and i2c1). Creating a second object for the same hardware block will overwrite the interrupt context of the first.

Usage

Dependencies

  • Hardware: Raspberry Pi Pico (RP2040) or Pico 2 (RP2350).
  • SDK: pico-sdk (Requires hardware_i2c and hardware_gpio libraries).
  • Library: pico_i2c_slave (Ensure your CMakeLists.txt links against the I2C slave library implementation).