SakuraIO

Fork of SakuraIO by SAKURA Internet

Committer:
chibiegg
Date:
Fri Jan 06 17:57:08 2017 +0900
Revision:
6:25e1fa75c64d
Parent:
3:c54a1eba22c4
Follow SakuraIOArduino v1.0.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chibiegg 3:c54a1eba22c4 1 /* SAKURA Internet IoT Communication Module Library for mbed
chibiegg 3:c54a1eba22c4 2 *
chibiegg 3:c54a1eba22c4 3 * The MIT License (MIT)
chibiegg 3:c54a1eba22c4 4 *
chibiegg 3:c54a1eba22c4 5 * Copyright (c) SAKURA Internet Inc.
chibiegg 3:c54a1eba22c4 6 *
chibiegg 3:c54a1eba22c4 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
chibiegg 3:c54a1eba22c4 8 * of this software and associated documentation files (the "Software"),
chibiegg 3:c54a1eba22c4 9 * to deal in the Software without restriction, including without limitation
chibiegg 3:c54a1eba22c4 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
chibiegg 3:c54a1eba22c4 11 * and/or sell copies of the Software, and to permit persons to whom the Software
chibiegg 3:c54a1eba22c4 12 * is furnished to do so, subject to the following conditions:
chibiegg 3:c54a1eba22c4 13 *
chibiegg 3:c54a1eba22c4 14 * The above copyright notice and this permission notice shall be included
chibiegg 3:c54a1eba22c4 15 * in all copies or substantial portions of the Software.
chibiegg 3:c54a1eba22c4 16 *
chibiegg 3:c54a1eba22c4 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
chibiegg 3:c54a1eba22c4 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
chibiegg 3:c54a1eba22c4 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
chibiegg 3:c54a1eba22c4 20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
chibiegg 3:c54a1eba22c4 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
chibiegg 3:c54a1eba22c4 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
chibiegg 3:c54a1eba22c4 23 */
chibiegg 3:c54a1eba22c4 24
spiralray 0:8d34375d954c 25 #include "mbed.h"
spiralray 0:8d34375d954c 26 #include "SakuraIO.h"
spiralray 0:8d34375d954c 27 #include "SakuraIO/debug.h"
spiralray 0:8d34375d954c 28
spiralray 0:8d34375d954c 29
spiralray 0:8d34375d954c 30 void SakuraIO_SPI::begin(){
spiralray 0:8d34375d954c 31 dbgln("CS=0");
spiralray 0:8d34375d954c 32 cs = 0;
spiralray 0:8d34375d954c 33 }
spiralray 0:8d34375d954c 34
spiralray 0:8d34375d954c 35 void SakuraIO_SPI::end(){
spiralray 0:8d34375d954c 36 dbgln("CS=1");
spiralray 0:8d34375d954c 37 cs = 1;
spiralray 0:8d34375d954c 38 wait_us(20);
spiralray 0:8d34375d954c 39 }
spiralray 0:8d34375d954c 40
spiralray 0:8d34375d954c 41 void SakuraIO_SPI::sendByte(uint8_t data){
spiralray 0:8d34375d954c 42 wait_us(20);
spiralray 0:8d34375d954c 43 dbg("Send=");
spiralray 0:8d34375d954c 44 dbgln(data);
spiralray 0:8d34375d954c 45 wait_us(10);
spiralray 0:8d34375d954c 46 spi.write(data);
spiralray 0:8d34375d954c 47 }
spiralray 0:8d34375d954c 48
spiralray 0:8d34375d954c 49
spiralray 0:8d34375d954c 50 uint8_t SakuraIO_SPI::receiveByte(bool stop){
spiralray 0:8d34375d954c 51 return receiveByte();
spiralray 0:8d34375d954c 52 }
spiralray 0:8d34375d954c 53
spiralray 0:8d34375d954c 54 uint8_t SakuraIO_SPI::receiveByte(){
spiralray 0:8d34375d954c 55 uint8_t ret;
spiralray 0:8d34375d954c 56 wait_us(10);
spiralray 0:8d34375d954c 57 ret = spi.write(0x00);
spiralray 0:8d34375d954c 58 dbg("Recv=");
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_SPI::SakuraIO_SPI(SPI &_spi, DigitalOut &_cs): spi(_spi), cs(_cs){
spiralray 0:8d34375d954c 64 cs = 1;
spiralray 0:8d34375d954c 65 }