SAKURA Internet IoT Communication Module Library for mbed

Dependents:   patlite_sakuraio sakuraio_lte_firmwareupdater shownet2017-iinebutton patlite_sakuraio_stack ... more

SAKURA Internet IoT Communication Module Library for mbed

Sakura Communication Module (with sakura.io) library for mbed.

Support

This library supports following products.

Reference

Please see the datasheet.

License

The MIT License (MIT)

Copyright (c) SAKURA Internet Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Committer:
spiralray
Date:
Sat Nov 19 03:20:17 2016 +0000
Revision:
0:8d34375d954c
Child:
1:20e1dfe45dab
First commit(This only works with SPI)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spiralray 0:8d34375d954c 1 #include "mbed.h"
spiralray 0:8d34375d954c 2 #include "SakuraIO.h"
spiralray 0:8d34375d954c 3 #include "SakuraIO/debug.h"
spiralray 0:8d34375d954c 4
spiralray 0:8d34375d954c 5 #define SAKURAIO_SLAVE_ADDR 0x4F
spiralray 0:8d34375d954c 6
spiralray 0:8d34375d954c 7 #define MODE_IDLE 0x00
spiralray 0:8d34375d954c 8 #define MODE_WRITE 0x01
spiralray 0:8d34375d954c 9 #define MODE_READ 0x02
spiralray 0:8d34375d954c 10
spiralray 0:8d34375d954c 11 void SakuraIO_I2C::begin(){
spiralray 0:8d34375d954c 12 mode = MODE_IDLE;
spiralray 0:8d34375d954c 13 }
spiralray 0:8d34375d954c 14
spiralray 0:8d34375d954c 15 void SakuraIO_I2C::end(){
spiralray 0:8d34375d954c 16 switch(mode){
spiralray 0:8d34375d954c 17 case MODE_WRITE:
spiralray 0:8d34375d954c 18 i2c.stop();
spiralray 0:8d34375d954c 19 break;
spiralray 0:8d34375d954c 20 case MODE_READ:
spiralray 0:8d34375d954c 21 i2c.read(true);
spiralray 0:8d34375d954c 22 break;
spiralray 0:8d34375d954c 23 }
spiralray 0:8d34375d954c 24
spiralray 0:8d34375d954c 25 mode = MODE_IDLE;
spiralray 0:8d34375d954c 26 }
spiralray 0:8d34375d954c 27
spiralray 0:8d34375d954c 28 void SakuraIO_I2C::sendByte(uint8_t data){
spiralray 0:8d34375d954c 29 if(mode != MODE_WRITE){
spiralray 0:8d34375d954c 30 dbgln("beginTr");
spiralray 0:8d34375d954c 31 i2c.start();
spiralray 0:8d34375d954c 32 i2c.write(SAKURAIO_SLAVE_ADDR<<1);
spiralray 0:8d34375d954c 33 mode = MODE_WRITE;
spiralray 0:8d34375d954c 34 }
spiralray 0:8d34375d954c 35 dbg("Write=");
spiralray 0:8d34375d954c 36 dbgln(data);
spiralray 0:8d34375d954c 37 i2c.write(data);
spiralray 0:8d34375d954c 38 }
spiralray 0:8d34375d954c 39
spiralray 0:8d34375d954c 40
spiralray 0:8d34375d954c 41 uint8_t SakuraIO_I2C::startReceive(uint8_t length){
spiralray 0:8d34375d954c 42 dbgln("endTransmission");
spiralray 0:8d34375d954c 43 i2c.stop();
spiralray 0:8d34375d954c 44 dbg("requestForm=");
spiralray 0:8d34375d954c 45 dbgln(length);
spiralray 0:8d34375d954c 46 i2c.start();
spiralray 0:8d34375d954c 47 i2c.write(SAKURAIO_SLAVE_ADDR<<1 | 1);
spiralray 0:8d34375d954c 48 mode = MODE_READ;
spiralray 0:8d34375d954c 49 }
spiralray 0:8d34375d954c 50
spiralray 0:8d34375d954c 51 uint8_t SakuraIO_I2C::receiveByte(){
spiralray 0:8d34375d954c 52 return i2c.read(true);
spiralray 0:8d34375d954c 53 }
spiralray 0:8d34375d954c 54
spiralray 0:8d34375d954c 55 uint8_t SakuraIO_I2C::receiveByte(bool stop){
spiralray 0:8d34375d954c 56 uint8_t ret = 0;
spiralray 0:8d34375d954c 57 ret = i2c.read(!stop);
spiralray 0:8d34375d954c 58 dbg("Read=");
spiralray 0:8d34375d954c 59 dbgln(ret);
spiralray 0:8d34375d954c 60 return ret;
spiralray 0:8d34375d954c 61 }
spiralray 0:8d34375d954c 62
spiralray 0:8d34375d954c 63 SakuraIO_I2C::SakuraIO_I2C(I2C &_i2c): i2c(_i2c){
spiralray 0:8d34375d954c 64 mode = MODE_IDLE;
spiralray 0:8d34375d954c 65 }