Kconfig: Add new WANT_SPI option to reduce code size

Make it possible to not compile in support for SPI 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:23:28 -04:00
parent b0fa36e221
commit 868760f5b1
8 changed files with 34 additions and 27 deletions

View File

@ -88,6 +88,14 @@ config USB_SERIAL_NUMBER
endmenu
# Optional features that can be disabled (for devices with small flash sizes)
config WANT_SPI
bool
depends on HAVE_GPIO && HAVE_GPIO_SPI
default y
config WANT_SOFTWARE_SPI
bool
depends on WANT_SPI
default y
config WANT_HARD_PWM
bool
depends on HAVE_GPIO_HARD_PWM
@ -118,15 +126,15 @@ config WANT_HD44780
default y
config WANT_THERMOCOUPLE
bool
depends on HAVE_GPIO_SPI
depends on WANT_SPI
default y
config WANT_ADXL345
bool
depends on HAVE_GPIO_SPI
depends on WANT_SPI
default y
config WANT_LIS2DW
bool
depends on HAVE_GPIO_SPI || HAVE_GPIO_I2C
depends on WANT_SPI || HAVE_GPIO_I2C
default y
config WANT_MPU9250
bool
@ -142,7 +150,7 @@ config WANT_HX71X
default y
config WANT_ADS1220
bool
depends on HAVE_GPIO_SPI
depends on WANT_SPI
default y
config WANT_LDC1612
bool
@ -150,16 +158,12 @@ config WANT_LDC1612
default y
config WANT_SENSOR_ANGLE
bool
depends on HAVE_GPIO_SPI
depends on WANT_SPI
default y
config WANT_SOFTWARE_I2C
bool
depends on HAVE_GPIO && HAVE_GPIO_I2C
default y
config WANT_SOFTWARE_SPI
bool
depends on HAVE_GPIO && HAVE_GPIO_SPI
default y
config NEED_SENSOR_BULK
bool
depends on WANT_ADXL345 || WANT_LIS2DW || WANT_MPU9250 || WANT_ICM20948 \
@ -167,6 +171,12 @@ config NEED_SENSOR_BULK
default y
menu "Optional features (to reduce code size)"
depends on HAVE_LIMITED_CODE_SIZE
config WANT_SPI
bool "Support communicating with external chips via SPI bus"
depends on HAVE_GPIO && HAVE_GPIO_SPI
config WANT_SOFTWARE_SPI
bool "Support software based SPI \"bit-banging\""
depends on WANT_SPI
config WANT_HARD_PWM
bool "Support hardware PWM (pulse width modulation)"
depends on HAVE_GPIO_HARD_PWM
@ -190,13 +200,13 @@ config WANT_HD44780
depends on HAVE_GPIO
config WANT_THERMOCOUPLE
bool "Support thermocouple MAX sensors"
depends on HAVE_GPIO_SPI
depends on WANT_SPI
config WANT_ADXL345
bool "Support adxl accelerometers"
depends on HAVE_GPIO_SPI
depends on WANT_SPI
config WANT_LIS2DW
bool "Support lis2dw and lis3dh 3-axis accelerometers"
depends on HAVE_GPIO_SPI || HAVE_GPIO_I2C
depends on WANT_SPI || HAVE_GPIO_I2C
config WANT_MPU9250
bool "Support MPU accelerometers"
depends on HAVE_GPIO_I2C
@ -208,19 +218,16 @@ config WANT_HX71X
depends on HAVE_GPIO
config WANT_ADS1220
bool "Support ADS 1220 ADC chip"
depends on HAVE_GPIO_SPI
depends on WANT_SPI
config WANT_LDC1612
bool "Support ldc1612 eddy current sensor"
depends on HAVE_GPIO_I2C
config WANT_SENSOR_ANGLE
bool "Support angle sensors"
depends on HAVE_GPIO_SPI
depends on WANT_SPI
config WANT_SOFTWARE_I2C
bool "Support software based I2C \"bit-banging\""
depends on HAVE_GPIO && HAVE_GPIO_I2C
config WANT_SOFTWARE_SPI
bool "Support software based SPI \"bit-banging\""
depends on HAVE_GPIO && HAVE_GPIO_SPI
endmenu
# Generic configuration options for CANbus

View File

@ -4,7 +4,7 @@ src-y += sched.c command.c basecmd.c debugcmds.c
src-$(CONFIG_HAVE_GPIO) += initial_pins.c gpiocmds.c stepper.c endstop.c \
trsync.c
src-$(CONFIG_HAVE_GPIO_ADC) += adccmds.c
src-$(CONFIG_HAVE_GPIO_SPI) += spicmds.c
src-$(CONFIG_WANT_SPI) += spicmds.c
src-$(CONFIG_HAVE_GPIO_SDIO) += sdiocmds.c
src-$(CONFIG_HAVE_GPIO_I2C) += i2ccmds.c
src-$(CONFIG_WANT_HARD_PWM) += pwmcmds.c

View File

@ -29,7 +29,7 @@ src-$(CONFIG_USBCANBUS) += $(canbus-src-y) atsamd/usbserial.c generic/usb_canbus
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_HAVE_GPIO_SPI) += atsamd/spi.c
src-$(CONFIG_WANT_SPI) += atsamd/spi.c
src-$(CONFIG_HAVE_SERCOM) += atsamd/sercom.c
src-$(CONFIG_WANT_HARD_PWM) += atsamd/hard_pwm.c
src-$(CONFIG_MACH_SAMC21) += atsamd/samd51_watchdog.c

View File

@ -12,7 +12,7 @@ CFLAGS += $(CFLAGS-y) -mmcu=$(CONFIG_MCU)
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_HAVE_GPIO_SPI) += avr/spi.c
src-$(CONFIG_WANT_SPI) += avr/spi.c
src-$(CONFIG_HAVE_GPIO_I2C) += avr/i2c.c
src-$(CONFIG_WANT_HARD_PWM) += avr/hard_pwm.c
src-$(CONFIG_AVR_WATCHDOG) += avr/watchdog.c

View File

@ -18,7 +18,7 @@ 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_HAVE_GPIO_SPI) += lpc176x/spi.c
src-$(CONFIG_WANT_SPI) += lpc176x/spi.c
src-$(CONFIG_USBSERIAL) += lpc176x/usbserial.c lpc176x/chipid.c
src-$(CONFIG_USBSERIAL) += generic/usb_cdc.c
src-$(CONFIG_SERIAL) += lpc176x/serial.c generic/serial_irq.c

View File

@ -29,7 +29,7 @@ src-$(CONFIG_USBCANBUS) += rp2040/can.c rp2040/chipid.c ../lib/can2040/can2040.c
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_HAVE_GPIO_SPI) += rp2040/spi.c
src-$(CONFIG_WANT_SPI) += rp2040/spi.c
src-$(CONFIG_HAVE_GPIO_I2C) += rp2040/i2c.c
# rp2040 stage2 building

View File

@ -6,7 +6,7 @@
// This file may be distributed under the terms of the GNU GPLv3 license.
#include <string.h> // memcpy
#include "autoconf.h" // CONFIG_HAVE_GPIO_SPI
#include "autoconf.h" // CONFIG_WANT_SPI
#include "board/gpio.h" // irq_disable
#include "board/irq.h" // irq_disable
#include "board/misc.h" // timer_read_time
@ -77,7 +77,7 @@ command_config_lis2dw(uint32_t *args)
switch (args[2]) {
case SPI_SERIAL:
if (CONFIG_HAVE_GPIO_SPI) {
if (CONFIG_WANT_SPI) {
ax->spi = spidev_oid_lookup(args[1]);
ax->bus_type = SPI_SERIAL;
break;
@ -126,7 +126,7 @@ lis2dw_query(struct lis2dw *ax, uint8_t oid)
uint8_t fifo_ovrn = 0;
uint8_t *d = &ax->sb.data[ax->sb.data_count];
if (CONFIG_HAVE_GPIO_SPI && ax->bus_type == SPI_SERIAL) {
if (CONFIG_WANT_SPI && ax->bus_type == SPI_SERIAL) {
uint8_t msg[7] = {0};
uint8_t fifo[2] = {LIS_FIFO_SAMPLES | LIS_AM_READ , 0};
@ -220,7 +220,7 @@ command_query_lis2dw_status(uint32_t *args)
uint32_t time2 = 0;
uint8_t status = 0;
if (CONFIG_HAVE_GPIO_SPI && ax->bus_type == SPI_SERIAL) {
if (CONFIG_WANT_SPI && ax->bus_type == SPI_SERIAL) {
uint8_t msg[2] = { LIS_FIFO_SAMPLES | LIS_AM_READ, 0x00 };
time1 = timer_read_time();
spidev_transfer(ax->spi, 1, sizeof(msg), msg);

View File

@ -75,7 +75,7 @@ src-$(CONFIG_MACH_STM32L4) += stm32/gpioperiph.c
src-$(CONFIG_MACH_STM32L4) += stm32/stm32h7_adc.c stm32/stm32f0_i2c.c
spi-src-y := stm32/spi.c
spi-src-$(CONFIG_MACH_STM32H7) := stm32/stm32h7_spi.c
src-$(CONFIG_HAVE_GPIO_SPI) += $(spi-src-y)
src-$(CONFIG_WANT_SPI) += $(spi-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