circuitpython/ports/espressif/bindings/espnow/__init__.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

95 lines
3.1 KiB
C
Raw Normal View History

2023-01-22 23:12:39 -05:00
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2023 MicroDev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "bindings/espnow/__init__.h"
2023-01-23 12:40:00 -05:00
#include "bindings/espnow/ESPNow.h"
#include "bindings/espnow/ESPNowPacket.h"
2023-02-02 11:04:24 -05:00
#include "bindings/espnow/Peer.h"
#include "bindings/espnow/Peers.h"
2023-01-22 23:12:39 -05:00
//| """ESP-NOW Module
//|
//| The `espnow` module provides an interface to the
//| `ESP-NOW <https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32/api-reference/network/esp_now.html>`_
//| protocol provided by Espressif on its SoCs.
2023-01-22 23:12:39 -05:00
//|
2023-01-23 12:40:00 -05:00
//| **Sender**
//|
//| .. code-block:: python
2023-01-22 23:12:39 -05:00
//|
//| import espnow
//|
//| e = espnow.ESPNow()
2023-02-02 11:04:24 -05:00
//| peer = espnow.Peer(mac=b'\xaa\xaa\xaa\xaa\xaa\xaa')
//| e.peers.append(peer)
2023-01-22 23:12:39 -05:00
//|
2023-02-02 11:04:24 -05:00
//| e.send("Starting...")
//| for i in range(10):
2023-02-03 14:33:33 -05:00
//| e.send(str(i)*20)
2023-02-02 11:04:24 -05:00
//| e.send(b'end')
2023-01-22 23:12:39 -05:00
//|
2023-01-23 12:40:00 -05:00
//| **Receiver**
//|
//| .. code-block:: python
2023-01-22 23:12:39 -05:00
//|
//| import espnow
//|
//| e = espnow.ESPNow()
2023-02-02 11:04:24 -05:00
//| packets = []
2023-01-22 23:12:39 -05:00
//|
//| while True:
2023-02-02 11:04:24 -05:00
//| if e:
//| packet = e.read()
2023-02-02 11:04:24 -05:00
//| packets.append(packet)
//| if packet.msg == b'end':
2023-01-22 23:12:39 -05:00
//| break
2023-02-02 11:04:24 -05:00
//|
//| print("packets:", f"length={len(packets)}")
//| for packet in packets:
//| print(packet)
2023-01-22 23:12:39 -05:00
//| """
//| ...
//|
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) },
2023-01-22 23:12:39 -05:00
// module classes
{ MP_ROM_QSTR(MP_QSTR_ESPNow), MP_ROM_PTR(&espnow_type) },
2023-08-14 00:47:22 -04:00
{ MP_ROM_QSTR(MP_QSTR_ESPNowPacket), MP_ROM_PTR(&espnow_packet_type_obj) },
2023-02-02 11:04:24 -05:00
{ MP_ROM_QSTR(MP_QSTR_Peer), MP_ROM_PTR(&espnow_peer_type) },
{ MP_ROM_QSTR(MP_QSTR_Peers), MP_ROM_PTR(&espnow_peers_type) },
2023-01-22 23:12:39 -05:00
};
STATIC MP_DEFINE_CONST_DICT(espnow_module_globals, espnow_module_globals_table);
const mp_obj_module_t espnow_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&espnow_module_globals,
};
MP_REGISTER_MODULE(MP_QSTR_espnow, espnow_module);