Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
5e64def6
Commit
5e64def6
authored
Oct 14, 2018
by
devsaurus
Browse files
add dac module
parent
d094944b
Changes
4
Show whitespace changes
Inline
Side-by-side
components/modules/Kconfig
View file @
5e64def6
...
...
@@ -74,6 +74,12 @@ config LUA_MODULE_CAN
help
Includes the can module.
config LUA_MODULE_DAC
bool "DAC module"
default "n"
help
Includes the dac module.
config LUA_MODULE_DHT
bool "DHT11/21/22/AM2301/AM2302 module"
default "n"
...
...
components/modules/dac.c
0 → 100644
View file @
5e64def6
// Module for interfacing with dac hardware
#include <string.h>
#include "module.h"
#include "lauxlib.h"
#include "driver/gpio.h"
#include "driver/dac.h"
#define GET_CHN(idx) \
int chn = luaL_checkint( L, idx ); \
luaL_argcheck( L, chn >= DAC_CHANNEL_1 && chn <= DAC_CHANNEL_MAX, idx, "invalid channel" );
// Lua: enable( dac_channel )
static
int
ldac_enable
(
lua_State
*
L
)
{
GET_CHN
(
1
);
if
(
dac_output_enable
(
chn
)
!=
ESP_OK
)
return
luaL_error
(
L
,
"dac failed"
);
return
0
;
}
// Lua: disable( dac_channel )
static
int
ldac_disable
(
lua_State
*
L
)
{
GET_CHN
(
1
);
if
(
dac_output_disable
(
chn
)
!=
ESP_OK
)
return
luaL_error
(
L
,
"dac failed"
);
return
0
;
}
// Lua: write( dac_channel )
static
int
ldac_write
(
lua_State
*
L
)
{
GET_CHN
(
1
);
int
data
=
luaL_checkint
(
L
,
2
);
luaL_argcheck
(
L
,
data
>=
0
&&
data
<=
255
,
2
,
"out of range"
);
if
(
dac_output_voltage
(
chn
,
data
)
!=
ESP_OK
)
return
luaL_error
(
L
,
"dac failed"
);
return
0
;
}
// Module function map
static
const
LUA_REG_TYPE
dac_map
[]
=
{
{
LSTRKEY
(
"enable"
),
LFUNCVAL
(
ldac_enable
)
},
{
LSTRKEY
(
"disable"
),
LFUNCVAL
(
ldac_disable
)
},
{
LSTRKEY
(
"write"
),
LFUNCVAL
(
ldac_write
)
},
{
LSTRKEY
(
"CHANNEL_1"
),
LNUMVAL
(
DAC_CHANNEL_1
)
},
{
LSTRKEY
(
"CHANNEL_2"
),
LNUMVAL
(
DAC_CHANNEL_2
)
},
{
LNILKEY
,
LNILVAL
}
};
NODEMCU_MODULE
(
DAC
,
"dac"
,
dac_map
,
NULL
);
docs/en/modules/dac.md
0 → 100644
View file @
5e64def6
# DAC Module
| Since | Origin / Contributor | Maintainer | Source |
| :----- | :-------------------- | :---------- | :------ |
| 2018-10-14 |
[
Arnim Läuger
](
https://github.com/devsaurus
)
|
[
Arnim Läuger
](
https://github.com/devsaurus
)
|
[
dac.c
](
../../../components/modules/dac.c
)
|
The DAC module provides access to the two built-in Digital to Analog Converters.
Each DAC is assigned to a dedicated GPIO:
-
DAC channel 1 is attached to GPIO25
-
DAC channel 2 is attached to GPIO26
The DACs are 8-bit, thus the output values are restricted to the range from 0 to 255.
## dac.disablee()
Disables DAC output on the related GPIO.
#### Syntax
```
lua
dac
.
disable
(
channel
)
```
#### Parameters
-
`channel`
DAC channel, one of
-
`dac.CHANNEL_1`
-
`dac.CHANNEL_2`
#### Returns
`nil`
An error is thrown in case of invalid parameters or if the dac failed.
## dac.enable()
Enables DAC output on the related GPIO.
#### Syntax
```
lua
dac
.
enable
(
channel
)
```
#### Parameters
-
`channel`
DAC channel, one of
-
`dac.CHANNEL_1`
-
`dac.CHANNEL_2`
#### Returns
`nil`
An error is thrown in case of invalid parameters or if the dac failed.
## dac.write()
Sets the output value of the DAC.
#### Syntax
```
lua
dac
.
write
(
channel
,
value
)
```
#### Parameters
-
`channel`
DAC channel, one of
-
`dac.CHANNEL_1`
-
`dac.CHANNEL_2`
-
`value`
output value
#### Returns
`nil`
An error is thrown in case of invalid parameters or if the dac failed.
mkdocs.yml
View file @
5e64def6
...
...
@@ -35,6 +35,7 @@ pages:
-
'
bit'
:
'
en/modules/bit.md'
-
'
bthci'
:
'
en/modules/bthci.md'
-
'
can'
:
'
en/modules/can.md'
-
'
dac'
:
'
en/modules/dac.md'
-
'
dht'
:
'
en/modules/dht.md'
-
'
encoder'
:
'
en/modules/encoder.md'
-
'
file'
:
'
en/modules/file.md'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment