Skip to content

Conversation

@gemenerik
Copy link
Member

@gemenerik gemenerik commented Nov 6, 2025

The deck's I2C address is selected by the Crazyflie via the I2C_ADDR pin (PC15). When PC15 is pulled high, the deck uses address 0x31; when low, it defaults to 0x30. It required a sizeable 100ms boot delay to ensure PC15 is stable before reading it.

PA12 (ADDR_SELECT) is used for LED position detection. The deck tests this pin at startup using pull-up/pull-down states to distinguish between floating (no LED), driven-low (bottom), and driven-high (top) states.

The I2C protocol was extended from v1 to v2 with two new commands:

  • CMD_GET_LED_POSITION: Reports whether the deck is mounted on top or bottom based on PA12 detection
  • CMD_GET_LED_CURRENT: Reports per-channel current readings (R, G, B, W) in milliamps. ADC channels 4-7 are sampled in round-robin during the main loop and converted using sense resistor values (3.4Ω for red, 1.0Ω for others)

Requires:

Detection is based on LED pulling ADDR_SELECT (PA12) high / low
Instead of auto-detecting deck variant via PA12, the Crazyflie now pulls
PC15 (I2C_ADDR) high to select address 0x11. Added 500ms boot delay to
ensure the Crazyflie has set PC15 before the deck reads it. PA12
(ADDR_SELECT) remains available for future I2C commands.
@gemenerik gemenerik marked this pull request as ready for review November 10, 2025 14:05
@gemenerik gemenerik requested a review from Copilot November 10, 2025 14:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements dynamic I2C address configuration for the color-led firmware, allowing the device's I2C slave address to be selected at runtime based on GPIO pin states. The base I2C address is 0x10 (OwnAddress1 = 0x20 in 8-bit format), with the option to increment to 0x11 (OwnAddress1 = 0x22) based on pin PC15.

Key changes:

  • Added runtime I2C address selection based on PC15 (I2C_ADDR) pin state
  • Introduced PA12 as ADDR_SELECT input pin with pulldown (currently unused in code but configured)
  • Modified GPIO initialization to support two new input pins for address configuration

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
color-led.ioc Updated STM32CubeMX configuration to add PC15 and PA12 as GPIO input pins and changed PA12 from output to input mode
Core/Src/main.c Implemented dynamic I2C address selection logic reading PC15 after 500ms delay, and updated GPIO initialization for new pin configurations
Core/Inc/main.h Added pin definitions for I2C_ADDR (PC15) and ADDR_SELECT (PA12)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gemenerik gemenerik changed the title Detect top/bottom variant and adjust I2C address accordingly Unique I2C address for top/bottom variant Nov 10, 2025
Extends I2C protocol (v1→v2) with two new commands:
- CMD_GET_LED_POSITION: Reports top/bottom mounting via PA12 detection
- CMD_GET_LED_CURRENT: Reports per-channel current readings (R,G,B,W)

LED position is detected once at startup using pull-up/pull-down testing
to distinguish between floating (no LED), driven-low (bottom), and
driven-high (top) states. Current monitoring reads ADC channels 4-7 in
round-robin fashion during main loop and converts to milliamps using
appropriate sense resistor values (3.4Ω for red, 1.0Ω for others).
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gemenerik gemenerik marked this pull request as draft November 13, 2025 08:39
@gemenerik
Copy link
Member Author

I2C address changing not working consistently

@gemenerik gemenerik force-pushed the rik/dynamic_i2c branch 3 times, most recently from b6d33aa to 5339d56 Compare November 13, 2025 15:13
gemenerik added a commit to bitcraze/crazyflie-firmware that referenced this pull request Nov 20, 2025
Refactor driver from single-deck to dual-deck architecture with context-based
state management. Previously the driver only supported one deck at a time. Now
both variants can operate simultaneously with separate state, parameters, and logging.

Driver changes:
- Context structure holds per-instance state (init, colors, thermal, current, position)
- Two deck drivers: bcColorLEDBot (PID 0x13) and bcColorLEDTop (PID 0x14)
- I2C addressing: bottom at 0x30, top at 0x31 (GPIO 11 controls address selection for top)
- Separate bootloader reset functions for each deck (both use DFU address 0x64)
- LED controller callback now forwards to all initialized instances

Parameter and log group changes:
- Renamed from colorled to colorLedBot and colorLedTop for separate control
- brightnessCorr shortened to brightCorr (firmware name length limits)
- Detection parameters: deck.bcColorLedBot and deck.bcColorLedTop
- New log variables: ledPos, ledCurR, ledCurG, ledCurB, ledCurW

Protocol enhancements (v1 → v2):
- Add CMD_GET_LED_POSITION and CMD_GET_LED_CURRENT commands
- Increase RXBUFFERSIZE to 9 bytes for current readings (4 channels × 2 bytes)
- Task loop refactored with dedicated polling functions (thermal: 100ms, current: 1000ms)
- LED position polled once during initialization (hardware-fixed value)

Note: LED current readings are PWM-based and only provide stable values at full
intensity (100% duty cycle). This feature and position detection are primarily
for production testing.

Luminance correction improvements:
- Red LED value updated to 139 lumens (from 90) accounting for actual circuit current
- Red's lower forward voltage (2.1V vs 2.9V) results in 1.54× higher current despite
  higher sense resistor, requiring luminance adjustment

GPIO initialization now includes proper error handling with debug messages.
Example app updated to auto-detect and select appropriate deck parameter group.

Requires:
- bitcraze/color-led-deck-firmware#3
- bitcraze/deck-ctrl-firmware#4
@gemenerik gemenerik marked this pull request as ready for review November 20, 2025 13:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gemenerik gemenerik requested review from tobbeanton and removed request for ArisMorgens and evoggy November 24, 2025 13:21
evoggy
evoggy previously approved these changes Nov 24, 2025
@gemenerik gemenerik merged commit f30f355 into master Nov 24, 2025
@gemenerik gemenerik deleted the rik/dynamic_i2c branch November 24, 2025 15:56
tobbeanton pushed a commit to EliaCereda/crazyflie-firmware that referenced this pull request Dec 16, 2025
Refactor driver from single-deck to dual-deck architecture with context-based
state management. Previously the driver only supported one deck at a time. Now
both variants can operate simultaneously with separate state, parameters, and logging.

Driver changes:
- Context structure holds per-instance state (init, colors, thermal, current, position)
- Two deck drivers: bcColorLEDBot (PID 0x13) and bcColorLEDTop (PID 0x14)
- I2C addressing: bottom at 0x30, top at 0x31 (GPIO 11 controls address selection for top)
- Separate bootloader reset functions for each deck (both use DFU address 0x64)
- LED controller callback now forwards to all initialized instances

Parameter and log group changes:
- Renamed from colorled to colorLedBot and colorLedTop for separate control
- brightnessCorr shortened to brightCorr (firmware name length limits)
- Detection parameters: deck.bcColorLedBot and deck.bcColorLedTop
- New log variables: ledPos, ledCurR, ledCurG, ledCurB, ledCurW

Protocol enhancements (v1 → v2):
- Add CMD_GET_LED_POSITION and CMD_GET_LED_CURRENT commands
- Increase RXBUFFERSIZE to 9 bytes for current readings (4 channels × 2 bytes)
- Task loop refactored with dedicated polling functions (thermal: 100ms, current: 1000ms)
- LED position polled once during initialization (hardware-fixed value)

Note: LED current readings are PWM-based and only provide stable values at full
intensity (100% duty cycle). This feature and position detection are primarily
for production testing.

Luminance correction improvements:
- Red LED value updated to 139 lumens (from 90) accounting for actual circuit current
- Red's lower forward voltage (2.1V vs 2.9V) results in 1.54× higher current despite
  higher sense resistor, requiring luminance adjustment

GPIO initialization now includes proper error handling with debug messages.
Example app updated to auto-detect and select appropriate deck parameter group.

Requires:
- bitcraze/color-led-deck-firmware#3
- bitcraze/deck-ctrl-firmware#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants