Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions arch/arm/src/common/stm32/Kconfig.comp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

# COMP supported only for M3M4 for now

config STM32_COMP_INIT_DISABLED
bool "Do not enable the comparator at initialization"
default n
---help---
The comparator is kept disabled until ioctl() enable command.

if STM32_HAVE_IP_COMP_M3M4_V2

if STM32_COMP1
Expand Down
101 changes: 68 additions & 33 deletions arch/arm/src/common/stm32/stm32_comp_m3m4_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ static int comp_config(struct stm32_comp_s *priv)

comp_putreg_csr(priv, regval);

#ifndef CONFIG_STM32_COMP_INIT_DISABLED
/* Enable Comparator */

comp_enable(priv, true);
Expand All @@ -774,6 +775,7 @@ static int comp_config(struct stm32_comp_s *priv)
{
comp_lock_set(priv, true);
}
#endif

return OK;
}
Expand Down Expand Up @@ -918,8 +920,41 @@ static int comp_read(struct comp_dev_s *dev)
#ifdef CONFIG_COMP
static int comp_ioctl(struct comp_dev_s *dev, int cmd, unsigned long arg)
{
#warning "Missing logic"
return -ENOTTY;
FAR struct stm32_comp_s *priv = (FAR struct stm32_comp_s *)dev->ad_priv;
int ret = OK;

switch (cmd)
{
case ANIOC_COMP_ENABLE:
{
/* Enable comparator */

ret = comp_enable(priv, true);
if (ret == OK && priv->lock)
{
comp_lock_set(priv, true);
}

break;
}

case ANIOC_COMP_DISABLE:
{
/* Disable comparator */

ret = comp_enable(priv, false);
break;
}

default:
{
aerr("ERROR: Unknown cmd: %d\n", cmd);
ret = -ENOTTY;
break;
}
}

return ret;
}
#endif

Expand Down Expand Up @@ -954,57 +989,57 @@ struct comp_dev_s *stm32_compinitialize(int intf)
switch (intf)
{
#ifdef CONFIG_STM32_COMP1
case 1:
ainfo("COMP1 selected\n");
dev = &g_comp1dev;
break;
case 1:
ainfo("COMP1 selected\n");
dev = &g_comp1dev;
break;
#endif

#ifdef CONFIG_STM32_COMP2
case 2:
ainfo("COMP2 selected\n");
dev = &g_comp2dev;
break;
case 2:
ainfo("COMP2 selected\n");
dev = &g_comp2dev;
break;
#endif

#ifdef CONFIG_STM32_COMP3
case 3:
ainfo("COMP3 selected\n");
dev = &g_comp3dev;
break;
case 3:
ainfo("COMP3 selected\n");
dev = &g_comp3dev;
break;
#endif

#ifdef CONFIG_STM32_COMP4
case 4:
ainfo("COMP4 selected\n");
dev = &g_comp4dev;
break;
case 4:
ainfo("COMP4 selected\n");
dev = &g_comp4dev;
break;
#endif

#ifdef CONFIG_STM32_COMP5
case 5:
ainfo("COMP5 selected\n");
dev = &g_comp5dev;
break;
case 5:
ainfo("COMP5 selected\n");
dev = &g_comp5dev;
break;
#endif

#ifdef CONFIG_STM32_COMP6
case 6:
ainfo("COMP6 selected\n");
dev = &g_comp6dev;
break;
case 6:
ainfo("COMP6 selected\n");
dev = &g_comp6dev;
break;
#endif

#ifdef CONFIG_STM32_COMP7
case 7:
ainfo("COMP7 selected\n");
dev = &g_comp7dev;
break;
case 7:
ainfo("COMP7 selected\n");
dev = &g_comp7dev;
break;
#endif

default:
aerr("ERROR: No COMP interface defined\n");
return NULL;
default:
aerr("ERROR: No COMP interface defined\n");
return NULL;
}

/* Configure selected comparator */
Expand Down
2 changes: 2 additions & 0 deletions boards/arm/stm32g4/nucleo-g431kb/configs/comp/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ CONFIG_BUILTIN=y
CONFIG_COMP=y
CONFIG_DAC=y
CONFIG_DEFAULT_SMALL=y
CONFIG_EXAMPLES_COMP=y
CONFIG_EXAMPLES_DAC=y
CONFIG_EXAMPLES_DAC_DEVPATH="/dev/dac5"
CONFIG_FILE_STREAM=y
Expand All @@ -37,6 +38,7 @@ CONFIG_STM32_COMP2=y
CONFIG_STM32_COMP2_HYST=3
CONFIG_STM32_COMP2_INM=4
CONFIG_STM32_COMP2_OUT=y
CONFIG_STM32_COMP_INIT_DISABLED=y
CONFIG_STM32_DAC3=y
CONFIG_STM32_DAC3CH2=y
CONFIG_STM32_DAC3CH2_MODE=3
Expand Down
11 changes: 10 additions & 1 deletion include/nuttx/analog/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@
* IN: None
* OUT: struct dac_info_s * */

/* COMP */

#define ANIOC_COMP_ENABLE _ANIOC(0x000d) /* Enable comparator
* IN: None
* OUT: None */
#define ANIOC_COMP_DISABLE _ANIOC(0x000e) /* Disable comparator
* IN: None
* OUT: None */

#define AN_FIRST 0x0001 /* First common command */
#define AN_NCMDS 12 /* Number of common commands */
#define AN_NCMDS 14 /* Number of common commands */

/* User defined ioctl commands are also supported. These will be forwarded
* by the upper-half driver to the lower-half driver via the ioctl()
Expand Down
Loading