Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OwnTech
Power API
Core
Commits
b8a73032
Commit
b8a73032
authored
Mar 02, 2022
by
Clément Foucher
Browse files
Integrate hardware configuration as a module.
parent
f86ebf35
Changes
31
Hide whitespace changes
Inline
Side-by-side
zephyr/boards/arm/owntech_board/dts/bindings/
can-standby-switch
.yaml
→
zephyr/boards/arm/owntech_board/dts/bindings/
gpio-device
.yaml
View file @
b8a73032
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
:
...
...
zephyr/boards/arm/owntech_board/dts/bindings/ngnd-switch.yaml
deleted
100644 → 0
View file @
f86ebf35
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)
zephyr/boards/arm/owntech_board/dts/can-standby-switch.dtsi
View file @
b8a73032
...
...
@@ -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";
};
};
...
...
zephyr/boards/arm/owntech_board/dts/ngnd.dtsi
View file @
b8a73032
...
...
@@ -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";
};
};
...
...
zephyr/boards/arm/owntech_board/dts/pinctrl.dtsi
View file @
b8a73032
...
...
@@ -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)>;
};
...
...
zephyr/modules/owntech_dac_driver/zephyr/CMakeLists.txt
View file @
b8a73032
...
...
@@ -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
()
zephyr/modules/owntech_dac_driver/zephyr/Kconfig
View file @
b8a73032
config OWNTECH_DAC_DRIVER
bool "Enable OwnTech DAC driver"
default y
depends on !DAC
zephyr/modules/owntech_dac_driver/zephyr/public_include/dac.h
View file @
b8a73032
...
...
@@ -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
();
...
...
zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.c
View file @
b8a73032
...
...
@@ -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
)
...
...
zephyr/modules/owntech_dac_driver/zephyr/src/stm32_dac_driver.h
View file @
b8a73032
...
...
@@ -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
);
...
...
zephyr/modules/owntech_data_acquisition/zephyr/CMakeLists.txt
View file @
b8a73032
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
...
...
zephyr/modules/owntech_data_acquisition/zephyr/Kconfig
View file @
b8a73032
config OWNTECH_DATA_ACQUISITION
bool "Enable OwnTech data acquisition using ADCs"
default y
select DMA
depends on !ADC
zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp
View file @
b8a73032
...
...
@@ -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
::
set
Adc12DualMode
(
uint8_t
dual_mode
)
int8_t
DataAcquisition
::
configure
Adc12DualMode
(
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
,
trig
ger_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
()
{
...
...
zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h
View file @
b8a73032
...
...
@@ -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
D
ataAcquisition
::
start().
* This function must be called BEFORE
d
ataAcquisition
.
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
set
Adc12DualMode
(
uint8_t
dual_mode
);
static
int8_t
configure
Adc12DualMode
(
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
D
ataAcquisition
::
start().
* This function must be called BEFORE
d
ataAcquisition
.
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 c
onfigur
e the trigger source of an ADC.
*
*
This function must be called BEFORE DataAcquisition::start()
.
* This function is used to c
hang
e 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
.
*
* T
ODO: Use an enumeration instead of LL c
onsta
nts for source
.
* T
his function must be called BEFORE dataAcquisiti
on
.
sta
rt()
.
*
* @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
configureAdc
TriggerSource
(
uint8_t
adc_number
,
uint32_t
trigger_source
);
static
int8_t
configureAdc
DefaultAllMeasurements
(
);
/**
* This functions starts the acquisition chain. It must be called
...
...
zephyr/modules/owntech_
vrefbuf_driver
/zephyr/CMakeLists.txt
→
zephyr/modules/owntech_
hardware_configuration
/zephyr/CMakeLists.txt
View file @
b8a73032
if
(
CONFIG_OWNTECH_VREFBUF_DRIVER
)
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/vrefbuf_driver.c
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
()
zephyr/modules/owntech_hardware_configuration/zephyr/Kconfig
0 → 100644
View file @
b8a73032
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
zephyr/modules/owntech_
vrefbuf_driver
/zephyr/module.yml
→
zephyr/modules/owntech_
hardware_configuration
/zephyr/module.yml
View file @
b8a73032
name
:
owntech_
vrefbuf_driver
name
:
owntech_
hardware_configuration
build
:
cmake
:
zephyr
kconfig
:
zephyr/Kconfig
zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.cpp
0 → 100644
View file @
b8a73032
/*
* 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
();
}
zephyr/modules/owntech_hardware_configuration/zephyr/public_api/HardwareConfiguration.h
0 → 100644
View file @
b8a73032
/*
* 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