update espnow api

This commit is contained in:
MicroDev 2023-01-23 23:10:00 +05:30
parent f15e84de6c
commit 3c10dd8b5f
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
7 changed files with 415 additions and 462 deletions

View File

@ -124,7 +124,7 @@ msgstr ""
msgid "%q init failed"
msgstr ""
#: shared-bindings/dualbank/__init__.c
#: ports/espressif/bindings/espnow/ESPNow.c shared-bindings/dualbank/__init__.c
msgid "%q is %q"
msgstr ""
@ -2430,7 +2430,7 @@ msgstr ""
msgid "addresses is empty"
msgstr ""
#: ports/espressif/bindings/espnow/Now.c
#: ports/espressif/bindings/espnow/ESPNow.c
msgid "an error occured"
msgstr ""
@ -3814,6 +3814,10 @@ msgstr ""
msgid "parameters must be registers in sequence r0 to r3"
msgstr ""
#: ports/espressif/bindings/espnow/ESPNow.c
msgid "peer already exists"
msgstr ""
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
msgid "pixel coordinates out of bounds"
msgstr ""
@ -4158,10 +4162,6 @@ msgstr ""
msgid "unindent doesn't match any outer indent level"
msgstr ""
#: ports/espressif/bindings/espnow/Now.c
msgid "unknown config param"
msgstr ""
#: py/objstr.c
#, c-format
msgid "unknown conversion specifier %c"

View File

@ -27,7 +27,7 @@
#include "shared-bindings/util.h"
#include "bindings/espnow/__init__.h"
#include "bindings/espnow/Now.h"
#include "bindings/espnow/ESPNow.h"
//| """ESP-NOW Module
//|
@ -36,7 +36,9 @@
//| protocol provided by Espressif on its SoCs
//| (`API docs <https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/network/esp_now.html>`_).
//|
//| **Sender:** ::
//| **Sender**
//|
//| .. code-block:: python
//|
//| import espnow
//|
@ -50,7 +52,9 @@
//| e.send(peer, str(i)*20, True)
//| e.send(b'end')
//|
//| **Receiver:** ::
//| **Receiver**
//|
//| .. code-block:: python
//|
//| import espnow
//|
@ -73,7 +77,7 @@ STATIC const mp_rom_map_elem_t espnow_module_globals_table[] = {
// module name
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_espnow) },
// module classes
{ MP_ROM_QSTR(MP_QSTR_Now), MP_ROM_PTR(&espnow_type) },
{ MP_ROM_QSTR(MP_QSTR_ESPNow), MP_ROM_PTR(&espnow_type) },
};
STATIC MP_DEFINE_CONST_DICT(espnow_module_globals, espnow_module_globals_table);

View File

@ -50,6 +50,9 @@ mp_obj_t mp_obj_tuple_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf);
extern const mp_obj_type_t mp_type_attrtuple;
// Relies on gcc Variadic Macros and Statement Expressions
#define MP_OBJ_NEW_TUPLE(...) ({mp_obj_t _z[] = {__VA_ARGS__}; mp_obj_new_tuple(MP_ARRAY_SIZE(_z), _z);})
#define MP_DEFINE_ATTRTUPLE(tuple_obj_name, fields, nitems, ...) \
const mp_rom_obj_tuple_t tuple_obj_name = { \
.base = {&mp_type_attrtuple}, \

View File

@ -72,7 +72,6 @@ int ringbuf_get16(ringbuf_t *r) {
if (r->used < 2) {
return -1;
}
int high_byte = ringbuf_get(r);
int low_byte = ringbuf_get(r);
return (high_byte << 8) | low_byte;
@ -92,6 +91,15 @@ int ringbuf_put(ringbuf_t *r, uint8_t v) {
return 0;
}
int ringbuf_put16(ringbuf_t *r, uint16_t v) {
if (r->size - r->used < 2) {
return -1;
}
ringbuf_put(r, (v >> 8) & 0xff);
ringbuf_put(r, v & 0xff);
return 0;
}
void ringbuf_clear(ringbuf_t *r) {
r->next_write = 0;
r->next_read = 0;
@ -132,57 +140,3 @@ size_t ringbuf_get_n(ringbuf_t *r, uint8_t *buf, size_t bufsize) {
}
return bufsize;
}
int ringbuf_put16(ringbuf_t *r, uint16_t v) {
if (r->size - r->used < 2) {
return -1;
}
ringbuf_put(r, (v >> 8) & 0xff);
ringbuf_put(r, v & 0xff);
return 0;
}
// Returns:
// 1: Success
// 0: Not enough data available to complete read (try again later)
// -1: Requested read is larger than buffer - will never succeed
int ringbuf_read(ringbuf_t *r, void *data, size_t data_len) {
if (ringbuf_avail(r) < data_len) {
return (r->size <= data_len) ? -1 : 0;
}
uint32_t iget = r->next_read;
uint32_t iget_a = (iget + data_len) % r->size;
uint8_t *datap = data;
if (iget_a < iget) {
// Copy part of the data from the space left at the end of the buffer
memcpy(datap, r->buf + iget, r->size - iget);
datap += (r->size - iget);
iget = 0;
}
memcpy(datap, r->buf + iget, iget_a - iget);
r->next_read = iget_a;
return 1;
}
// Returns:
// 1: Success
// 0: Not enough free space available to complete write (try again later)
// -1: Requested write is larger than buffer - will never succeed
int ringbuf_write(ringbuf_t *r, const void *data, size_t data_len) {
if (ringbuf_free(r) < data_len) {
return (r->size <= data_len) ? -1 : 0;
}
uint32_t iput = r->next_write;
uint32_t iput_a = (iput + data_len) % r->size;
const uint8_t *datap = data;
if (iput_a < iput) {
// Copy part of the data to the end of the buffer
memcpy(r->buf + iput, datap, r->size - iput);
datap += (r->size - iput);
iput = 0;
}
memcpy(r->buf + iput, datap, iput_a - iput);
r->next_write = iput_a;
return 1;
}

View File

@ -61,15 +61,5 @@ size_t ringbuf_get_n(ringbuf_t *r, uint8_t *buf, size_t bufsize);
// Note: big-endian. Return -1 if can't read or write two bytes.
int ringbuf_get16(ringbuf_t *r);
int ringbuf_put16(ringbuf_t *r, uint16_t v);
int ringbuf_read(ringbuf_t *r, void *data, size_t data_len);
int ringbuf_write(ringbuf_t *r, const void *data, size_t data_len);
static inline size_t ringbuf_free(ringbuf_t *r) {
return (r->size + r->next_read - r->next_write - 1) % r->size;
}
static inline size_t ringbuf_avail(ringbuf_t *r) {
return (r->size + r->next_write - r->next_read) % r->size;
}
#endif // MICROPY_INCLUDED_PY_RINGBUF_H