NEC Near Field Communication RF module library for mbed H001-000003-001 (950MHz), H001-000013-001 (920MHz), TY24FM-E2024 (2.4GHz)
Dependents: NECnfc_sample Drone_air Drone_ground
NEC Near Field Communication RF module library
NEC製の近距離無線モジュール用のライブラリです。
NECnfc.h
- Committer:
- okini3939
- Date:
- 2012-07-17
- Revision:
- 0:337524afec9b
- Child:
- 2:9e108187ccfe
File content as of revision 0:337524afec9b:
/** * NEC Near Field Communication RF module library for mbed * Copyright (c) 2012 Suga * Released under the MIT License: http://mbed.org/license/mit */ /** @file * @brief NEC Near Field Communication RF module library for mbed * @note H001-000003-001 (950MHz), TY24FM-E2024 (2.4GHz) */ #include "mbed.h" enum NECTYPE { NECTYPE_950MHz, NECTYPE_2400MHz, }; enum NECMSG { NECMSG_ACK = 0x00, NECMSG_NOACK = 0x01, NECMSG_SEARCH = 0x10, NECMSG_SEND_DAT = 0x11, NECMSG_RESEND = 0x12, NECMSG_SEND_NOACK = 0x13, NECMSG_ENERGY_DETECT = 0x16, NECMSG_SEND_CMD = 0x17, NECMSG_WRITE_RFCONF = 0x21, NECMSG_READ_RSSI = 0x24, NECMSG_READ_CONFIG = 0x29, NECMSG_WRITE_CONFIG = 0x2A, NECMSG_READ_DEFAULT = 0x7D, NECMSG_WRITE_DEFAULT = 0x7E, NECMSG_RESET = 0x77, }; enum NECPWR { NECPWR_LOW = 0x00, NECPWR_MID = 0x01, NECPWR_HIGH = 0x02, }; enum NECBAUD { NECBAUD_9600 = 0x02, NECBAUD_50k = 0x06, NECBAUD_100k = 0x07, }; enum NECUART { UART_4800 = 0x01, UART_9600 = 0x02, UART_19200 = 0x04, UART_38400 = 0x05, UART_56700 = 0x06, UART_115200 = 0x08, }; struct ifMessage { uint16_t start; uint8_t length; uint8_t msgid; uint8_t msgno; uint32_t dstid; uint32_t srcid; uint8_t parameter[242]; } __attribute__((packed)); /** * NECnfc class */ class NECnfc { public: /** * Default constructor */ NECnfc (PinName p_tx, PinName p_rx, PinName p_reset); /** * configuration */ int begin (int ch, NECBAUD baud, NECUART uart = UART_115200, NECPWR power = NECPWR_LOW, NECTYPE type = NECTYPE_950MHz); /** * send */ int send (int msgid, unsigned long dest, char *param, int len); /** * read */ int read (struct ifMessage *ifmsg, int timeout = 5000); /** * read data ready */ int readable (); protected: void isr_rx (); private: Serial rf; DigitalOut reset; int msgno; struct ifMessage rxmsg; char *rxbuf; int rxlen, rxmode; volatile int rxflg; };