FeliCa Link library sample
Dependencies: RCS730 SB1602E mbed
FeliCa Link Library using sample (NUCLEO-F411RE).
- SCL/D15 ... SCL
- SDA/D14 ... SDA
- D8(PA_9) ... IRQ
- D7(PA_8) ... RFDET (LED blink)
SB1602E is used for debugging. Not necessary.
main.cpp@1:ae718eabf3a7, 2015-03-29 (annotated)
- Committer:
- hiro99ma
- Date:
- Sun Mar 29 06:27:14 2015 +0000
- Revision:
- 1:ae718eabf3a7
- Parent:
- 0:6efd0ff1fcbe
import miss fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hiro99ma | 0:6efd0ff1fcbe | 1 | #include "mbed.h" |
hiro99ma | 0:6efd0ff1fcbe | 2 | #include "SB1602E.h" |
hiro99ma | 0:6efd0ff1fcbe | 3 | #include "RCS730.h" |
hiro99ma | 0:6efd0ff1fcbe | 4 | |
hiro99ma | 0:6efd0ff1fcbe | 5 | namespace { |
hiro99ma | 0:6efd0ff1fcbe | 6 | DigitalOut led(LED1); |
hiro99ma | 0:6efd0ff1fcbe | 7 | I2C i2c(I2C_SDA, I2C_SCL); |
hiro99ma | 0:6efd0ff1fcbe | 8 | SB1602E lcd(i2c); |
hiro99ma | 0:6efd0ff1fcbe | 9 | RCS730 felica(i2c); |
hiro99ma | 0:6efd0ff1fcbe | 10 | |
hiro99ma | 0:6efd0ff1fcbe | 11 | //PortIn po(PortA, 0x0300); // PA_8, PA_9 |
hiro99ma | 0:6efd0ff1fcbe | 12 | InterruptIn int_rfdet(PA_8); |
hiro99ma | 0:6efd0ff1fcbe | 13 | InterruptIn int_irq(PA_9); |
hiro99ma | 0:6efd0ff1fcbe | 14 | } |
hiro99ma | 0:6efd0ff1fcbe | 15 | |
hiro99ma | 0:6efd0ff1fcbe | 16 | namespace { |
hiro99ma | 0:6efd0ff1fcbe | 17 | |
hiro99ma | 0:6efd0ff1fcbe | 18 | bool cbRxHTRead(void *pUser, uint8_t *pData, uint8_t Len) |
hiro99ma | 0:6efd0ff1fcbe | 19 | { |
hiro99ma | 0:6efd0ff1fcbe | 20 | uint8_t nob = pData[13] << 4; //16byte * NoB |
hiro99ma | 0:6efd0ff1fcbe | 21 | pData[0] = static_cast<uint8_t>(13 + nob); |
hiro99ma | 0:6efd0ff1fcbe | 22 | pData[10] = 0; //ST1 |
hiro99ma | 0:6efd0ff1fcbe | 23 | pData[11] = 0; //ST2 |
hiro99ma | 0:6efd0ff1fcbe | 24 | for (int i = 0; i < nob; i++) { |
hiro99ma | 0:6efd0ff1fcbe | 25 | pData[13 + i] = static_cast<uint8_t>(i); |
hiro99ma | 0:6efd0ff1fcbe | 26 | } |
hiro99ma | 0:6efd0ff1fcbe | 27 | |
hiro99ma | 0:6efd0ff1fcbe | 28 | return true; |
hiro99ma | 0:6efd0ff1fcbe | 29 | } |
hiro99ma | 0:6efd0ff1fcbe | 30 | |
hiro99ma | 0:6efd0ff1fcbe | 31 | bool cbRxHTWrite(void *pUser, uint8_t *pData, uint8_t Len) |
hiro99ma | 0:6efd0ff1fcbe | 32 | { |
hiro99ma | 0:6efd0ff1fcbe | 33 | pData[16 + 16] = '\0'; |
hiro99ma | 0:6efd0ff1fcbe | 34 | lcd.puts(1, reinterpret_cast<char*>(pData + 16)); |
hiro99ma | 0:6efd0ff1fcbe | 35 | pData[0] = 12; |
hiro99ma | 0:6efd0ff1fcbe | 36 | pData[10] = 0; //ST1 |
hiro99ma | 0:6efd0ff1fcbe | 37 | pData[11] = 0; //ST2 |
hiro99ma | 0:6efd0ff1fcbe | 38 | |
hiro99ma | 0:6efd0ff1fcbe | 39 | return true; |
hiro99ma | 0:6efd0ff1fcbe | 40 | } |
hiro99ma | 0:6efd0ff1fcbe | 41 | |
hiro99ma | 0:6efd0ff1fcbe | 42 | void rfdetect_on() |
hiro99ma | 0:6efd0ff1fcbe | 43 | { |
hiro99ma | 0:6efd0ff1fcbe | 44 | led = !led; |
hiro99ma | 0:6efd0ff1fcbe | 45 | } |
hiro99ma | 0:6efd0ff1fcbe | 46 | |
hiro99ma | 0:6efd0ff1fcbe | 47 | void rfdetect_off() |
hiro99ma | 0:6efd0ff1fcbe | 48 | { |
hiro99ma | 0:6efd0ff1fcbe | 49 | led = 0; |
hiro99ma | 0:6efd0ff1fcbe | 50 | } |
hiro99ma | 0:6efd0ff1fcbe | 51 | |
hiro99ma | 0:6efd0ff1fcbe | 52 | void irq() |
hiro99ma | 0:6efd0ff1fcbe | 53 | { |
hiro99ma | 0:6efd0ff1fcbe | 54 | felica.isrIrq(); |
hiro99ma | 0:6efd0ff1fcbe | 55 | } |
hiro99ma | 0:6efd0ff1fcbe | 56 | } |
hiro99ma | 0:6efd0ff1fcbe | 57 | |
hiro99ma | 0:6efd0ff1fcbe | 58 | int main() |
hiro99ma | 0:6efd0ff1fcbe | 59 | { |
hiro99ma | 0:6efd0ff1fcbe | 60 | int ret; |
hiro99ma | 0:6efd0ff1fcbe | 61 | |
hiro99ma | 0:6efd0ff1fcbe | 62 | led = 0; |
hiro99ma | 0:6efd0ff1fcbe | 63 | lcd.puts(0, "OK "); |
hiro99ma | 0:6efd0ff1fcbe | 64 | |
hiro99ma | 0:6efd0ff1fcbe | 65 | int_rfdet.fall(rfdetect_on); |
hiro99ma | 0:6efd0ff1fcbe | 66 | int_rfdet.rise(rfdetect_off); |
hiro99ma | 0:6efd0ff1fcbe | 67 | |
hiro99ma | 0:6efd0ff1fcbe | 68 | int_irq.fall(irq); |
hiro99ma | 0:6efd0ff1fcbe | 69 | |
hiro99ma | 0:6efd0ff1fcbe | 70 | RCS730::callbacktable_t table = { |
hiro99ma | 0:6efd0ff1fcbe | 71 | 0, |
hiro99ma | 0:6efd0ff1fcbe | 72 | cbRxHTRead, |
hiro99ma | 0:6efd0ff1fcbe | 73 | cbRxHTWrite |
hiro99ma | 0:6efd0ff1fcbe | 74 | }; |
hiro99ma | 0:6efd0ff1fcbe | 75 | felica.setCallbackTable(&table); |
hiro99ma | 0:6efd0ff1fcbe | 76 | |
hiro99ma | 0:6efd0ff1fcbe | 77 | ret = felica.initFTMode(RCS730::OPMODE_PLUG); |
hiro99ma | 0:6efd0ff1fcbe | 78 | if (ret != 0) { |
hiro99ma | 0:6efd0ff1fcbe | 79 | lcd.puts(0, "1"); |
hiro99ma | 0:6efd0ff1fcbe | 80 | } |
hiro99ma | 0:6efd0ff1fcbe | 81 | |
hiro99ma | 0:6efd0ff1fcbe | 82 | while(true) { |
hiro99ma | 0:6efd0ff1fcbe | 83 | ; |
hiro99ma | 0:6efd0ff1fcbe | 84 | } |
hiro99ma | 0:6efd0ff1fcbe | 85 | } |