Kconfig: Add new WANT_I2C option to reduce code size

Make it possible to not compile in support for I2C on chips with small
flash sizes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2025-04-09 12:36:24 -04:00
parent 868760f5b1
commit 04e7eb20fd
8 changed files with 43 additions and 33 deletions

View file

@ -96,6 +96,14 @@ config WANT_SOFTWARE_SPI
bool
depends on WANT_SPI
default y
config WANT_I2C
bool
depends on HAVE_GPIO && HAVE_GPIO_I2C
default y
config WANT_SOFTWARE_I2C
bool
depends on WANT_I2C
default y
config WANT_HARD_PWM
bool
depends on HAVE_GPIO_HARD_PWM
@ -134,15 +142,15 @@ config WANT_ADXL345
default y
config WANT_LIS2DW
bool
depends on WANT_SPI || HAVE_GPIO_I2C
depends on WANT_SPI || WANT_I2C
default y
config WANT_MPU9250
bool
depends on HAVE_GPIO_I2C
depends on WANT_I2C
default y
config WANT_ICM20948
bool
depends on HAVE_GPIO_I2C
depends on WANT_I2C
default y
config WANT_HX71X
bool
@ -154,16 +162,12 @@ config WANT_ADS1220
default y
config WANT_LDC1612
bool
depends on HAVE_GPIO_I2C
depends on WANT_I2C
default y
config WANT_SENSOR_ANGLE
bool
depends on WANT_SPI
default y
config WANT_SOFTWARE_I2C
bool
depends on HAVE_GPIO && HAVE_GPIO_I2C
default y
config NEED_SENSOR_BULK
bool
depends on WANT_ADXL345 || WANT_LIS2DW || WANT_MPU9250 || WANT_ICM20948 \
@ -177,6 +181,12 @@ config WANT_SPI
config WANT_SOFTWARE_SPI
bool "Support software based SPI \"bit-banging\""
depends on WANT_SPI
config WANT_I2C
bool "Support communicating with external chips via I2C bus"
depends on HAVE_GPIO && HAVE_GPIO_I2C
config WANT_SOFTWARE_I2C
bool "Support software based I2C \"bit-banging\""
depends on WANT_I2C
config WANT_HARD_PWM
bool "Support hardware PWM (pulse width modulation)"
depends on HAVE_GPIO_HARD_PWM
@ -206,13 +216,13 @@ config WANT_ADXL345
depends on WANT_SPI
config WANT_LIS2DW
bool "Support lis2dw and lis3dh 3-axis accelerometers"
depends on WANT_SPI || HAVE_GPIO_I2C
depends on WANT_SPI || WANT_I2C
config WANT_MPU9250
bool "Support MPU accelerometers"
depends on HAVE_GPIO_I2C
depends on WANT_I2C
config WANT_ICM20948
bool "Support ICM20948 accelerometer"
depends on HAVE_GPIO_I2C
depends on WANT_I2C
config WANT_HX71X
bool "Support HX711 and HX717 ADC chips"
depends on HAVE_GPIO
@ -221,13 +231,10 @@ config WANT_ADS1220
depends on WANT_SPI
config WANT_LDC1612
bool "Support ldc1612 eddy current sensor"
depends on HAVE_GPIO_I2C
depends on WANT_I2C
config WANT_SENSOR_ANGLE
bool "Support angle sensors"
depends on WANT_SPI
config WANT_SOFTWARE_I2C
bool "Support software based I2C \"bit-banging\""
depends on HAVE_GPIO && HAVE_GPIO_I2C
endmenu
# Generic configuration options for CANbus

View file

@ -5,9 +5,9 @@ src-$(CONFIG_HAVE_GPIO) += initial_pins.c gpiocmds.c stepper.c endstop.c \
trsync.c
src-$(CONFIG_HAVE_GPIO_ADC) += adccmds.c
src-$(CONFIG_WANT_SPI) += spicmds.c
src-$(CONFIG_HAVE_GPIO_SDIO) += sdiocmds.c
src-$(CONFIG_HAVE_GPIO_I2C) += i2ccmds.c
src-$(CONFIG_WANT_I2C) += i2ccmds.c
src-$(CONFIG_WANT_HARD_PWM) += pwmcmds.c
src-$(CONFIG_HAVE_GPIO_SDIO) += sdiocmds.c
src-$(CONFIG_WANT_BUTTONS) += buttons.c
src-$(CONFIG_WANT_TMCUART) += tmcuart.c

View file

@ -28,7 +28,7 @@ canbus-src-y += atsamd/fdcan.c atsamd/chipid.c
src-$(CONFIG_USBCANBUS) += $(canbus-src-y) atsamd/usbserial.c generic/usb_canbus.c
src-$(CONFIG_CANSERIAL) += $(canbus-src-y) generic/canbus.c
src-$(CONFIG_HAVE_GPIO_ADC) += atsamd/adc.c
src-$(CONFIG_HAVE_GPIO_I2C) += atsamd/i2c.c
src-$(CONFIG_WANT_I2C) += atsamd/i2c.c
src-$(CONFIG_WANT_SPI) += atsamd/spi.c
src-$(CONFIG_HAVE_SERCOM) += atsamd/sercom.c
src-$(CONFIG_WANT_HARD_PWM) += atsamd/hard_pwm.c

View file

@ -13,7 +13,7 @@ src-y += avr/main.c avr/timer.c
src-$(CONFIG_HAVE_GPIO) += avr/gpio.c
src-$(CONFIG_HAVE_GPIO_ADC) += avr/adc.c
src-$(CONFIG_WANT_SPI) += avr/spi.c
src-$(CONFIG_HAVE_GPIO_I2C) += avr/i2c.c
src-$(CONFIG_WANT_I2C) += avr/i2c.c
src-$(CONFIG_WANT_HARD_PWM) += avr/hard_pwm.c
src-$(CONFIG_AVR_WATCHDOG) += avr/watchdog.c
src-$(CONFIG_USBSERIAL) += avr/usbserial.c generic/usb_cdc.c

View file

@ -17,7 +17,7 @@ src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_timer.c
src-y += generic/armcm_reset.c generic/crc16_ccitt.c
src-y += ../lib/lpc176x/device/system_LPC17xx.c
src-$(CONFIG_HAVE_GPIO_ADC) += lpc176x/adc.c
src-$(CONFIG_HAVE_GPIO_I2C) += lpc176x/i2c.c
src-$(CONFIG_WANT_I2C) += lpc176x/i2c.c
src-$(CONFIG_WANT_SPI) += lpc176x/spi.c
src-$(CONFIG_USBSERIAL) += lpc176x/usbserial.c lpc176x/chipid.c
src-$(CONFIG_USBSERIAL) += generic/usb_cdc.c

View file

@ -30,7 +30,7 @@ src-$(CONFIG_USBCANBUS) += generic/canserial.c generic/usb_canbus.c
src-$(CONFIG_USBCANBUS) += ../lib/fast-hash/fasthash.c rp2040/usbserial.c
src-$(CONFIG_WANT_HARD_PWM) += rp2040/hard_pwm.c
src-$(CONFIG_WANT_SPI) += rp2040/spi.c
src-$(CONFIG_HAVE_GPIO_I2C) += rp2040/i2c.c
src-$(CONFIG_WANT_I2C) += rp2040/i2c.c
# rp2040 stage2 building
STAGE2_FILE := $(shell echo $(CONFIG_RP2040_STAGE2_FILE))

View file

@ -85,7 +85,7 @@ command_config_lis2dw(uint32_t *args)
shutdown("bus_type spi unsupported");
}
case I2C_SERIAL:
if (CONFIG_HAVE_GPIO_I2C) {
if (CONFIG_WANT_I2C) {
ax->i2c = i2cdev_oid_lookup(args[1]);
ax->bus_type = I2C_SERIAL;
break;
@ -147,7 +147,7 @@ lis2dw_query(struct lis2dw *ax, uint8_t oid)
for (uint32_t i = 0; i < BYTES_PER_SAMPLE; i++)
d[i] = msg[i + 1];
} else if (CONFIG_HAVE_GPIO_I2C && ax->bus_type == I2C_SERIAL) {
} else if (CONFIG_WANT_I2C && ax->bus_type == I2C_SERIAL) {
uint8_t msg_reg[] = {LIS_AR_DATAX0};
if (ax->model == LIS3DH)
msg_reg[0] |= LIS_MS_I2C;
@ -226,7 +226,7 @@ command_query_lis2dw_status(uint32_t *args)
spidev_transfer(ax->spi, 1, sizeof(msg), msg);
time2 = timer_read_time();
status = msg[1];
} else if (CONFIG_HAVE_GPIO_I2C && ax->bus_type == I2C_SERIAL) {
} else if (CONFIG_WANT_I2C && ax->bus_type == I2C_SERIAL) {
uint8_t fifo_reg[1] = {LIS_FIFO_SAMPLES};
uint8_t fifo[1];

View file

@ -43,39 +43,42 @@ src-y += generic/armcm_boot.c generic/armcm_irq.c generic/armcm_reset.c
src-$(CONFIG_MACH_STM32F0) += ../lib/stm32f0/system_stm32f0xx.c
src-$(CONFIG_MACH_STM32F0) += generic/timer_irq.c stm32/stm32f0_timer.c
src-$(CONFIG_MACH_STM32F0) += stm32/stm32f0.c stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32F0) += stm32/stm32f0_adc.c stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32F0) += stm32/stm32f0_adc.c
src-$(CONFIG_MACH_STM32F103) += ../lib/stm32f1/system_stm32f1xx.c
src-$(CONFIG_MACH_STM32F103) += stm32/adc.c
src-$(CONFIG_MACH_N32G45x) += ../lib/stm32f1/system_stm32f1xx.c
src-$(CONFIG_MACH_N32G45x) += ../lib/n32g45x/n32g45x_adc.c stm32/n32g45x_adc.c
src-$(CONFIG_MACH_STM32F1) += stm32/stm32f1.c generic/armcm_timer.c stm32/i2c.c
src-$(CONFIG_MACH_STM32F1) += stm32/stm32f1.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32F2) += ../lib/stm32f2/system_stm32f2xx.c
src-$(CONFIG_MACH_STM32F2) += stm32/stm32f4.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32F2) += stm32/gpioperiph.c stm32/adc.c stm32/i2c.c
src-$(CONFIG_MACH_STM32F2) += stm32/gpioperiph.c stm32/adc.c
src-$(CONFIG_MACH_STM32F4) += ../lib/stm32f4/system_stm32f4xx.c
src-$(CONFIG_MACH_STM32F4) += stm32/stm32f4.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32F4) += stm32/gpioperiph.c stm32/adc.c stm32/i2c.c
src-$(CONFIG_MACH_STM32F4) += stm32/gpioperiph.c stm32/adc.c
src-$(CONFIG_MACH_STM32F7) += ../lib/stm32f7/system_stm32f7xx.c
src-$(CONFIG_MACH_STM32F7) += stm32/stm32f7.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32F7) += stm32/gpioperiph.c stm32/adc.c stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32F7) += stm32/gpioperiph.c stm32/adc.c
src-$(CONFIG_MACH_STM32G0) += generic/timer_irq.c stm32/stm32f0_timer.c
src-$(CONFIG_MACH_STM32G0) += stm32/stm32g0.c stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32G0) += stm32/stm32f0_adc.c stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32G0) += stm32/stm32f0_adc.c
src-$(CONFIG_MACH_STM32G4) += ../lib/stm32g4/system_stm32g4xx.c
src-$(CONFIG_MACH_STM32G4) += stm32/stm32g4.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32G4) += stm32/gpioperiph.c stm32/stm32h7_adc.c
src-$(CONFIG_MACH_STM32G4) += stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32H7) += ../lib/stm32h7/system_stm32h7xx.c
src-$(CONFIG_MACH_STM32H7) += stm32/stm32h7.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32H7) += stm32/gpioperiph.c stm32/stm32h7_adc.c
src-$(CONFIG_MACH_STM32H7) += stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32L4) += ../lib/stm32l4/system_stm32l4xx.c
src-$(CONFIG_MACH_STM32L4) += stm32/stm32l4.c generic/armcm_timer.c
src-$(CONFIG_MACH_STM32L4) += stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32L4) += stm32/stm32h7_adc.c stm32/stm32f0_i2c.c
src-$(CONFIG_MACH_STM32L4) += stm32/stm32h7_adc.c
spi-src-y := stm32/spi.c
spi-src-$(CONFIG_MACH_STM32H7) := stm32/stm32h7_spi.c
src-$(CONFIG_WANT_SPI) += $(spi-src-y)
i2c-src-y := stm32/stm32f0_i2c.c
i2c-src-$(CONFIG_MACH_STM32F1) := stm32/i2c.c
i2c-src-$(CONFIG_MACH_STM32F2) := stm32/i2c.c
i2c-src-$(CONFIG_MACH_STM32F4) := stm32/i2c.c
src-$(CONFIG_WANT_I2C) += $(i2c-src-y)
sdio-src-y := stm32/sdio.c
src-$(CONFIG_HAVE_GPIO_SDIO) += $(sdio-src-y)
usb-src-$(CONFIG_HAVE_STM32_USBFS) := stm32/usbfs.c