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
310faf7f
Unverified
Commit
310faf7f
authored
Sep 07, 2019
by
Terry Ellison
Committed by
GitHub
Sep 07, 2019
Browse files
Merge pull request #2886 from nodemcu/dev
Next master drop
parents
68c425c0
a08e74d9
Changes
368
Hide whitespace changes
Inline
Side-by-side
app/modules/ws2801.c
View file @
310faf7f
#include "module.h"
#include "module.h"
#include "lauxlib.h"
#include "lauxlib.h"
#include "platform.h"
#include "platform.h"
#include "c_stdlib.h"
#include <stdlib.h>
#include "c_string.h"
#include <string.h>
#include "osapi.h"
/**
/**
* Code is based on https://github.com/CHERTS/esp8266-devkit/blob/master/Espressif/examples/EspLightNode/user/ws2801.c
* Code is based on https://github.com/CHERTS/esp8266-devkit/blob/master/Espressif/examples/EspLightNode/user/ws2801.c
...
@@ -122,11 +123,10 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) {
...
@@ -122,11 +123,10 @@ static int ICACHE_FLASH_ATTR ws2801_writergb(lua_State* L) {
return
0
;
return
0
;
}
}
static
const
LUA_REG_TYPE
ws2801_map
[]
=
LROT_BEGIN
(
ws2801
)
{
LROT_FUNCENTRY
(
write
,
ws2801_writergb
)
{
LSTRKEY
(
"write"
),
LFUNCVAL
(
ws2801_writergb
)},
LROT_FUNCENTRY
(
init
,
ws2801_init_lua
)
{
LSTRKEY
(
"init"
),
LFUNCVAL
(
ws2801_init_lua
)},
LROT_END
(
ws2801
,
NULL
,
0
)
{
LNILKEY
,
LNILVAL
}
};
NODEMCU_MODULE
(
WS2801
,
"ws2801"
,
ws2801_map
,
NULL
);
NODEMCU_MODULE
(
WS2801
,
"ws2801"
,
ws2801
,
NULL
);
app/modules/ws2812.c
View file @
310faf7f
...
@@ -2,9 +2,9 @@
...
@@ -2,9 +2,9 @@
#include "lauxlib.h"
#include "lauxlib.h"
#include "lmem.h"
#include "lmem.h"
#include "platform.h"
#include "platform.h"
#include
"c_
stdlib.h
"
#include
<
stdlib.h
>
#include
"c_
math.h
"
#include
<
math.h
>
#include
"c_
string.h
"
#include
<
string.h
>
#include "user_interface.h"
#include "user_interface.h"
#include "driver/uart.h"
#include "driver/uart.h"
#include "osapi.h"
#include "osapi.h"
...
@@ -201,7 +201,7 @@ static int ws2812_new_buffer(lua_State *L) {
...
@@ -201,7 +201,7 @@ static int ws2812_new_buffer(lua_State *L) {
ws2812_buffer
*
buffer
=
allocate_buffer
(
L
,
leds
,
colorsPerLed
);
ws2812_buffer
*
buffer
=
allocate_buffer
(
L
,
leds
,
colorsPerLed
);
c_
memset
(
buffer
->
values
,
0
,
colorsPerLed
*
leds
);
memset
(
buffer
->
values
,
0
,
colorsPerLed
*
leds
);
return
1
;
return
1
;
}
}
...
@@ -295,7 +295,7 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t
...
@@ -295,7 +295,7 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t
return
0
;
return
0
;
}
}
uint8_t
*
tmp_pixels
=
c_
malloc
(
buffer
->
colorsPerLed
*
sizeof
(
uint8_t
)
*
shift
);
uint8_t
*
tmp_pixels
=
malloc
(
buffer
->
colorsPerLed
*
sizeof
(
uint8_t
)
*
shift
);
int
i
,
j
;
int
i
,
j
;
size_t
shift_len
,
remaining_len
;
size_t
shift_len
,
remaining_len
;
// calculate length of shift section and remaining section
// calculate length of shift section and remaining section
...
@@ -305,37 +305,37 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t
...
@@ -305,37 +305,37 @@ int ws2812_buffer_shift(ws2812_buffer * buffer, int shiftValue, unsigned shift_t
if
(
shiftValue
>
0
)
if
(
shiftValue
>
0
)
{
{
// Store the values which are moved out of the array (last n pixels)
// Store the values which are moved out of the array (last n pixels)
c_
memcpy
(
tmp_pixels
,
&
buffer
->
values
[
offset
+
(
size
-
shift
)
*
buffer
->
colorsPerLed
],
shift_len
);
memcpy
(
tmp_pixels
,
&
buffer
->
values
[
offset
+
(
size
-
shift
)
*
buffer
->
colorsPerLed
],
shift_len
);
// Move pixels to end
// Move pixels to end
os_memmove
(
&
buffer
->
values
[
offset
+
shift
*
buffer
->
colorsPerLed
],
&
buffer
->
values
[
offset
],
remaining_len
);
os_memmove
(
&
buffer
->
values
[
offset
+
shift
*
buffer
->
colorsPerLed
],
&
buffer
->
values
[
offset
],
remaining_len
);
// Fill beginning with temp data
// Fill beginning with temp data
if
(
shift_type
==
SHIFT_LOGICAL
)
if
(
shift_type
==
SHIFT_LOGICAL
)
{
{
c_
memset
(
&
buffer
->
values
[
offset
],
0
,
shift_len
);
memset
(
&
buffer
->
values
[
offset
],
0
,
shift_len
);
}
}
else
else
{
{
c_
memcpy
(
&
buffer
->
values
[
offset
],
tmp_pixels
,
shift_len
);
memcpy
(
&
buffer
->
values
[
offset
],
tmp_pixels
,
shift_len
);
}
}
}
}
else
else
{
{
// Store the values which are moved out of the array (last n pixels)
// Store the values which are moved out of the array (last n pixels)
c_
memcpy
(
tmp_pixels
,
&
buffer
->
values
[
offset
],
shift_len
);
memcpy
(
tmp_pixels
,
&
buffer
->
values
[
offset
],
shift_len
);
// Move pixels to end
// Move pixels to end
os_memmove
(
&
buffer
->
values
[
offset
],
&
buffer
->
values
[
offset
+
shift
*
buffer
->
colorsPerLed
],
remaining_len
);
os_memmove
(
&
buffer
->
values
[
offset
],
&
buffer
->
values
[
offset
+
shift
*
buffer
->
colorsPerLed
],
remaining_len
);
// Fill beginning with temp data
// Fill beginning with temp data
if
(
shift_type
==
SHIFT_LOGICAL
)
if
(
shift_type
==
SHIFT_LOGICAL
)
{
{
c_
memset
(
&
buffer
->
values
[
offset
+
(
size
-
shift
)
*
buffer
->
colorsPerLed
],
0
,
shift_len
);
memset
(
&
buffer
->
values
[
offset
+
(
size
-
shift
)
*
buffer
->
colorsPerLed
],
0
,
shift_len
);
}
}
else
else
{
{
c_
memcpy
(
&
buffer
->
values
[
offset
+
(
size
-
shift
)
*
buffer
->
colorsPerLed
],
tmp_pixels
,
shift_len
);
memcpy
(
&
buffer
->
values
[
offset
+
(
size
-
shift
)
*
buffer
->
colorsPerLed
],
tmp_pixels
,
shift_len
);
}
}
}
}
// Free memory
// Free memory
c_
free
(
tmp_pixels
);
free
(
tmp_pixels
);
return
0
;
return
0
;
}
}
...
@@ -386,7 +386,7 @@ static int ws2812_buffer_replace(lua_State* L) {
...
@@ -386,7 +386,7 @@ static int ws2812_buffer_replace(lua_State* L) {
luaL_argcheck
(
L
,
srcLen
+
start
-
1
<=
buffer
->
size
,
2
,
"Does not fit into destination"
);
luaL_argcheck
(
L
,
srcLen
+
start
-
1
<=
buffer
->
size
,
2
,
"Does not fit into destination"
);
c_
memcpy
(
buffer
->
values
+
(
start
-
1
)
*
buffer
->
colorsPerLed
,
src
,
srcLen
*
buffer
->
colorsPerLed
);
memcpy
(
buffer
->
values
+
(
start
-
1
)
*
buffer
->
colorsPerLed
,
src
,
srcLen
*
buffer
->
colorsPerLed
);
return
0
;
return
0
;
}
}
...
@@ -425,6 +425,7 @@ static int ws2812_buffer_mix(lua_State* L) {
...
@@ -425,6 +425,7 @@ static int ws2812_buffer_mix(lua_State* L) {
val
+=
(
int32_t
)(
source
[
src
].
values
[
i
]
*
source
[
src
].
factor
);
val
+=
(
int32_t
)(
source
[
src
].
values
[
i
]
*
source
[
src
].
factor
);
}
}
val
+=
128
;
// rounding istead of floor
val
>>=
8
;
val
>>=
8
;
if
(
val
<
0
)
{
if
(
val
<
0
)
{
...
@@ -503,7 +504,7 @@ static int ws2812_buffer_set(lua_State* L) {
...
@@ -503,7 +504,7 @@ static int ws2812_buffer_set(lua_State* L) {
return
luaL_error
(
L
,
"string size will exceed strip length"
);
return
luaL_error
(
L
,
"string size will exceed strip length"
);
}
}
c_
memcpy
(
&
buffer
->
values
[
buffer
->
colorsPerLed
*
led
],
buf
,
len
);
memcpy
(
&
buffer
->
values
[
buffer
->
colorsPerLed
*
led
],
buf
,
len
);
}
}
else
else
{
{
...
@@ -534,7 +535,7 @@ static int ws2812_buffer_sub(lua_State* L) {
...
@@ -534,7 +535,7 @@ static int ws2812_buffer_sub(lua_State* L) {
if
(
end
>
(
ptrdiff_t
)
l
)
end
=
(
ptrdiff_t
)
l
;
if
(
end
>
(
ptrdiff_t
)
l
)
end
=
(
ptrdiff_t
)
l
;
if
(
start
<=
end
)
{
if
(
start
<=
end
)
{
ws2812_buffer
*
result
=
allocate_buffer
(
L
,
end
-
start
+
1
,
lhs
->
colorsPerLed
);
ws2812_buffer
*
result
=
allocate_buffer
(
L
,
end
-
start
+
1
,
lhs
->
colorsPerLed
);
c_
memcpy
(
result
->
values
,
lhs
->
values
+
lhs
->
colorsPerLed
*
(
start
-
1
),
lhs
->
colorsPerLed
*
(
end
-
start
+
1
));
memcpy
(
result
->
values
,
lhs
->
values
+
lhs
->
colorsPerLed
*
(
start
-
1
),
lhs
->
colorsPerLed
*
(
end
-
start
+
1
));
}
else
{
}
else
{
ws2812_buffer
*
result
=
allocate_buffer
(
L
,
0
,
lhs
->
colorsPerLed
);
ws2812_buffer
*
result
=
allocate_buffer
(
L
,
0
,
lhs
->
colorsPerLed
);
}
}
...
@@ -552,8 +553,8 @@ static int ws2812_buffer_concat(lua_State* L) {
...
@@ -552,8 +553,8 @@ static int ws2812_buffer_concat(lua_State* L) {
ws2812_buffer
*
buffer
=
allocate_buffer
(
L
,
leds
,
colorsPerLed
);
ws2812_buffer
*
buffer
=
allocate_buffer
(
L
,
leds
,
colorsPerLed
);
c_
memcpy
(
buffer
->
values
,
lhs
->
values
,
lhs
->
colorsPerLed
*
lhs
->
size
);
memcpy
(
buffer
->
values
,
lhs
->
values
,
lhs
->
colorsPerLed
*
lhs
->
size
);
c_
memcpy
(
buffer
->
values
+
lhs
->
colorsPerLed
*
lhs
->
size
,
rhs
->
values
,
rhs
->
colorsPerLed
*
rhs
->
size
);
memcpy
(
buffer
->
values
+
lhs
->
colorsPerLed
*
lhs
->
size
,
rhs
->
values
,
rhs
->
colorsPerLed
*
rhs
->
size
);
return
1
;
return
1
;
}
}
...
@@ -578,7 +579,7 @@ static int ws2812_buffer_tostring(lua_State* L) {
...
@@ -578,7 +579,7 @@ static int ws2812_buffer_tostring(lua_State* L) {
luaL_addchar
(
&
result
,
','
);
luaL_addchar
(
&
result
,
','
);
}
}
char
numbuf
[
5
];
char
numbuf
[
5
];
c_
sprintf
(
numbuf
,
"%d"
,
buffer
->
values
[
p
]);
sprintf
(
numbuf
,
"%d"
,
buffer
->
values
[
p
]);
luaL_addstring
(
&
result
,
numbuf
);
luaL_addstring
(
&
result
,
numbuf
);
}
}
luaL_addchar
(
&
result
,
')'
);
luaL_addchar
(
&
result
,
')'
);
...
@@ -591,44 +592,42 @@ static int ws2812_buffer_tostring(lua_State* L) {
...
@@ -591,44 +592,42 @@ static int ws2812_buffer_tostring(lua_State* L) {
}
}
static
const
LUA_REG_TYPE
ws2812_buffer_map
[]
=
LROT_BEGIN
(
ws2812_buffer
)
{
LROT_FUNCENTRY
(
dump
,
ws2812_buffer_dump
)
{
LSTRKEY
(
"dump"
),
LFUNCVAL
(
ws2812_buffer_dump
)},
LROT_FUNCENTRY
(
fade
,
ws2812_buffer_fade
)
{
LSTRKEY
(
"fade"
),
LFUNCVAL
(
ws2812_buffer_fade
)},
LROT_FUNCENTRY
(
fill
,
ws2812_buffer_fill_lua
)
{
LSTRKEY
(
"fill"
),
LFUNCVAL
(
ws2812_buffer_fill_lua
)},
LROT_FUNCENTRY
(
get
,
ws2812_buffer_get
)
{
LSTRKEY
(
"get"
),
LFUNCVAL
(
ws2812_buffer_get
)},
LROT_FUNCENTRY
(
replace
,
ws2812_buffer_replace
)
{
LSTRKEY
(
"replace"
),
LFUNCVAL
(
ws2812_buffer_replace
)},
LROT_FUNCENTRY
(
mix
,
ws2812_buffer_mix
)
{
LSTRKEY
(
"mix"
),
LFUNCVAL
(
ws2812_buffer_mix
)},
LROT_FUNCENTRY
(
power
,
ws2812_buffer_power
)
{
LSTRKEY
(
"power"
),
LFUNCVAL
(
ws2812_buffer_power
)},
LROT_FUNCENTRY
(
set
,
ws2812_buffer_set
)
{
LSTRKEY
(
"set"
),
LFUNCVAL
(
ws2812_buffer_set
)},
LROT_FUNCENTRY
(
shift
,
ws2812_buffer_shift_lua
)
{
LSTRKEY
(
"shift"
),
LFUNCVAL
(
ws2812_buffer_shift_lua
)},
LROT_FUNCENTRY
(
size
,
ws2812_buffer_size
)
{
LSTRKEY
(
"size"
),
LFUNCVAL
(
ws2812_buffer_size
)},
LROT_FUNCENTRY
(
sub
,
ws2812_buffer_sub
)
{
LSTRKEY
(
"sub"
),
LFUNCVAL
(
ws2812_buffer_sub
)},
LROT_FUNCENTRY
(
__concat
,
ws2812_buffer_concat
)
{
LSTRKEY
(
"__concat"
),
LFUNCVAL
(
ws2812_buffer_concat
)},
LROT_TABENTRY
(
__index
,
ws2812_buffer
)
{
LSTRKEY
(
"__index"
),
LROVAL
(
ws2812_buffer_map
)},
LROT_FUNCENTRY
(
__tostring
,
ws2812_buffer_tostring
)
{
LSTRKEY
(
"__tostring"
),
LFUNCVAL
(
ws2812_buffer_tostring
)},
LROT_END
(
ws2812_buffer
,
ws2812_buffer
,
LROT_MASK_INDEX
)
{
LNILKEY
,
LNILVAL
}
};
LROT_BEGIN
(
ws2812
)
static
const
LUA_REG_TYPE
ws2812_map
[]
=
LROT_FUNCENTRY
(
init
,
ws2812_init
)
{
LROT_FUNCENTRY
(
newBuffer
,
ws2812_new_buffer
)
{
LSTRKEY
(
"init"
),
LFUNCVAL
(
ws2812_init
)},
LROT_FUNCENTRY
(
write
,
ws2812_write
)
{
LSTRKEY
(
"newBuffer"
),
LFUNCVAL
(
ws2812_new_buffer
)},
LROT_NUMENTRY
(
FADE_IN
,
FADE_IN
)
{
LSTRKEY
(
"write"
),
LFUNCVAL
(
ws2812_write
)},
LROT_NUMENTRY
(
FADE_OUT
,
FADE_OUT
)
{
LSTRKEY
(
"FADE_IN"
),
LNUMVAL
(
FADE_IN
)
},
LROT_NUMENTRY
(
MODE_SINGLE
,
MODE_SINGLE
)
{
LSTRKEY
(
"FADE_OUT"
),
LNUMVAL
(
FADE_OUT
)
},
LROT_NUMENTRY
(
MODE_DUAL
,
MODE_DUAL
)
{
LSTRKEY
(
"MODE_SINGLE"
),
LNUMVAL
(
MODE_SINGLE
)
},
LROT_NUMENTRY
(
SHIFT_LOGICAL
,
SHIFT_LOGICAL
)
{
LSTRKEY
(
"MODE_DUAL"
),
LNUMVAL
(
MODE_DUAL
)
},
LROT_NUMENTRY
(
SHIFT_CIRCULAR
,
SHIFT_CIRCULAR
)
{
LSTRKEY
(
"SHIFT_LOGICAL"
),
LNUMVAL
(
SHIFT_LOGICAL
)
},
LROT_END
(
ws2812
,
NULL
,
0
)
{
LSTRKEY
(
"SHIFT_CIRCULAR"
),
LNUMVAL
(
SHIFT_CIRCULAR
)
},
{
LNILKEY
,
LNILVAL
}
};
int
luaopen_ws2812
(
lua_State
*
L
)
{
int
luaopen_ws2812
(
lua_State
*
L
)
{
// TODO: Make sure that the GPIO system is initialized
// TODO: Make sure that the GPIO system is initialized
luaL_rometatable
(
L
,
"ws2812.buffer"
,
(
void
*
)
ws2812_buffer_map
);
// create metatable for ws2812.buffer
luaL_rometatable
(
L
,
"ws2812.buffer"
,
LROT_TABLEREF
(
ws2812_buffer
));
return
0
;
return
0
;
}
}
NODEMCU_MODULE
(
WS2812
,
"ws2812"
,
ws2812
_map
,
luaopen_ws2812
);
NODEMCU_MODULE
(
WS2812
,
"ws2812"
,
ws2812
,
luaopen_ws2812
);
app/modules/ws2812.h
View file @
310faf7f
...
@@ -5,9 +5,9 @@
...
@@ -5,9 +5,9 @@
#include "lauxlib.h"
#include "lauxlib.h"
#include "lmem.h"
#include "lmem.h"
#include "platform.h"
#include "platform.h"
#include
"c_
stdlib.h
"
#include
<
stdlib.h
>
#include
"c_
math.h
"
#include
<
math.h
>
#include
"c_
string.h
"
#include
<
string.h
>
#include "user_interface.h"
#include "user_interface.h"
#include "driver/uart.h"
#include "driver/uart.h"
#include "osapi.h"
#include "osapi.h"
...
...
app/modules/ws2812_effects.c
View file @
310faf7f
...
@@ -2,9 +2,9 @@
...
@@ -2,9 +2,9 @@
#include "lauxlib.h"
#include "lauxlib.h"
#include "lmem.h"
#include "lmem.h"
#include "platform.h"
#include "platform.h"
#include
"c_
stdlib.h
"
#include
<
stdlib.h
>
#include
"c_
math.h
"
#include
<
math.h
>
#include
"c_
string.h
"
#include
<
string.h
>
#include "user_interface.h"
#include "user_interface.h"
#include "driver/uart.h"
#include "driver/uart.h"
#include "osapi.h"
#include "osapi.h"
...
@@ -18,8 +18,6 @@
...
@@ -18,8 +18,6 @@
#define DEFAULT_MODE 0
#define DEFAULT_MODE 0
#define DEFAULT_COLOR 0xFF0000
#define DEFAULT_COLOR 0xFF0000
#define UINT32_MAX 4294967295U
#define SPEED_MIN 0
#define SPEED_MIN 0
#define SPEED_MAX 255
#define SPEED_MAX 255
#define SPEED_DEFAULT 150
#define SPEED_DEFAULT 150
...
@@ -161,11 +159,11 @@ static int ws2812_effects_init(lua_State *L) {
...
@@ -161,11 +159,11 @@ static int ws2812_effects_init(lua_State *L) {
// get rid of old state
// get rid of old state
if
(
state
!=
NULL
)
{
if
(
state
!=
NULL
)
{
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
state
->
buffer_ref
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
state
->
buffer_ref
);
os_
free
((
void
*
)
state
);
free
((
void
*
)
state
);
}
}
// Allocate memory and set all to zero
// Allocate memory and set all to zero
size_t
size
=
sizeof
(
ws2812_effects
)
+
buffer
->
colorsPerLed
*
sizeof
(
uint8_t
);
size_t
size
=
sizeof
(
ws2812_effects
)
+
buffer
->
colorsPerLed
*
sizeof
(
uint8_t
);
state
=
(
ws2812_effects
*
)
os_z
alloc
(
size
);
state
=
(
ws2812_effects
*
)
c
alloc
(
1
,
size
);
// initialize
// initialize
state
->
speed
=
SPEED_DEFAULT
;
state
->
speed
=
SPEED_DEFAULT
;
state
->
mode_delay
=
DELAY_DEFAULT
;
state
->
mode_delay
=
DELAY_DEFAULT
;
...
@@ -307,7 +305,7 @@ static int ws2812_effects_mode_blink() {
...
@@ -307,7 +305,7 @@ static int ws2812_effects_mode_blink() {
else
{
else
{
// off
// off
ws2812_buffer
*
buffer
=
state
->
buffer
;
ws2812_buffer
*
buffer
=
state
->
buffer
;
c_
memset
(
&
buffer
->
values
[
0
],
0
,
buffer
->
size
*
buffer
->
colorsPerLed
);
memset
(
&
buffer
->
values
[
0
],
0
,
buffer
->
size
*
buffer
->
colorsPerLed
);
}
}
return
0
;
return
0
;
}
}
...
@@ -1038,23 +1036,22 @@ static int ws2812_effects_tostring(lua_State* L) {
...
@@ -1038,23 +1036,22 @@ static int ws2812_effects_tostring(lua_State* L) {
return
1
;
return
1
;
}
}
static
const
LUA_REG_TYPE
ws2812_effects_map
[]
=
LROT_BEGIN
(
ws2812_effects
)
{
LROT_FUNCENTRY
(
init
,
ws2812_effects_init
)
{
LSTRKEY
(
"init"
),
LFUNCVAL
(
ws2812_effects_init
)},
LROT_FUNCENTRY
(
set_brightness
,
ws2812_effects_set_brightness
)
{
LSTRKEY
(
"set_brightness"
),
LFUNCVAL
(
ws2812_effects_set_brightness
)},
LROT_FUNCENTRY
(
set_color
,
ws2812_effects_set_color
)
{
LSTRKEY
(
"set_color"
),
LFUNCVAL
(
ws2812_effects_set_color
)},
LROT_FUNCENTRY
(
set_speed
,
ws2812_effects_set_speed
)
{
LSTRKEY
(
"set_speed"
),
LFUNCVAL
(
ws2812_effects_set_speed
)},
LROT_FUNCENTRY
(
set_delay
,
ws2812_effects_set_delay
)
{
LSTRKEY
(
"set_delay"
),
LFUNCVAL
(
ws2812_effects_set_delay
)},
LROT_FUNCENTRY
(
set_mode
,
ws2812_effects_set_mode
)
{
LSTRKEY
(
"set_mode"
),
LFUNCVAL
(
ws2812_effects_set_mode
)},
LROT_FUNCENTRY
(
start
,
ws2812_effects_start
)
{
LSTRKEY
(
"start"
),
LFUNCVAL
(
ws2812_effects_start
)},
LROT_FUNCENTRY
(
stop
,
ws2812_effects_stop
)
{
LSTRKEY
(
"stop"
),
LFUNCVAL
(
ws2812_effects_stop
)},
LROT_FUNCENTRY
(
get_delay
,
ws2812_effects_get_delay
)
{
LSTRKEY
(
"get_delay"
),
LFUNCVAL
(
ws2812_effects_get_delay
)},
LROT_FUNCENTRY
(
get_speed
,
ws2812_effects_get_speed
)
{
LSTRKEY
(
"get_speed"
),
LFUNCVAL
(
ws2812_effects_get_speed
)},
LROT_TABENTRY
(
__index
,
ws2812_effects
)
{
LSTRKEY
(
"__index"
),
LROVAL
(
ws2812_effects_map
)},
LROT_FUNCENTRY
(
__tostring
,
ws2812_effects_tostring
)
{
LSTRKEY
(
"__tostring"
),
LFUNCVAL
(
ws2812_effects_tostring
)},
LROT_END
(
ws2812_effects
,
ws2812_effects
,
LROT_MASK_INDEX
)
{
LNILKEY
,
LNILVAL
}
};
NODEMCU_MODULE
(
WS2812_EFFECTS
,
"ws2812_effects"
,
ws2812_effects
_map
,
NULL
);
NODEMCU_MODULE
(
WS2812_EFFECTS
,
"ws2812_effects"
,
ws2812_effects
,
NULL
);
app/modules/xpt2046.c
View file @
310faf7f
...
@@ -203,15 +203,15 @@ static int xpt2046_getPositionAvg( lua_State* L ) {
...
@@ -203,15 +203,15 @@ static int xpt2046_getPositionAvg( lua_State* L ) {
}
}
// Module function map
// Module function map
static
const
LUA_REG_TYPE
xpt2046_map
[]
=
{
LROT_BEGIN
(
xpt2046
)
{
LSTRKE
Y
(
"
isTouched
"
),
LFUNCVAL
(
xpt2046_isTouched
)
},
LROT_FUNCENTR
Y
(
isTouched
,
xpt2046_isTouched
)
{
LSTRKE
Y
(
"
getRaw
"
),
LFUNCVAL
(
xpt2046_getRaw
)
},
LROT_FUNCENTR
Y
(
getRaw
,
xpt2046_getRaw
)
{
LSTRKE
Y
(
"
getPosition
"
),
LFUNCVAL
(
xpt2046_getPosition
)
},
LROT_FUNCENTR
Y
(
getPosition
,
xpt2046_getPosition
)
{
LSTRKE
Y
(
"
getPositionAvg
"
),
LFUNCVAL
(
xpt2046_getPositionAvg
)
},
LROT_FUNCENTR
Y
(
getPositionAvg
,
xpt2046_getPositionAvg
)
{
LSTRKE
Y
(
"
setCalibration
"
),
LFUNCVAL
(
xpt2046_setCalibration
)
},
LROT_FUNCENTR
Y
(
setCalibration
,
xpt2046_setCalibration
)
{
LSTRKE
Y
(
"
init
"
),
LFUNCVAL
(
xpt2046_init
)
},
LROT_FUNCENTR
Y
(
init
,
xpt2046_init
)
{
LNILKEY
,
LNILVAL
}
LROT_END
(
xpt2046
,
NULL
,
0
)
};
NODEMCU_MODULE
(
XPT2046
,
"xpt2046"
,
xpt2046
_map
,
NULL
);
NODEMCU_MODULE
(
XPT2046
,
"xpt2046"
,
xpt2046
,
NULL
);
app/mqtt/Makefile
View file @
310faf7f
...
@@ -38,9 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
...
@@ -38,9 +38,6 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
# Required for each makefile to inherit from the parent
# Required for each makefile to inherit from the parent
#
#
INCLUDES
:=
$(INCLUDES)
-I
$(PDIR)
include
INCLUDES
+=
-I
./
INCLUDES
+=
-I
../libc
PDIR
:=
../
$(PDIR)
PDIR
:=
../
$(PDIR)
sinclude
$(PDIR)Makefile
sinclude
$(PDIR)Makefile
app/mqtt/mqtt_msg.c
View file @
310faf7f
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
*
*
*/
*/
#include
"c_
string.h
"
#include
<
string.h
>
#include "mqtt_msg.h"
#include "mqtt_msg.h"
#define MQTT_MAX_FIXED_HEADER_SIZE 3
#define MQTT_MAX_FIXED_HEADER_SIZE 3
...
@@ -61,7 +61,7 @@ static int append_string(mqtt_connection_t* connection, const char* string, int
...
@@ -61,7 +61,7 @@ static int append_string(mqtt_connection_t* connection, const char* string, int
connection
->
buffer
[
connection
->
message
.
length
++
]
=
len
>>
8
;
connection
->
buffer
[
connection
->
message
.
length
++
]
=
len
>>
8
;
connection
->
buffer
[
connection
->
message
.
length
++
]
=
len
&
0xff
;
connection
->
buffer
[
connection
->
message
.
length
++
]
=
len
&
0xff
;
c_
memcpy
(
connection
->
buffer
+
connection
->
message
.
length
,
string
,
len
);
memcpy
(
connection
->
buffer
+
connection
->
message
.
length
,
string
,
len
);
connection
->
message
.
length
+=
len
;
connection
->
message
.
length
+=
len
;
return
len
+
2
;
return
len
+
2
;
...
@@ -121,7 +121,7 @@ static mqtt_message_t* fini_message(mqtt_connection_t* connection, int type, int
...
@@ -121,7 +121,7 @@ static mqtt_message_t* fini_message(mqtt_connection_t* connection, int type, int
void
mqtt_msg_init
(
mqtt_connection_t
*
connection
,
uint8_t
*
buffer
,
uint16_t
buffer_length
)
void
mqtt_msg_init
(
mqtt_connection_t
*
connection
,
uint8_t
*
buffer
,
uint16_t
buffer_length
)
{
{
c_
memset
(
connection
,
0
,
sizeof
(
connection
));
memset
(
connection
,
0
,
sizeof
(
connection
));
connection
->
buffer
=
buffer
;
connection
->
buffer
=
buffer
;
connection
->
buffer_length
=
buffer_length
;
connection
->
buffer_length
=
buffer_length
;
}
}
...
@@ -299,7 +299,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
...
@@ -299,7 +299,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
variable_header
->
lengthMsb
=
0
;
variable_header
->
lengthMsb
=
0
;
variable_header
->
lengthLsb
=
4
;
variable_header
->
lengthLsb
=
4
;
c_
memcpy
(
variable_header
->
magic
,
"MQTT"
,
4
);
memcpy
(
variable_header
->
magic
,
"MQTT"
,
4
);
variable_header
->
version
=
4
;
variable_header
->
version
=
4
;
variable_header
->
flags
=
0
;
variable_header
->
flags
=
0
;
variable_header
->
keepaliveMsb
=
info
->
keepalive
>>
8
;
variable_header
->
keepaliveMsb
=
info
->
keepalive
>>
8
;
...
@@ -310,7 +310,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
...
@@ -310,7 +310,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if
(
info
->
client_id
!=
NULL
&&
info
->
client_id
[
0
]
!=
'\0'
)
if
(
info
->
client_id
!=
NULL
&&
info
->
client_id
[
0
]
!=
'\0'
)
{
{
if
(
append_string
(
connection
,
info
->
client_id
,
c_
strlen
(
info
->
client_id
))
<
0
)
if
(
append_string
(
connection
,
info
->
client_id
,
strlen
(
info
->
client_id
))
<
0
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
}
}
else
else
...
@@ -318,10 +318,10 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
...
@@ -318,10 +318,10 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if
(
info
->
will_topic
!=
NULL
&&
info
->
will_topic
[
0
]
!=
'\0'
)
if
(
info
->
will_topic
!=
NULL
&&
info
->
will_topic
[
0
]
!=
'\0'
)
{
{
if
(
append_string
(
connection
,
info
->
will_topic
,
c_
strlen
(
info
->
will_topic
))
<
0
)
if
(
append_string
(
connection
,
info
->
will_topic
,
strlen
(
info
->
will_topic
))
<
0
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
if
(
append_string
(
connection
,
info
->
will_message
,
c_
strlen
(
info
->
will_message
))
<
0
)
if
(
append_string
(
connection
,
info
->
will_message
,
strlen
(
info
->
will_message
))
<
0
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
variable_header
->
flags
|=
MQTT_CONNECT_FLAG_WILL
;
variable_header
->
flags
|=
MQTT_CONNECT_FLAG_WILL
;
...
@@ -332,7 +332,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
...
@@ -332,7 +332,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if
(
info
->
username
!=
NULL
&&
info
->
username
[
0
]
!=
'\0'
)
if
(
info
->
username
!=
NULL
&&
info
->
username
[
0
]
!=
'\0'
)
{
{
if
(
append_string
(
connection
,
info
->
username
,
c_
strlen
(
info
->
username
))
<
0
)
if
(
append_string
(
connection
,
info
->
username
,
strlen
(
info
->
username
))
<
0
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
variable_header
->
flags
|=
MQTT_CONNECT_FLAG_USERNAME
;
variable_header
->
flags
|=
MQTT_CONNECT_FLAG_USERNAME
;
...
@@ -340,7 +340,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
...
@@ -340,7 +340,7 @@ mqtt_message_t* mqtt_msg_connect(mqtt_connection_t* connection, mqtt_connect_inf
if
(
info
->
password
!=
NULL
&&
info
->
password
[
0
]
!=
'\0'
)
if
(
info
->
password
!=
NULL
&&
info
->
password
[
0
]
!=
'\0'
)
{
{
if
(
append_string
(
connection
,
info
->
password
,
c_
strlen
(
info
->
password
))
<
0
)
if
(
append_string
(
connection
,
info
->
password
,
strlen
(
info
->
password
))
<
0
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
variable_header
->
flags
|=
MQTT_CONNECT_FLAG_PASSWORD
;
variable_header
->
flags
|=
MQTT_CONNECT_FLAG_PASSWORD
;
...
@@ -356,7 +356,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi
...
@@ -356,7 +356,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi
if
(
topic
==
NULL
||
topic
[
0
]
==
'\0'
)
if
(
topic
==
NULL
||
topic
[
0
]
==
'\0'
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
if
(
append_string
(
connection
,
topic
,
c_
strlen
(
topic
))
<
0
)
if
(
append_string
(
connection
,
topic
,
strlen
(
topic
))
<
0
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
if
(
qos
>
0
)
if
(
qos
>
0
)
...
@@ -369,7 +369,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi
...
@@ -369,7 +369,7 @@ mqtt_message_t* mqtt_msg_publish(mqtt_connection_t* connection, const char* topi
if
(
connection
->
message
.
length
+
data_length
>
connection
->
buffer_length
)
if
(
connection
->
message
.
length
+
data_length
>
connection
->
buffer_length
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
c_
memcpy
(
connection
->
buffer
+
connection
->
message
.
length
,
data
,
data_length
);
memcpy
(
connection
->
buffer
+
connection
->
message
.
length
,
data
,
data_length
);
connection
->
message
.
length
+=
data_length
;
connection
->
message
.
length
+=
data_length
;
return
fini_message
(
connection
,
MQTT_MSG_TYPE_PUBLISH
,
0
,
qos
,
retain
);
return
fini_message
(
connection
,
MQTT_MSG_TYPE_PUBLISH
,
0
,
qos
,
retain
);
...
@@ -422,7 +422,7 @@ mqtt_message_t* mqtt_msg_subscribe_topic(mqtt_connection_t* connection, const ch
...
@@ -422,7 +422,7 @@ mqtt_message_t* mqtt_msg_subscribe_topic(mqtt_connection_t* connection, const ch
if
(
topic
==
NULL
||
topic
[
0
]
==
'\0'
)
if
(
topic
==
NULL
||
topic
[
0
]
==
'\0'
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
if
(
append_string
(
connection
,
topic
,
c_
strlen
(
topic
))
<
0
)
if
(
append_string
(
connection
,
topic
,
strlen
(
topic
))
<
0
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
if
(
connection
->
message
.
length
+
1
>
connection
->
buffer_length
)
if
(
connection
->
message
.
length
+
1
>
connection
->
buffer_length
)
...
@@ -462,7 +462,7 @@ mqtt_message_t* mqtt_msg_unsubscribe_topic(mqtt_connection_t* connection, const
...
@@ -462,7 +462,7 @@ mqtt_message_t* mqtt_msg_unsubscribe_topic(mqtt_connection_t* connection, const
if
(
topic
==
NULL
||
topic
[
0
]
==
'\0'
)
if
(
topic
==
NULL
||
topic
[
0
]
==
'\0'
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
if
(
append_string
(
connection
,
topic
,
c_
strlen
(
topic
))
<
0
)
if
(
append_string
(
connection
,
topic
,
strlen
(
topic
))
<
0
)
return
fail_message
(
connection
);
return
fail_message
(
connection
);
return
&
connection
->
message
;
return
&
connection
->
message
;
...
...
app/mqtt/mqtt_msg.h
View file @
310faf7f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#ifndef MQTT_MSG_H
#ifndef MQTT_MSG_H
#define MQTT_MSG_H
#define MQTT_MSG_H
#include
"c_types
.h
"
#include
<stdint
.h
>
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
...
...
app/mqtt/msg_queue.c
View file @
310faf7f
#include
"c_
string.h
"
#include
<
string.h
>
#include
"c_
stdlib.h
"
#include
<
stdlib.h
>
#include
"c_
stdio.h
"
#include
<
stdio.h
>
#include "msg_queue.h"
#include "msg_queue.h"
#include "user_config.h"
msg_queue_t
*
msg_enqueue
(
msg_queue_t
**
head
,
mqtt_message_t
*
msg
,
uint16_t
msg_id
,
int
msg_type
,
int
publish_qos
){
msg_queue_t
*
msg_enqueue
(
msg_queue_t
**
head
,
mqtt_message_t
*
msg
,
uint16_t
msg_id
,
int
msg_type
,
int
publish_qos
){
if
(
!
head
){
if
(
!
head
){
...
@@ -11,19 +12,19 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i
...
@@ -11,19 +12,19 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i
NODE_DBG
(
"empty message
\n
"
);
NODE_DBG
(
"empty message
\n
"
);
return
NULL
;
return
NULL
;
}
}
msg_queue_t
*
node
=
(
msg_queue_t
*
)
c
_z
alloc
(
sizeof
(
msg_queue_t
));
msg_queue_t
*
node
=
(
msg_queue_t
*
)
calloc
(
1
,
sizeof
(
msg_queue_t
));
if
(
!
node
){
if
(
!
node
){
NODE_DBG
(
"not enough memory
\n
"
);
NODE_DBG
(
"not enough memory
\n
"
);
return
NULL
;
return
NULL
;
}
}
node
->
msg
.
data
=
(
uint8_t
*
)
c
_z
alloc
(
msg
->
length
);
node
->
msg
.
data
=
(
uint8_t
*
)
calloc
(
1
,
msg
->
length
);
if
(
!
node
->
msg
.
data
){
if
(
!
node
->
msg
.
data
){
NODE_DBG
(
"not enough memory
\n
"
);
NODE_DBG
(
"not enough memory
\n
"
);
c_
free
(
node
);
free
(
node
);
return
NULL
;
return
NULL
;
}
}
c_
memcpy
(
node
->
msg
.
data
,
msg
->
data
,
msg
->
length
);
memcpy
(
node
->
msg
.
data
,
msg
->
data
,
msg
->
length
);
node
->
msg
.
length
=
msg
->
length
;
node
->
msg
.
length
=
msg
->
length
;
node
->
next
=
NULL
;
node
->
next
=
NULL
;
node
->
msg_id
=
msg_id
;
node
->
msg_id
=
msg_id
;
...
@@ -43,10 +44,10 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i
...
@@ -43,10 +44,10 @@ msg_queue_t *msg_enqueue(msg_queue_t **head, mqtt_message_t *msg, uint16_t msg_i
void
msg_destroy
(
msg_queue_t
*
node
){
void
msg_destroy
(
msg_queue_t
*
node
){
if
(
!
node
)
return
;
if
(
!
node
)
return
;
if
(
node
->
msg
.
data
){
if
(
node
->
msg
.
data
){
c_
free
(
node
->
msg
.
data
);
free
(
node
->
msg
.
data
);
node
->
msg
.
data
=
NULL
;
node
->
msg
.
data
=
NULL
;
}
}
c_
free
(
node
);
free
(
node
);
}
}
msg_queue_t
*
msg_dequeue
(
msg_queue_t
**
head
){
msg_queue_t
*
msg_dequeue
(
msg_queue_t
**
head
){
...
...
app/net/Makefile
View file @
310faf7f
...
@@ -36,9 +36,6 @@ endif
...
@@ -36,9 +36,6 @@ endif
# Required for each makefile to inherit from the parent
# Required for each makefile to inherit from the parent
#
#
INCLUDES
:=
$(INCLUDES)
-I
$(PDIR)
include
INCLUDES
+=
-I
./
INCLUDES
+=
-I
../libc
PDIR
:=
../
$(PDIR)
PDIR
:=
../
$(PDIR)
sinclude
$(PDIR)Makefile
sinclude
$(PDIR)Makefile
app/net/nodemcu_mdns.c
View file @
310faf7f
...
@@ -48,7 +48,7 @@
...
@@ -48,7 +48,7 @@
#include "osapi.h"
#include "osapi.h"
#include "os_type.h"
#include "os_type.h"
#include "user_interface.h"
#include "user_interface.h"
#include
"c_
string.h
"
#include
<
string.h
>
#include "nodemcu_mdns.h"
#include "nodemcu_mdns.h"
#if 0
#if 0
...
@@ -484,7 +484,7 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_
...
@@ -484,7 +484,7 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_
hdr
->
numextrarr
=
htons
(
1
);
hdr
->
numextrarr
=
htons
(
1
);
query
=
(
char
*
)
hdr
+
SIZEOF_DNS_HDR
;
query
=
(
char
*
)
hdr
+
SIZEOF_DNS_HDR
;
query_end
=
(
char
*
)
p
->
payload
+
p
->
tot_len
;
query_end
=
(
char
*
)
p
->
payload
+
p
->
tot_len
;
c_
strlcpy
(
tmpBuf
,
service_name_with_suffix
,
sizeof
(
tmpBuf
));
strlcpy
(
tmpBuf
,
service_name_with_suffix
,
sizeof
(
tmpBuf
));
pHostname
=
tmpBuf
;
pHostname
=
tmpBuf
;
--
pHostname
;
--
pHostname
;
...
@@ -618,9 +618,9 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_
...
@@ -618,9 +618,9 @@ mdns_send_service(struct nodemcu_mdns_info *info, u16_t id, struct ip_addr *dst_
ans
.
type
=
htons
(
DNS_RRTYPE_SRV
);
ans
.
type
=
htons
(
DNS_RRTYPE_SRV
);
ans
.
class
=
htons
(
dns_class
);
ans
.
class
=
htons
(
dns_class
);
ans
.
ttl
=
htonl
(
min
(
max_ttl
,
300
));
ans
.
ttl
=
htonl
(
min
(
max_ttl
,
300
));
c_
strlcpy
(
tmpBuf
,
ms_info
->
host_name
,
sizeof
(
tmpBuf
));
strlcpy
(
tmpBuf
,
ms_info
->
host_name
,
sizeof
(
tmpBuf
));
c_
strlcat
(
tmpBuf
,
"."
,
sizeof
(
tmpBuf
));
strlcat
(
tmpBuf
,
"."
,
sizeof
(
tmpBuf
));
c_
strlcat
(
tmpBuf
,
MDNS_LOCAL
,
sizeof
(
tmpBuf
));
strlcat
(
tmpBuf
,
MDNS_LOCAL
,
sizeof
(
tmpBuf
));
length
=
os_strlen
(
tmpBuf
)
+
MDNS_LENGTH_ADD
;
length
=
os_strlen
(
tmpBuf
)
+
MDNS_LENGTH_ADD
;
ans
.
len
=
htons
(
SIZEOF_MDNS_SERVICE
+
length
);
ans
.
len
=
htons
(
SIZEOF_MDNS_SERVICE
+
length
);
length
=
0
;
length
=
0
;
...
@@ -931,9 +931,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr,
...
@@ -931,9 +931,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr,
actual_rr
=
DNS_RRTYPE_PTR
;
actual_rr
=
DNS_RRTYPE_PTR
;
}
}
}
else
{
}
else
{
c_
strlcpy
(
tmpBuf
,
ms_info
->
host_name
,
sizeof
(
tmpBuf
));
strlcpy
(
tmpBuf
,
ms_info
->
host_name
,
sizeof
(
tmpBuf
));
c_
strlcat
(
tmpBuf
,
"."
,
sizeof
(
tmpBuf
));
strlcat
(
tmpBuf
,
"."
,
sizeof
(
tmpBuf
));
c_
strlcat
(
tmpBuf
,
MDNS_LOCAL
,
sizeof
(
tmpBuf
));
strlcat
(
tmpBuf
,
MDNS_LOCAL
,
sizeof
(
tmpBuf
));
no_rr_name
=
tmpBuf
;
no_rr_name
=
tmpBuf
;
if
(
mdns_compare_name
((
unsigned
char
*
)
tmpBuf
,
if
(
mdns_compare_name
((
unsigned
char
*
)
tmpBuf
,
...
@@ -944,9 +944,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr,
...
@@ -944,9 +944,9 @@ mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr,
actual_rr
=
DNS_RRTYPE_A
;
actual_rr
=
DNS_RRTYPE_A
;
}
}
}
else
{
}
else
{
c_
strlcpy
(
tmpBuf
,
ms_info
->
host_desc
,
sizeof
(
tmpBuf
));
strlcpy
(
tmpBuf
,
ms_info
->
host_desc
,
sizeof
(
tmpBuf
));
c_
strlcat
(
tmpBuf
,
"."
,
sizeof
(
tmpBuf
));
strlcat
(
tmpBuf
,
"."
,
sizeof
(
tmpBuf
));
c_
strlcat
(
tmpBuf
,
service_name_with_suffix
,
sizeof
(
tmpBuf
));
strlcat
(
tmpBuf
,
service_name_with_suffix
,
sizeof
(
tmpBuf
));
if
(
mdns_compare_name
((
unsigned
char
*
)
tmpBuf
,
if
(
mdns_compare_name
((
unsigned
char
*
)
tmpBuf
,
(
unsigned
char
*
)
qptr
,
(
unsigned
char
*
)
hdr
)
==
0
)
{
(
unsigned
char
*
)
qptr
,
(
unsigned
char
*
)
hdr
)
==
0
)
{
if
(
qry_type
==
DNS_RRTYPE_TXT
||
qry_type
==
DNS_RRTYPE_SRV
||
qry_type
==
DNS_RRTYPE_ANY
)
{
if
(
qry_type
==
DNS_RRTYPE_TXT
||
qry_type
==
DNS_RRTYPE_SRV
||
qry_type
==
DNS_RRTYPE_ANY
)
{
...
@@ -1003,7 +1003,7 @@ mdns_set_servicename(const char *name) {
...
@@ -1003,7 +1003,7 @@ mdns_set_servicename(const char *name) {
if
(
service_name_with_suffix
)
{
if
(
service_name_with_suffix
)
{
os_free
(
service_name_with_suffix
);
os_free
(
service_name_with_suffix
);
}
}
service_name_with_suffix
=
c_
strdup
(
tmpBuf
);
service_name_with_suffix
=
strdup
(
tmpBuf
);
}
}
static
u8_t
reg_counter
;
static
u8_t
reg_counter
;
...
@@ -1029,15 +1029,15 @@ mdns_dup_info(const struct nodemcu_mdns_info *info) {
...
@@ -1029,15 +1029,15 @@ mdns_dup_info(const struct nodemcu_mdns_info *info) {
// calculate length
// calculate length
int
len
=
sizeof
(
struct
nodemcu_mdns_info
);
int
len
=
sizeof
(
struct
nodemcu_mdns_info
);
len
+=
c_
strlen
(
info
->
host_name
)
+
1
;
len
+=
strlen
(
info
->
host_name
)
+
1
;
len
+=
c_
strlen
(
info
->
host_desc
)
+
1
;
len
+=
strlen
(
info
->
host_desc
)
+
1
;
len
+=
c_
strlen
(
info
->
service_name
)
+
1
;
len
+=
strlen
(
info
->
service_name
)
+
1
;
int
i
;
int
i
;
for
(
i
=
0
;
i
<
sizeof
(
info
->
txt_data
)
/
sizeof
(
info
->
txt_data
[
0
])
&&
info
->
txt_data
[
i
];
i
++
)
{
for
(
i
=
0
;
i
<
sizeof
(
info
->
txt_data
)
/
sizeof
(
info
->
txt_data
[
0
])
&&
info
->
txt_data
[
i
];
i
++
)
{
len
+=
c_
strlen
(
info
->
txt_data
[
i
])
+
1
;
len
+=
strlen
(
info
->
txt_data
[
i
])
+
1
;
}
}
#define COPY_OVER(dest, src, p) len =
c_
strlen(src) + 1; memcpy(p, src, len); dest = p; p += len
#define COPY_OVER(dest, src, p) len = strlen(src) + 1; memcpy(p, src, len); dest = p; p += len
result
=
(
struct
nodemcu_mdns_info
*
)
os_zalloc
(
len
);
result
=
(
struct
nodemcu_mdns_info
*
)
os_zalloc
(
len
);
if
(
result
)
{
if
(
result
)
{
...
...
app/pcm/Makefile
View file @
310faf7f
...
@@ -38,10 +38,5 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
...
@@ -38,10 +38,5 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
# Required for each makefile to inherit from the parent
# Required for each makefile to inherit from the parent
#
#
INCLUDES
:=
$(INCLUDES)
-I
$(PDIR)
include
INCLUDES
+=
-I
./
INCLUDES
+=
-I
../lua
INCLUDES
+=
-I
../libc
INCLUDES
+=
-I
../platform
PDIR
:=
../
$(PDIR)
PDIR
:=
../
$(PDIR)
sinclude
$(PDIR)Makefile
sinclude
$(PDIR)Makefile
app/pcm/drv_sigma_delta.c
View file @
310faf7f
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
#include "platform.h"
#include "platform.h"
#include "hw_timer.h"
#include "hw_timer.h"
#include "task/task.h"
#include "task/task.h"
#include
"c_
stdlib.h
"
#include
<
stdlib.h
>
#include "pcm.h"
#include "pcm.h"
...
...
app/pcm/pcm_core.c
View file @
310faf7f
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
#include "lauxlib.h"
#include "lauxlib.h"
#include "task/task.h"
#include "task/task.h"
#include
"c_
string.h
"
#include
<
string.h
>
#include
"c_
stdlib.h
"
#include
<
stdlib.h
>
#include "pcm.h"
#include "pcm.h"
...
@@ -58,9 +58,9 @@ void pcm_data_play( task_param_t param, uint8 prio )
...
@@ -58,9 +58,9 @@ void pcm_data_play( task_param_t param, uint8 prio )
if
(
lua_type
(
L
,
-
1
)
==
LUA_TSTRING
)
{
if
(
lua_type
(
L
,
-
1
)
==
LUA_TSTRING
)
{
data
=
lua_tolstring
(
L
,
-
1
,
&
string_len
);
data
=
lua_tolstring
(
L
,
-
1
,
&
string_len
);
if
(
string_len
>
buf
->
buf_size
)
{
if
(
string_len
>
buf
->
buf_size
)
{
uint8_t
*
new_data
=
(
uint8_t
*
)
c_
malloc
(
string_len
);
uint8_t
*
new_data
=
(
uint8_t
*
)
malloc
(
string_len
);
if
(
new_data
)
{
if
(
new_data
)
{
if
(
buf
->
data
)
c_
free
(
buf
->
data
);
if
(
buf
->
data
)
free
(
buf
->
data
);
buf
->
buf_size
=
string_len
;
buf
->
buf_size
=
string_len
;
buf
->
data
=
new_data
;
buf
->
data
=
new_data
;
}
}
...
@@ -70,7 +70,7 @@ void pcm_data_play( task_param_t param, uint8 prio )
...
@@ -70,7 +70,7 @@ void pcm_data_play( task_param_t param, uint8 prio )
if
(
data
)
{
if
(
data
)
{
size_t
to_copy
=
string_len
>
buf
->
buf_size
?
buf
->
buf_size
:
string_len
;
size_t
to_copy
=
string_len
>
buf
->
buf_size
?
buf
->
buf_size
:
string_len
;
c_
memcpy
(
buf
->
data
,
data
,
to_copy
);
memcpy
(
buf
->
data
,
data
,
to_copy
);
buf
->
rpos
=
0
;
buf
->
rpos
=
0
;
buf
->
len
=
to_copy
;
buf
->
len
=
to_copy
;
...
...
app/platform/Makefile
View file @
310faf7f
...
@@ -38,13 +38,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
...
@@ -38,13 +38,7 @@ STD_CFLAGS=-std=gnu11 -Wimplicit
# Required for each makefile to inherit from the parent
# Required for each makefile to inherit from the parent
#
#
INCLUDES
:=
$(INCLUDES)
-I
$(PDIR)
include
INCLUDES
+=
-I
../spiffs
-I
../u8g2lib/u8g2/src/clib
-I
../ucglib/ucg/src/clib
INCLUDES
+=
-I
./
INCLUDES
+=
-I
../spiffs
INCLUDES
+=
-I
../libc
INCLUDES
+=
-I
../lua
INCLUDES
+=
-I
../u8g2lib/u8g2/src/clib
INCLUDES
+=
-I
../ucglib/ucg/src/clib
PDIR
:=
../
$(PDIR)
PDIR
:=
../
$(PDIR)
sinclude
$(PDIR)Makefile
sinclude
$(PDIR)Makefile
app/platform/common.c
View file @
310faf7f
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
#include "platform.h"
#include "platform.h"
#include "common.h"
#include "common.h"
#include
"c_
string.h
"
#include
<
string.h
>
#include
"c_
stdio.h
"
#include
<
stdio.h
>
void
cmn_platform_init
(
void
)
void
cmn_platform_init
(
void
)
{
{
...
@@ -102,7 +102,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size
...
@@ -102,7 +102,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size
{
{
rest
=
toaddr
&
blkmask
;
rest
=
toaddr
&
blkmask
;
temp
=
toaddr
&
~
blkmask
;
// this is the actual aligned address
temp
=
toaddr
&
~
blkmask
;
// this is the actual aligned address
//
c_
memcpy( tmpdata, ( const void* )temp, blksize );
// memcpy( tmpdata, ( const void* )temp, blksize );
platform_s_flash_read
(
tmpdata
,
temp
,
blksize
);
platform_s_flash_read
(
tmpdata
,
temp
,
blksize
);
for
(
i
=
rest
;
size
&&
(
i
<
blksize
);
i
++
,
size
--
,
pfrom
++
)
for
(
i
=
rest
;
size
&&
(
i
<
blksize
);
i
++
,
size
--
,
pfrom
++
)
tmpdata
[
i
]
=
*
pfrom
;
tmpdata
[
i
]
=
*
pfrom
;
...
@@ -125,7 +125,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size
...
@@ -125,7 +125,7 @@ uint32_t platform_flash_write( const void *from, uint32_t toaddr, uint32_t size
// And the final part of a block if needed
// And the final part of a block if needed
if
(
rest
)
if
(
rest
)
{
{
//
c_
memcpy( tmpdata, ( const void* )toaddr, blksize );
// memcpy( tmpdata, ( const void* )toaddr, blksize );
platform_s_flash_read
(
tmpdata
,
toaddr
,
blksize
);
platform_s_flash_read
(
tmpdata
,
toaddr
,
blksize
);
for
(
i
=
0
;
size
&&
(
i
<
rest
);
i
++
,
size
--
,
pfrom
++
)
for
(
i
=
0
;
size
&&
(
i
<
rest
);
i
++
,
size
--
,
pfrom
++
)
tmpdata
[
i
]
=
*
pfrom
;
tmpdata
[
i
]
=
*
pfrom
;
...
...
app/platform/cpu_esp8266.h
View file @
310faf7f
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
#define __CPU_ESP8266_H__
#define __CPU_ESP8266_H__
#ifndef NO_CPU_ESP8266_INCLUDE
#ifndef NO_CPU_ESP8266_INCLUDE
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "os_type.h"
#include "os_type.h"
#include "spi_flash.h"
#include "spi_flash.h"
#include "pin_map.h"
#include "pin_map.h"
...
@@ -15,7 +18,13 @@
...
@@ -15,7 +18,13 @@
#define NUM_PWM GPIO_PIN_NUM
#define NUM_PWM GPIO_PIN_NUM
#define NUM_ADC 1
#define NUM_ADC 1
#define NUM_CAN 0
#define NUM_CAN 0
#ifndef I2C_MASTER_OLD_VERSION
#define NUM_I2C 10
#else
#define NUM_I2C 1
#define NUM_I2C 1
#endif //I2C_MASTER_OLD_VERSION
#define NUM_OW GPIO_PIN_NUM
#define NUM_OW GPIO_PIN_NUM
#define NUM_TMR 7
#define NUM_TMR 7
...
...
app/platform/flash_api.c
View file @
310faf7f
...
@@ -6,7 +6,8 @@
...
@@ -6,7 +6,8 @@
#include "user_config.h"
#include "user_config.h"
#include "flash_api.h"
#include "flash_api.h"
#include "spi_flash.h"
#include "spi_flash.h"
#include "c_stdio.h"
#include <stdio.h>
#include <string.h>
uint32_t
flash_detect_size_byte
(
void
)
uint32_t
flash_detect_size_byte
(
void
)
{
{
...
@@ -25,7 +26,7 @@ uint32_t flash_detect_size_byte(void)
...
@@ -25,7 +26,7 @@ uint32_t flash_detect_size_byte(void)
dummy_size
=
FLASH_SIZE_256KBYTE
;
dummy_size
=
FLASH_SIZE_256KBYTE
;
while
((
dummy_size
<
FLASH_SIZE_16MBYTE
)
&&
while
((
dummy_size
<
FLASH_SIZE_16MBYTE
)
&&
(
SPI_FLASH_RESULT_OK
==
flash_read
(
dummy_size
,
(
uint32
*
)
data_new
,
FLASH_BUFFER_SIZE_DETECT
))
&&
(
SPI_FLASH_RESULT_OK
==
flash_read
(
dummy_size
,
(
uint32
*
)
data_new
,
FLASH_BUFFER_SIZE_DETECT
))
&&
(
0
!=
os_
memcmp
(
data_orig
,
data_new
,
FLASH_BUFFER_SIZE_DETECT
))
(
0
!=
memcmp
(
data_orig
,
data_new
,
FLASH_BUFFER_SIZE_DETECT
))
)
)
{
{
dummy_size
*=
2
;
dummy_size
*=
2
;
...
@@ -39,16 +40,19 @@ uint32_t flash_detect_size_byte(void)
...
@@ -39,16 +40,19 @@ uint32_t flash_detect_size_byte(void)
#undef FLASH_BUFFER_SIZE_DETECT
#undef FLASH_BUFFER_SIZE_DETECT
}
}
SPIFlashInfo
flash_rom_getinfo
(
void
)
static
SPIFlashInfo
spi_flash_info
=
{
0
};
SPIFlashInfo
*
flash_rom_getinfo
(
void
)
{
{
volatile
SPIFlashInfo
spi_flash_info
ICACHE_STORE_ATTR
;
if
(
spi_flash_info
.
entry_point
==
0
)
{
spi_flash_read
(
0
,
(
uint32
*
)(
&
spi_flash_info
),
sizeof
(
spi_flash_info
));
spi_flash_read
(
0
,
(
uint32
*
)(
&
spi_flash_info
),
sizeof
(
spi_flash_info
));
return
spi_flash_info
;
}
return
&
spi_flash_info
;
}
}
uint8_t
flash_rom_get_size_type
(
void
)
uint8_t
flash_rom_get_size_type
(
void
)
{
{
return
flash_rom_getinfo
()
.
size
;
return
flash_rom_getinfo
()
->
size
;
}
}
uint32_t
flash_rom_get_size_byte
(
void
)
uint32_t
flash_rom_get_size_byte
(
void
)
...
@@ -56,7 +60,7 @@ uint32_t flash_rom_get_size_byte(void)
...
@@ -56,7 +60,7 @@ uint32_t flash_rom_get_size_byte(void)
static
uint32_t
flash_size
=
0
;
static
uint32_t
flash_size
=
0
;
if
(
flash_size
==
0
)
if
(
flash_size
==
0
)
{
{
switch
(
flash_rom_getinfo
()
.
size
)
switch
(
flash_rom_getinfo
()
->
size
)
{
{
case
SIZE_2MBIT
:
case
SIZE_2MBIT
:
// 2Mbit, 256kByte
// 2Mbit, 256kByte
...
@@ -107,99 +111,15 @@ uint32_t flash_rom_get_size_byte(void)
...
@@ -107,99 +111,15 @@ uint32_t flash_rom_get_size_byte(void)
return
flash_size
;
return
flash_size
;
}
}
bool
flash_rom_set_size_type
(
uint8_t
size
)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
NODE_DBG
(
"
\n
BEGIN SET FLASH HEADER
\n
"
);
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
ICACHE_STORE_ATTR
;
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_read
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
{
NODE_DBG
(
"
\n
flash_rom_set_size_type(%u), was %u
\n
"
,
size
,
((
SPIFlashInfo
*
)
data
)
->
size
);
((
SPIFlashInfo
*
)
data
)
->
size
=
size
;
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
(
0
*
SPI_FLASH_SEC_SIZE
))
{
NODE_DBG
(
"
\n
SECTOR 0 ERASE SUCCESS
\n
"
);
}
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_write
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
{
NODE_DBG
(
"
\n
WRITE SUCCESS, %u
\n
"
,
size
);
}
}
NODE_DBG
(
"
\n
END SET FLASH HEADER
\n
"
);
return
true
;
}
bool
flash_rom_set_size_byte
(
uint32_t
size
)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
bool
result
=
true
;
uint32_t
flash_size
=
0
;
switch
(
size
)
{
case
256
*
1024
:
// 2Mbit, 256kByte
flash_size
=
SIZE_2MBIT
;
flash_rom_set_size_type
(
flash_size
);
break
;
case
512
*
1024
:
// 4Mbit, 512kByte
flash_size
=
SIZE_4MBIT
;
flash_rom_set_size_type
(
flash_size
);
break
;
case
1
*
1024
*
1024
:
// 8Mbit, 1MByte
flash_size
=
SIZE_8MBIT
;
flash_rom_set_size_type
(
flash_size
);
break
;
case
2
*
1024
*
1024
:
// 16Mbit, 2MByte
flash_size
=
SIZE_16MBIT
;
flash_rom_set_size_type
(
flash_size
);
break
;
case
4
*
1024
*
1024
:
// 32Mbit, 4MByte
flash_size
=
SIZE_32MBIT
;
flash_rom_set_size_type
(
flash_size
);
break
;
case
8
*
1024
*
1024
:
// 64Mbit, 8MByte
flash_size
=
SIZE_64MBIT
;
flash_rom_set_size_type
(
flash_size
);
break
;
case
16
*
1024
*
1024
:
// 128Mbit, 16MByte
flash_size
=
SIZE_128MBIT
;
flash_rom_set_size_type
(
flash_size
);
break
;
default:
// Unknown flash size.
result
=
false
;
break
;
}
return
result
;
}
uint16_t
flash_rom_get_sec_num
(
void
)
uint16_t
flash_rom_get_sec_num
(
void
)
{
{
//static uint16_t sec_num = 0;
// return flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE);
// c_printf("\nflash_rom_get_size_byte()=%d\n", ( flash_rom_get_size_byte() / (SPI_FLASH_SEC_SIZE) ));
// if( sec_num == 0 )
//{
// sec_num = 4 * 1024 * 1024 / (SPI_FLASH_SEC_SIZE);
//}
//return sec_num;
return
(
flash_rom_get_size_byte
()
/
(
SPI_FLASH_SEC_SIZE
)
);
return
(
flash_rom_get_size_byte
()
/
(
SPI_FLASH_SEC_SIZE
)
);
}
}
uint8_t
flash_rom_get_mode
(
void
)
uint8_t
flash_rom_get_mode
(
void
)
{
{
SPIFlashInfo
spi_flash_info
=
flash_rom_getinfo
();
uint8_t
mode
=
flash_rom_getinfo
()
->
mode
;
switch
(
spi_flash_info
.
mode
)
switch
(
mode
)
{
{
// Reserved for future use
// Reserved for future use
case
MODE_QIO
:
case
MODE_QIO
:
...
@@ -211,14 +131,14 @@ uint8_t flash_rom_get_mode(void)
...
@@ -211,14 +131,14 @@ uint8_t flash_rom_get_mode(void)
case
MODE_DOUT
:
case
MODE_DOUT
:
break
;
break
;
}
}
return
spi_flash_info
.
mode
;
return
mode
;
}
}
uint32_t
flash_rom_get_speed
(
void
)
uint32_t
flash_rom_get_speed
(
void
)
{
{
uint32_t
speed
=
0
;
uint32_t
speed
=
0
;
SPIFlashInfo
spi_flash_info
=
flash_rom_getinfo
();
uint8_t
spi_speed
=
flash_rom_getinfo
()
->
speed
;
switch
(
spi_
flash_info
.
speed
)
switch
(
spi_speed
)
{
{
case
SPEED_40MHZ
:
case
SPEED_40MHZ
:
// 40MHz
// 40MHz
...
@@ -240,47 +160,6 @@ uint32_t flash_rom_get_speed(void)
...
@@ -240,47 +160,6 @@ uint32_t flash_rom_get_speed(void)
return
speed
;
return
speed
;
}
}
bool
flash_rom_set_speed
(
uint32_t
speed
)
{
// Dangerous, here are dinosaur infested!!!!!
// Reboot required!!!
// If you don't know what you're doing, your nodemcu may turn into stone ...
NODE_DBG
(
"
\n
BEGIN SET FLASH HEADER
\n
"
);
uint8_t
data
[
SPI_FLASH_SEC_SIZE
]
ICACHE_STORE_ATTR
;
uint8_t
speed_type
=
SPEED_40MHZ
;
if
(
speed
<
26700000
)
{
speed_type
=
SPEED_20MHZ
;
}
else
if
(
speed
<
40000000
)
{
speed_type
=
SPEED_26MHZ
;
}
else
if
(
speed
<
80000000
)
{
speed_type
=
SPEED_40MHZ
;
}
else
if
(
speed
>=
80000000
)
{
speed_type
=
SPEED_80MHZ
;
}
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_read
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
{
((
SPIFlashInfo
*
)(
&
data
[
0
]))
->
speed
=
speed_type
;
NODE_DBG
(
"
\n
flash_rom_set_speed(%u), was %u
\n
"
,
speed_type
,
((
SPIFlashInfo
*
)(
&
data
[
0
]))
->
speed
);
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_erase_sector
(
0
*
SPI_FLASH_SEC_SIZE
))
{
NODE_DBG
(
"
\n
ERASE SUCCESS
\n
"
);
}
if
(
SPI_FLASH_RESULT_OK
==
spi_flash_write
(
0
,
(
uint32
*
)
data
,
SPI_FLASH_SEC_SIZE
))
{
NODE_DBG
(
"
\n
WRITE SUCCESS, %u
\n
"
,
speed_type
);
}
}
NODE_DBG
(
"
\n
END SET FLASH HEADER
\n
"
);
return
true
;
}
uint8_t
byte_of_aligned_array
(
const
uint8_t
*
aligned_array
,
uint32_t
index
)
uint8_t
byte_of_aligned_array
(
const
uint8_t
*
aligned_array
,
uint32_t
index
)
{
{
if
(
(((
uint32_t
)
aligned_array
)
%
4
)
!=
0
)
if
(
(((
uint32_t
)
aligned_array
)
%
4
)
!=
0
)
...
@@ -303,31 +182,5 @@ uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index)
...
@@ -303,31 +182,5 @@ uint16_t word_of_aligned_array(const uint16_t *aligned_array, uint32_t index)
volatile
uint32_t
v
=
((
uint32_t
*
)
aligned_array
)[
index
/
2
];
volatile
uint32_t
v
=
((
uint32_t
*
)
aligned_array
)[
index
/
2
];
uint16_t
*
p
=
(
uint16_t
*
)
(
&
v
);
uint16_t
*
p
=
(
uint16_t
*
)
(
&
v
);
return
(
index
%
2
==
0
)
?
p
[
0
]
:
p
[
1
];
return
(
index
%
2
==
0
)
?
p
[
0
]
:
p
[
1
];
// return p[ (index % 2) ]; // -- why error???
// (byte_of_aligned_array((uint8_t *)aligned_array, index * 2 + 1) << 8) | byte_of_aligned_array((uint8_t *)aligned_array, index * 2);
}
}
// uint8_t flash_rom_get_checksum(void)
// {
// // SPIFlashInfo spi_flash_info ICACHE_STORE_ATTR = flash_rom_getinfo();
// // uint32_t address = sizeof(spi_flash_info) + spi_flash_info.segment_size;
// // uint32_t address_aligned_4bytes = (address + 3) & 0xFFFFFFFC;
// // uint8_t buffer[64] = {0};
// // spi_flash_read(address, (uint32 *) buffer, 64);
// // uint8_t i = 0;
// // c_printf("\nBEGIN DUMP\n");
// // for (i = 0; i < 64; i++)
// // {
// // c_printf("%02x," , buffer[i]);
// // }
// // i = (address + 0x10) & 0x10 - 1;
// // c_printf("\nSIZE:%d CHECK SUM:%02x\n", spi_flash_info.segment_size, buffer[i]);
// // c_printf("\nEND DUMP\n");
// // return buffer[0];
// return 0;
// }
// uint8_t flash_rom_calc_checksum(void)
// {
// return 0;
// }
app/platform/flash_api.h
View file @
310faf7f
...
@@ -79,18 +79,14 @@ typedef struct
...
@@ -79,18 +79,14 @@ typedef struct
uint32_t
segment_size
;
uint32_t
segment_size
;
}
ICACHE_STORE_TYPEDEF_ATTR
SPIFlashInfo
;
}
ICACHE_STORE_TYPEDEF_ATTR
SPIFlashInfo
;
SPIFlashInfo
flash_rom_getinfo
(
void
);
SPIFlashInfo
*
flash_rom_getinfo
(
void
);
uint8_t
flash_rom_get_size_type
(
void
);
uint8_t
flash_rom_get_size_type
(
void
);
uint32_t
flash_rom_get_size_byte
(
void
);
uint32_t
flash_rom_get_size_byte
(
void
);
uint32_t
flash_detect_size_byte
(
void
);
uint32_t
flash_detect_size_byte
(
void
);
bool
flash_rom_set_size_type
(
uint8_t
);
bool
flash_rom_set_size_byte
(
uint32_t
);
uint16_t
flash_rom_get_sec_num
(
void
);
uint16_t
flash_rom_get_sec_num
(
void
);
uint8_t
flash_rom_get_mode
(
void
);
uint8_t
flash_rom_get_mode
(
void
);
uint32_t
flash_rom_get_speed
(
void
);
uint32_t
flash_rom_get_speed
(
void
);
uint8_t
byte_of_aligned_array
(
const
uint8_t
*
aligned_array
,
uint32_t
index
);
uint8_t
byte_of_aligned_array
(
const
uint8_t
*
aligned_array
,
uint32_t
index
);
uint16_t
word_of_aligned_array
(
const
uint16_t
*
aligned_array
,
uint32_t
index
);
uint16_t
word_of_aligned_array
(
const
uint16_t
*
aligned_array
,
uint32_t
index
);
// uint8_t flash_rom_get_checksum(void);
// uint8_t flash_rom_calc_checksum(void);
#endif // __FLASH_API_H__
#endif // __FLASH_API_H__
app/platform/hw_timer.c
View file @
310faf7f
...
@@ -17,8 +17,8 @@
...
@@ -17,8 +17,8 @@
* a small numeric value that is known not to clash.
* a small numeric value that is known not to clash.
*******************************************************************************/
*******************************************************************************/
#include "platform.h"
#include "platform.h"
#include
"c_
stdio.h
"
#include
<
stdio.h
>
#include
"c_
stdlib.h
"
#include
<
stdlib.h
>
#include "ets_sys.h"
#include "ets_sys.h"
#include "os_type.h"
#include "os_type.h"
#include "osapi.h"
#include "osapi.h"
...
@@ -86,6 +86,15 @@ static int32_t last_timer_load;
...
@@ -86,6 +86,15 @@ static int32_t last_timer_load;
#define LOCK() do { ets_intr_lock(); lock_count++; } while (0)
#define LOCK() do { ets_intr_lock(); lock_count++; } while (0)
#define UNLOCK() if (--lock_count == 0) ets_intr_unlock()
#define UNLOCK() if (--lock_count == 0) ets_intr_unlock()
/*
* It is possible to reserve the timer exclusively, for one module alone.
* This way the interrupt overhead is minimal.
* Drawback is that no other module can use the timer at same time.
* If flag if true, indicates someone reserved the timer exclusively.
* Unline shared used (default), only one client can reserve exclusively.
*/
static
bool
reserved_exclusively
=
false
;
/*
/*
* To start a timer, you write to FRCI_LOAD_ADDRESS, and that starts the counting
* To start a timer, you write to FRCI_LOAD_ADDRESS, and that starts the counting
* down. When it reaches zero, the interrupt fires -- but the counting continues.
* down. When it reaches zero, the interrupt fires -- but the counting continues.
...
@@ -275,6 +284,8 @@ static void ICACHE_RAM_ATTR insert_active_tu(timer_user *tu) {
...
@@ -275,6 +284,8 @@ static void ICACHE_RAM_ATTR insert_active_tu(timer_user *tu) {
*******************************************************************************/
*******************************************************************************/
bool
ICACHE_RAM_ATTR
platform_hw_timer_arm_ticks
(
os_param_t
owner
,
uint32_t
ticks
)
bool
ICACHE_RAM_ATTR
platform_hw_timer_arm_ticks
(
os_param_t
owner
,
uint32_t
ticks
)
{
{
if
(
reserved_exclusively
)
return
false
;
timer_user
*
tu
=
find_tu_and_remove
(
owner
);
timer_user
*
tu
=
find_tu_and_remove
(
owner
);
if
(
!
tu
)
{
if
(
!
tu
)
{
...
@@ -322,6 +333,8 @@ bool ICACHE_RAM_ATTR platform_hw_timer_arm_us(os_param_t owner, uint32_t microse
...
@@ -322,6 +333,8 @@ bool ICACHE_RAM_ATTR platform_hw_timer_arm_us(os_param_t owner, uint32_t microse
*******************************************************************************/
*******************************************************************************/
bool
platform_hw_timer_set_func
(
os_param_t
owner
,
void
(
*
user_hw_timer_cb_set
)(
os_param_t
),
os_param_t
arg
)
bool
platform_hw_timer_set_func
(
os_param_t
owner
,
void
(
*
user_hw_timer_cb_set
)(
os_param_t
),
os_param_t
arg
)
{
{
if
(
reserved_exclusively
)
return
false
;
timer_user
*
tu
=
find_tu
(
owner
);
timer_user
*
tu
=
find_tu
(
owner
);
if
(
!
tu
)
{
if
(
!
tu
)
{
return
false
;
return
false
;
...
@@ -393,6 +406,8 @@ static void ICACHE_RAM_ATTR hw_timer_nmi_cb(void)
...
@@ -393,6 +406,8 @@ static void ICACHE_RAM_ATTR hw_timer_nmi_cb(void)
*******************************************************************************/
*******************************************************************************/
uint32_t
ICACHE_RAM_ATTR
platform_hw_timer_get_delay_ticks
(
os_param_t
owner
)
uint32_t
ICACHE_RAM_ATTR
platform_hw_timer_get_delay_ticks
(
os_param_t
owner
)
{
{
if
(
reserved_exclusively
)
return
0
;
timer_user
*
tu
=
find_tu
(
owner
);
timer_user
*
tu
=
find_tu
(
owner
);
if
(
!
tu
)
{
if
(
!
tu
)
{
return
0
;
return
0
;
...
@@ -412,7 +427,7 @@ uint32_t ICACHE_RAM_ATTR platform_hw_timer_get_delay_ticks(os_param_t owner)
...
@@ -412,7 +427,7 @@ uint32_t ICACHE_RAM_ATTR platform_hw_timer_get_delay_ticks(os_param_t owner)
/******************************************************************************
/******************************************************************************
* FunctionName : platform_hw_timer_init
* FunctionName : platform_hw_timer_init
* Description : initialize the hardware isr timer
* Description : initialize the hardware isr timer
for shared use i.e. multiple owners.
* Parameters : os_param_t owner
* Parameters : os_param_t owner
* FRC1_TIMER_SOURCE_TYPE source_type:
* FRC1_TIMER_SOURCE_TYPE source_type:
* FRC1_SOURCE, timer use frc1 isr as isr source.
* FRC1_SOURCE, timer use frc1 isr as isr source.
...
@@ -424,10 +439,12 @@ uint32_t ICACHE_RAM_ATTR platform_hw_timer_get_delay_ticks(os_param_t owner)
...
@@ -424,10 +439,12 @@ uint32_t ICACHE_RAM_ATTR platform_hw_timer_get_delay_ticks(os_param_t owner)
*******************************************************************************/
*******************************************************************************/
bool
platform_hw_timer_init
(
os_param_t
owner
,
FRC1_TIMER_SOURCE_TYPE
source_type
,
bool
autoload
)
bool
platform_hw_timer_init
(
os_param_t
owner
,
FRC1_TIMER_SOURCE_TYPE
source_type
,
bool
autoload
)
{
{
if
(
reserved_exclusively
)
return
false
;
timer_user
*
tu
=
find_tu_and_remove
(
owner
);
timer_user
*
tu
=
find_tu_and_remove
(
owner
);
if
(
!
tu
)
{
if
(
!
tu
)
{
tu
=
(
timer_user
*
)
c_
malloc
(
sizeof
(
*
tu
));
tu
=
(
timer_user
*
)
malloc
(
sizeof
(
*
tu
));
if
(
!
tu
)
{
if
(
!
tu
)
{
return
false
;
return
false
;
}
}
...
@@ -456,19 +473,25 @@ bool platform_hw_timer_init(os_param_t owner, FRC1_TIMER_SOURCE_TYPE source_type
...
@@ -456,19 +473,25 @@ bool platform_hw_timer_init(os_param_t owner, FRC1_TIMER_SOURCE_TYPE source_type
/******************************************************************************
/******************************************************************************
* FunctionName : platform_hw_timer_close
* FunctionName : platform_hw_timer_close
* Description : ends use of the hardware isr timer
* Description : ends use of the hardware isr timer
.
* Parameters : os_param_t owner
* Parameters : os_param_t owner
.
* Returns : true if it worked
* Returns : true if it worked
*******************************************************************************/
*******************************************************************************/
bool
ICACHE_RAM_ATTR
platform_hw_timer_close
(
os_param_t
owner
)
bool
ICACHE_RAM_ATTR
platform_hw_timer_close
(
os_param_t
owner
)
{
{
if
(
reserved_exclusively
)
return
false
;
timer_user
*
tu
=
find_tu_and_remove
(
owner
);
timer_user
*
tu
=
find_tu_and_remove
(
owner
);
if
(
tu
)
{
if
(
tu
)
{
LOCK
();
if
(
tu
==
inactive
)
{
tu
->
next
=
inactive
;
inactive
==
NULL
;
inactive
=
tu
;
}
else
{
UNLOCK
();
LOCK
();
tu
->
next
=
inactive
;
inactive
=
tu
;
UNLOCK
();
}
}
}
// This will never actually run....
// This will never actually run....
...
@@ -484,3 +507,91 @@ bool ICACHE_RAM_ATTR platform_hw_timer_close(os_param_t owner)
...
@@ -484,3 +507,91 @@ bool ICACHE_RAM_ATTR platform_hw_timer_close(os_param_t owner)
return
true
;
return
true
;
}
}
/******************************************************************************
* FunctionName : platform_hw_timer_init_exclusive
* Description : initialize the hardware isr timer for exclusive use by the caller.
* Parameters : FRC1_TIMER_SOURCE_TYPE source_type:
* FRC1_SOURCE, timer use frc1 isr as isr source.
* NMI_SOURCE, timer use nmi isr as isr source.
* bool autoload:
* 0, not autoload,
* 1, autoload mode,
* void (* frc1_timer_cb)(os_param_t): timer callback function when FRC1_SOURCE is being used
* os_param_t arg : argument passed to frc1_timer_cb or NULL
* void (* nmi_timer_cb)(void) : timer callback function when NMI_SOURCE is being used
* Returns : true if it worked, false if the timer is already served for shared or exclusive use
*******************************************************************************/
bool
platform_hw_timer_init_exclusive
(
FRC1_TIMER_SOURCE_TYPE
source_type
,
bool
autoload
,
void
(
*
frc1_timer_cb
)(
os_param_t
),
os_param_t
arg
,
void
(
*
nmi_timer_cb
)(
void
)
)
{
if
(
active
||
inactive
)
return
false
;
if
(
reserved_exclusively
)
return
false
;
reserved_exclusively
=
true
;
RTC_REG_WRITE
(
FRC1_CTRL_ADDRESS
,
(
autoload
?
FRC1_AUTO_LOAD
:
0
)
|
DIVIDED_BY_16
|
FRC1_ENABLE_TIMER
|
TM_EDGE_INT
);
if
(
source_type
==
NMI_SOURCE
)
{
ETS_FRC_TIMER1_NMI_INTR_ATTACH
(
nmi_timer_cb
);
}
else
{
ETS_FRC_TIMER1_INTR_ATTACH
((
void
(
*
)(
void
*
))
frc1_timer_cb
,
(
void
*
)
arg
);
}
TM1_EDGE_INT_ENABLE
();
ETS_FRC1_INTR_ENABLE
();
return
true
;
}
/******************************************************************************
* FunctionName : platform_hw_timer_close_exclusive
* Description : ends use of the hardware isr timer in exclusive mode.
* Parameters :
* Returns : true if it worked
*******************************************************************************/
bool
ICACHE_RAM_ATTR
platform_hw_timer_close_exclusive
()
{
if
(
!
reserved_exclusively
)
return
true
;
reserved_exclusively
=
false
;
/* Set no reload mode */
RTC_REG_WRITE
(
FRC1_CTRL_ADDRESS
,
DIVIDED_BY_16
|
TM_EDGE_INT
);
TM1_EDGE_INT_DISABLE
();
ETS_FRC1_INTR_DISABLE
();
return
true
;
}
/******************************************************************************
* FunctionName : platform_hw_timer_arm_ticks_exclusive
* Description : set a trigger timer delay for this timer.
* Parameters : uint32 ticks :
* Returns : true if it worked
*******************************************************************************/
bool
ICACHE_RAM_ATTR
platform_hw_timer_arm_ticks_exclusive
(
uint32_t
ticks
)
{
RTC_REG_WRITE
(
FRC1_LOAD_ADDRESS
,
ticks
);
return
true
;
}
/******************************************************************************
* FunctionName : platform_hw_timer_arm_us_exclusive
* Description : set a trigger timer delay for this timer.
* Parameters : uint32 microseconds :
* in autoload mode
* 50 ~ 0x7fffff; for FRC1 source.
* 100 ~ 0x7fffff; for NMI source.
* in non autoload mode:
* 10 ~ 0x7fffff;
* Returns : true if it worked
*******************************************************************************/
bool
ICACHE_RAM_ATTR
platform_hw_timer_arm_us_exclusive
(
uint32_t
microseconds
)
{
RTC_REG_WRITE
(
FRC1_LOAD_ADDRESS
,
US_TO_RTC_TIMER_TICKS
(
microseconds
));
return
true
;
}
Prev
1
…
9
10
11
12
13
14
15
16
17
…
19
Next
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