Loading...
Searching...
No Matches
m6e_nano.h
Go to the documentation of this file.
1#include <zephyr/kernel.h>
2#include <zephyr/device.h>
3
4#ifndef M6E_NANO_H
5#define M6E_NANO_H
6
7#define M6E_NANO_BUF_SIZE 255
8#define M6E_NANO_MAX_TAGS 150
9
10// Packet header for M6E Nano
11#define TMR_START_HEADER 0xFF
12
13// Op codes for M6E Nano
14#define TMR_SR_OPCODE_VERSION 0x03
15#define TMR_SR_OPCODE_VERSION_STARTUP 0x04
16#define TMR_SR_OPCODE_SET_BAUD_RATE 0x06
17#define TMR_SR_OPCODE_READ_TAG_ID_SINGLE 0x21
18#define TMR_SR_OPCODE_READ_TAG_ID_MULTIPLE 0x22
19#define TMR_SR_OPCODE_WRITE_TAG_ID 0x23
20#define TMR_SR_OPCODE_WRITE_TAG_DATA 0x24
21#define TMR_SR_OPCODE_KILL_TAG 0x26
22#define TMR_SR_OPCODE_READ_TAG_DATA 0x28
23#define TMR_SR_OPCODE_CLEAR_TAG_ID_BUFFER 0x2A
24#define TMR_SR_OPCODE_MULTI_PROTOCOL_TAG_OP 0x2F
25#define TMR_SR_OPCODE_GET_READ_TX_POWER 0x62
26#define TMR_SR_OPCODE_GET_WRITE_TX_POWER 0x64
27#define TMR_SR_OPCODE_GET_USER_GPIO_INPUTS 0x66
28#define TMR_SR_OPCODE_GET_POWER_MODE 0x68
29#define TMR_SR_OPCODE_GET_READER_OPTIONAL_PARAMS 0x6A
30#define TMR_SR_OPCODE_GET_PROTOCOL_PARAM 0x6B
31#define TMR_SR_OPCODE_SET_ANTENNA_PORT 0x91
32#define TMR_SR_OPCODE_SET_TAG_PROTOCOL 0x93
33#define TMR_SR_OPCODE_SET_READ_TX_POWER 0x92
34#define TMR_SR_OPCODE_SET_WRITE_TX_POWER 0x94
35#define TMR_SR_OPCODE_SET_USER_GPIO_OUTPUTS 0x96
36#define TMR_SR_OPCODE_SET_REGION 0x97
37#define TMR_SR_OPCODE_SET_POWER_MODE 0x98
38#define TMR_SR_OPCODE_SET_READER_OPTIONAL_PARAMS 0x9A
39#define TMR_SR_OPCODE_SET_PROTOCOL_PARAM 0x9B
40
41// Power modes for M6E Nano
42#define TMR_SR_POWER_MODE_FULL 0x00
43#define TMR_SR_POWER_MODE_MIN_SAVE 0x01
44#define TMR_SR_POWER_MODE_MED_SAVE 0x02
45#define TMR_SR_POWER_MODE_MAX_SAVE 0x03
46
47// Number of ms before stop waiting for response from module
48#define COMMAND_TIME_OUT 2000
49
50// Define all the ways functions can return
51#define RESPONSE_PENDING 0
52#define ERROR_COMMAND_RESPONSE_TIMEOUT 1
53#define ERROR_CORRUPT_RESPONSE 2
54#define ERROR_WRONG_OPCODE_RESPONSE 3
55#define ERROR_UNKNOWN_OPCODE 4
56#define RESPONSE_IS_TEMPERATURE 5
57#define RESPONSE_IS_KEEPALIVE 6
58#define RESPONSE_IS_TEMPTHROTTLE 7
59#define RESPONSE_IS_TAGFOUND 8
60#define RESPONSE_IS_NOTAGFOUND 9
61#define RESPONSE_IS_UNKNOWN 10
62#define RESPONSE_SUCCESS 11
63#define RESPONSE_FAIL 12
64#define RESPONSE_CLEAR 13
65#define RESPONSE_STARTUP 14
66
67// Define the allowed regions - these set the internal freq of the module
68#define REGION_INDIA 0x04
69#define REGION_JAPAN 0x05
70#define REGION_CHINA 0x06
71#define REGION_EUROPE 0x08
72#define REGION_KOREA 0x09
73#define REGION_AUSTRALIA 0x0B
74#define REGION_NEWZEALAND 0x0C
75#define REGION_NORTHAMERICA 0x0D
76#define REGION_OPEN 0xFF
77
78// Define the allowed tag protocols
79#define TMR_TAG_PROTOCOL_NONE 0x00
80#define TMR_TAG_PROTOCOL_ISO180006B 0x03
81#define TMR_TAG_PROTOCOL_GEN2 0x05
82#define TMR_TAG_PROTOCOL_ISO180006B_UCODE 0x06
83#define TMR_TAG_PROTOCOL_IPX64 0x07
84#define TMR_TAG_PROTOCOL_IPX256 0x08
85#define TMR_TAG_PROTOCOL_ATA 0x1D
86
87/* wait serial output with 1000ms timeout */
88#define CFG_M6E_NANO_SERIAL_TIMEOUT 1000
89
90// Set command to be transmitted
91typedef int (*m6e_nano_send_command_t)(const struct device *dev, uint8_t *command,
92 const uint8_t length, bool timeout);
93
94// Callback
95typedef void (*m6e_nano_callback_t)(const struct device *dev, void *user_data);
96
97// Set the data callback function for the device
98typedef void (*m6e_nano_set_callback_t)(const struct device *dev, m6e_nano_callback_t callback,
99 void *user_data);
100
102 // m6e_nano_send_command_t send_command;
104};
105
113// static inline void m6e_nano_send_command(const struct device *dev, uint8_t *command,
114// const uint8_t length, bool timeout)
115// {
116// struct m6e_nano_api *api = (struct m6e_nano_api *)dev->api;
117// return api->send_command(dev, command, length, timeout);
118// }
119
127static inline void m6e_nano_set_callback(const struct device *dev, m6e_nano_callback_t callback,
128 void *user_data)
129{
130 struct m6e_nano_api *api = (struct m6e_nano_api *)dev->api;
131 return api->set_callback(dev, callback, user_data);
132}
133
136 size_t len;
137 size_t msg_len;
138};
139
150
153 const struct device *uart_dev;
154};
155
165int user_send_command(const struct device *dev, uint8_t *command, const uint8_t length, const bool timeout);
166
167/* Library Functions */
174uint8_t m6e_nano_get_tag_epc_bytes(const struct device *dev);
175
182uint8_t m6e_nano_get_tag_rssi(const struct device *dev);
183
190uint16_t m6e_nano_get_tag_timestamp(const struct device *dev);
191
198uint32_t m6e_nano_get_tag_freq(const struct device *dev);
199
205void m6e_nano_disable_read_filter(const struct device *dev);
206
212void m6e_nano_stop_reading(const struct device *dev);
213
220void m6e_nano_set_power_mode(const struct device *dev, uint8_t mode);
221
227void m6e_nano_set_antenna_port(const struct device *dev);
228
235void m6e_nano_set_read_power(const struct device *dev, uint16_t power);
236
242void m6e_nano_start_reading(const struct device *dev);
243
251void m6e_nano_set_region(const struct device *dev, uint8_t region);
252
258int m6e_nano_get_version(const struct device *dev);
259
266void m6e_nano_set_tag_protocol(const struct device *dev, uint8_t protocol);
267
273void m6e_nano_get_write_power(const struct device *dev);
274
281void m6e_nano_set_baud(const struct device *dev, long baud_rate);
282
291void m6e_nano_send_generic_command(const struct device *dev, uint8_t *command, uint8_t size,
292 uint8_t opcode);
293
300uint8_t m6e_nano_parse_response(const struct device *dev);
301
302#endif // M6E_NANO_PERIPHERAL_H
void m6e_nano_send_generic_command(const struct device *dev, uint8_t *command, uint8_t size, uint8_t opcode)
Send a generic command to the M6E Nano.
void m6e_nano_stop_reading(const struct device *dev)
Stop a continuous read operation.
int user_send_command(const struct device *dev, uint8_t *command, const uint8_t length, const bool timeout)
Set the command to be transmitted by the UART peripheral.
void m6e_nano_set_region(const struct device *dev, uint8_t region)
Set the operating region of the M6E Nano. This controls the transmission frequency of the RFID reader...
uint32_t m6e_nano_get_tag_freq(const struct device *dev)
Retrieve the frequency of the tag.
uint16_t m6e_nano_get_tag_timestamp(const struct device *dev)
Retrieve the timestamp of the tag.
#define M6E_NANO_BUF_SIZE
Definition m6e_nano.h:7
void m6e_nano_disable_read_filter(const struct device *dev)
Disable the read filter.
uint8_t m6e_nano_parse_response(const struct device *dev)
Parse the tag response from the M6E Nano.
void m6e_nano_set_power_mode(const struct device *dev, uint8_t mode)
Set the power mode of the M6E Nano.
int(* m6e_nano_send_command_t)(const struct device *dev, uint8_t *command, const uint8_t length, bool timeout)
Definition m6e_nano.h:91
void(* m6e_nano_set_callback_t)(const struct device *dev, m6e_nano_callback_t callback, void *user_data)
Definition m6e_nano.h:98
void m6e_nano_set_tag_protocol(const struct device *dev, uint8_t protocol)
Set the tag protocol of the M6E Nano.
void m6e_nano_get_write_power(const struct device *dev)
Retrieve the write power of the M6E Nano.
void(* m6e_nano_callback_t)(const struct device *dev, void *user_data)
Definition m6e_nano.h:95
uint8_t m6e_nano_get_tag_rssi(const struct device *dev)
Retrieve the RSSI of the tag.
void m6e_nano_set_antenna_port(const struct device *dev)
Set the antenna port of the M6E Nano.
void m6e_nano_start_reading(const struct device *dev)
Start a continuous read operation.
int m6e_nano_get_version(const struct device *dev)
Retrieve the firmware version of the M6E Nano.
void m6e_nano_set_read_power(const struct device *dev, uint16_t power)
Set the read power of the M6E Nano.
uint8_t m6e_nano_get_tag_epc_bytes(const struct device *dev)
Retrieve the number of bytes from EPC.
void m6e_nano_set_baud(const struct device *dev, long baud_rate)
Set the baudrate of the M6E Nano.
Definition m6e_nano.h:101
m6e_nano_set_callback_t set_callback
Definition m6e_nano.h:103
Definition m6e_nano.h:134
size_t len
Definition m6e_nano.h:136
uint8_t data[M6E_NANO_BUF_SIZE]
Definition m6e_nano.h:135
size_t msg_len
Definition m6e_nano.h:137
Definition m6e_nano.h:151
const struct device * uart_dev
Definition m6e_nano.h:153
struct m6e_nano_data * data
Definition m6e_nano.h:152
Definition m6e_nano.h:140
m6e_nano_callback_t callback
Definition m6e_nano.h:147
bool debug
Definition m6e_nano.h:141
uint8_t status
Definition m6e_nano.h:142
struct m6e_nano_buf response
Definition m6e_nano.h:144
bool has_response
Definition m6e_nano.h:145
struct m6e_nano_buf command
Definition m6e_nano.h:143
void * user_data
Definition m6e_nano.h:148