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

Committer:
okini3939
Date:
2016-04-07
Revision:
7:9c963cb53ef7
Parent:
5:e5a358e9ed94

File content as of revision 7:9c963cb53ef7:

#include "NECnfc.h"

void NECnfc::setReset (bool flg) {
    if (_reset) {
        if (flg) {
            _reset->output();
            _reset->write(0);
        } else {
            _reset->input();
            _reset->mode(PullNone);
        }
    }
}

void NECnfc::isrUart () {
    recvData(getUart());
}

int NECnfc::getUart () {
    return _nec.getc();
}

void NECnfc::putUart (char c) {
    _nec.putc(c);
}

int NECnfc::lockUart (int ms) {
    return 0;
}

void NECnfc::unlockUart () {
}

void NECnfc::initUart (PinName reset, PinName wakeup, PinName mode, int baud) {
    if (baud) _nec.baud(baud);
    _nec.attach(this, &NECnfc::isrUart, Serial::RxIrq);

    _reset = NULL;
    if (reset != NC) {
        _reset = new DigitalInOut(reset);
    }
    _wakeup = NULL;
    if (wakeup != NC) {
        _wakeup = new DigitalOut(wakeup);
        _wakeup->write(0);
    }
    _wmode = NULL;
    if (mode != NC) {
        _wmode = new DigitalIn(mode);
        _wmode->mode(PullUp);
    }
}

int NECnfc::sleep (int wait) {

    if (!_wakeup) return -1;

    DBG("sleep\r\n");
    _wakeup->write(1);
    if (wait && _wmode) {
        while (! _wmode->read());
    }
    return 0;
}

int NECnfc::wakeup (int wait) {

    if (!_wakeup) return -1;

    DBG("wakeup\r\n");
    _wakeup->write(0);
    if (wait && _wmode) {
        while (_wmode->read());
    }
    return 0;
}