function_name
stringlengths 1
80
| function
stringlengths 14
10.6k
| comment
stringlengths 12
8.02k
| normalized_comment
stringlengths 6
6.55k
|
|---|---|---|---|
cmdGetTime
|
cmdGetTime(CmdPacket *cmd) {
cmdResponseStart(CMD_RESP_V, sntp_get_current_timestamp(), 0);
cmdResponseEnd();
return;
}
|
/* Command handler for time*/
|
Command handler for time
|
cmdAddCallback
|
cmdAddCallback(CmdPacket *cmd) {
CmdRequest req;
cmdRequest(&req, cmd);
if (cmd->argc != 1 || cmd->value == 0) return;
char name[16];
uint16_t len;
// get the callback name
len = cmdArgLen(&req);
if (len > 15) return; // max size of name is 15 characters
if (cmdPopArg(&req, (uint8_t *)name, len)) return;
name[len] = 0;
DBG("cmdAddCallback: name=%s\n", name);
cmdAddCb(name, cmd->value); // save the sensor callback
}
|
/* Command handler to add a callback to the named-callbacks list, this is for a callback to the uC*/
|
Command handler to add a callback to the named-callbacks list, this is for a callback to the uC
|
cmdWifiGetApCount
|
static void ICACHE_FLASH_ATTR cmdWifiGetApCount(CmdPacket *cmd) {
int n = wifiGetApCount();
DBG("WifiGetApCount : %d\n", n);
cmdResponseStart(CMD_RESP_V, n, 0);
cmdResponseEnd();
}
|
/* Query the number of wifi access points*/
|
Query the number of wifi access points
|
cmdWifiGetApName
|
static void ICACHE_FLASH_ATTR cmdWifiGetApName(CmdPacket *cmd) {
CmdRequest req;
cmdRequest(&req, cmd);
int argc = cmdGetArgc(&req);
DBG("cmdWifiGetApName: argc %d\n", argc);
if (argc != 1)
return;
uint16_t i;
cmdPopArg(&req, (uint8_t*)&i, 2);
uint32_t callback = req.cmd->value;
char myssid[33];
wifiGetApName(i, myssid);
myssid[32] = '\0';
DBG("wifiGetApName(%d) -> {%s}\n", i, myssid);
cmdResponseStart(CMD_RESP_CB, callback, 1);
cmdResponseBody(myssid, strlen(myssid)+1);
cmdResponseEnd();
}
|
/* Query the name of a wifi access point*/
|
Query the name of a wifi access point
|
cmdWifiStartScan
|
static void ICACHE_FLASH_ATTR cmdWifiStartScan(CmdPacket *cmd) {
// call a function that belongs in esp-link/cgiwifi.c due to variable access
wifiStartScan();
}
|
/* Start scanning, API interface*/
|
Start scanning, API interface
|
cmdMqttGetClientId
|
void ICACHE_FLASH_ATTR cmdMqttGetClientId(CmdPacket *cmd) {
CmdRequest req;
cmdRequest(&req, cmd);
if(cmd->argc != 0 || cmd->value == 0) {
cmdResponseStart(CMD_RESP_V, 0, 0);
cmdResponseEnd();
return;
}
uint32_t callback = req.cmd->value;
cmdResponseStart(CMD_RESP_CB, callback, 1);
cmdResponseBody(flashConfig.mqtt_clientid, strlen(flashConfig.mqtt_clientid)+1);
cmdResponseEnd();
os_printf("MqttGetClientId : %s\n", flashConfig.mqtt_clientid);
}
|
/* Command handler for MQTT information*/
|
Command handler for MQTT information
|
cmdResponseStart
|
cmdResponseStart(uint16_t cmd, uint32_t value, uint16_t argc) {
DBG("cmdResponse: cmd=%d val=%d argc=%d\n", cmd, value, argc);
uart0_write_char(SLIP_END);
cmdProtoWriteBuf((uint8_t*)&cmd, 2);
resp_crc = crc16_data((uint8_t*)&cmd, 2, 0);
cmdProtoWriteBuf((uint8_t*)&argc, 2);
resp_crc = crc16_data((uint8_t*)&argc, 2, resp_crc);
cmdProtoWriteBuf((uint8_t*)&value, 4);
resp_crc = crc16_data((uint8_t*)&value, 4, resp_crc);
}
|
/* Start a response, returns the partial CRC*/
|
Start a response, returns the partial CRC
|
cmdResponseBody
|
cmdResponseBody(const void *data, uint16_t len) {
cmdProtoWriteBuf((uint8_t*)&len, 2);
resp_crc = crc16_data((uint8_t*)&len, 2, resp_crc);
cmdProtoWriteBuf(data, len);
resp_crc = crc16_data(data, len, resp_crc);
uint16_t pad = (4-((len+2)&3))&3; // get to multiple of 4
if (pad > 0) {
uint32_t temp = 0;
cmdProtoWriteBuf((uint8_t*)&temp, pad);
resp_crc = crc16_data((uint8_t*)&temp, pad, resp_crc);
}
}
|
/* Adds data to a response, returns the partial CRC*/
|
Adds data to a response, returns the partial CRC
|
cmdResponseEnd
|
cmdResponseEnd() {
cmdProtoWriteBuf((uint8_t*)&resp_crc, 2);
uart0_write_char(SLIP_END);
}
|
/* Ends a response*/
|
Ends a response
|
cmdExec
|
cmdExec(const CmdList *scp, CmdPacket *packet) {
// Iterate through the command table and call the appropriate function
while (scp->sc_function != NULL) {
if(scp->sc_name == packet->cmd) {
DBG("cmdExec: Dispatching cmd=%s\n", scp->sc_text);
// call command function
scp->sc_function(packet);
return;
}
scp++;
}
DBG("cmdExec: cmd=%d not found\n", packet->cmd);
}
|
/* Execute a parsed command*/
|
Execute a parsed command
|
cmdParsePacket
|
cmdParsePacket(uint8_t *buf, short len) {
// minimum command length
if (len < sizeof(CmdPacket)) return;
// init pointers into buffer
CmdPacket *packet = (CmdPacket*)buf;
uint8_t *data_ptr = (uint8_t*)&packet->args;
uint8_t *data_limit = data_ptr+len;
DBG("cmdParsePacket: cmd=%d argc=%d value=%u\n",
packet->cmd,
packet->argc,
packet->value
);
#if 0
// print out arguments
uint16_t argn = 0;
uint16_t argc = packet->argc;
while (data_ptr+2 < data_limit && argc--) {
short l = *(uint16_t*)data_ptr;
os_printf("cmdParsePacket: arg[%d] len=%d:", argn++, l);
data_ptr += 2;
while (data_ptr < data_limit && l--) {
os_printf(" %02X", *data_ptr++);
}
os_printf("\n");
}
#endif
if (!cmdInSync && packet->cmd != CMD_SYNC) {
// we have not received a sync, perhaps we reset? Tell MCU to do a sync
cmdResponseStart(CMD_SYNC, 0, 0);
cmdResponseEnd();
} else if (data_ptr <= data_limit) {
cmdExec(commands, packet);
} else {
DBG("cmdParsePacket: packet length overrun, parsing arg %d\n", packet->argc);
}
}
|
/* Parse a packet and print info about it*/
|
Parse a packet and print info about it
|
cmdRequest
|
cmdRequest(CmdRequest *req, CmdPacket* cmd) {
req->cmd = cmd;
req->arg_num = 0;
req->arg_ptr = (uint8_t*)&cmd->args;
}
|
/* Fill out a CmdRequest struct given a CmdPacket*/
|
Fill out a CmdRequest struct given a CmdPacket
|
cmdGetArgc
|
cmdGetArgc(CmdRequest *req) {
return req->cmd->argc;
}
|
/* Return the number of arguments given a command struct*/
|
Return the number of arguments given a command struct
|
cmdPopArg
|
cmdPopArg(CmdRequest *req, void *data, uint16_t len) {
uint16_t length;
if (req->arg_num >= req->cmd->argc)
return -1;
length = *(uint16_t*)req->arg_ptr;
if (length != len) return -1; // safety check
req->arg_ptr += 2;
os_memcpy(data, req->arg_ptr, length);
req->arg_ptr += (length+3)&~3; // round up to multiple of 4
req->arg_num ++;
return 0;
}
|
/* -1 on error*/
|
-1 on error
|
cmdSkipArg
|
cmdSkipArg(CmdRequest *req) {
uint16_t length;
if (req->arg_num >= req->cmd->argc) return;
length = *(uint16_t*)req->arg_ptr;
req->arg_ptr += 2;
req->arg_ptr += (length+3)&~3;
req->arg_num ++;
}
|
/* Skip the next argument*/
|
Skip the next argument
|
cmdArgLen
|
cmdArgLen(CmdRequest *req) {
return *(uint16_t*)req->arg_ptr;
}
|
/* Return the length of the next argument*/
|
Return the length of the next argument
|
multipartCreateContext
|
MultipartCtx * ICACHE_FLASH_ATTR multipartCreateContext(MultipartCallback callback)
{
MultipartCtx * ctx = (MultipartCtx *)os_malloc(sizeof(MultipartCtx));
ctx->callBack = callback;
ctx->position = ctx->startTime = ctx->recvPosition = ctx->boundaryBufferPtr = 0;
ctx->boundaryBuffer = NULL;
ctx->state = STATE_SEARCH_BOUNDARY;
return ctx;
}
|
/* this method is responsible for creating the multipart context*/
|
this method is responsible for creating the multipart context
|
multipartAllocBoundaryBuffer
|
void ICACHE_FLASH_ATTR multipartAllocBoundaryBuffer(MultipartCtx * context)
{
if( context->boundaryBuffer == NULL )
context->boundaryBuffer = (char *)os_malloc(3*BOUNDARY_SIZE + 1);
context->boundaryBufferPtr = 0;
}
|
/* for allocating buffer for multipart upload */
|
for allocating buffer for multipart upload
|
multipartFreeBoundaryBuffer
|
void ICACHE_FLASH_ATTR multipartFreeBoundaryBuffer(MultipartCtx * context)
{
if( context->boundaryBuffer != NULL )
{
os_free(context->boundaryBuffer);
context->boundaryBuffer = NULL;
}
}
|
/* for freeing multipart buffer*/
|
for freeing multipart buffer
|
multipartDestroyContext
|
void ICACHE_FLASH_ATTR multipartDestroyContext(MultipartCtx * context)
{
multipartFreeBoundaryBuffer(context);
os_free(context);
}
|
/* for destroying the context*/
|
for destroying the context
|
httpdGetMimetype
|
const char ICACHE_FLASH_ATTR *httpdGetMimetype(char *url) {
int i = 0;
//Go find the extension
char *ext = url + (strlen(url) - 1);
while (ext != url && *ext != '.') ext--;
if (*ext == '.') ext++;
//ToDo: os_strcmp is case sensitive; we may want to do case-intensive matching here...
while (mimeTypes[i].ext != NULL && os_strcmp(ext, mimeTypes[i].ext) != 0) i++;
return mimeTypes[i].mimetype;
}
|
/*Returns a static char* to a mime type for a given url to a file.*/
|
Returns a static char* to a mime type for a given url to a file.
|
httpdHexVal
|
static int httpdHexVal(char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
return 0;
}
|
/*Stupid li'l helper function that returns the value of a hex char.*/
|
Stupid li'l helper function that returns the value of a hex char.
|
httpdSetOutputBuffer
|
void ICACHE_FLASH_ATTR httpdSetOutputBuffer(HttpdConnData *conn, char *buff, short max) {
conn->priv->sendBuff = buff;
conn->priv->sendBuffLen = 0;
conn->priv->sendBuffMax = max;
}
|
/*Setup an output buffer*/
|
Setup an output buffer
|
httpdStartResponse
|
void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code) {
char buff[128];
int l;
conn->priv->code = code;
char *status = code < 400 ? "OK" : "ERROR";
l = os_sprintf(buff, "HTTP/1.0 %d %s\r\nServer: esp-link\r\nConnection: close\r\n", code, status);
httpdSend(conn, buff, l);
}
|
/*Start the response headers.*/
|
Start the response headers.
|
httpdHeader
|
void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const char *val) {
char buff[256];
int l;
l = os_sprintf(buff, "%s: %s\r\n", field, val);
httpdSend(conn, buff, l);
}
|
/*Send a http header.*/
|
Send a http header.
|
httpdEndHeaders
|
void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn) {
httpdSend(conn, "\r\n", -1);
}
|
/*Finish the headers.*/
|
Finish the headers.
|
httpdRedirect
|
void ICACHE_FLASH_ATTR httpdRedirect(HttpdConnData *conn, char *newUrl) {
char buff[1024];
int l;
conn->priv->code = 302;
l = os_sprintf(buff, "HTTP/1.0 302 Found\r\nServer: esp8266-link\r\nConnection: close\r\n"
"Location: %s\r\n\r\nRedirecting to %s\r\n", newUrl, newUrl);
httpdSend(conn, buff, l);
}
|
/*Redirect to the given URL.*/
|
Redirect to the given URL.
|
cgiRedirect
|
int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) {
if (connData->conn == NULL) {
//Connection aborted. Clean up.
return HTTPD_CGI_DONE;
}
httpdRedirect(connData, (char*)connData->cgiArg);
return HTTPD_CGI_DONE;
}
|
/*Use this as a cgi function to redirect one url to another.*/
|
Use this as a cgi function to redirect one url to another.
|
httpdSend
|
int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len) {
if (len<0) len = strlen(data);
if (conn->priv->sendBuffLen + len>conn->priv->sendBuffMax) {
DBG("%sERROR! httpdSend full (%d of %d)\n",
connStr, conn->priv->sendBuffLen, conn->priv->sendBuffMax);
return 0;
}
os_memcpy(conn->priv->sendBuff + conn->priv->sendBuffLen, data, len);
conn->priv->sendBuffLen += len;
return 1;
}
|
/*Returns 1 for success, 0 for out-of-memory.*/
|
Returns 1 for success, 0 for out-of-memory.
|
httpdFlush
|
void ICACHE_FLASH_ATTR httpdFlush(HttpdConnData *conn) {
if (conn->priv->sendBuffLen != 0) {
sint8 status = espconn_sent(conn->conn, (uint8_t*)conn->priv->sendBuff, conn->priv->sendBuffLen);
if (status != 0) {
DBG("%sERROR! espconn_sent returned %d, trying to send %d to %s\n",
connStr, status, conn->priv->sendBuffLen, conn->url);
}
conn->priv->sendBuffLen = 0;
}
}
|
/*Helper function to send any data in conn->priv->sendBuff*/
|
Helper function to send any data in conn->priv->sendBuff
|
httpdReconCb
|
static void ICACHE_FLASH_ATTR httpdReconCb(void *arg, sint8 err) {
debugConn(arg, "httpdReconCb");
struct espconn* pCon = (struct espconn *)arg;
HttpdConnData *conn = (HttpdConnData *)pCon->reverse;
if (conn == NULL) return; // aborted connection
DBG("%s***** reset, err=%d\n", connStr, err);
httpdRetireConn(conn);
}
|
/* of "you need to reconnect". Sigh... Note that there is no DisconCb after ReconCb*/
|
of "you need to reconnect". Sigh... Note that there is no DisconCb after ReconCb
|
httpdInit
|
void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, int port) {
int i;
for (i = 0; i<MAX_CONN; i++) {
connData[i].conn = NULL;
}
httpdConn.type = ESPCONN_TCP;
httpdConn.state = ESPCONN_NONE;
httpdTcp.local_port = port;
httpdConn.proto.tcp = &httpdTcp;
builtInUrls = fixedUrls;
DBG("Httpd init, conn=%p\n", &httpdConn);
espconn_regist_connectcb(&httpdConn, httpdConnectCb);
espconn_accept(&httpdConn);
espconn_tcp_set_max_con_allow(&httpdConn, MAX_CONN);
}
|
/*Httpd initialization routine. Call this to kick off webserver functionality.*/
|
Httpd initialization routine. Call this to kick off webserver functionality.
|
httpdLookUpConn
|
HttpdConnData * ICACHE_FLASH_ATTR httpdLookUpConn(uint8_t * ip, int port) {
int i;
for (i = 0; i<MAX_CONN; i++)
{
HttpdConnData *conn = connData+i;
if (conn->conn == NULL)
continue;
if (conn->cgi == NULL)
continue;
if (conn->conn->proto.tcp->remote_port != port )
continue;
if (os_memcmp(conn->conn->proto.tcp->remote_ip, ip, 4) != 0)
continue;
return conn;
}
return NULL;
}
|
/* looks up connection handle based on ip / port*/
|
looks up connection handle based on ip / port
|
app_init
|
void app_init() {
}
|
/* initialize the custom stuff that goes beyond esp-link*/
|
initialize the custom stuff that goes beyond esp-link
|
setNow
|
static inline void setNow(void)
{
g_now.ms = f_time_getMs();
g_now.ticks = f_fps_ticksGet();
}
|
/* list of FTimer*/
|
list of FTimer
|
f_collection__get
|
FCollection* f_collection__get(void)
{
return g_current;
}
|
/* New entities are added to this collection*/
|
New entities are added to this collection
|
f_ecs__init
|
static void f_ecs__init(void)
{
for(int i = F_ECS__NUM; i--; ) {
g_lists[i] = f_list_new();
}
f_component__init();
f_system__init();
f_template__init();
}
|
/* Set to prevent using freed entities*/
|
Set to prevent using freed entities
|
f_embed__init
|
static void f_embed__init(void)
{
g_dirs = f_strhash_new();
g_files = f_strhash_new();
#if F_CONFIG_FILES_EMBED
f_embed__populate();
#endif
}
|
/* table of FEmbeddedFile*/
|
table of FEmbeddedFile
|
f_input_button__init
|
void f_input_button__init(void)
{
g_buttons = f_list_new();
}
|
/* list of FButton*/
|
list of FButton
|
skipVariableMarker
|
static uint8 skipVariableMarker(void)
{
uint16 left = getBits1(16);
if (left < 2)
return PJPG_BAD_VARIABLE_MARKER;
left -= 2;
while (left)
{
getBits1(8);
left--;
}
return 0;
}
|
/* Used to skip unrecognized markers.*/
|
Used to skip unrecognized markers.
|
readDRIMarker
|
static uint8 readDRIMarker(void)
{
if (getBits1(16) != 4)
return PJPG_BAD_DRI_LENGTH;
gRestartInterval = getBits1(16);
return 0;
}
|
/* Read a define restart interval (DRI) marker.*/
|
Read a define restart interval (DRI) marker.
|
locateSOFMarker
|
static uint8 locateSOFMarker(void)
{
uint8 c;
uint8 status = locateSOIMarker();
if (status)
return status;
status = processMarkers(&c);
if (status)
return status;
switch (c)
{
case M_SOF2:
{
// Progressive JPEG - not supported by picojpeg (would require too
// much memory, or too many IDCT's for embedded systems).
return PJPG_UNSUPPORTED_MODE;
}
case M_SOF0: /* baseline DCT */
{
status = readSOFMarker();
if (status)
return status;
break;
}
case M_SOF9:
{
return PJPG_NO_ARITHMITIC_SUPPORT;
}
case M_SOF1: /* extended sequential DCT */
default:
{
return PJPG_UNSUPPORTED_MARKER;
}
}
return 0;
}
|
/* Find a start of frame (SOF) marker.*/
|
Find a start of frame (SOF) marker.
|
locateSOSMarker
|
static uint8 locateSOSMarker(uint8* pFoundEOI)
{
uint8 c;
uint8 status;
*pFoundEOI = 0;
status = processMarkers(&c);
if (status)
return status;
if (c == M_EOI)
{
*pFoundEOI = 1;
return 0;
}
else if (c != M_SOS)
return PJPG_UNEXPECTED_MARKER;
return readSOSMarker();
}
|
/* Find a start of scan (SOS) marker.*/
|
Find a start of scan (SOS) marker.
|
fixInBuffer
|
static void fixInBuffer(void)
{
/* In case any 0xFF's where pulled into the buffer during marker scanning */
if (gBitsLeft > 0)
stuffChar((uint8)gBitBuf);
stuffChar((uint8)(gBitBuf >> 8));
gBitsLeft = 8;
getBits2(8);
getBits2(8);
}
|
/* into the bit buffer during initial marker scanning.*/
|
into the bit buffer during initial marker scanning.
|
createWinogradQuant
|
static void createWinogradQuant(int16* pQuant)
{
uint8 i;
for (i = 0; i < 64; i++)
{
long x = pQuant[i];
x *= gWinogradQuant[i];
pQuant[i] = (int16)((x + (1 << (PJPG_WINOGRAD_QUANT_SCALE_BITS - PJPG_DCT_SCALE_BITS - 1))) >> (PJPG_WINOGRAD_QUANT_SCALE_BITS - PJPG_DCT_SCALE_BITS));
}
}
|
/* Multiply quantization matrix by the Winograd IDCT scale factors*/
|
Multiply quantization matrix by the Winograd IDCT scale factors
|
imul_b1_b3
|
static PJPG_INLINE int16 imul_b1_b3(int16 w)
{
long x = (w * 362L);
x += 128L;
return (int16)(PJPG_ARITH_SHIFT_RIGHT_8_L(x));
}
|
/* 362, 256+106*/
|
362, 256+106
|
imul_b2
|
static PJPG_INLINE int16 imul_b2(int16 w)
{
long x = (w * 669L);
x += 128L;
return (int16)(PJPG_ARITH_SHIFT_RIGHT_8_L(x));
}
|
/* 669, 256+256+157*/
|
669, 256+256+157
|
imul_b4
|
static PJPG_INLINE int16 imul_b4(int16 w)
{
long x = (w * 277L);
x += 128L;
return (int16)(PJPG_ARITH_SHIFT_RIGHT_8_L(x));
}
|
/* 277, 256+21*/
|
277, 256+21
|
copyY
|
static void copyY(uint8 dstOfs)
{
uint8 i;
uint8* pRDst = gMCUBufR + dstOfs;
uint8* pGDst = gMCUBufG + dstOfs;
uint8* pBDst = gMCUBufB + dstOfs;
int16* pSrc = gCoeffBuf;
for (i = 64; i > 0; i--)
{
uint8 c = (uint8)*pSrc++;
*pRDst++ = c;
*pGDst++ = c;
*pBDst++ = c;
}
}
|
/* Convert Y to RGB*/
|
Convert Y to RGB
|
convertCb
|
static void convertCb(uint8 dstOfs)
{
uint8 i;
uint8* pDstG = gMCUBufG + dstOfs;
uint8* pDstB = gMCUBufB + dstOfs;
int16* pSrc = gCoeffBuf;
for (i = 64; i > 0; i--)
{
uint8 cb = (uint8)*pSrc++;
int16 cbG, cbB;
cbG = ((cb * 88U) >> 8U) - 44U;
pDstG[0] = subAndClamp(pDstG[0], cbG);
cbB = (cb + ((cb * 198U) >> 8U)) - 227U;
pDstB[0] = addAndClamp(pDstB[0], cbB);
++pDstG;
++pDstB;
}
}
|
/* Cb convert to RGB and accumulate*/
|
Cb convert to RGB and accumulate
|
convertCr
|
static void convertCr(uint8 dstOfs)
{
uint8 i;
uint8* pDstR = gMCUBufR + dstOfs;
uint8* pDstG = gMCUBufG + dstOfs;
int16* pSrc = gCoeffBuf;
for (i = 64; i > 0; i--)
{
uint8 cr = (uint8)*pSrc++;
int16 crR, crG;
crR = (cr + ((cr * 103U) >> 8U)) - 179;
pDstR[0] = addAndClamp(pDstR[0], crR);
crG = ((cr * 183U) >> 8U) - 91;
pDstG[0] = subAndClamp(pDstG[0], crG);
++pDstR;
++pDstG;
}
}
|
/* Cr convert to RGB and accumulate*/
|
Cr convert to RGB and accumulate
|
lv_img_decoder_built_in_close
|
void lv_img_decoder_built_in_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
{
(void)decoder; /*Unused*/
lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
if(user_data) {
#if LV_USE_FILESYSTEM
if(user_data->f) {
lv_fs_close(user_data->f);
lv_mem_free(user_data->f);
}
#endif
if(user_data->palette) lv_mem_free(user_data->palette);
if(user_data->opa) lv_mem_free(user_data->opa);
lv_mem_free(user_data);
dsc->user_data = NULL;
}
}
|
/**
* Close the pending decoding. Free resources etc.
* @param decoder pointer to the decoder the function associated with
* @param dsc pointer to decoder descriptor
*/
|
Close the pending decoding. Free resources etc. @param decoder pointer to the decoder the function associated with @param dsc pointer to decoder descriptor
|
lv_obj_invalidate
|
void lv_obj_invalidate(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
/*Truncate the area to the object*/
lv_area_t obj_coords;
lv_coord_t ext_size = obj->ext_draw_pad;
lv_area_copy(&obj_coords, &obj->coords);
obj_coords.x1 -= ext_size;
obj_coords.y1 -= ext_size;
obj_coords.x2 += ext_size;
obj_coords.y2 += ext_size;
lv_obj_invalidate_area(obj, &obj_coords);
}
|
/**
* Mark the object as invalid therefore its current position will be redrawn by 'lv_refr_task'
* @param obj pointer to an object
*/
|
Mark the object as invalid therefore its current position will be redrawn by 'lv_refr_task' @param obj pointer to an object
|
lv_mem_deinit
|
void lv_mem_deinit(void)
{
#if LV_MEM_CUSTOM == 0
memset(work_mem, 0x00, (LV_MEM_SIZE / sizeof(MEM_UNIT)) * sizeof(MEM_UNIT));
lv_mem_ent_t * full = (lv_mem_ent_t *)work_mem;
full->header.s.used = 0;
/*The total mem size id reduced by the first header and the close patterns */
full->header.s.d_size = LV_MEM_SIZE - sizeof(lv_mem_header_t);
#endif
}
|
/**
* Clean up the memory buffer which frees all the allocated memories.
* @note It work only if `LV_MEM_CUSTOM == 0`
*/
|
Clean up the memory buffer which frees all the allocated memories. @note It work only if `LV_MEM_CUSTOM == 0`
|
default_extension_encoder
|
static bool checkreturn default_extension_encoder(pb_ostream_t *stream,
const pb_extension_t *extension)
{
const pb_field_t *field = (const pb_field_t*)extension->type->arg;
if (PB_ATYPE(field->type) == PB_ATYPE_POINTER)
{
/* For pointer extensions, the pointer is stored directly
* in the extension structure. This avoids having an extra
* indirection. */
return encode_field(stream, field, &extension->dest);
}
else
{
return encode_field(stream, field, extension->dest);
}
}
|
/* Default handler for extension fields. Expects to have a pb_field_t
* pointer in the extension->type->arg field. */
|
Default handler for extension fields. Expects to have a pb_field_t pointer in the extension->type->arg field.
|
pb_readbyte
|
static bool checkreturn pb_readbyte(pb_istream_t *stream, pb_byte_t *buf)
{
if (stream->bytes_left == 0)
PB_RETURN_ERROR(stream, "end-of-stream");
#ifndef PB_BUFFER_ONLY
if (!stream->callback(stream, buf, 1))
PB_RETURN_ERROR(stream, "io error");
#else
*buf = *(const pb_byte_t*)stream->state;
stream->state = (pb_byte_t*)stream->state + 1;
#endif
stream->bytes_left--;
return true;
}
|
/* Read a single byte from input stream. buf may not be NULL.
* This is an optimization for the varint decoding. */
|
Read a single byte from input stream. buf may not be NULL. This is an optimization for the varint decoding.
|
default_extension_decoder
|
static bool checkreturn default_extension_decoder(pb_istream_t *stream,
pb_extension_t *extension, uint32_t tag, pb_wire_type_t wire_type)
{
const pb_field_t *field = (const pb_field_t*)extension->type->arg;
pb_field_iter_t iter;
if (field->tag != tag)
return true;
iter_from_extension(&iter, extension);
extension->found = true;
return decode_field(stream, wire_type, &iter);
}
|
/* Default handler for extension fields. Expects a pb_field_t structure
* in extension->type->arg. */
|
Default handler for extension fields. Expects a pb_field_t structure in extension->type->arg.
|
dumpCmdQueue
|
void IRAM_ATTR dumpCmdQueue(i2c_t *i2c)
{
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
uint8_t i=0;
while(i<16) {
I2C_COMMAND_t c;
c.val=i2c->dev->command[i].val;
log_e("[%2d] %c op[%d] val[%d] exp[%d] en[%d] bytes[%d]",i,(c.done?'Y':'N'),
c.op_code,
c.ack_val,
c.ack_exp,
c.ack_en,
c.byte_num);
i++;
}
#endif
}
|
/* Stickbreaker ISR mode debug support
*/
|
Stickbreaker ISR mode debug support
|
fix16_log2
|
fix16_t fix16_log2(fix16_t x)
{
// Note that a negative x gives a non-real result.
// If x == 0, the limit of log2(x) as x -> 0 = -infinity.
// log2(-ve) gives a complex result.
if (x <= 0) return fix16_overflow;
// If the input is less than one, the result is -log2(1.0 / in)
if (x < fix16_one)
{
// Note that the inverse of this would overflow.
// This is the exact answer for log2(1.0 / 65536)
if (x == 1) return fix16_from_int(-16);
fix16_t inverse = fix16_div(fix16_one, x);
return -fix16__log2_inner(inverse);
}
// If input >= 1, just proceed as normal.
// Note that x == fix16_one is a special case, where the answer is 0.
return fix16__log2_inner(x);
}
|
/**
* calculates the log base 2 of input.
* Note that negative inputs are invalid! (will return fix16_overflow, since there are no exceptions)
*
* i.e. 2 to the power output = input.
* It's equivalent to the log or ln functions, except it uses base 2 instead of base 10 or base e.
* This is useful as binary things like this are easy for binary devices, like modern microprocessros, to calculate.
*
* This can be used as a helper function to calculate powers with non-integer powers and/or bases.
*/
|
calculates the log base 2 of input. Note that negative inputs are invalid! (will return fix16_overflow, since there are no exceptions)
i.e. 2 to the power output = input. It's equivalent to the log or ln functions, except it uses base 2 instead of base 10 or base e. This is useful as binary things like this are easy for binary devices, like modern microprocessros, to calculate.
This can be used as a helper function to calculate powers with non-integer powers and/or bases.
|
fix16_slog2
|
fix16_t fix16_slog2(fix16_t x)
{
fix16_t retval = fix16_log2(x);
// The only overflow possible is when the input is negative.
if(retval == fix16_overflow)
return fix16_minimum;
return retval;
}
|
/**
* This is a wrapper for fix16_log2 which implements saturation arithmetic.
*/
|
This is a wrapper for fix16_log2 which implements saturation arithmetic.
|
fix16_add
|
fix16_t fix16_add(fix16_t a, fix16_t b)
{
// Use unsigned integers because overflow with signed integers is
// an undefined operation (http://www.airs.com/blog/archives/120).
uint32_t _a = a, _b = b;
uint32_t sum = _a + _b;
// Overflow can only happen if sign of a == sign of b, and then
// it causes sign of sum != sign of a.
if (!((_a ^ _b) & 0x80000000) && ((_a ^ sum) & 0x80000000))
return fix16_overflow;
return sum;
}
|
/* Subtraction and addition with overflow detection.
* The versions without overflow detection are inlined in the header.
*/
|
Subtraction and addition with overflow detection. The versions without overflow detection are inlined in the header.
|
fix16_smul
|
fix16_t fix16_smul(fix16_t inArg0, fix16_t inArg1)
{
fix16_t result = fix16_mul(inArg0, inArg1);
if (result == fix16_overflow)
{
if ((inArg0 >= 0) == (inArg1 >= 0))
return fix16_maximum;
else
return fix16_minimum;
}
return result;
}
|
/* Wrapper around fix16_mul to add saturating arithmetic. */
|
Wrapper around fix16_mul to add saturating arithmetic.
|
fix16_sdiv
|
fix16_t fix16_sdiv(fix16_t inArg0, fix16_t inArg1)
{
fix16_t result = fix16_div(inArg0, inArg1);
if (result == fix16_overflow)
{
if ((inArg0 >= 0) == (inArg1 >= 0))
return fix16_maximum;
else
return fix16_minimum;
}
return result;
}
|
/* Wrapper around fix16_div to add saturating arithmetic. */
|
Wrapper around fix16_div to add saturating arithmetic.
|
get_vlen_of_uint16
|
int8_t get_vlen_of_uint16(uint16_t vint) {
return vint > 16383 ? 3 : (vint > 127 ? 2 : 1);
}
|
/* occupy if stored as a variable integer*/
|
occupy if stored as a variable integer
|
get_vlen_of_uint32
|
int8_t get_vlen_of_uint32(uint32_t vint) {
return vint > 268435455 ? 5 : (vint > 2097151 ? 4
: (vint > 16383 ? 3 : (vint > 127 ? 2 : 1)));
}
|
/* occupy if stored as a variable integer*/
|
occupy if stored as a variable integer
|
write_uint8
|
void write_uint8(byte *ptr, uint8_t input) {
ptr[0] = input;
}
|
/* in big-endian sequence*/
|
in big-endian sequence
|
write_uint16
|
void write_uint16(byte *ptr, uint16_t input) {
ptr[0] = input >> 8;
ptr[1] = input & 0xFF;
}
|
/* in big-endian sequence*/
|
in big-endian sequence
|
write_uint32
|
void write_uint32(byte *ptr, uint32_t input) {
int i = 4;
while (i--)
*ptr++ = (input >> (8 * i)) & 0xFF;
}
|
/* in big-endian sequence*/
|
in big-endian sequence
|
write_uint64
|
void write_uint64(byte *ptr, uint64_t input) {
int i = 8;
while (i--)
*ptr++ = (input >> (8 * i)) & 0xFF;
}
|
/* in big-endian sequence*/
|
in big-endian sequence
|
write_vint16
|
int write_vint16(byte *ptr, uint16_t vint) {
int len = get_vlen_of_uint16(vint);
for (int i = len - 1; i > 0; i--)
*ptr++ = 0x80 + ((vint >> (7 * i)) & 0x7F);
*ptr = vint & 0x7F;
return len;
}
|
/* in variable integer format*/
|
in variable integer format
|
write_vint32
|
int write_vint32(byte *ptr, uint32_t vint) {
int len = get_vlen_of_uint32(vint);
for (int i = len - 1; i > 0; i--)
*ptr++ = 0x80 + ((vint >> (7 * i)) & 0x7F);
*ptr = vint & 0x7F;
return len;
}
|
/* in variable integer format*/
|
in variable integer format
|
read_uint8
|
uint8_t read_uint8(byte *ptr) {
return *ptr;
}
|
/* at a given memory location*/
|
at a given memory location
|
read_uint16
|
uint16_t read_uint16(byte *ptr) {
return (*ptr << 8) + ptr[1];
}
|
/* at a given memory location*/
|
at a given memory location
|
read_uint32
|
uint32_t read_uint32(byte *ptr) {
uint32_t ret;
ret = ((uint32_t)*ptr++) << 24;
ret += ((uint32_t)*ptr++) << 16;
ret += ((uint32_t)*ptr++) << 8;
ret += *ptr;
return ret;
}
|
/* at a given memory location*/
|
at a given memory location
|
read_uint64
|
uint64_t read_uint64(byte *ptr) {
uint32_t ret = 0;
int len = 8;
while (len--)
ret += (*ptr++ << (8 * len));
return ret;
}
|
/* at a given memory location*/
|
at a given memory location
|
read_vint16
|
uint16_t read_vint16(byte *ptr, int8_t *vlen) {
uint16_t ret = 0;
int8_t len = 3; // read max 3 bytes
do {
ret <<= 7;
ret += *ptr & 0x7F;
len--;
} while ((*ptr++ & 0x80) == 0x80 && len);
if (vlen)
*vlen = 3 - len;
return ret;
}
|
/* Also returns the length of the varint*/
|
Also returns the length of the varint
|
read_vint32
|
uint32_t read_vint32(byte *ptr, int8_t *vlen) {
uint32_t ret = 0;
int8_t len = 5; // read max 5 bytes
do {
ret <<= 7;
ret += *ptr & 0x7F;
len--;
} while ((*ptr++ & 0x80) == 0x80 && len);
if (vlen)
*vlen = 5 - len;
return ret;
}
|
/* Also returns the length of the varint*/
|
Also returns the length of the varint
|
float_to_double
|
int64_t float_to_double(const void *val) {
uint32_t bytes = *((uint32_t *) val);
uint8_t exp8 = (bytes >> 23) & 0xFF;
uint16_t exp11 = exp8;
if (exp11 != 0) {
if (exp11 < 127)
exp11 = 1023 - (127 - exp11);
else
exp11 = 1023 + (exp11 - 127);
}
return ((int64_t)(bytes >> 31) << 63)
| ((int64_t)exp11 << 52)
| ((int64_t)(bytes & 0x7FFFFF) << (52-23) );
}
|
/* Converts float to Sqlite's Big-endian double*/
|
Converts float to Sqlite's Big-endian double
|
get_pagesize
|
int32_t get_pagesize(byte page_size_exp) {
return (int32_t) 1 << page_size_exp;
}
|
/* Returns actual page size from given exponent*/
|
Returns actual page size from given exponent
|
acquire_last_pos
|
uint16_t acquire_last_pos(struct dblog_write_context *wctx, byte *ptr) {
uint16_t last_pos = read_uint16(ptr + 5);
if (last_pos == 0) {
dblog_append_empty_row(wctx);
last_pos = read_uint16(ptr + 5);
}
return last_pos;
}
|
/* Creates one, if no record found.*/
|
Creates one, if no record found.
|
derive_col_type_or_len
|
uint32_t derive_col_type_or_len(int type, const void *val, int len) {
uint32_t col_type_or_len = 0;
if (val != NULL) {
switch (type) {
case DBLOG_TYPE_INT:
col_type_or_len = (len == 1 ? 1 : (len == 2 ? 2 : (len == 4 ? 4 : 6)));
//if (len == 1) {
// int8_t *typed_val = (int8_t *) val;
// col_type_or_len = (*typed_val == 0 ? 8 : (*typed_val == 1 ? 9 : 0));
//} else
// col_type_or_len = (len == 2 ? 2 : (len == 4 ? 4 : 6));
break;
case DBLOG_TYPE_REAL:
col_type_or_len = 7;
break;
case DBLOG_TYPE_BLOB:
col_type_or_len = len * 2 + 12;
break;
case DBLOG_TYPE_TEXT:
col_type_or_len = len * 2 + 13;
}
}
return col_type_or_len;
}
|
/* See https://www.sqlite.org/fileformat.html#record_format*/
|
See https://www.sqlite.org/fileformat.html#record_format
|
init_bt_tbl_leaf
|
void init_bt_tbl_leaf(byte *ptr) {
ptr[0] = 13; // Leaf table b-tree page
write_uint16(ptr + 1, 0); // No freeblocks
write_uint16(ptr + 3, 0); // No records yet
write_uint16(ptr + 5, 0); // No records yet
write_uint8(ptr + 7, 0); // Fragmented free bytes
}
|
/* Initializes the buffer as a B-Tree Leaf table*/
|
Initializes the buffer as a B-Tree Leaf table
|
init_bt_tbl_inner
|
void init_bt_tbl_inner(byte *ptr) {
ptr[0] = 5; // Interior table b-tree page
write_uint16(ptr + 1, 0); // No freeblocks
write_uint16(ptr + 3, 0); // No records yet
write_uint16(ptr + 5, 0); // No records yet
write_uint8(ptr + 7, 0); // Fragmented free bytes
}
|
/* Initializes the buffer as a B-Tree Interior table*/
|
Initializes the buffer as a B-Tree Interior table
|
write_rec_len_rowid_hdr_len
|
void write_rec_len_rowid_hdr_len(byte *ptr, uint16_t rec_len, uint32_t rowid, uint16_t hdr_len) {
// write record len
*ptr++ = 0x80 + (rec_len >> 14);
*ptr++ = 0x80 + ((rec_len >> 7) & 0x7F);
*ptr++ = rec_len & 0x7F;
// write row id
ptr += write_vint32(ptr, rowid);
// write header len
*ptr++ = 0x80 + (hdr_len >> 7);
*ptr = hdr_len & 0x7F;
}
|
/* No corruption checking because no unreliable source*/
|
No corruption checking because no unreliable source
|
write_page
|
int write_page(struct dblog_write_context *wctx, uint32_t page_no, int32_t page_size) {
check_sums(wctx->buf, page_size, 0);
if ((wctx->write_fn)(wctx, wctx->buf, page_no * page_size, page_size) != page_size)
return DBLOG_RES_WRITE_ERR;
return DBLOG_RES_OK;
}
|
/* Writes a page to disk using the given callback function*/
|
Writes a page to disk using the given callback function
|
read_bytes_wctx
|
int read_bytes_wctx(struct dblog_write_context *wctx, byte *buf, long pos, int32_t size) {
if ((wctx->read_fn)(wctx, buf, pos, size) != size)
return DBLOG_RES_READ_ERR;
return DBLOG_RES_OK;
}
|
/* for Write context*/
|
for Write context
|
read_bytes_rctx
|
int read_bytes_rctx(struct dblog_read_context *rctx, byte *buf, long pos, int32_t size) {
if ((rctx->read_fn)(rctx, buf, pos, size) != size)
return DBLOG_RES_READ_ERR;
return DBLOG_RES_OK;
}
|
/* for Read context*/
|
for Read context
|
get_col_val
|
const void *get_col_val(byte *buf, uint16_t rec_data_pos,
int col_idx, uint32_t *out_col_type, uint16_t limit) {
byte *data_ptr;
uint16_t rec_len;
uint16_t hdr_len;
byte *hdr_ptr = locate_column(buf + rec_data_pos, col_idx,
&data_ptr, &rec_len, &hdr_len, limit);
if (!hdr_ptr)
return NULL;
int8_t cur_len_of_len;
*out_col_type = read_vint32(hdr_ptr, &cur_len_of_len);
return data_ptr;
}
|
/* See https://www.sqlite.org/fileformat.html#record_format*/
|
See https://www.sqlite.org/fileformat.html#record_format
|
check_signature
|
int check_signature(byte *buf) {
if (memcmp(buf, dblog_sig, 16) && memcmp(buf, sqlite_sig, 16))
return DBLOG_RES_INVALID_SIG;
if (buf[68] != 0xA5)
return DBLOG_RES_INVALID_SIG;
return DBLOG_RES_OK;
}
|
/* Checks possible signatures that a file can have*/
|
Checks possible signatures that a file can have
|
get_page_size_exp
|
byte get_page_size_exp(int32_t page_size) {
if (page_size == 1)
return 16;
byte exp = 9;
while (page_size >> exp)
exp++;
return exp - 1;
}
|
/* Returns exponent for given page size*/
|
Returns exponent for given page size
|
dblog_write_init_with_script
|
int dblog_write_init_with_script(struct dblog_write_context *wctx,
char *table_name, char *table_script) {
return form_page1(wctx, table_name, table_script);
}
|
/* See .h file for API description*/
|
See .h file for API description
|
dblog_write_init
|
int dblog_write_init(struct dblog_write_context *wctx) {
return dblog_write_init_with_script(wctx, 0, 0);
}
|
/* See .h file for API description*/
|
See .h file for API description
|
dblog_get_col_val
|
const void *dblog_get_col_val(struct dblog_write_context *wctx,
int col_idx, uint32_t *out_col_type) {
int32_t page_size = get_pagesize(wctx->page_size_exp);
uint16_t last_pos = read_uint16(wctx->buf + 5);
if (last_pos == 0)
return NULL;
if (last_pos > page_size - wctx->page_resv_bytes - 7)
return NULL;
return get_col_val(wctx->buf, last_pos, col_idx,
out_col_type, page_size - wctx->page_resv_bytes - last_pos);
}
|
/* See .h file for API description*/
|
See .h file for API description
|
dblog_flush
|
int dblog_flush(struct dblog_write_context *wctx) {
int32_t page_size = get_pagesize(wctx->page_size_exp);
int res = write_page(wctx, wctx->cur_write_page, page_size);
if (res)
return res;
int ret = wctx->flush_fn(wctx);
if (!ret)
wctx->state = DBLOG_ST_WRITE_NOT_PENDING;
return ret;
}
|
/* See .h file for API description*/
|
See .h file for API description
|
dblog_not_finalized
|
int dblog_not_finalized(struct dblog_write_context *wctx) {
int res = read_bytes_wctx(wctx, wctx->buf, 0, 72);
if (res)
return res;
if (memcmp(wctx->buf, sqlite_sig, 16) == 0)
return DBLOG_RES_OK;
return DBLOG_RES_NOT_FINALIZED;
}
|
/* See .h file for API description*/
|
See .h file for API description
|
dblog_recover
|
int dblog_recover(struct dblog_write_context *wctx) {
wctx->state = DBLOG_ST_TO_RECOVER;
wctx->cur_write_page = 0;
int res = dblog_finalize(wctx);
if (res)
return res;
return DBLOG_RES_OK;
}
|
/* See .h file for API description*/
|
See .h file for API description
|
read_cur_page
|
int read_cur_page(struct dblog_read_context *rctx) {
int32_t page_size = get_pagesize(rctx->page_size_exp);
int res = read_bytes_rctx(rctx, rctx->buf, rctx->cur_page * page_size, page_size);
if (res)
return res;
if (rctx->buf[0] != 13)
return DBLOG_RES_NOT_FOUND;
return DBLOG_RES_OK;
}
|
/* Reads current page*/
|
Reads current page
|
dblog_read_col_val
|
const void *dblog_read_col_val(struct dblog_read_context *rctx,
int col_idx, uint32_t *out_col_type) {
if (rctx->cur_page == 0)
dblog_read_first_row(rctx);
uint16_t rec_pos = read_uint16(rctx->buf + 8 + rctx->cur_rec_pos * 2);
return get_col_val(rctx->buf, rec_pos, col_idx, out_col_type,
get_pagesize(rctx->page_size_exp) - rec_pos);
}
|
/* See .h file for API description*/
|
See .h file for API description
|
dblog_derive_data_len
|
uint32_t dblog_derive_data_len(uint32_t col_type_or_len) {
if (col_type_or_len >= 12) {
if (col_type_or_len % 2)
return (col_type_or_len - 13)/2;
return (col_type_or_len - 12)/2;
} else
if (col_type_or_len < 8)
return col_data_lens[col_type_or_len];
return 0;
}
|
/* See .h file for API description*/
|
See .h file for API description
|
dblog_read_first_row
|
int dblog_read_first_row(struct dblog_read_context *rctx) {
rctx->cur_page = 1;
if (read_cur_page(rctx))
return DBLOG_RES_NOT_FOUND;
rctx->cur_rec_pos = 0;
return DBLOG_RES_OK;
}
|
/* See .h file for API description*/
|
See .h file for API description
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.