From b8a73032256182cf81cc09d084e29fff385a1d2b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Foucher?= <cfoucher@laas.fr>
Date: Wed, 2 Mar 2022 10:08:24 +0000
Subject: [PATCH] Integrate hardware configuration as a module.

---
 ...n-standby-switch.yaml => gpio-device.yaml} |  8 +-
 .../dts/bindings/ngnd-switch.yaml             | 14 ---
 .../owntech_board/dts/can-standby-switch.dtsi |  4 +-
 zephyr/boards/arm/owntech_board/dts/ngnd.dtsi |  4 +-
 .../boards/arm/owntech_board/dts/pinctrl.dtsi | 48 ----------
 .../owntech_dac_driver/zephyr/CMakeLists.txt  |  1 -
 .../modules/owntech_dac_driver/zephyr/Kconfig |  1 +
 .../zephyr/public_include/dac.h               | 11 +--
 .../zephyr/src/stm32_dac_driver.c             | 11 ++-
 .../zephyr/src/stm32_dac_driver.h             |  3 +-
 .../zephyr/CMakeLists.txt                     |  5 +-
 .../owntech_data_acquisition/zephyr/Kconfig   |  2 +-
 .../zephyr/public_api/DataAcquisition.cpp     | 58 ++++++++++-
 .../zephyr/public_api/DataAcquisition.h       | 48 +++++++---
 .../zephyr/CMakeLists.txt                     | 17 ++++
 .../zephyr/Kconfig                            |  6 ++
 .../zephyr/module.yml                         |  2 +-
 .../public_api/HardwareConfiguration.cpp      | 96 +++++++++++++++++++
 .../zephyr/public_api/HardwareConfiguration.h | 66 +++++++++++++
 .../zephyr/src/dac_configuration.cpp}         | 29 +-----
 .../zephyr/src/dac_configuration.h            | 33 +++++++
 .../src/hardware_auto_configuration.cpp       | 81 ++++++++++++++++
 .../zephyr/src/led_configuration.cpp}         | 62 +++++++-----
 .../zephyr/src/led_configuration.h            | 35 +++++++
 .../zephyr/src/ngnd_configuration.cpp         | 49 ++++++++++
 .../zephyr/src/ngnd_configuration.h           | 34 +++++++
 .../zephyr/src/timer_configuration.cpp        | 73 ++++++++++++++
 .../zephyr/src/timer_configuration.h          | 45 +++++++++
 .../zephyr/src/owntech_ngnd_driver.c          |  2 +-
 .../zephyr/CMakeLists.txt                     |  8 --
 .../owntech_vrefbuf_driver/zephyr/Kconfig     |  3 -
 zephyr/prj.conf                               |  2 +-
 32 files changed, 700 insertions(+), 161 deletions(-)
 rename zephyr/boards/arm/owntech_board/dts/bindings/{can-standby-switch.yaml => gpio-device.yaml} (65%)
 delete mode 100644 zephyr/boards/arm/owntech_board/dts/bindings/ngnd-switch.yaml
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/Kconfig
 rename zephyr/modules/{owntech_vrefbuf_driver => owntech_hardware_configuration}/zephyr/module.yml (56%)
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h
 rename zephyr/modules/{owntech_dac_driver/zephyr/src/owntech_dac_configure.c => owntech_hardware_configuration/zephyr/src/dac_configuration.cpp} (69%)
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.h
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/src/hardware_auto_configuration.cpp
 rename zephyr/modules/{owntech_vrefbuf_driver/zephyr/src/vrefbuf_driver.c => owntech_hardware_configuration/zephyr/src/led_configuration.cpp} (52%)
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/src/led_configuration.h
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.cpp
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.h
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.cpp
 create mode 100644 zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.h
 delete mode 100644 zephyr/modules/owntech_vrefbuf_driver/zephyr/CMakeLists.txt
 delete mode 100644 zephyr/modules/owntech_vrefbuf_driver/zephyr/Kconfig

diff --git a/zephyr/boards/arm/owntech_board/dts/bindings/can-standby-switch.yaml b/zephyr/boards/arm/owntech_board/dts/bindings/gpio-device.yaml
similarity index 65%
rename from zephyr/boards/arm/owntech_board/dts/bindings/can-standby-switch.yaml
rename to zephyr/boards/arm/owntech_board/dts/bindings/gpio-device.yaml
index 09d9689..3dd17d6 100644
--- a/zephyr/boards/arm/owntech_board/dts/bindings/can-standby-switch.yaml
+++ b/zephyr/boards/arm/owntech_board/dts/bindings/gpio-device.yaml
@@ -1,11 +1,11 @@
-description: CAN Standby Switch
+description: GPIO-controllable device
 
-compatible: "can-standby-switch"
+compatible: "gpio-device"
 
 child-binding:
-  description: CAN Stanby GPIO node
+  description: GPIO node
   properties:
-    can-standby-gpios:
+    gpios:
       type: phandle-array
       required: true
     label:
diff --git a/zephyr/boards/arm/owntech_board/dts/bindings/ngnd-switch.yaml b/zephyr/boards/arm/owntech_board/dts/bindings/ngnd-switch.yaml
deleted file mode 100644
index 59ffafc..0000000
--- a/zephyr/boards/arm/owntech_board/dts/bindings/ngnd-switch.yaml
+++ /dev/null
@@ -1,14 +0,0 @@
-description: Neutral-Ground Switch
-
-compatible: "ngnd-switch"
-
-child-binding:
-    description: Neutral-Ground GPIO node
-    properties:
-       ngnd-gpios:
-          type: phandle-array
-          required: true
-       label:
-          required: true
-          type: string
-          description: Human readable string describing the device (used as device_get_binding() argument)
diff --git a/zephyr/boards/arm/owntech_board/dts/can-standby-switch.dtsi b/zephyr/boards/arm/owntech_board/dts/can-standby-switch.dtsi
index 7da3f81..5185624 100644
--- a/zephyr/boards/arm/owntech_board/dts/can-standby-switch.dtsi
+++ b/zephyr/boards/arm/owntech_board/dts/can-standby-switch.dtsi
@@ -6,10 +6,10 @@
 
 / {
 	can-standby-switch {
-		compatible = "can-standby-switch";
+		compatible = "gpio-device";
 		label = "CAN_STANDBY";
 		can-standby-gpio-pin {
-			can-standby-gpios = <&gpiob 10 GPIO_ACTIVE_HIGH>;
+			gpios = <&gpiob 10 GPIO_ACTIVE_HIGH>;
 			label = "CAN Standby output";
 		};
 	};
diff --git a/zephyr/boards/arm/owntech_board/dts/ngnd.dtsi b/zephyr/boards/arm/owntech_board/dts/ngnd.dtsi
index 44a3852..09a0e48 100644
--- a/zephyr/boards/arm/owntech_board/dts/ngnd.dtsi
+++ b/zephyr/boards/arm/owntech_board/dts/ngnd.dtsi
@@ -6,10 +6,10 @@
 
  / {
 	ngnd: ngnd-switch {
-		compatible = "ngnd-switch";
+		compatible = "gpio-device";
 		label = "NGND";
 		ngnd-gpio-pin {
-			ngnd-gpios = <&gpiob 11 GPIO_ACTIVE_HIGH>;
+			gpios = <&gpiob 11 GPIO_ACTIVE_HIGH>;
 			label = "Neutral to GND shunt";
 		};
 	};
diff --git a/zephyr/boards/arm/owntech_board/dts/pinctrl.dtsi b/zephyr/boards/arm/owntech_board/dts/pinctrl.dtsi
index 9cdc791..421ef4f 100644
--- a/zephyr/boards/arm/owntech_board/dts/pinctrl.dtsi
+++ b/zephyr/boards/arm/owntech_board/dts/pinctrl.dtsi
@@ -7,54 +7,6 @@
 / {
 	soc {
 		pinctrl: pin-controller@48000000 {
-			hrtim1_cha1_pa8: hrtim1_cha1_pa8 {
-				pinmux = <STM32_PINMUX('A', 8, AF13)>;
-			};
-
-			hrtim1_cha2_pa9: hrtim1_cha2_pa9 {
-				pinmux = <STM32_PINMUX('A', 9, AF13)>;
-			};
-
-			hrtim1_chb1_pa10: hrtim1_chb1_pa10 {
-				pinmux = <STM32_PINMUX('A', 10, AF13)>;
-			};
-
-			hrtim1_chb2_pa11: hrtim1_chb2_pa11 {
-				pinmux = <STM32_PINMUX('A', 11, AF13)>;
-			};
-
-			hrtim1_chc1_pb12: hrtim1_chc1_pb12 {
-				pinmux = <STM32_PINMUX('B', 12, AF13)>;
-			};
-
-			hrtim1_chc2_pb13: hrtim1_chc2_pb13 {
-				pinmux = <STM32_PINMUX('B', 13, AF13)>;
-			};
-
-			hrtim1_chd1_pb14: hrtim1_chd1_pb14 {
-				pinmux = <STM32_PINMUX('B', 14, AF13)>;
-			};
-
-			hrtim1_chd2_pb15: hrtim1_chd2_pb15 {
-				pinmux = <STM32_PINMUX('B', 15, AF13)>;
-			};
-
-			hrtim1_che1_pc8: hrtim1_che1_pc8 {
-				pinmux = <STM32_PINMUX('C', 8, AF3)>;
-			};
-
-			hrtim1_che2_pc9: hrtim1_che2_pc9 {
-				pinmux = <STM32_PINMUX('C', 9, AF3)>;
-			};
-
-			hrtim1_chf1_pc6: hrtim1_chf1_pc6 {
-				pinmux = <STM32_PINMUX('C', 6, AF13)>;
-			};
-
-			hrtim1_chf2_pc7: hrtim1_chf2_pc7 {
-				pinmux = <STM32_PINMUX('C', 7, AF13)>;
-			};
-
 			tim4_etr_pb3: tim4_etr_pb3 {
 				pinmux = <STM32_PINMUX('B', 3, AF2)>;
 			};
diff --git a/zephyr/modules/owntech_dac_driver/zephyr/CMakeLists.txt b/zephyr/modules/owntech_dac_driver/zephyr/CMakeLists.txt
index ca08a94..b18b1ec 100644
--- a/zephyr/modules/owntech_dac_driver/zephyr/CMakeLists.txt
+++ b/zephyr/modules/owntech_dac_driver/zephyr/CMakeLists.txt
@@ -6,6 +6,5 @@ if(CONFIG_OWNTECH_DAC_DRIVER)
   # Select source files to be compiled
   zephyr_library_sources(
     ./src/stm32_dac_driver.c
-    ./src/owntech_dac_configure.c
     )
 endif()
diff --git a/zephyr/modules/owntech_dac_driver/zephyr/Kconfig b/zephyr/modules/owntech_dac_driver/zephyr/Kconfig
index d1474cf..cd7ea23 100644
--- a/zephyr/modules/owntech_dac_driver/zephyr/Kconfig
+++ b/zephyr/modules/owntech_dac_driver/zephyr/Kconfig
@@ -1,3 +1,4 @@
 config OWNTECH_DAC_DRIVER
 	bool "Enable OwnTech DAC driver"
 	default y
+	depends on !DAC
diff --git a/zephyr/modules/owntech_dac_driver/zephyr/public_include/dac.h b/zephyr/modules/owntech_dac_driver/zephyr/public_include/dac.h
index cc1c8c6..713f612 100644
--- a/zephyr/modules/owntech_dac_driver/zephyr/public_include/dac.h
+++ b/zephyr/modules/owntech_dac_driver/zephyr/public_include/dac.h
@@ -64,10 +64,10 @@ typedef struct
 	uint32_t       step_data;
 } dac_function_config_t;
 
-typedef struct
+typedef enum
 {
-	uint32_t pin_connect;
-	uint32_t pin_buffer_enable;
+	dac_pin_internal,
+	dac_pin_external
 } dac_pin_config_t;
 
 
@@ -78,7 +78,7 @@ typedef void (*dac_api_setconstvalue) (const struct device* dev, uint8_t channel
 typedef void (*dac_api_setfunction)   (const struct device* dev, uint8_t channel, const dac_function_config_t* config);
 typedef void (*dac_api_fn_upd_reset)  (const struct device* dev, uint8_t channel, uint32_t reset_data);
 typedef void (*dac_api_fn_upd_step)   (const struct device* dev, uint8_t channel, uint32_t step_data);
-typedef void (*dac_api_pinconfigure)  (const struct device* dev, uint8_t channel, const dac_pin_config_t* config);
+typedef void (*dac_api_pinconfigure)  (const struct device* dev, uint8_t channel, dac_pin_config_t config);
 typedef void (*dac_api_start)         (const struct device* dev, uint8_t channel);
 typedef void (*dac_api_stop)          (const struct device* dev, uint8_t channel);
 
@@ -121,7 +121,7 @@ static inline void dac_function_update_step(const struct device* dev, uint8_t ch
 	api->fn_upd_step(dev, channel, step_data);
 }
 
-static inline void dac_pin_configure(const struct device* dev, uint8_t channel, const dac_pin_config_t* pin_config)
+static inline void dac_pin_configure(const struct device* dev, uint8_t channel, dac_pin_config_t pin_config)
 {
 	const struct dac_driver_api* api = (const struct dac_driver_api*)(dev->api);
 
@@ -145,7 +145,6 @@ static inline void dac_stop(const struct device* dev, uint8_t channel)
 /////
 // Owntech-specific config
 
-void owntech_dac_dac2_constant_init();
 void owntech_dac_dac1_dac3_current_mode_init();
 
 
diff --git a/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.c b/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.c
index 43c4a42..d6005ca 100644
--- a/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.c
+++ b/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.c
@@ -183,14 +183,21 @@ static void dac_stm32_function_update_step(const struct device* dev, uint8_t cha
 	}
 }
 
-static void dac_stm32_pin_configure(const struct device* dev, uint8_t channel, const dac_pin_config_t* pin_config)
+static void dac_stm32_pin_configure(const struct device* dev, uint8_t channel, dac_pin_config_t pin_config)
 {
 	struct stm32_dac_driver_data* data = (struct stm32_dac_driver_data*)dev->data;
 	DAC_TypeDef* dac_dev = data->dac_struct;
 
 	uint8_t dac_channel = __LL_DAC_DECIMAL_NB_TO_CHANNEL(channel);
 
-	LL_DAC_ConfigOutput(dac_dev, dac_channel, LL_DAC_OUTPUT_MODE_NORMAL, pin_config->pin_buffer_enable, pin_config->pin_connect);
+	if (pin_config == dac_pin_internal)
+	{
+		LL_DAC_ConfigOutput(dac_dev, dac_channel, LL_DAC_OUTPUT_MODE_NORMAL, LL_DAC_OUTPUT_BUFFER_DISABLE, LL_DAC_OUTPUT_CONNECT_INTERNAL);
+	}
+	else if (pin_config == dac_pin_external)
+	{
+		LL_DAC_ConfigOutput(dac_dev, dac_channel, LL_DAC_OUTPUT_MODE_NORMAL, LL_DAC_OUTPUT_BUFFER_ENABLE, LL_DAC_OUTPUT_CONNECT_GPIO);
+	}
 }
 
 static void dac_stm32_start(const struct device* dev, uint8_t channel)
diff --git a/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.h b/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.h
index e467713..376473a 100644
--- a/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.h
+++ b/zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.h
@@ -50,7 +50,6 @@ typedef enum
 	dac_mode_function
 } dac_mode_t;
 
-
 struct stm32_dac_driver_data
 {
 	DAC_TypeDef* dac_struct;
@@ -70,7 +69,7 @@ static void dac_stm32_set_const_value(const struct device* dev, uint8_t channel,
 static void dac_stm32_set_function(const struct device* dev, uint8_t channel, const dac_function_config_t* function_config);
 static void dac_stm32_function_update_reset(const struct device* dev, uint8_t channel, uint32_t reset_data);
 static void dac_stm32_function_update_step(const struct device* dev, uint8_t channel, uint32_t step_data);
-static void dac_stm32_pin_configure(const struct device* dev, uint8_t channel, const dac_pin_config_t* pin_config);
+static void dac_stm32_pin_configure(const struct device* dev, uint8_t channel, dac_pin_config_t pin_config);
 static void dac_stm32_start(const struct device* dev, uint8_t channel);
 static void dac_stm32_stop(const struct device* dev, uint8_t channel);
 
diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/CMakeLists.txt b/zephyr/modules/owntech_data_acquisition/zephyr/CMakeLists.txt
index 8856c5c..862d127 100644
--- a/zephyr/modules/owntech_data_acquisition/zephyr/CMakeLists.txt
+++ b/zephyr/modules/owntech_data_acquisition/zephyr/CMakeLists.txt
@@ -1,8 +1,11 @@
-
 if(CONFIG_OWNTECH_DATA_ACQUISITION)
+  # Select directory to add to the include path
   zephyr_include_directories(./public_api)
 
+  # Define the current folder as a Zephyr library
   zephyr_library()
+
+  # Select source files to be compiled
   zephyr_library_sources(
     ./adc/adc.c
     ./adc/adc_channels.c
diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/Kconfig b/zephyr/modules/owntech_data_acquisition/zephyr/Kconfig
index 01b77a2..3265b02 100644
--- a/zephyr/modules/owntech_data_acquisition/zephyr/Kconfig
+++ b/zephyr/modules/owntech_data_acquisition/zephyr/Kconfig
@@ -1,5 +1,5 @@
-
 config OWNTECH_DATA_ACQUISITION
 	bool "Enable OwnTech data acquisition using ADCs"
 	default y
 	select DMA
+	depends on !ADC
diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp
index f6be5a4..aac77f1 100644
--- a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp
+++ b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp
@@ -27,6 +27,9 @@
 // Stdlib
 #include <string.h>
 
+// STM32 LL
+#include <stm32g4xx_ll_adc.h>
+
 // OwnTech Power API
 #include "../adc/adc.h"
 #include "../dma/dma.h"
@@ -67,8 +70,14 @@ void DataAcquisition::initialize()
 {
 	if (initialized == 0)
 	{
+		// Initialize the ADCs
 		adc_init();
 		initialized = 1;
+
+		// Perform default configration
+		configureAdcTriggerSource(1, hrtim1);
+		configureAdcTriggerSource(2, hrtim1);
+		configureAdcTriggerSource(3, software);
 	}
 }
 
@@ -115,7 +124,7 @@ void  DataAcquisition::setChannnelAssignment(uint8_t adc_number, const char* cha
 /////
 // Public static configuration functions
 
-int8_t DataAcquisition::setAdc12DualMode(uint8_t dual_mode)
+int8_t DataAcquisition::configureAdc12DualMode(uint8_t dual_mode)
 {
 	/////
 	// Guard
@@ -179,7 +188,7 @@ int8_t DataAcquisition::configureAdcChannels(uint8_t adc_number, const char* cha
 	return NOERROR;
 }
 
-int8_t DataAcquisition::configureAdcTriggerSource(uint8_t adc_number, uint32_t trigger_source)
+int8_t DataAcquisition::configureAdcTriggerSource(uint8_t adc_number, adc_src_t trigger_source)
 {
 	/////
 	// Guard
@@ -199,12 +208,55 @@ int8_t DataAcquisition::configureAdcTriggerSource(uint8_t adc_number, uint32_t t
 
 	/////
 	// Proceed
+	uint32_t trig;
+	switch (trigger_source)
+	{
+	case hrtim1:
+		trig = LL_ADC_REG_TRIG_EXT_HRTIM_TRG1;
+		break;
+	case software:
+	default:
+		trig = LL_ADC_REG_TRIG_SOFTWARE;
+		break;
+	}
 
-	adc_configure_trigger_source(adc_number, trigger_source);
+	adc_configure_trigger_source(adc_number, trig);
 
 	return NOERROR;
 }
 
+int8_t DataAcquisition::configureAdcDefaultAllMeasurements()
+{
+	uint8_t init_status;
+
+	uint8_t number_of_channels_adc1 = 3;
+	uint8_t number_of_channels_adc2 = 3;
+
+	const char* adc1_channels[] =
+	{
+		"V1_LOW",
+		"V2_LOW",
+		"V_HIGH"
+	};
+
+	const char* adc2_channels[] =
+	{
+		"I1_LOW",
+		"I2_LOW",
+		"I_HIGH"
+	};
+
+	init_status = dataAcquisition.configureAdcChannels(1, adc1_channels, number_of_channels_adc1);
+
+	if (init_status != NOERROR)
+	{
+		return init_status;
+	}
+
+	init_status = dataAcquisition.configureAdcChannels(2, adc2_channels, number_of_channels_adc2);
+
+	return NOERROR;
+}
 
 int8_t DataAcquisition::start()
 {
diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h
index 65f0c41..06a4722 100644
--- a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h
+++ b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h
@@ -34,6 +34,15 @@
 #include <arm_math.h>
 
 
+/////
+// Public enums
+typedef enum
+{
+	hrtim1,
+	software
+} adc_src_t;
+
+
 /////
 // Static class definition
 
@@ -56,21 +65,23 @@ public:
 
 	/**
 	 * Use this function to set ADC 1 and ADC 2 in dual mode.
+	 * By default, ADC 1 and 2 are not in dual mode.
 	 *
-	 * This function must be called BEFORE DataAcquisition::start().
+	 * This function must be called BEFORE dataAcquisition.start().
 	 *
-	 * @param  dual_mode Status of the dual mode: true to enable,
-	 *         false to disable. false by default.
+	 * @param  dual_mode Status of the dual mode:
+	 *         true to enable,
+	 *         false to disable.
 	 * @return 0 is everything went well,
 	 *         EALREADYSTARTED if the module has already been started.
 	 */
-	static int8_t setAdc12DualMode(uint8_t dual_mode);
+	static int8_t configureAdc12DualMode(uint8_t dual_mode);
 
 	/**
 	 * This function is used to configure the channels to be
 	 * enabled on a given ADC.
 	 *
-	 * This function must be called BEFORE DataAcquisition::start().
+	 * This function must be called BEFORE dataAcquisition.start().
 	 *
 	 * @param  adc_number Number of the ADC on which channel configuration is
 	 *         to be done.
@@ -88,19 +99,32 @@ public:
 	static int8_t configureAdcChannels(uint8_t adc_number, const char* channel_list[], uint8_t channel_count);
 
 	/**
-	 * This function is used to configure the trigger source of an ADC.
-	 *
-	 * This function must be called BEFORE DataAcquisition::start().
+	 * This function is used to change the trigger source of an ADC.
+	 * By default, triggger source for ADC 1 and ADC 2 is on HRTIM1,
+	 * and ADC 3 is software-triggered.
 	 *
-	 * TODO: Use an enumeration instead of LL constants for source.
+	 * This function must be called BEFORE dataAcquisition.start().
 	 *
 	 * @param  adc_number Number of the ADC to configure
-	 * @param  trigger_source Source of the trigger as defined
-	 *         in stm32gxx_ll_adc.h (LL_ADC_REG_TRIG_***)
+	 * @param  trigger_source Source of the trigger
+	 * @return 0 is everything went well,
+	 *         EALREADYSTARTED if the module has already been started.
+	 */
+	static int8_t configureAdcTriggerSource(uint8_t adc_number, adc_src_t trigger_source);
+
+	/**
+	 * This function is used to configure all ADC channels in default configuration.
+	 * Channels will be attributed as follows:
+ 	 * ADC1 -   V1_LOW      ADC2 -  I1_LOW
+ 	 *          V2_LOW              I2_LOW
+ 	 *          V_HIGH              I_HIGH
+	 *
+	 * This function must be called BEFORE dataAcquisition.start().
+	 *
 	 * @return 0 is everything went well,
 	 *         EALREADYSTARTED if the module has already been started.
 	 */
-	static int8_t configureAdcTriggerSource(uint8_t adc_number, uint32_t trigger_source);
+	static int8_t configureAdcDefaultAllMeasurements();
 
 	/**
 	 * This functions starts the acquisition chain. It must be called
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt b/zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt
new file mode 100644
index 0000000..b525d58
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/CMakeLists.txt
@@ -0,0 +1,17 @@
+if(CONFIG_OWNTECH_HARDWARE_CONFIGURATION)
+  # Select directory to add to the include path
+  zephyr_include_directories(./public_api)
+
+  # Define the current folder as a Zephyr library
+  zephyr_library()
+
+  # Select source files to be compiled
+  zephyr_library_sources(
+    src/hardware_auto_configuration.cpp
+	src/dac_configuration.cpp
+	src/ngnd_configuration.cpp
+	src/led_configuration.cpp
+	src/timer_configuration.cpp
+	public_api/HardwareConfiguration.cpp
+    )
+endif()
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/Kconfig b/zephyr/modules/owntech_hardware_configuration/zephyr/Kconfig
new file mode 100644
index 0000000..5793393
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/Kconfig
@@ -0,0 +1,6 @@
+config OWNTECH_HARDWARE_CONFIGURATION
+	bool "Enable OwnTech hardware configuration module"
+	default y
+	depends on OWNTECH_DAC_DRIVER
+	depends on OWNTECH_NGND_DRIVER
+	depends on OWNTECH_TIMER_DRIVER
diff --git a/zephyr/modules/owntech_vrefbuf_driver/zephyr/module.yml b/zephyr/modules/owntech_hardware_configuration/zephyr/module.yml
similarity index 56%
rename from zephyr/modules/owntech_vrefbuf_driver/zephyr/module.yml
rename to zephyr/modules/owntech_hardware_configuration/zephyr/module.yml
index dd0020e..43a6a19 100644
--- a/zephyr/modules/owntech_vrefbuf_driver/zephyr/module.yml
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/module.yml
@@ -1,4 +1,4 @@
-name: owntech_vrefbuf_driver
+name: owntech_hardware_configuration
 build:
   cmake: zephyr
   kconfig: zephyr/Kconfig
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp
new file mode 100644
index 0000000..6c76638
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2022 LAAS-CNRS
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published by
+ *   the Free Software Foundation, either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGLPV2.1
+ */
+
+/**
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
+ */
+
+
+// OwnTech headers
+#include "../src/dac_configuration.h"
+#include "../src/ngnd_configuration.h"
+#include "../src/led_configuration.h"
+#include "../src/timer_configuration.h"
+
+// Current class header
+#include "HardwareConfiguration.h"
+
+
+/////
+// Public object to interact with the class
+
+HardwareConfiguration hwConfig;
+
+
+/////
+// Public static configuration functions
+
+
+/////
+// DAC
+
+void HardwareConfiguration::initDac1Dac3CurrentMode()
+{
+	dac_config_dac1_dac3_current_mode_init();
+}
+
+
+/////
+// NGND
+
+void HardwareConfiguration::setNgndOn()
+{
+	ngnd_config_on();
+}
+
+void HardwareConfiguration::setNgndOff()
+{
+	ngnd_config_off();
+}
+
+/////
+// LED
+
+void HardwareConfiguration::setLedOn()
+{
+	led_config_on();
+}
+
+void HardwareConfiguration::setLedOff()
+{
+	led_config_off();
+}
+
+void HardwareConfiguration::setLedToggle()
+{
+	led_config_toggle();
+}
+
+// Incremental encoder
+
+void HardwareConfiguration::startLoggingIncrementalEncoder()
+{
+	timer_incremental_encoder_tim4_start();
+}
+
+uint32_t HardwareConfiguration::getIncrementalEncoderValue()
+{
+	return timer_incremental_encoder_tim4_get_step();
+}
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h
new file mode 100644
index 0000000..d393536
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2022 LAAS-CNRS
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published by
+ *   the Free Software Foundation, either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGLPV2.1
+ */
+
+/**
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
+ */
+
+
+#ifndef HARDWARECONFIGURATION_H_
+#define HARDWARECONFIGURATION_H_
+
+
+#include <stdint.h>
+
+
+/////
+// Static class definition
+
+class HardwareConfiguration
+{
+
+public:
+	// DAC
+	void initDac1Dac3CurrentMode();
+
+	// NGND
+	void setNgndOn();
+	void setNgndOff();
+
+	// LED
+	void setLedOn();
+	void setLedOff();
+	void setLedToggle();
+
+	// Incremental encoder
+	void startLoggingIncrementalEncoder();
+	uint32_t getIncrementalEncoderValue();
+
+};
+
+
+/////
+// Public object to interact with the class
+
+extern HardwareConfiguration hwConfig;
+
+
+
+#endif // HARDWARECONFIGURATION_H_
diff --git a/zephyr/modules/owntech_dac_driver/zephyr/src/owntech_dac_configure.c b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp
similarity index 69%
rename from zephyr/modules/owntech_dac_driver/zephyr/src/owntech_dac_configure.c
rename to zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp
index c731101..cf19771 100644
--- a/zephyr/modules/owntech_dac_driver/zephyr/src/owntech_dac_configure.c
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp
@@ -19,7 +19,6 @@
 
 /**
  * @date   2022
- *
  * @author Clément Foucher <clement.foucher@laas.fr>
  */
 
@@ -34,24 +33,8 @@
 #include "dac.h"
 
 
-// TODO: this function must *always* be run.
-// Write a driver to load on startup without user action?
-void owntech_dac_dac2_constant_init()
-{
-	const struct device* dac2 = device_get_binding(DAC2_DEVICE);
-
-	dac_pin_config_t pin_config =
-	{
-		.pin_connect       = LL_DAC_OUTPUT_CONNECT_GPIO,
-		.pin_buffer_enable = LL_DAC_OUTPUT_BUFFER_ENABLE
-	};
-
-	dac_set_const_value(dac2, 1, 2048U);
-	dac_pin_configure(dac2, 1, &pin_config);
-	dac_start(dac2, 1);
-}
 
-void owntech_dac_dac1_dac3_current_mode_init()
+void dac_config_dac1_dac3_current_mode_init()
 {
 	const struct device* dac1 = device_get_binding(DAC1_DEVICE);
 	const struct device* dac3 = device_get_binding(DAC3_DEVICE);
@@ -66,15 +49,9 @@ void owntech_dac_dac1_dac3_current_mode_init()
 		.step_data = 200
 	};
 
-	dac_pin_config_t pin_config =
-	{
-		.pin_connect       = LL_DAC_OUTPUT_CONNECT_INTERNAL,
-		.pin_buffer_enable = LL_DAC_OUTPUT_BUFFER_DISABLE
-	};
-
 	// DAC 1
 	dac_set_function(dac1, 1, &function_config);
-	dac_pin_configure(dac1, 1, &pin_config);
+	dac_pin_configure(dac1, 1, dac_pin_internal);
 	dac_start(dac1, 1);
 
 	// DAC 3
@@ -82,6 +59,6 @@ void owntech_dac_dac1_dac3_current_mode_init()
 	function_config.step_trigger_source = LL_DAC_TRIG_EXT_HRTIM_STEP_TRG2;
 
 	dac_set_function(dac3, 1, &function_config);
-	dac_pin_configure(dac3, 1, &pin_config);
+	dac_pin_configure(dac3, 1, dac_pin_internal);
 	dac_start(dac3, 1);
 }
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.h
new file mode 100644
index 0000000..fcd827e
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2022 LAAS-CNRS
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published by
+ *   the Free Software Foundation, either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGLPV2.1
+ */
+
+/**
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
+ */
+
+
+#ifndef DAC_CONFIGURATION_H_
+#define DAC_CONFIGURATION_H_
+
+
+void dac_config_dac1_dac3_current_mode_init();
+
+
+#endif // DAC_CONFIGURATION_H_
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/hardware_auto_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hardware_auto_configuration.cpp
new file mode 100644
index 0000000..d9167c8
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hardware_auto_configuration.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2022 LAAS-CNRS
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published by
+ *   the Free Software Foundation, either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGLPV2.1
+ */
+
+/**
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
+ *
+ * @brief  This file automatically performs some hardware configuration
+ *         using Zephyr macros.
+ *         Configuration done in this file is low-level peripheral configuration
+ *         required for OwnTech board to operate, do not mess with it unless you
+ *         are absolutely sure of what you're doing.
+ *         This file does not contain any public function.
+ */
+
+
+// Zephyr
+#include <zephyr.h>
+#include <device.h>
+
+// STM32 LL
+#include <stm32_ll_bus.h>
+#include <stm32_ll_system.h>
+
+// Owntech driver
+#include "dac.h"
+
+
+/////
+// Functions to be run
+
+static int _vrefbuf_init(const struct device* dev)
+{
+	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
+	LL_VREFBUF_SetVoltageScaling(LL_VREFBUF_VOLTAGE_SCALE0);
+	LL_VREFBUF_DisableHIZ();
+	LL_VREFBUF_Enable();
+
+	return 0;
+}
+
+static int _dac2_init(const struct device* dev)
+{
+	const struct device* dac2 = device_get_binding(DAC2_DEVICE);
+
+	dac_set_const_value(dac2, 1, 2048U);
+	dac_pin_configure(dac2, 1, dac_pin_external);
+	dac_start(dac2, 1);
+
+	return 0;
+}
+
+
+/////
+// Zephyr macros to automatically run above functions
+
+SYS_INIT(_vrefbuf_init,
+         PRE_KERNEL_1, // To be run in the first init phase
+         CONFIG_KERNEL_INIT_PRIORITY_DEVICE
+        );
+
+SYS_INIT(_dac2_init,
+         PRE_KERNEL_2, // To be run in the second init phase (depends on DAC driver initialization)
+         CONFIG_KERNEL_INIT_PRIORITY_DEVICE
+        );
diff --git a/zephyr/modules/owntech_vrefbuf_driver/zephyr/src/vrefbuf_driver.c b/zephyr/modules/owntech_hardware_configuration/zephyr/src/led_configuration.cpp
similarity index 52%
rename from zephyr/modules/owntech_vrefbuf_driver/zephyr/src/vrefbuf_driver.c
rename to zephyr/modules/owntech_hardware_configuration/zephyr/src/led_configuration.cpp
index c2064ae..cc637d8 100644
--- a/zephyr/modules/owntech_vrefbuf_driver/zephyr/src/vrefbuf_driver.c
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/led_configuration.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 LAAS-CNRS
+ * Copyright (c) 2022 LAAS-CNRS
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU Lesser General Public License as published by
@@ -18,36 +18,52 @@
  */
 
 /**
- * @author  Clément Foucher <clement.foucher@laas.fr>
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
  */
 
 
 // Zephyr
-#include <zephyr.h>
-#include <device.h>
+#include "zephyr.h"
+#include "drivers/gpio.h"
 
-// STM32 LL
-#include "stm32_ll_bus.h"
-#include "stm32_ll_system.h"
 
+static struct gpio_dt_spec led_pin_spec = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
+static bool init = false;
 
-static int vrefbuf_init(const struct device* dev)
+
+void led_config_init()
+{
+	gpio_pin_configure_dt(&led_pin_spec, GPIO_OUTPUT_ACTIVE);
+	init = true;
+}
+
+void led_config_on()
 {
-	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
-	LL_VREFBUF_SetVoltageScaling(LL_VREFBUF_VOLTAGE_SCALE0);
-	LL_VREFBUF_DisableHIZ();
-	LL_VREFBUF_Enable();
+	if (init == false)
+	{
+		led_config_init();
+	}
 
-	return 0;
+	gpio_pin_set_dt(&led_pin_spec, 1);
 }
 
-DEVICE_DEFINE(vrefbuf_driver,
-              "vrefbuf_driver",
-              vrefbuf_init,
-              NULL,
-              NULL,
-              NULL,
-              PRE_KERNEL_1,
-              CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
-              NULL
-             );
+void led_config_off()
+{
+	if (init == false)
+	{
+		led_config_init();
+	}
+
+	gpio_pin_set_dt(&led_pin_spec, 0);
+}
+
+void led_config_toggle()
+{
+	if (init == false)
+	{
+		led_config_init();
+	}
+
+	gpio_pin_toggle_dt(&led_pin_spec);
+}
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/led_configuration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/src/led_configuration.h
new file mode 100644
index 0000000..17e65a7
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/led_configuration.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2022 LAAS-CNRS
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published by
+ *   the Free Software Foundation, either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGLPV2.1
+ */
+
+/**
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
+ */
+
+
+#ifndef LED_CONFIGURATION_H_
+#define LED_CONFIGURATION_H_
+
+
+void led_config_on();
+void led_config_off();
+void led_config_toggle();
+
+
+#endif // LED_CONFIGURATION_H_
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.cpp
new file mode 100644
index 0000000..0d6efc6
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2022 LAAS-CNRS
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published by
+ *   the Free Software Foundation, either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGLPV2.1
+ */
+
+/**
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
+ */
+
+
+#include "ngnd.h"
+
+static const struct device* ngnd_switch = nullptr;
+
+
+void ngnd_config_on()
+{
+	if (ngnd_switch == NULL)
+	{
+		ngnd_switch = device_get_binding(NGND_DEVICE);
+	}
+
+	ngnd_set(ngnd_switch, 1);
+}
+
+void ngnd_config_off()
+{
+	if (ngnd_switch == NULL)
+	{
+		ngnd_switch = device_get_binding(NGND_DEVICE);
+	}
+
+	ngnd_set(ngnd_switch, 0);
+}
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.h
new file mode 100644
index 0000000..4fb2726
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2022 LAAS-CNRS
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published by
+ *   the Free Software Foundation, either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGLPV2.1
+ */
+
+/**
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
+ */
+
+
+#ifndef NGND_CONFIGURATION_H_
+#define NGND_CONFIGURATION_H_
+
+
+void ngnd_config_on();
+void ngnd_config_off();
+
+
+#endif // NGND_CONFIGURATION_H_
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.cpp
new file mode 100644
index 0000000..3fa04a6
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2022 LAAS-CNRS
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published by
+ *   the Free Software Foundation, either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGLPV2.1
+ */
+
+/**
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
+ */
+
+#include "timer.h"
+
+
+static const struct device* timer4 = NULL;
+
+static bool timer4init    = false;
+static bool timer4started = false;
+
+
+static void _timer_incremental_encoder_tim4_init()
+{
+	// Configure timer
+	timer4 = device_get_binding(TIMER4_DEVICE);
+	struct timer_config_t timer_cfg =
+	{
+		.timer_enable_irq = 0,
+		.timer_enable_encoder = 1,
+		.timer_enc_pin_mode = pull_up
+
+	};
+	timer_config(timer4, &timer_cfg);
+	timer4init = true;
+}
+
+void timer_incremental_encoder_tim4_start()
+{
+	if (timer4init == false)
+	{
+		_timer_incremental_encoder_tim4_init();
+	}
+
+	if (timer4started == false)
+	{
+		timer_start(timer4);
+		timer4started = true;
+	}
+}
+
+uint32_t timer_incremental_encoder_tim4_get_step()
+{
+	if (timer4started == true)
+	{
+		return timer_get_count(timer4);
+	}
+	else
+	{
+		return 0;
+	}
+}
diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.h
new file mode 100644
index 0000000..f29360d
--- /dev/null
+++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2022 LAAS-CNRS
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published by
+ *   the Free Software Foundation, either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGLPV2.1
+ */
+
+/**
+ * @date   2022
+ * @author Clément Foucher <clement.foucher@laas.fr>
+ */
+
+
+#ifndef TIMER_CONFIGURATION_H_
+#define TIMER_CONFIGURATION_H_
+
+
+#include <stdint.h>
+
+
+/**
+ * @brief Launches the timer4 which is adapted for reading an encoder.
+ */
+void timer_incremental_encoder_tim4_start();
+
+/**
+ * @brief Gets the encoder step value.
+ * @return An uint32 value of the counter which corresponds to the step of the system.
+ */
+uint32_t timer_incremental_encoder_tim4_get_step();
+
+
+#endif // TIMER_CONFIGURATION_H_
diff --git a/zephyr/modules/owntech_ngnd_driver/zephyr/src/owntech_ngnd_driver.c b/zephyr/modules/owntech_ngnd_driver/zephyr/src/owntech_ngnd_driver.c
index aef47a0..d8271af 100644
--- a/zephyr/modules/owntech_ngnd_driver/zephyr/src/owntech_ngnd_driver.c
+++ b/zephyr/modules/owntech_ngnd_driver/zephyr/src/owntech_ngnd_driver.c
@@ -44,7 +44,7 @@ static int ngnd_init(const struct device* dev)
 {
 	struct owntech_ngnd_driver_dev_data* data = dev->data;
 
-	const struct gpio_dt_spec ngnd_spec = GPIO_DT_SPEC_GET(DT_CHILD(NGND_NODE, ngnd_gpio_pin), ngnd_gpios);
+	const struct gpio_dt_spec ngnd_spec = GPIO_DT_SPEC_GET(DT_CHILD(NGND_NODE, ngnd_gpio_pin), gpios);
 	data->ngnd_pin_spec = ngnd_spec;
 
 	gpio_pin_configure_dt(&data->ngnd_pin_spec, GPIO_OUTPUT_ACTIVE);
diff --git a/zephyr/modules/owntech_vrefbuf_driver/zephyr/CMakeLists.txt b/zephyr/modules/owntech_vrefbuf_driver/zephyr/CMakeLists.txt
deleted file mode 100644
index 0fd815f..0000000
--- a/zephyr/modules/owntech_vrefbuf_driver/zephyr/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-if(CONFIG_OWNTECH_VREFBUF_DRIVER)
-  # Define the current folder as a Zephyr library
-  zephyr_library()
-  # Select source files to be compiled
-  zephyr_library_sources(
-    ./src/vrefbuf_driver.c
-    )
-endif()
diff --git a/zephyr/modules/owntech_vrefbuf_driver/zephyr/Kconfig b/zephyr/modules/owntech_vrefbuf_driver/zephyr/Kconfig
deleted file mode 100644
index a633c22..0000000
--- a/zephyr/modules/owntech_vrefbuf_driver/zephyr/Kconfig
+++ /dev/null
@@ -1,3 +0,0 @@
-config OWNTECH_VREFBUF_DRIVER
-	bool "Enable OwnTech VREFBUF driver for STM32"
-	default y
diff --git a/zephyr/prj.conf b/zephyr/prj.conf
index 0e06f53..0ae42f9 100644
--- a/zephyr/prj.conf
+++ b/zephyr/prj.conf
@@ -36,6 +36,6 @@ CONFIG_ASSERT=y
 #CONFIG_OWNTECH_HRTIM_DRIVER=n
 #CONFIG_OWNTECH_NGND_DRIVER=n
 #CONFIG_OWNTECH_DATA_ACQUISITION=n
-#CONFIG_OWNTECH_VREFBUF_DRIVER=n
 #CONFIG_OWNTECH_DAC_DRIVER=n
 #CONFIG_OWNTECH_COMPARATOR_DRIVER=n
+#OWNTECH_HARDWARE_CONFIGURATION=n
-- 
GitLab