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_hal.cpp@7:9c963cb53ef7, 2016-04-07 (annotated)
- Committer:
- okini3939
- Date:
- Thu Apr 07 00:56:50 2016 +0000
- Revision:
- 7:9c963cb53ef7
- Parent:
- 5:e5a358e9ed94
bug fix;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 4:07e752ff8dce | 1 | #include "NECnfc.h" |
okini3939 | 4:07e752ff8dce | 2 | |
okini3939 | 4:07e752ff8dce | 3 | void NECnfc::setReset (bool flg) { |
okini3939 | 4:07e752ff8dce | 4 | if (_reset) { |
okini3939 | 4:07e752ff8dce | 5 | if (flg) { |
okini3939 | 4:07e752ff8dce | 6 | _reset->output(); |
okini3939 | 4:07e752ff8dce | 7 | _reset->write(0); |
okini3939 | 4:07e752ff8dce | 8 | } else { |
okini3939 | 4:07e752ff8dce | 9 | _reset->input(); |
okini3939 | 4:07e752ff8dce | 10 | _reset->mode(PullNone); |
okini3939 | 4:07e752ff8dce | 11 | } |
okini3939 | 4:07e752ff8dce | 12 | } |
okini3939 | 4:07e752ff8dce | 13 | } |
okini3939 | 4:07e752ff8dce | 14 | |
okini3939 | 4:07e752ff8dce | 15 | void NECnfc::isrUart () { |
okini3939 | 4:07e752ff8dce | 16 | recvData(getUart()); |
okini3939 | 4:07e752ff8dce | 17 | } |
okini3939 | 4:07e752ff8dce | 18 | |
okini3939 | 4:07e752ff8dce | 19 | int NECnfc::getUart () { |
okini3939 | 4:07e752ff8dce | 20 | return _nec.getc(); |
okini3939 | 4:07e752ff8dce | 21 | } |
okini3939 | 4:07e752ff8dce | 22 | |
okini3939 | 4:07e752ff8dce | 23 | void NECnfc::putUart (char c) { |
okini3939 | 4:07e752ff8dce | 24 | _nec.putc(c); |
okini3939 | 4:07e752ff8dce | 25 | } |
okini3939 | 4:07e752ff8dce | 26 | |
okini3939 | 4:07e752ff8dce | 27 | int NECnfc::lockUart (int ms) { |
okini3939 | 4:07e752ff8dce | 28 | return 0; |
okini3939 | 4:07e752ff8dce | 29 | } |
okini3939 | 4:07e752ff8dce | 30 | |
okini3939 | 4:07e752ff8dce | 31 | void NECnfc::unlockUart () { |
okini3939 | 4:07e752ff8dce | 32 | } |
okini3939 | 4:07e752ff8dce | 33 | |
okini3939 | 4:07e752ff8dce | 34 | void NECnfc::initUart (PinName reset, PinName wakeup, PinName mode, int baud) { |
okini3939 | 4:07e752ff8dce | 35 | if (baud) _nec.baud(baud); |
okini3939 | 4:07e752ff8dce | 36 | _nec.attach(this, &NECnfc::isrUart, Serial::RxIrq); |
okini3939 | 4:07e752ff8dce | 37 | |
okini3939 | 4:07e752ff8dce | 38 | _reset = NULL; |
okini3939 | 4:07e752ff8dce | 39 | if (reset != NC) { |
okini3939 | 4:07e752ff8dce | 40 | _reset = new DigitalInOut(reset); |
okini3939 | 4:07e752ff8dce | 41 | } |
okini3939 | 4:07e752ff8dce | 42 | _wakeup = NULL; |
okini3939 | 4:07e752ff8dce | 43 | if (wakeup != NC) { |
okini3939 | 4:07e752ff8dce | 44 | _wakeup = new DigitalOut(wakeup); |
okini3939 | 4:07e752ff8dce | 45 | _wakeup->write(0); |
okini3939 | 4:07e752ff8dce | 46 | } |
okini3939 | 4:07e752ff8dce | 47 | _wmode = NULL; |
okini3939 | 4:07e752ff8dce | 48 | if (mode != NC) { |
okini3939 | 4:07e752ff8dce | 49 | _wmode = new DigitalIn(mode); |
okini3939 | 4:07e752ff8dce | 50 | _wmode->mode(PullUp); |
okini3939 | 4:07e752ff8dce | 51 | } |
okini3939 | 4:07e752ff8dce | 52 | } |
okini3939 | 4:07e752ff8dce | 53 | |
okini3939 | 4:07e752ff8dce | 54 | int NECnfc::sleep (int wait) { |
okini3939 | 4:07e752ff8dce | 55 | |
okini3939 | 5:e5a358e9ed94 | 56 | if (!_wakeup) return -1; |
okini3939 | 4:07e752ff8dce | 57 | |
okini3939 | 4:07e752ff8dce | 58 | DBG("sleep\r\n"); |
okini3939 | 4:07e752ff8dce | 59 | _wakeup->write(1); |
okini3939 | 5:e5a358e9ed94 | 60 | if (wait && _wmode) { |
okini3939 | 4:07e752ff8dce | 61 | while (! _wmode->read()); |
okini3939 | 4:07e752ff8dce | 62 | } |
okini3939 | 4:07e752ff8dce | 63 | return 0; |
okini3939 | 4:07e752ff8dce | 64 | } |
okini3939 | 4:07e752ff8dce | 65 | |
okini3939 | 4:07e752ff8dce | 66 | int NECnfc::wakeup (int wait) { |
okini3939 | 4:07e752ff8dce | 67 | |
okini3939 | 5:e5a358e9ed94 | 68 | if (!_wakeup) return -1; |
okini3939 | 4:07e752ff8dce | 69 | |
okini3939 | 4:07e752ff8dce | 70 | DBG("wakeup\r\n"); |
okini3939 | 4:07e752ff8dce | 71 | _wakeup->write(0); |
okini3939 | 5:e5a358e9ed94 | 72 | if (wait && _wmode) { |
okini3939 | 4:07e752ff8dce | 73 | while (_wmode->read()); |
okini3939 | 4:07e752ff8dce | 74 | } |
okini3939 | 4:07e752ff8dce | 75 | return 0; |
okini3939 | 4:07e752ff8dce | 76 | } |