1

I have a multiple choice menu defined like this:

menu "Audio"

choice
    prompt "Select Audio Output"
    default I2S
    help
        This option selects the audio output.

    config AUDIO_OUTPUT_MODE_I2S
        bool "Generic I2S"
    config AUDIO_OUTPUT_MODE_I2S_MERUS
        bool "Merus Audio I2S"
    config AUDIO_OUTPUT_MODE_DAC_BUILT_IN
        bool "Built-In DAC"
endchoice

config AUDIO_OUTPUT_MODE
    string
    default I2S
    default I2S if AUDIO_OUTPUT_MODE_I2S
    default I2S_MERUS if AUDIO_OUTPUT_MODE_I2S_MERUS
    default DAC_BUILT_IN if AUDIO_OUTPUT_MODE_DAC_BUILT_IN

config DAC_BUG_WORKAROUND
    bool "Activate workaround when using Built-In DAC"

endmenu

I want to map the choice to an enum, but Kconfig only has tristate and string types, so I can't do this, because the value of AUDIO_OUTPUT_MODE is a string and not a literal:

my_enum = AUDIO_OUTPUT_MODE;

Using int directly would work, but is there a cleaner solution?

artless noise
  • 21,212
  • 6
  • 68
  • 105
Michael Böckling
  • 7,341
  • 6
  • 55
  • 76

1 Answers1

0

In your makefile, you can pass the selection as a preprocessor definition:

CFLAGS-$(CONFIG_CHOICE_A) += -Dchoice=enum_value_a
CFLAGS-$(CONFIG_CHOICE_B) += -Dchoice=enum_value_b
CFLAGS-$(CONFIG_CHOICE_C) += -Dchoice=enum_value_c

Then append the selected flags:

CFLAGS += $(CFLAGS-y)

Then access it in this case as the "choice" macro in your C code.

Mark K Cowan
  • 1,755
  • 1
  • 20
  • 28
  • Thats an interesting trick, I'm not sure I would want to introduce an additional coupling with my enum though. I went with int values which turned out to be okayish. – Michael Böckling Nov 02 '17 at 13:18