add i2s.mute()
This commit is contained in:
parent
48b9518d76
commit
30ada6f084
|
@ -272,7 +272,9 @@ static int node_i2s_read( lua_State *L )
|
||||||
int wait_ms = luaL_optint(L, 3, 0);
|
int wait_ms = luaL_optint(L, 3, 0);
|
||||||
char * data = luaM_malloc( L, bytes );
|
char * data = luaM_malloc( L, bytes );
|
||||||
size_t read;
|
size_t read;
|
||||||
i2s_read(i2s_id, data, bytes, &read, wait_ms / portTICK_RATE_MS);
|
if (i2s_read(i2s_id, data, bytes, &read, wait_ms / portTICK_RATE_MS) != ESP_OK)
|
||||||
|
return luaL_error( L, "I2S driver error" );
|
||||||
|
|
||||||
lua_pushlstring(L, data, read);
|
lua_pushlstring(L, data, read);
|
||||||
luaM_free(L, data);
|
luaM_free(L, data);
|
||||||
|
|
||||||
|
@ -298,6 +300,21 @@ static int node_i2s_write( lua_State *L )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lua: mute( i2s_id )
|
||||||
|
static int node_i2s_mute( lua_State *L )
|
||||||
|
{
|
||||||
|
int stack = 0;
|
||||||
|
|
||||||
|
int i2s_id = luaL_checkinteger( L, ++stack );
|
||||||
|
I2S_CHECK_ID( i2s_id );
|
||||||
|
|
||||||
|
if (i2s_zero_dma_buffer( i2s_id ) != ESP_OK)
|
||||||
|
return luaL_error( L, "I2S driver error" );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Module function map
|
// Module function map
|
||||||
static const LUA_REG_TYPE i2s_map[] =
|
static const LUA_REG_TYPE i2s_map[] =
|
||||||
{
|
{
|
||||||
|
@ -305,6 +322,7 @@ static const LUA_REG_TYPE i2s_map[] =
|
||||||
{ LSTRKEY( "stop" ), LFUNCVAL( node_i2s_stop ) },
|
{ LSTRKEY( "stop" ), LFUNCVAL( node_i2s_stop ) },
|
||||||
{ LSTRKEY( "read" ), LFUNCVAL( node_i2s_read ) },
|
{ LSTRKEY( "read" ), LFUNCVAL( node_i2s_read ) },
|
||||||
{ LSTRKEY( "write" ), LFUNCVAL( node_i2s_write ) },
|
{ LSTRKEY( "write" ), LFUNCVAL( node_i2s_write ) },
|
||||||
|
{ LSTRKEY( "mute" ), LFUNCVAL( node_i2s_mute ) },
|
||||||
|
|
||||||
{ LSTRKEY( "FORMAT_I2S" ), LNUMVAL( I2S_COMM_FORMAT_I2S ) },
|
{ LSTRKEY( "FORMAT_I2S" ), LNUMVAL( I2S_COMM_FORMAT_I2S ) },
|
||||||
{ LSTRKEY( "FORMAT_I2S_MSB" ), LNUMVAL( I2S_COMM_FORMAT_I2S_MSB ) },
|
{ LSTRKEY( "FORMAT_I2S_MSB" ), LNUMVAL( I2S_COMM_FORMAT_I2S_MSB ) },
|
||||||
|
|
|
@ -11,6 +11,39 @@ The I2S module provides access to the in-built two I2S controllers.
|
||||||
!!! note "ADC mode configuration"
|
!!! note "ADC mode configuration"
|
||||||
Only ADC1 is available for ADC built-in mode.
|
Only ADC1 is available for ADC built-in mode.
|
||||||
|
|
||||||
|
|
||||||
|
## i2s.mute()
|
||||||
|
Mute the I2S channel. The hardware buffer is instantly filled with silence.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`i2s.mute(i2s_num)
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
- `i2s_num` I2S peripheral 0 or 1
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
`nil`
|
||||||
|
|
||||||
|
An error is thrown in case of invalid parameters or if the i2s driver failed.
|
||||||
|
|
||||||
|
|
||||||
|
## i2s.read()
|
||||||
|
Read data from I2S receive buffer.
|
||||||
|
|
||||||
|
#### Syntax
|
||||||
|
`i2s.read(i2s_num, size[, wait_ms])`
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
- `i2s_num` I2S peripheral 0 or 1
|
||||||
|
- `size` Bytes to read
|
||||||
|
- `wait_ms` Millisecond to wait if data is not ready. Optional, defaults to 0 (not to wait) when omitted.
|
||||||
|
|
||||||
|
#### Returns
|
||||||
|
Data read from data-in pin. If data is not ready in `wait_ms` millisecond, less than `size` bytes can be returned.
|
||||||
|
|
||||||
|
An error is thrown in case of invalid parameters or if the i2s driver failed.
|
||||||
|
|
||||||
|
|
||||||
## i2s.start()
|
## i2s.start()
|
||||||
Configuration and start I2S bus.
|
Configuration and start I2S bus.
|
||||||
|
|
||||||
|
@ -65,7 +98,7 @@ i2s.start(i2s_num, cfg, cb)
|
||||||
#### Returns
|
#### Returns
|
||||||
`nil`
|
`nil`
|
||||||
|
|
||||||
An error is thrown in case of invalid parameters or if the channel failed.
|
An error is thrown in case of invalid parameters or if the i2s driver failed.
|
||||||
|
|
||||||
|
|
||||||
## i2s.stop()
|
## i2s.stop()
|
||||||
|
@ -80,22 +113,7 @@ Stop I2S bus.
|
||||||
#### Returns
|
#### Returns
|
||||||
`nil`
|
`nil`
|
||||||
|
|
||||||
An error is thrown in case of invalid parameters or if the channel failed.
|
An error is thrown in case of invalid parameters or if the i2s driver failed.
|
||||||
|
|
||||||
|
|
||||||
## i2s.read()
|
|
||||||
Read data from I2S receive buffer.
|
|
||||||
|
|
||||||
#### Syntax
|
|
||||||
`i2s.read(i2s_num, size[, wait_ms])`
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `i2s_num` I2S peripheral 0 or 1
|
|
||||||
- `size` Bytes to read
|
|
||||||
- `wait_ms` Millisecond to wait if data is not ready. Optional, defaults to 0 (not to wait) when omitted.
|
|
||||||
|
|
||||||
#### Returns
|
|
||||||
Data read from data-in pin. If data is not ready in `wait_ms` millisecond, less than `size` bytes can be returned.
|
|
||||||
|
|
||||||
|
|
||||||
## i2s.write()
|
## i2s.write()
|
||||||
|
|
Loading…
Reference in New Issue