Source code for jitxexamples.essentials.footgun_listings
import jitx
from jitx.net import provide
from jitxlib.protocols.serial import I2C
from .pin_assignment import STM32H7
######################################
# Foot Gun - Multiple Parent
######################################
[docs]
class BadWrapper(jitx.Circuit):
U = STM32H7()
TEMP_ARRAY = [U.PA[2], U.PA[3]]
@provide.all_of(I2C)
def I2C_PORT(self, b: I2C):
return [
{
b.sda: self.TEMP_ARRAY[0],
b.scl: self.TEMP_ARRAY[1],
}
]
[docs]
class GoodWrapper(jitx.Circuit):
U = STM32H7()
# Code that uses `TEMP_ARRAY`.
@provide.all_of(I2C)
def I2C_PORT(self, b: I2C):
TEMP_ARRAY = [self.U.PA[2], self.U.PA[3]]
return [
{
b.sda: TEMP_ARRAY[0],
b.scl: TEMP_ARRAY[1],
}
]
######################################
######################################