From 45351e428413874c33e407d55f03486aad51b0ee Mon Sep 17 00:00:00 2001 From: Rocio Date: Thu, 7 Jul 2022 22:56:30 -0400 Subject: [PATCH] Network: Made kconfig ds18 and moisture sensor --- examples/moisture_sensor_hw390/Kconfig | 1 + examples/moisture_sensor_hw390/main.c | 2 +- firmware/peripherals/Kconfig | 9 ++---- firmware/peripherals/ds18_sensor/Kconfig | 11 ++----- firmware/peripherals/moisture_sensor/Kconfig | 31 +++++++++++++++++++ .../moisture_sensor/moisture_sensor.c | 2 +- tests/ds18/Kconfig | 1 + tests/ds18/main.c | 2 +- 8 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 examples/moisture_sensor_hw390/Kconfig create mode 100644 tests/ds18/Kconfig diff --git a/examples/moisture_sensor_hw390/Kconfig b/examples/moisture_sensor_hw390/Kconfig new file mode 100644 index 000000000..7f37683f4 --- /dev/null +++ b/examples/moisture_sensor_hw390/Kconfig @@ -0,0 +1 @@ +rsource "../../firmware/peripherals/moisture_sensor/Kconfig" diff --git a/examples/moisture_sensor_hw390/main.c b/examples/moisture_sensor_hw390/main.c index 20a5bc687..e71ae80f1 100644 --- a/examples/moisture_sensor_hw390/main.c +++ b/examples/moisture_sensor_hw390/main.c @@ -26,7 +26,7 @@ #include "periph/adc.h" #include "ztimer.h" -#define RES ADC_RES_10BIT +#define RES CONFIG_ADC_RES #define DELAY_MS 5000U int main (void) { diff --git a/firmware/peripherals/Kconfig b/firmware/peripherals/Kconfig index 797ff829a..25ad0a0b7 100644 --- a/firmware/peripherals/Kconfig +++ b/firmware/peripherals/Kconfig @@ -1,9 +1,4 @@ menu "Peripherals" -menu "Hardware Periph Setup" -if BOARD_M4A_24G -rsource "../../boards/m4a-24g/Kconfig.periph" -endif -endmenu -rsource "ds18_sensor/Kconfig" -rsource "moisture_sensor/Kconfig" + rsource "ds18_sensor/Kconfig" + rsource "moisture_sensor/Kconfig" endmenu diff --git a/firmware/peripherals/ds18_sensor/Kconfig b/firmware/peripherals/ds18_sensor/Kconfig index eb85418fd..881d97316 100644 --- a/firmware/peripherals/ds18_sensor/Kconfig +++ b/firmware/peripherals/ds18_sensor/Kconfig @@ -1,10 +1,5 @@ menu "ds18 for soil" -# Set if the ds18 for soil is connected -config DS18_SOIL_CONNECTED - bool "Set if it's connected" - default y -# Set the GPIO where it's connected -config DS18_SOIL_GPIO - int "GPIO where the ds18 is attached" - default 0 + config PIN_TEMP_SENSOR + int "Pin to connect temperature sensor" + default 5 endmenu diff --git a/firmware/peripherals/moisture_sensor/Kconfig b/firmware/peripherals/moisture_sensor/Kconfig index 2bebad15e..852b1e4da 100644 --- a/firmware/peripherals/moisture_sensor/Kconfig +++ b/firmware/peripherals/moisture_sensor/Kconfig @@ -1,3 +1,34 @@ menu "Moisture sensor setup" +choice ADC_RES + prompt "ADC_BITS_RESOLUTION" + default ADC_RES_10BIT +config ADC_RES_6BIT + bool "ADC resolution: 6 bit" + +config ADC_RES_8BIT + bool "ADC resolution: 8 bit" + +config ADC_RES_10BIT + bool "ADC resolution: 10 bit" + +config ADC_RES_12BIT + bool "ADC resolution: 12 bit" + +config ADC_RES_14BIT + bool "ADC resolution: 14 bit" + +config ADC_RES_1B6IT + bool "ADC resolution: 16 bit" +endchoice + +config ADC_RES +int + +default 255 if ADC_RES_6BIT +default 48 if ADC_RES_8BIT +default 32 if ADC_RES_10BIT +default 0 if ADC_RES_12BIT +default 254 if ADC_RES_14BIT +default 253 if ADC_RES_16BIT endmenu diff --git a/firmware/peripherals/moisture_sensor/moisture_sensor.c b/firmware/peripherals/moisture_sensor/moisture_sensor.c index 3f489df12..5441ece5b 100644 --- a/firmware/peripherals/moisture_sensor/moisture_sensor.c +++ b/firmware/peripherals/moisture_sensor/moisture_sensor.c @@ -24,7 +24,7 @@ #define DEFAULT_MIN 356 #define DEFAULT_MAX 880 -#define RES ADC_RES_10BIT +#define RES (CONFIG_ADC_RES) int init_moisture (void) { diff --git a/tests/ds18/Kconfig b/tests/ds18/Kconfig new file mode 100644 index 000000000..f11371af6 --- /dev/null +++ b/tests/ds18/Kconfig @@ -0,0 +1 @@ +rsource "../../firmware/peripherals/ds18_sensor/Kconfig" diff --git a/tests/ds18/main.c b/tests/ds18/main.c index 7f1637e63..a2fe9816a 100644 --- a/tests/ds18/main.c +++ b/tests/ds18/main.c @@ -26,7 +26,7 @@ #include "ds18_sensor.h" void test_init_ds18(void) { - int err = init_temperature_sensor(5); + int err = init_temperature_sensor(CONFIG_PIN_TEMP_SENSOR); TEST_ASSERT_EQUAL_INT(0, err); }