esp_now_netdev.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef ESP_NOW_NETDEV_H
21 #define ESP_NOW_NETDEV_H
22 
23 #include "net/netdev.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
32 #define ESP_NOW_MAX_SIZE_RAW (250)
33 
37 #define ESP_NOW_ADDR_LEN ETHERNET_ADDR_LEN
38 
42 #define ESP_NOW_HEADER_LENGTH (sizeof(esp_now_pkt_hdr_t))
43 
47 #define ESP_NOW_MAX_SIZE (ESP_NOW_MAX_SIZE_RAW - ESP_NOW_HEADER_LENGTH)
48 
54 #ifndef ESP_NOW_BUFSIZE
55 #define ESP_NOW_BUFSIZE (ESP_NOW_MAX_SIZE_RAW + ESP_NOW_ADDR_LEN)
56 #endif
57 
61 extern const netdev_driver_t esp_now_driver;
62 
66 typedef struct __attribute__((packed))
67 {
68  uint8_t flags;
70 
74 #define ESP_NOW_PKT_HDR_FLAG_SIXLO (1)
75 
79 typedef struct
80 {
83  uint8_t addr[ESP_NOW_ADDR_LEN];
85  uint8_t rx_len;
86  uint8_t* rx_mac;
87  uint8_t* rx_data;
89  uint8_t tx_mem[ESP_NOW_MAX_SIZE_RAW];
91 #ifdef MODULE_GNRC
92  gnrc_nettype_t proto;
93 #endif
94 
97  uint8_t scan_event;
100 
107 
114 int esp_now_set_channel(uint8_t channel);
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif /* ESP_NOW_NETDEV_H */
121 
esp_now_netdev_t::netdev
netdev_t netdev
netdev parent struct
Definition: esp_now_netdev.h:81
netdev_driver
Structure to hold driver interface -> function mapping.
Definition: netdev.h:344
ESP_NOW_MAX_SIZE_RAW
#define ESP_NOW_MAX_SIZE_RAW
Maximum raw packet size that can be used with ESP-NOW (including headers)
Definition: esp_now_netdev.h:32
esp_now_netdev_t
Device descriptor for ESP-NOW devices.
Definition: esp_now_netdev.h:79
esp_now_netdev_t::rx_len
uint8_t rx_len
number of bytes received
Definition: esp_now_netdev.h:85
esp_now_netdev_t::scan_event
uint8_t scan_event
ESP-NOW peers have to be scanned.
Definition: esp_now_netdev.h:97
esp_now_driver
const netdev_driver_t esp_now_driver
Reference to the netdev device driver struct.
esp_now_netdev_t::rx_mac
uint8_t * rx_mac
source mac of received data
Definition: esp_now_netdev.h:86
netdev_esp_now_setup
esp_now_netdev_t * netdev_esp_now_setup(void)
ESP-NOW netdev initialization function.
esp_now_pkt_hdr_t
Header with necessary flags for ESP-NOW packets.
Definition: esp_now_netdev.h:66
netdev.h
Definitions low-level network driver interface.
esp_now_set_channel
int esp_now_set_channel(uint8_t channel)
Set the channel used by ESP-NOW netdev.
esp_now_netdev_t::dev_lock
mutex_t dev_lock
device is already in use
Definition: esp_now_netdev.h:95
netdev
Structure to hold driver state.
Definition: netdev.h:302
gnrc_nettype_t
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:50
esp_now_netdev_t::rx_data
uint8_t * rx_data
received
Definition: esp_now_netdev.h:87
ESP_NOW_ADDR_LEN
#define ESP_NOW_ADDR_LEN
Length of ESP-NOW addresses.
Definition: esp_now_netdev.h:37
esp_now_pkt_hdr_t::flags
uint8_t flags
Flags.
Definition: esp_now_netdev.h:68
mutex_t
Mutex structure.
Definition: mutex.h:120