diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp index 19ef299d3bd46203ba3ba947fc87eb75cd7c7e9e..e3984c0fa15752945adb0c92926dca9757b943a8 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp @@ -94,6 +94,15 @@ void HardwareConfiguration::initDac1Dac3CurrentMode() dac_config_dac1_dac3_current_mode_init(); } +void HardwareConfiguration::initDacConstValue(uint8_t dac_number) +{ + dac_config_const_value_init(dac_number); +} + +void HardwareConfiguration::setDacConstValue(uint8_t dac_number, uint8_t channel, uint32_t const_value) +{ + dac_set_const_value(dac_number, channel, const_value); +} ///// // NGND diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h index 6272e61ba4ff3cc70911f4532893fdf45ebc21be..283edf63a45483d0fb6e367820b4c8a9dd483016 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h @@ -82,6 +82,8 @@ public: // DAC static void initDac1Dac3CurrentMode(); + static void initDacConstValue(uint8_t dac_number); + static void setDacConstValue(uint8_t dac_number, uint8_t channel, uint32_t const_value); // NGND static void setNgndOn(); diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp index b213ff5134496d9a823deb9027ada158d859e93a..0ae089b89625ccc9000dffe73ccffcb23f80b7b6 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp @@ -21,6 +21,7 @@ * @date 2022 * * @author Clément Foucher <clement.foucher@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> */ @@ -32,6 +33,7 @@ static const struct device* dac1 = DEVICE_DT_GET(DAC1_DEVICE); +static const struct device* dac2 = DEVICE_DT_GET(DAC2_DEVICE); static const struct device* dac3 = DEVICE_DT_GET(DAC3_DEVICE); @@ -63,3 +65,51 @@ void dac_config_dac1_dac3_current_mode_init() dac_start(dac3, 1); } } + +void dac_config_const_value_init(uint8_t dac_number) +{ + const struct device* dac_dev; + + if (dac_number == 1) + { + dac_dev = dac1; + } + else if (dac_number == 3) + { + dac_dev = dac3; + } + else + { + dac_dev = dac2; //sets the dac 2 as default + } + + if (device_is_ready(dac_dev) == true) + { + dac_set_const_value(dac_dev,1,0); + dac_pin_configure(dac_dev, 1, dac_pin_external); + dac_start(dac_dev, 1); + } +} + +void dac_set_const_value(uint8_t dac_number, uint8_t channel, uint32_t const_value) +{ + const struct device* dac_dev; + + if (dac_number == 1) + { + dac_dev = dac1; + } + else if (dac_number == 3) + { + dac_dev = dac3; + } + else + { + dac_dev = dac2; //sets the dac 2 as default + } + + if (device_is_ready(dac_dev) == true) + { + dac_set_const_value(dac_dev,channel,const_value); + } +} diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.h b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.h index fcd827ec0f47c56a868dec40c01c0cc2fb441270..fff576e0f7ea1358bf184a56cbab8e56752a906e 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.h +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.h @@ -20,14 +20,20 @@ /** * @date 2022 * @author Clément Foucher <clement.foucher@laas.fr> + * @author Luiz Villa <luiz.villa@laas.fr> */ #ifndef DAC_CONFIGURATION_H_ #define DAC_CONFIGURATION_H_ +// Stdlib +#include <stdint.h> + void dac_config_dac1_dac3_current_mode_init(); +void dac_config_const_value_init(uint8_t dac_number); +void dac_set_const_value(uint8_t dac_number, uint8_t channel, uint32_t const_value); #endif // DAC_CONFIGURATION_H_